/* CRFI Clínica — estilos de la aplicación */
:root {
  --navy: #0B1F3A; --navy-2: #122F5A; --blue: #1A4A8A; --blue-soft: #EAF0FA;
  --gold: #F5C518; --gold-2: #D4A800; --gold-soft: #FFF7D6;
  --bg: #F3F5F9; --surface: #FFFFFF; --surface-2: #F8FAFC; --line: #E2E8F0; --line-2: #CBD5E1;
  --text: #1E293B; --muted: #64748B; --faint: #94A3B8;
  --ok: #047857; --ok-soft: #D1FAE5; --warn: #B45309; --warn-soft: #FEF3C7;
  --danger: #B91C1C; --danger-soft: #FEE2E2; --info: #1D4ED8; --info-soft: #DBEAFE;
  --violet: #6D28D9; --violet-soft: #EDE9FE;
  --radius: 14px; --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 4px 16px rgba(15,23,42,.06);
  --shadow-lg: 0 10px 40px rgba(15,23,42,.18);
  --fs: 1; --sidebar: 248px; --topbar: 64px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html { font-size: calc(16px * var(--fs)); -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.45; -webkit-font-smoothing: antialiased;
}
a { color: var(--blue); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; color: var(--navy); }
h1 { font-size: 1.6rem; font-weight: 800; letter-spacing: -.01em; }
h2 { font-size: 1.2rem; font-weight: 750; }
h3 { font-size: 1.02rem; font-weight: 700; }
p { margin: 0; }
svg.i { width: 1.15em; height: 1.15em; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; vertical-align: -0.2em; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: .86rem; }
.xs { font-size: .76rem; }
.bold { font-weight: 700; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: .6rem; }
.row.wrap { flex-wrap: wrap; }
.row.top { align-items: flex-start; }
.col { display: flex; flex-direction: column; gap: .6rem; }
.between { justify-content: space-between; }
.gap-lg { gap: 1rem; }
.mt { margin-top: 1rem; } .mt-s { margin-top: .5rem; } .mb { margin-bottom: 1rem; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pre { white-space: pre-wrap; }

/* ─── Shell ─── */
#app { min-height: 100vh; }
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
  background: var(--navy); color: #fff; position: sticky; top: 0; height: 100vh; overflow-y: auto;
  display: flex; flex-direction: column; padding: 1rem .75rem;
}
.brand { display: flex; align-items: center; gap: .7rem; padding: .25rem .5rem 1.1rem; text-decoration: none; color: #fff; }
.brand-badge { width: 42px; height: 42px; border-radius: 11px; background: var(--gold); color: var(--navy); display: grid; place-items: center; font-weight: 900; font-size: .82rem; letter-spacing: .04em; flex: none; }
.brand strong { display: block; font-size: .82rem; letter-spacing: .03em; text-transform: uppercase; }
.brand span { font-size: .72rem; opacity: .65; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: .8rem; padding: .72rem .8rem; border-radius: 10px;
  color: rgba(255,255,255,.78); text-decoration: none; font-weight: 600; font-size: .95rem;
}
.nav a svg { width: 1.3em; height: 1.3em; }
.nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav a.active { background: rgba(245,197,24,.16); color: var(--gold); }
.nav .badge { margin-left: auto; }
.nav-sep { height: 1px; background: rgba(255,255,255,.1); margin: .7rem .5rem; }
.sidebar .me { margin-top: auto; padding: .75rem .5rem 0; border-top: 1px solid rgba(255,255,255,.1); display: flex; align-items: center; gap: .6rem; }
.sidebar .me .name { font-size: .85rem; font-weight: 700; }
.sidebar .me .role { font-size: .72rem; opacity: .6; }
.sidebar .me a { color: rgba(255,255,255,.7); text-decoration: none; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar); background: rgba(243,245,249,.92);
  backdrop-filter: blur(8px); display: flex; align-items: center; gap: .8rem; padding: 0 1.5rem;
  border-bottom: 1px solid var(--line);
}
.topbar .search { flex: 1; max-width: 560px; position: relative; }
.topbar .search input { padding-left: 2.6rem; background: var(--surface); }
.topbar .search svg { position: absolute; left: .85rem; top: 50%; transform: translateY(-50%); color: var(--muted); }
.topbar .mobile-brand { display: none; }
.view { padding: 1.5rem; max-width: 1280px; width: 100%; margin: 0 auto; }
.view.wide { max-width: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }
.page-head .sub { color: var(--muted); margin-top: .25rem; }
.bottom-nav { display: none; }

/* ─── Botones ─── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem; min-height: 44px;
  padding: .55rem 1.05rem; border-radius: 10px; border: 1px solid var(--line-2); background: var(--surface);
  color: var(--navy); font-weight: 650; cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { background: var(--surface-2); border-color: var(--faint); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-2); }
.btn.gold { background: var(--gold); border-color: var(--gold); color: var(--navy); }
.btn.gold:hover { background: var(--gold-2); border-color: var(--gold-2); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--danger); border-color: #FCA5A5; }
.btn.danger.solid { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: rgba(15,23,42,.05); }
.btn.sm { min-height: 36px; padding: .35rem .75rem; font-size: .88rem; border-radius: 8px; }
.btn.lg { min-height: 56px; padding: .8rem 1.4rem; font-size: 1.08rem; border-radius: 12px; }
.btn.xl { min-height: 72px; padding: 1rem 1.6rem; font-size: 1.2rem; border-radius: 14px; }
.btn.block { width: 100%; }
.btn.icon { padding: .5rem; min-width: 44px; }
.btn svg { width: 1.2em; height: 1.2em; }
.btn-group { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ─── Tarjetas ─── */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 1.1rem 1.25rem; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); }
.card-body { padding: 1.1rem 1.25rem; }
.card + .card { margin-top: 1rem; }
.grid { display: grid; gap: 1rem; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.side { grid-template-columns: minmax(0, 1fr) 360px; align-items: start; }
.stat { padding: 1rem 1.2rem; }
.stat .k { font-size: .8rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .v { font-size: 1.9rem; font-weight: 800; color: var(--navy); margin-top: .15rem; }
.stat.hl { background: var(--gold-soft); border-color: #F6E3A0; }

/* ─── Formularios ─── */
label.f { display: flex; flex-direction: column; gap: .3rem; font-size: .86rem; font-weight: 650; color: #334155; min-width: 0; }
label.f .hint { font-weight: 400; color: var(--muted); font-size: .78rem; }
input[type=text], input[type=password], input[type=search], input[type=email], input[type=tel], input[type=number], input[type=date], input[type=time], input[type=datetime-local], select, textarea {
  width: 100%; min-height: 46px; padding: .6rem .8rem; border: 1px solid var(--line-2); border-radius: 10px;
  background: var(--surface); outline: none; font-size: 1rem; transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 92px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(26,74,138,.15); }
input.big, .big input { min-height: 56px; font-size: 1.15rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .9rem 1rem; }
.form-grid .span2 { grid-column: span 2; }
.form-grid .full { grid-column: 1 / -1; }
.check { display: inline-flex; align-items: center; gap: .55rem; cursor: pointer; font-weight: 550; min-height: 40px; }
.check input { width: 22px; height: 22px; accent-color: var(--navy); }
fieldset { border: 0; padding: 0; margin: 0; }
.section-title { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 750; margin: 1.1rem 0 .55rem; }

/* Chips seleccionables */
.chips { display: flex; flex-wrap: wrap; gap: .45rem; }
.chip {
  display: inline-flex; align-items: center; gap: .35rem; padding: .5rem .85rem; min-height: 40px; border-radius: 999px;
  border: 1px solid var(--line-2); background: var(--surface); cursor: pointer; font-weight: 600; font-size: .92rem; user-select: none;
}
.chip:hover { border-color: var(--blue); }
.chip.on { background: var(--navy); border-color: var(--navy); color: #fff; }
.chip.on.gold { background: var(--gold); border-color: var(--gold); color: var(--navy); }
.chip .x { opacity: .7; }

/* Escala de dolor EVA */
.eva { display: grid; grid-template-columns: repeat(11, 1fr); gap: 4px; }
.eva button { min-height: 46px; border-radius: 8px; border: 2px solid transparent; font-weight: 800; cursor: pointer; color: #fff; font-size: 1rem; }
.eva button.on { border-color: var(--navy); box-shadow: 0 0 0 2px #fff inset; transform: scale(1.06); }
.eva-legend { display: flex; justify-content: space-between; font-size: .75rem; color: var(--muted); margin-top: .3rem; }

/* Signos vitales */
.vitals { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: .7rem; }
.vitals label.f input { text-align: center; font-weight: 700; font-size: 1.1rem; }
.vital-pair { display: flex; align-items: center; gap: .3rem; }
.vital-pair span { color: var(--muted); font-weight: 700; }

/* ─── Badges / estado ─── */
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .18rem .6rem; border-radius: 999px; font-size: .76rem; font-weight: 700; white-space: nowrap; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.badge.dot::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.st-programada { background: #F1F5F9; color: #475569; border-color: #E2E8F0; }
.st-confirmada { background: var(--info-soft); color: var(--info); border-color: #BFDBFE; }
.st-en_espera { background: var(--gold-soft); color: #8A6A00; border-color: #F6E3A0; }
.st-en_atencion { background: var(--violet-soft); color: var(--violet); border-color: #DDD6FE; }
.st-completada { background: var(--ok-soft); color: var(--ok); border-color: #A7F3D0; }
.st-cancelada { background: #F1F5F9; color: #94A3B8; border-color: #E2E8F0; text-decoration: line-through; }
.st-no_asistio { background: var(--danger-soft); color: var(--danger); border-color: #FECACA; }
.st-activa { background: var(--info-soft); color: var(--info); border-color: #BFDBFE; }
.st-suspendida { background: var(--warn-soft); color: var(--warn); border-color: #FDE68A; }
.st-borrador { background: var(--warn-soft); color: var(--warn); border-color: #FDE68A; }
.st-firmada { background: var(--ok-soft); color: var(--ok); border-color: #A7F3D0; }
.badge.red { background: var(--danger-soft); color: var(--danger); border-color: #FECACA; }
.badge.gold { background: var(--gold-soft); color: #8A6A00; border-color: #F6E3A0; }
.badge.navy { background: var(--navy); color: #fff; border-color: var(--navy); }

.allergy {
  display: flex; align-items: center; gap: .6rem; background: var(--danger-soft); color: var(--danger);
  border: 1px solid #FECACA; border-radius: 10px; padding: .55rem .85rem; font-weight: 700;
}
.allergy.none { background: var(--ok-soft); color: var(--ok); border-color: #A7F3D0; font-weight: 600; }
.notice { display: flex; gap: .7rem; align-items: flex-start; padding: .8rem 1rem; border-radius: 12px; background: var(--info-soft); color: #1E3A8A; border: 1px solid #BFDBFE; }
.notice.warn { background: var(--warn-soft); color: #78350F; border-color: #FDE68A; }
.notice.danger { background: var(--danger-soft); color: #7F1D1D; border-color: #FECACA; }
.notice.ok { background: var(--ok-soft); color: #064E3B; border-color: #A7F3D0; }

/* ─── Listas ─── */
.list { display: flex; flex-direction: column; }
.list-item { display: flex; align-items: center; gap: .9rem; padding: .85rem 1.25rem; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; }
.list-item:last-child { border-bottom: 0; }
a.list-item:hover, .list-item.click:hover { background: var(--surface-2); cursor: pointer; }
.avatar { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: .9rem; color: #fff; background: var(--blue); flex: none; letter-spacing: .02em; }
.avatar.lg { width: 64px; height: 64px; font-size: 1.3rem; }
.avatar.F { background: #BE185D; } .avatar.M { background: #1D4ED8; }
.time-col { width: 64px; flex: none; font-weight: 800; color: var(--navy); font-size: 1.05rem; }
.empty { padding: 2rem 1rem; text-align: center; color: var(--muted); }
.empty svg { width: 2.4rem; height: 2.4rem; color: var(--faint); display: block; margin: 0 auto .5rem; }

table.t { width: 100%; border-collapse: collapse; font-size: .93rem; }
table.t th { text-align: left; font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: .7rem 1rem; border-bottom: 1px solid var(--line); background: var(--surface-2); font-weight: 750; }
table.t td { padding: .75rem 1rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.t tr:last-child td { border-bottom: 0; }
table.t tr.click:hover td { background: var(--surface-2); cursor: pointer; }
.table-wrap { overflow-x: auto; }

/* Progreso */
.progress { height: 10px; background: #E2E8F0; border-radius: 99px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--blue), #3B82F6); border-radius: 99px; }
.progress.done > i { background: var(--ok); }

/* Pestañas */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); overflow-x: auto; margin-bottom: 1.1rem; scrollbar-width: none; }
.tabs a { padding: .75rem 1rem; text-decoration: none; color: var(--muted); font-weight: 650; border-bottom: 3px solid transparent; white-space: nowrap; display: flex; align-items: center; gap: .4rem; }
.tabs a.active { color: var(--navy); border-color: var(--gold); }
.tabs a .count { font-size: .72rem; background: var(--line); color: var(--muted); padding: 0 .45rem; border-radius: 99px; }

/* Paciente encabezado */
.pt-head { display: flex; gap: 1rem; align-items: flex-start; flex-wrap: wrap; }
.pt-head .info { flex: 1; min-width: 240px; }
.pt-head h1 { font-size: 1.55rem; }
.pt-meta { display: flex; flex-wrap: wrap; gap: .3rem 1rem; color: var(--muted); margin-top: .35rem; font-size: .93rem; }
.pt-meta b { color: var(--text); font-weight: 650; }

/* Línea de tiempo */
.timeline { position: relative; padding-left: 1.6rem; }
.timeline::before { content: ''; position: absolute; left: .55rem; top: .3rem; bottom: .3rem; width: 2px; background: var(--line); }
.tl-item { position: relative; padding: .2rem 0 1.15rem; }
.tl-item .dot { position: absolute; left: -1.6rem; top: .35rem; width: 1.15rem; height: 1.15rem; border-radius: 50%; display: grid; place-items: center; background: var(--surface); border: 2px solid var(--blue); }
.tl-item.consulta .dot { border-color: var(--navy); background: var(--navy); }
.tl-item.receta .dot { border-color: var(--violet); }
.tl-item.orden .dot { border-color: var(--gold-2); background: var(--gold); }
.tl-item.sesion .dot { border-color: var(--ok); }
.tl-item.archivo .dot { border-color: var(--faint); }
.tl-item .when { font-size: .78rem; color: var(--muted); font-weight: 600; }
.tl-item .ttl { font-weight: 700; color: var(--navy); }
.tl-card { display: block; text-decoration: none; color: inherit; padding: .6rem .8rem; border-radius: 10px; margin-left: -.8rem; }
a.tl-card:hover { background: var(--surface); box-shadow: var(--shadow); }

/* ─── Modal ─── */
.modal-back { position: fixed; inset: 0; background: rgba(11,31,58,.5); z-index: 100; display: flex; align-items: flex-start; justify-content: center; padding: 4vh 1rem; overflow-y: auto; animation: fade .15s; }
.modal { background: var(--surface); border-radius: 18px; width: 100%; max-width: 640px; box-shadow: var(--shadow-lg); animation: pop .18s; }
.modal.lg { max-width: 900px; }
.modal.sm { max-width: 440px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1.1rem 1.4rem; border-bottom: 1px solid var(--line); }
.modal-body { padding: 1.25rem 1.4rem; }
.modal-foot { display: flex; justify-content: flex-end; gap: .6rem; padding: 1rem 1.4rem; border-top: 1px solid var(--line); flex-wrap: wrap; background: var(--surface-2); border-radius: 0 0 18px 18px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } }

/* Toast */
.toasts { position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: .5rem; align-items: center; pointer-events: none; }
.toast { background: var(--navy); color: #fff; padding: .8rem 1.2rem; border-radius: 12px; box-shadow: var(--shadow-lg); font-weight: 600; display: flex; gap: .6rem; align-items: center; animation: pop .2s; max-width: 90vw; }
.toast.err { background: var(--danger); }
.toast.ok svg { color: #6EE7B7; }

/* Autocompletar */
.ac { position: relative; }
.ac-list { position: absolute; left: 0; right: 0; top: calc(100% + 4px); background: var(--surface); border: 1px solid var(--line-2); border-radius: 12px; box-shadow: var(--shadow-lg); z-index: 60; max-height: 320px; overflow-y: auto; }
.ac-item { padding: .65rem .9rem; cursor: pointer; border-bottom: 1px solid var(--line); }
.ac-item:last-child { border-bottom: 0; }
.ac-item:hover, .ac-item.sel { background: var(--blue-soft); }
.ac-item .code { font-weight: 800; color: var(--navy); margin-right: .4rem; }

/* Dictado */
.dict { position: relative; }
.dict textarea { padding-right: 3.4rem; }
.mic { position: absolute; right: .45rem; top: .45rem; width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--line-2); background: var(--surface); color: var(--blue); display: grid; place-items: center; cursor: pointer; }
.mic:hover { background: var(--blue-soft); }
.mic.on { background: var(--danger); color: #fff; border-color: var(--danger); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(185,28,28,.45); } 50% { box-shadow: 0 0 0 9px rgba(185,28,28,0); } }

/* Consulta: secciones */
.sec { padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--line); }
.sec:last-child { border-bottom: 0; }
.sec > .sec-h { display: flex; align-items: center; gap: .6rem; margin-bottom: .75rem; }
.sec > .sec-h .n { width: 28px; height: 28px; border-radius: 50%; background: var(--navy); color: var(--gold); font-weight: 800; display: grid; place-items: center; font-size: .85rem; flex: none; }
.savebar { position: sticky; bottom: 0; z-index: 20; background: rgba(255,255,255,.96); backdrop-filter: blur(6px); border-top: 1px solid var(--line); padding: .8rem 1.25rem; display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; border-radius: 0 0 var(--radius) var(--radius); }
.save-state { font-size: .85rem; color: var(--muted); display: flex; gap: .35rem; align-items: center; }
details.more > summary { cursor: pointer; font-weight: 700; color: var(--blue); list-style: none; display: flex; align-items: center; gap: .4rem; min-height: 40px; }
details.more > summary::-webkit-details-marker { display: none; }

/* Inicio: tarjetas de cita */
.appt { display: flex; align-items: center; gap: 1rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); }
.appt:last-child { border-bottom: 0; }
.appt.now { background: linear-gradient(90deg, var(--gold-soft), transparent 70%); }
.appt.done { opacity: .62; }
.appt .who { flex: 1; min-width: 0; }
.appt .who .nm { font-weight: 750; font-size: 1.06rem; color: var(--navy); text-decoration: none; }
.appt .actions { display: flex; gap: .4rem; flex-wrap: wrap; justify-content: flex-end; }
.hello { background: linear-gradient(120deg, var(--navy) 0%, var(--navy-2) 70%, #1B3C6E 100%); color: #fff; border-radius: 18px; padding: 1.4rem 1.6rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; position: relative; overflow: hidden; }
.hello::after { content: ''; position: absolute; right: -60px; top: -60px; width: 220px; height: 220px; border-radius: 50%; background: rgba(245,197,24,.12); }
.hello h1 { color: #fff; font-size: 1.65rem; }
.hello .sub { color: rgba(255,255,255,.75); margin-top: .25rem; }
.hello .big-num { text-align: center; position: relative; z-index: 1; }
.hello .big-num b { display: block; font-size: 2.6rem; color: var(--gold); line-height: 1; }
.hello .big-num span { font-size: .8rem; opacity: .8; text-transform: uppercase; letter-spacing: .05em; }

.alert-card { border-left: 5px solid var(--warn); }

/* ─── Agenda ─── */
.ag-toolbar { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.ag-date { font-weight: 800; font-size: 1.15rem; color: var(--navy); min-width: 220px; }
.ag-date::first-letter, .cap::first-letter { text-transform: uppercase; }
.cap { display: inline-block; }
div.cap { display: block; }
.ag-wrap { overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); max-height: calc(100vh - 210px); }
.ag-grid { display: grid; position: relative; min-width: 100%; }
.ag-head { position: sticky; top: 0; z-index: 5; background: var(--surface); border-bottom: 1px solid var(--line); padding: .6rem .5rem; font-weight: 750; font-size: .88rem; color: var(--navy); display: flex; align-items: center; gap: .45rem; min-height: 52px; }
.ag-head .sw { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.ag-corner { position: sticky; left: 0; top: 0; z-index: 6; background: var(--surface); border-bottom: 1px solid var(--line); }
.ag-hours { position: sticky; left: 0; z-index: 4; background: var(--surface); border-right: 1px solid var(--line); }
.ag-hour { height: var(--slot); font-size: .76rem; color: var(--muted); text-align: right; padding: 0 .5rem; transform: translateY(-.55em); font-weight: 600; }
.ag-col { position: relative; border-right: 1px solid var(--line); }
.ag-slot { height: var(--slot); border-bottom: 1px dashed #EEF2F7; cursor: pointer; }
.ag-slot.h { border-bottom-color: var(--line); }
.ag-slot:hover { background: var(--blue-soft); }
.ag-ev { position: absolute; left: 3px; right: 3px; border-radius: 8px; padding: .25rem .45rem; font-size: .8rem; line-height: 1.25; overflow: hidden; cursor: pointer; border-left: 4px solid var(--c, var(--blue)); background: color-mix(in srgb, var(--c, #1A4A8A) 12%, white); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.ag-ev:hover { z-index: 3; box-shadow: var(--shadow-lg); }
.ag-ev b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-ev .t { font-size: .72rem; color: var(--muted); }
.ag-ev.s-completada { opacity: .55; }
.ag-ev.s-en_espera { background: var(--gold-soft); border-left-color: var(--gold-2); }
.ag-ev.s-en_atencion { background: var(--violet-soft); border-left-color: var(--violet); }
.ag-ev.s-no_asistio { background: var(--danger-soft); border-left-color: var(--danger); opacity: .7; }
.ag-now { position: absolute; left: 0; right: 0; height: 2px; background: var(--danger); z-index: 2; pointer-events: none; }
.ag-now::before { content: ''; position: absolute; left: -4px; top: -4px; width: 10px; height: 10px; border-radius: 50%; background: var(--danger); }
.slots { display: flex; flex-wrap: wrap; gap: .4rem; }
.slots .chip { min-width: 72px; justify-content: center; }

/* ─── Gráficas simples ─── */
.bars { display: flex; flex-direction: column; gap: .55rem; }
.bar-row { display: grid; grid-template-columns: minmax(120px, 34%) 1fr auto; gap: .7rem; align-items: center; font-size: .9rem; }
.bar-row .track { height: 12px; background: var(--surface-2); border-radius: 99px; overflow: hidden; border: 1px solid var(--line); }
.bar-row .track i { display: block; height: 100%; background: var(--blue); border-radius: 99px; }
.bar-row .val { font-weight: 750; min-width: 3ch; text-align: right; }
.chart-svg text { font-size: 11px; fill: var(--muted); }

/* ─── Login ─── */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; }
.login-art { background: var(--navy); color: #fff; padding: 3rem; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.login-art::before { content: ''; position: absolute; inset: 0; background-image: repeating-linear-gradient(-55deg, transparent, transparent 30px, rgba(245,197,24,.05) 30px, rgba(245,197,24,.05) 31px); }
.login-art > * { position: relative; }
.login-art h1 { color: #fff; font-size: 2.6rem; line-height: 1.05; font-weight: 900; max-width: 14ch; }
.login-art h1 em { color: var(--gold); font-style: normal; }
.login-art .feat { display: grid; gap: .8rem; margin-top: 2rem; max-width: 420px; }
.login-art .feat div { display: flex; gap: .7rem; align-items: center; color: rgba(255,255,255,.85); }
.login-art .feat svg { color: var(--gold); width: 1.4em; height: 1.4em; }
.login-form { display: flex; align-items: center; justify-content: center; padding: 2rem 1.25rem; background: var(--surface); }
.login-form form { width: 100%; max-width: 400px; display: flex; flex-direction: column; gap: 1rem; }
.demo-users { display: grid; gap: .4rem; }
.demo-users button { text-align: left; display: flex; align-items: center; gap: .7rem; padding: .55rem .8rem; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); cursor: pointer; }
.demo-users button:hover { border-color: var(--blue); }

/* Mosaico grande (modo sencillo) */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.tile { display: flex; flex-direction: column; gap: .6rem; padding: 1.4rem; border-radius: 18px; background: var(--surface); border: 2px solid var(--line); text-decoration: none; color: var(--navy); font-weight: 800; font-size: 1.2rem; box-shadow: var(--shadow); cursor: pointer; }
.tile svg { width: 2.4rem; height: 2.4rem; color: var(--blue); }
.tile:hover { border-color: var(--gold); }
.tile.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.tile.primary svg { color: var(--gold); }
.tile small { font-weight: 500; font-size: .85rem; color: var(--muted); }
.tile.primary small { color: rgba(255,255,255,.7); }

body.simple .hide-simple { display: none !important; }
body:not(.simple) .only-simple { display: none !important; }

/* ─── Impresión ─── */
.print-toolbar { display: flex; gap: .6rem; margin-bottom: 1rem; flex-wrap: wrap; }
.sheet { background: #fff; color: #111; width: 100%; max-width: 816px; margin: 0 auto; padding: 40px 48px; box-shadow: var(--shadow-lg); border-radius: 4px; font-size: 14px; line-height: 1.45; }
.sheet h1, .sheet h2, .sheet h3 { color: #0B1F3A; }
.sheet .sh-head { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 3px solid #0B1F3A; padding-bottom: 12px; margin-bottom: 14px; }
.sheet .sh-clinic { font-weight: 900; font-size: 17px; color: #0B1F3A; text-transform: uppercase; letter-spacing: .02em; }
.sheet .sh-doc { font-size: 13px; }
.sheet .sh-doc b { font-size: 16px; color: #0B1F3A; }
.sheet .sh-box { border: 1px solid #CBD5E1; border-radius: 6px; padding: 8px 12px; margin: 10px 0; }
.sheet .sh-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px 14px; font-size: 13px; }
.sheet .sh-grid span { color: #555; }
.sheet .rx-item { padding: 8px 0; border-bottom: 1px dashed #CBD5E1; }
.sheet .rx-item b { font-size: 15px; }
.sheet .sign { margin-top: 56px; display: flex; justify-content: flex-end; }
.sheet .sign div { width: 280px; border-top: 1px solid #111; text-align: center; padding-top: 6px; font-size: 13px; }
.sheet .foot { margin-top: 18px; font-size: 11px; color: #555; border-top: 1px solid #E2E8F0; padding-top: 8px; display: flex; justify-content: space-between; gap: 1rem; }
.sheet table { width: 100%; border-collapse: collapse; font-size: 13px; }
.sheet table th, .sheet table td { border-bottom: 1px solid #E2E8F0; padding: 5px 6px; text-align: left; vertical-align: top; }
.sheet .lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: #555; font-weight: 700; margin-top: 10px; }
.sheet.half { max-width: 816px; }

@media print {
  @page { size: letter; margin: 12mm; }
  body { background: #fff; }
  .sidebar, .topbar, .bottom-nav, .print-toolbar, .toasts { display: none !important; }
  .shell { display: block; }
  .view { padding: 0; max-width: none; }
  .sheet { box-shadow: none; padding: 0; max-width: none; border-radius: 0; }
}

/* ─── Responsivo ─── */
@media (max-width: 1100px) {
  .grid.side { grid-template-columns: 1fr; }
  .grid.c4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  :root { --topbar: 58px; }
  .shell { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar { padding: 0 1rem; }
  .topbar .mobile-brand { display: flex; }
  .view { padding: 1rem 1rem 6.5rem; }
  .bottom-nav {
    display: grid; grid-template-columns: repeat(var(--n, 5), 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    background: var(--surface); border-top: 1px solid var(--line); padding: .3rem .3rem calc(.3rem + env(safe-area-inset-bottom));
    box-shadow: 0 -4px 16px rgba(15,23,42,.06);
  }
  .bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: .4rem .2rem; text-decoration: none; color: var(--muted); font-size: .7rem; font-weight: 700; border-radius: 10px; }
  .bottom-nav a svg { width: 1.5rem; height: 1.5rem; }
  .bottom-nav a.active { color: var(--navy); background: var(--gold-soft); }
  .grid.c2, .grid.c3 { grid-template-columns: 1fr; }
  .login { grid-template-columns: 1fr; }
  .login-art { display: none; }
  .appt { flex-wrap: wrap; }
  .appt .actions { width: 100%; justify-content: flex-start; padding-left: calc(64px + 1rem); }
  .form-grid .span2 { grid-column: 1 / -1; }
  .modal-back { padding: 0; align-items: flex-end; }
  .modal { border-radius: 18px 18px 0 0; max-height: 94vh; overflow-y: auto; }
  .modal-foot { border-radius: 0; position: sticky; bottom: 0; }
  .sheet { padding: 20px; font-size: 13px; }
  .sheet .sh-grid { grid-template-columns: repeat(2, 1fr); }
  h1 { font-size: 1.35rem; }
  .hello h1 { font-size: 1.35rem; }
  .eva button { min-height: 40px; font-size: .9rem; }
}
@media (max-width: 560px) {
  .grid.c4 { grid-template-columns: 1fr 1fr; }
  .topbar .search { max-width: none; }
  .page-head .btn-group { width: 100%; }
  .page-head .btn-group .btn { flex: 1; }
  .appt .actions { padding-left: 0; }
  .time-col { width: 52px; font-size: .95rem; }
  .card-head, .card-body, .list-item, .sec, .appt { padding-left: 1rem; padding-right: 1rem; }
  .hide-xs { display: none !important; }
}

/* Formato impreso encima de la app */
.print-overlay { position: fixed; inset: 0; z-index: 150; overflow-y: auto; background: var(--bg); padding: 1.25rem; }
body.printing { overflow: hidden; }
@media print {
  body.printing #app, body.printing .modal-back { display: none !important; }
  .print-overlay { position: static; padding: 0; overflow: visible; background: #fff; }
}
@media (max-width: 900px) { .savebar { padding: .6rem 1rem; bottom: calc(64px + env(safe-area-inset-bottom)); } }
a.chip { text-decoration: none; color: inherit; }
a.chip.on { color: #fff; }
.vitals > label.f:first-child { grid-column: span 2; }
.vital-pair input { padding-left: .3rem; padding-right: .3rem; }
input[type=number]::-webkit-outer-spin-button, input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
input[type=number] { -moz-appearance: textfield; }

/* ═════════ Pulido visual v3 ═════════ */
:root { --font-head: "Montserrat", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; --radius: 16px; }
h1, h2, h3, .brand strong, .stat .v, .time-col, .hello .big-num b, .ag-date, .tile, .sec > .sec-h .n { font-family: var(--font-head); }
h1 { font-weight: 800; letter-spacing: -.015em; }
h2, h3 { font-weight: 700; letter-spacing: -.005em; }
.btn { font-weight: 650; letter-spacing: .005em; }

/* Marca */
.brand-mark { border-radius: 11px; flex: none; box-shadow: 0 2px 8px rgba(0,0,0,.18); }
.brand strong { font-weight: 800; }

/* Barra lateral */
.sidebar { background: linear-gradient(180deg, #0B1F3A 0%, #0E2747 100%); box-shadow: 1px 0 0 rgba(255,255,255,.04); }
.nav a { position: relative; transition: background .15s, color .15s; }
.nav a.active { background: rgba(245,197,24,.13); }
.nav a.active::before { content: ''; position: absolute; left: -.75rem; top: 22%; bottom: 22%; width: 4px; border-radius: 0 4px 4px 0; background: var(--gold); }
.sidebar .me { background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.08); border-radius: 14px; padding: .65rem .7rem; margin-top: auto; }
.sidebar .me a:hover { color: var(--gold); }

/* Barra superior */
.topbar { gap: 1rem; }
.topbar .search input { border-radius: 12px; box-shadow: 0 1px 2px rgba(15,23,42,.04); }
.top-date { margin-left: auto; color: var(--muted); font-size: .88rem; font-weight: 600; white-space: nowrap; }

/* Tarjetas y estadísticas */
.card { box-shadow: 0 1px 2px rgba(15,23,42,.04), 0 6px 20px rgba(15,23,42,.05); }
.card-head { background: linear-gradient(180deg, #fff, #FBFCFE); border-radius: var(--radius) var(--radius) 0 0; }
.stat { position: relative; overflow: hidden; }
.stat::after { content: ''; position: absolute; right: -18px; top: -18px; width: 70px; height: 70px; border-radius: 50%; background: var(--blue-soft); opacity: .7; }
.stat.hl::after { background: rgba(245,197,24,.25); }
.stat .k, .stat .v { position: relative; z-index: 1; }
.hello { box-shadow: 0 10px 30px rgba(11,31,58,.18); }
.hello::before { content: ''; position: absolute; inset: 0; background-image: repeating-linear-gradient(-55deg, transparent, transparent 28px, rgba(245,197,24,.05) 28px, rgba(245,197,24,.05) 29px); pointer-events: none; }
.tile { transition: transform .12s, border-color .15s, box-shadow .15s; }
.tile:hover { transform: translateY(-2px); box-shadow: 0 10px 28px rgba(15,23,42,.10); }
.list-item, .appt { transition: background .12s; }
.avatar { box-shadow: 0 0 0 2px #fff, 0 1px 3px rgba(0,0,0,.15); }
.tabs a { border-radius: 8px 8px 0 0; }
.tabs a:hover { color: var(--navy); background: rgba(15,23,42,.03); }
.page-head h1 { font-size: 1.75rem; }

/* Login */
.login-form { flex-direction: column; justify-content: space-between; gap: 2rem; }
.login-form form { margin: auto 0; }
.login-art h1 { font-family: var(--font-head); font-weight: 900; }

/* Pie: Diseñado por NEST */
.credit { display: flex; align-items: center; justify-content: center; gap: .6rem; padding: 1.4rem 1rem 1.8rem; color: var(--faint); font-size: .78rem; font-weight: 600; letter-spacing: .03em; }
.credit a { display: inline-flex; align-items: center; padding: .3rem .4rem; border-radius: 8px; opacity: .8; transition: opacity .15s, background .15s; }
.credit a:hover { opacity: 1; background: rgba(15,23,42,.04); }
.credit img { height: 21px; width: auto; display: block; }
.credit.light { color: rgba(255,255,255,.55); }
.main > .credit { margin-top: auto; border-top: 1px solid var(--line); }

@media (max-width: 1100px) { .hide-tablet { display: none !important; } }
@media (max-width: 900px) {
  .main > .credit { padding-bottom: calc(5.5rem + env(safe-area-inset-bottom)); }
  .view { padding-bottom: 1rem; }
  .nav a.active::before { display: none; }
}
@media print { .credit { display: none !important; } }
