/* ==========================================================================
   Estructura: menú lateral, barra superior y contenido (responsive)
   ========================================================================== */
.app { min-height: 100vh; }

/* ---------- Menú lateral ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; z-index: 40;
  width: var(--sidebar-w);
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, #0b3f3c 0%, #0d2f2e 100%);
  color: #d5efec;
  transition: transform 0.25s ease;
}
.sidebar .brand { display: flex; align-items: center; gap: 12px; padding: 18px 20px 14px; color: #fff; text-decoration: none; }
.sidebar .brand:hover { text-decoration: none; }
.brand-mark { width: 38px; height: 38px; border-radius: 10px; background: #fff; color: var(--brand-700); display: grid; place-items: center; flex: none; }
.brand-name { font-size: 1.15rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.1; }
.brand-sub { display: block; font-size: 0.72rem; font-weight: 500; color: #8fd0c9; margin-top: 2px; max-width: 170px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.nav { flex: 1; overflow-y: auto; padding: 8px 12px 16px; }
.nav-label { padding: 14px 10px 6px; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: #6fb8b0; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  min-height: 42px; padding: 0 12px; margin: 2px 0;
  border-radius: 10px; color: #cdeae6; font-weight: 500; font-size: 0.94rem;
  text-decoration: none; position: relative;
}
.nav-item:hover { background: rgba(255, 255, 255, 0.08); color: #fff; text-decoration: none; }
.nav-item.active { background: rgba(255, 255, 255, 0.15); color: #fff; font-weight: 600; }
.nav-item.active::before { content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 4px; border-radius: 0 4px 4px 0; background: var(--brand-200); }
.nav-item svg { flex: none; opacity: 0.9; }
.nav-item .count { margin-left: auto; min-width: 22px; padding: 1px 7px; border-radius: 999px; background: rgba(255, 255, 255, 0.16); font-size: 0.74rem; text-align: center; }
.nav-item .count.alert { background: var(--amber); color: #fff; }
.nav-sub { margin-left: 10px; padding-left: 8px; border-left: 1px solid rgba(255, 255, 255, 0.14); }

.nav-patient { margin: 10px 4px 6px; padding: 12px; border-radius: 12px; background: rgba(255, 255, 255, 0.08); }
.nav-patient .exp { font-family: var(--mono); font-size: 0.75rem; color: #8fd0c9; letter-spacing: 0.04em; }
.nav-patient .name { color: #fff; font-weight: 600; line-height: 1.25; word-break: break-word; }

.sidebar-foot { padding: 12px 16px 16px; border-top: 1px solid rgba(255, 255, 255, 0.1); display: flex; align-items: center; gap: 10px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--brand-500); color: #fff; display: grid; place-items: center; font-weight: 700; flex: none; font-size: 0.9rem; }
.sidebar-foot .who { min-width: 0; flex: 1; line-height: 1.25; }
.sidebar-foot .who b { display: block; color: #fff; font-size: 0.88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot .who span { font-size: 0.75rem; color: #8fd0c9; }
.sidebar-foot .btn { color: #cdeae6; }
.sidebar-foot .btn:hover { background: rgba(255, 255, 255, 0.12); }

.scrim { position: fixed; inset: 0; z-index: 35; background: rgba(15, 23, 42, 0.5); opacity: 0; pointer-events: none; transition: opacity 0.2s; }

/* ---------- Zona principal ---------- */
.main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30;
  height: var(--topbar-h); padding: 0 24px;
  display: flex; align-items: center; gap: 14px;
  background: rgba(255, 255, 255, 0.92); backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
}
.topbar .menu-btn { display: none; }
.top-search { position: relative; flex: 1; max-width: 440px; }
.top-search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.top-search input { width: 100%; height: 40px; padding: 0 12px 0 40px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2); }
.top-search input:focus { outline: none; background: #fff; border-color: var(--brand-600); box-shadow: var(--ring); }
.topbar .spacer { flex: 1; }
.topbar .who-chip { display: flex; align-items: center; gap: 10px; font-size: 0.88rem; color: var(--text-2); }
.topbar .who-chip b { font-weight: 600; }

.content { flex: 1; padding: 24px; width: 100%; max-width: 1280px; margin: 0 auto; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 16px; margin-bottom: 20px; }
.page-head h1 { flex: 1; min-width: 200px; }
.page-head .actions { display: flex; flex-wrap: wrap; gap: 10px; }
.page-sub { color: var(--muted); margin-top: 2px; font-size: 0.92rem; }

/* ---------- Pantalla de acceso ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: radial-gradient(1200px 600px at 10% -10%, #d7f5f0 0%, transparent 60%), radial-gradient(900px 500px at 100% 110%, #cfe8f7 0%, transparent 55%), var(--bg); }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow); padding: 32px 28px; }
.auth-brand { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 24px; text-align: center; }
.auth-brand .brand-mark { width: 56px; height: 56px; border-radius: 16px; background: var(--brand-700); color: #fff; }
.auth-brand h1 { font-size: 1.5rem; }
.auth-brand p { margin: 0; color: var(--muted); }
.auth-card form { display: flex; flex-direction: column; gap: 16px; }
.auth-links { margin-top: 18px; text-align: center; font-size: 0.9rem; }
.auth-foot { margin-top: 20px; text-align: center; font-size: 0.78rem; color: var(--muted); }
.demo-box { margin-top: 20px; padding: 14px; border: 1px dashed var(--brand-500); border-radius: var(--radius); background: var(--brand-50); display: flex; flex-direction: column; gap: 8px; }
.demo-box p { margin: 0 0 4px; }
.demo-box .btn { justify-content: space-between; text-align: left; white-space: normal; }
.pw-wrap { position: relative; }
.pw-wrap .input { padding-right: 46px; }
.pw-wrap button { position: absolute; right: 4px; top: 4px; }

/* ---------- Responsive ---------- */
@media (max-width: 1023px) {
  .sidebar { transform: translateX(-100%); box-shadow: none; }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  .scrim.open { opacity: 1; pointer-events: auto; }
  .main { margin-left: 0; }
  .topbar { padding: 0 14px; }
  .topbar .menu-btn { display: inline-flex; }
  .topbar .who-chip b { display: none; }
  .content { padding: 16px 14px 90px; }
  .nav-sub-desktop { display: none; }
}
@media (min-width: 1024px) {
  .patient-tabs { display: none !important; }
}
@media (max-width: 560px) {
  .top-search { max-width: none; }
  .topbar .who-chip { display: none; }
  h1 { font-size: 1.35rem; }
}

/* ---------- Impresión (recibos) ---------- */
@media print {
  body { background: #fff; }
  .sidebar, .topbar, .scrim, .toasts, .no-print { display: none !important; }
  .main { margin: 0; }
  .content { padding: 0; max-width: none; }
  .modal-backdrop { position: static; background: none; padding: 0; display: block; }
  .modal { box-shadow: none; border: 0; max-width: none; max-height: none; }
  .modal-head, .modal-foot { display: none !important; }
  body.printing > *:not(.print-root) { display: none !important; }
}
