/* Layout: barra lateral de pacientes (navy, como el logotipo) + área clínica con pestañas */
:root {
  --navy: #213863;
  --navy-2: #2c4a7e;
  --cream: #f3ecdc;
  --bg: #f5f6f9;
  --surface: #ffffff;
  --surface-2: #eef1f6;
  --line: #d9dfe9;
  --fg: #1c2638;
  --muted: #5d6a80;
  --accent: #2c4a7e;
  --accent-soft: #e3e9f4;
  --ok: #2f8a5b;
  --ok-soft: #e1f2e8;
  --warn: #b7791f;
  --warn-soft: #fbf0db;
  --bad: #c0392b;
  --bad-soft: #fbe3e0;
  --f-display: 'Lexend', 'Segoe UI', system-ui, sans-serif;
  --f-body: 'Inter', 'Segoe UI', system-ui, sans-serif;
  --r: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1626; --surface: #152038; --surface-2: #1b2945; --line: #2a3a5c; --fg: #e8ecf3; --muted: #9aa7bf;
    --accent: #9db7ea; --accent-soft: #22345a; --ok: #5cc28c; --ok-soft: #173a2a; --warn: #e3ae55; --warn-soft: #3d2f15;
    --bad: #ef7d70; --bad-soft: #432020; --navy: #101b31; --navy-2: #1b2b4d; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0e1626; --surface: #152038; --surface-2: #1b2945; --line: #2a3a5c; --fg: #e8ecf3; --muted: #9aa7bf;
  --accent: #9db7ea; --accent-soft: #22345a; --ok: #5cc28c; --ok-soft: #173a2a; --warn: #e3ae55; --warn-soft: #3d2f15;
  --bad: #ef7d70; --bad-soft: #432020; --navy: #101b31; --navy-2: #1b2b4d; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--fg); font: 14px/1.5 var(--f-body); }
h1, h2, h3 { font-family: var(--f-display); font-weight: 500; text-wrap: balance; margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.num, td, output { font-variant-numeric: tabular-nums; }

.app { display: grid; grid-template-columns: 280px 1fr; min-height: 100vh; }
/* Sidebar */
.side { background: var(--navy); color: var(--cream); display: flex; flex-direction: column; gap: 16px; padding: 20px 14px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; gap: 12px; align-items: center; padding: 0 6px; }
.brand img { width: 46px; height: 46px; border-radius: 6px; }
.brand b { font-family: var(--f-display); font-weight: 500; font-size: 15px; display: block; letter-spacing: .01em; }
.brand small { font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; opacity: .75; }
.side input[type=search] { width: 100%; background: rgba(243,236,220,.1); border: 1px solid rgba(243,236,220,.2); border-radius: var(--r); padding: 8px 10px; color: var(--cream); }
.side input::placeholder { color: rgba(243,236,220,.55); }
.plist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.plist button { width: 100%; text-align: left; background: none; border: 0; border-radius: var(--r); padding: 9px 10px; cursor: pointer; display: grid; gap: 2px; color: var(--cream); }
.plist button:hover { background: rgba(243,236,220,.08); }
.plist button[aria-current="true"] { background: rgba(243,236,220,.16); }
.plist .pn { font-weight: 600; }
.plist .pm { font-size: 12px; opacity: .75; display: flex; gap: 8px; align-items: center; }
.wk { font-size: 11px; padding: 1px 7px; border-radius: 99px; background: rgba(243,236,220,.15); }
.side .grow { flex: 1; }
.side .sbtn { width: 100%; background: var(--cream); color: var(--navy); border: 0; border-radius: var(--r); padding: 9px; font-weight: 600; cursor: pointer; }
.side .slink { background: none; border: 1px solid rgba(243,236,220,.25); color: var(--cream); border-radius: var(--r); padding: 7px; cursor: pointer; font-size: 12.5px; }
.side .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.proto-note { font-size: 11px; opacity: .65; line-height: 1.4; padding: 0 4px; }

/* Main */
.main { min-width: 0; padding-block: 20px 40px; padding-left: max(24px, env(safe-area-inset-left, 0px)); padding-right: max(24px, env(safe-area-inset-right, 0px)); display: flex; flex-direction: column; gap: 18px; }
.topbar { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: flex-end; justify-content: space-between; }
.topbar h1 { font-size: 26px; }
.topbar .meta { color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; }
.role { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.seg { display: inline-flex; background: var(--surface-2); border-radius: var(--r); padding: 3px; gap: 2px; }
.seg button { border: 0; background: none; padding: 5px 10px; border-radius: 6px; cursor: pointer; color: var(--muted); font-size: 13px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--fg); box-shadow: 0 1px 2px rgba(0,0,0,.08); font-weight: 600; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 14px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; font-weight: 500; }
.tabs button[aria-selected="true"] { color: var(--fg); border-bottom-color: var(--accent); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 18px; min-width: 0; }
.card h2 { font-size: 17px; margin-bottom: 12px; }
.card h3 { font-size: 14px; margin-bottom: 8px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.eyebrow { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); font-weight: 600; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; display: grid; gap: 2px; }
.kpi .v { font-family: var(--f-display); font-size: 24px; font-weight: 500; font-variant-numeric: tabular-nums; }
.kpi .d { font-size: 12.5px; }

/* Estados */
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; background: transparent; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }
.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 2px 9px; border-radius: 99px; background: var(--surface-2); color: var(--muted); white-space: nowrap; font-weight: 500; }
.pill.ok { background: var(--ok-soft); color: var(--ok); } .pill.warn { background: var(--warn-soft); color: var(--warn); } .pill.bad { background: var(--bad-soft); color: var(--bad); } .pill.acc { background: var(--accent-soft); color: var(--accent); }
.up-good { color: var(--ok); } .up-bad { color: var(--bad); }

/* Formularios */
.fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
label.f { display: grid; gap: 4px; font-size: 12.5px; color: var(--muted); font-weight: 500; }
label.f input, label.f select, label.f textarea, .in { background: var(--surface); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; color: var(--fg); font-size: 14px; width: 100%; }
textarea { resize: vertical; }
.btn { border: 1px solid var(--line); background: var(--surface); border-radius: var(--r); padding: 7px 13px; cursor: pointer; font-weight: 500; display: inline-flex; gap: 6px; align-items: center; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--surface); }
:root .btn.primary { color: #fff; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.primary { color: #0e1626; } }
:root[data-theme="dark"] .btn.primary { color: #0e1626; }
.btn.danger { color: var(--bad); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* Hoja de seguimiento */
.tablewrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); }
table.sheet { border-collapse: collapse; width: 100%; min-width: 900px; }
.sheet th, .sheet td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.sheet thead th { background: var(--navy); color: var(--cream); font-weight: 500; font-size: 12.5px; position: sticky; top: 0; z-index: 1; }
.sheet thead th small { display: block; opacity: .75; font-weight: 400; }
.sheet thead input { background: rgba(243,236,220,.12); border: 1px solid rgba(243,236,220,.25); color: var(--cream); border-radius: 5px; padding: 2px 6px; font-size: 12px; margin-top: 4px; width: 100%; }
.sheet tr.sec td { background: var(--surface-2); font-family: var(--f-display); font-weight: 500; padding-top: 10px; }
.sheet tr.sec td small { font-family: var(--f-body); font-weight: 400; color: var(--muted); margin-left: 8px; }
.sheet .pl b { font-weight: 600; display: block; font-size: 13px; }
.sheet .pl small { color: var(--muted); font-size: 11.5px; }
.sheet .pl .u { color: var(--muted); font-weight: 400; }
.cellw { display: flex; align-items: center; gap: 7px; }
.cellw input, .cellw select { width: 92px; border: 1px solid var(--line); border-radius: 5px; padding: 4px 7px; background: var(--surface); text-align: right; font-variant-numeric: tabular-nums; }
.cellw output { width: 92px; text-align: right; padding: 4px 8px; background: var(--surface-2); border-radius: 5px; color: var(--fg); min-height: 28px; }
.cellw .cat { font-size: 11px; color: var(--muted); white-space: nowrap; }
.delta { font-size: 12.5px; white-space: nowrap; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12.5px; color: var(--muted); align-items: center; }
.legend span { display: inline-flex; gap: 6px; align-items: center; }

/* Timeline */
.tl { list-style: none; margin: 0; padding: 0; display: grid; gap: 0; }
.tl li { display: grid; grid-template-columns: 56px 1fr auto; gap: 12px; padding: 9px 0; border-bottom: 1px dashed var(--line); align-items: start; }
.tl li:last-child { border-bottom: 0; }
.tl .wkb { font-family: var(--f-display); font-weight: 500; font-size: 13px; background: var(--surface-2); border-radius: 6px; text-align: center; padding: 3px 0; }
.tl li.now .wkb { background: var(--accent); color: var(--surface); }
.tl .tt { font-weight: 600; }
.tl .td { font-size: 12.5px; color: var(--muted); }

/* Consultas */
.clist { display: grid; gap: 10px; }
.citem { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; display: grid; gap: 6px; background: var(--surface); }
.citem header { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.citem .txt { white-space: pre-wrap; }
.citem.prog { border-style: dashed; }
.a-Medicina { background: var(--accent-soft); color: var(--accent); }
.a-Nutrición { background: var(--ok-soft); color: var(--ok); }
.a-Psicología { background: var(--warn-soft); color: var(--warn); }

/* Gráficos */
.chartbox { position: relative; height: 280px; }

/* Importación */
.drop { border: 1.5px dashed var(--line); border-radius: 10px; padding: 18px; text-align: center; display: grid; gap: 8px; justify-items: center; background: var(--surface-2); }
.drop.over { border-color: var(--accent); }
table.mini { border-collapse: collapse; width: 100%; }
.mini th, .mini td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; font-size: 13px; vertical-align: middle; }
.mini th { color: var(--muted); font-weight: 500; font-size: 12px; }
.mini input.in, .mini select.in { padding: 3px 6px; font-size: 13px; }
.srcline { font-size: 11.5px; color: var(--muted); max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doclist { display: grid; gap: 6px; }
.doclist div { display: flex; gap: 10px; align-items: center; font-size: 13px; }

/* Informe */
.report { background: #fff; color: #1c2638; max-width: 820px; margin: 0 auto; border-radius: 6px; box-shadow: 0 2px 16px rgba(20,30,60,.12); overflow: hidden; }
.report .rh { background: #213863; color: #f3ecdc; display: flex; align-items: center; gap: 16px; padding: 18px 28px; }
.report .rh img { width: 54px; height: 54px; border-radius: 6px; }
.report .rh .t1 { font-family: var(--f-display); font-size: 17px; }
.report .rh .t2 { font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; opacity: .8; }
.report .rh .rt { margin-left: auto; text-align: right; }
.report .rb { padding: 22px 28px 28px; display: grid; gap: 18px; }
.report h2 { font-size: 20px; color: #213863; }
.report h3 { font-size: 13px; color: #213863; text-transform: uppercase; letter-spacing: .08em; border-bottom: 1px solid #d9dfe9; padding-bottom: 4px; margin-bottom: 6px; font-family: var(--f-body); font-weight: 700; }
.report .pdata { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px 14px; font-size: 12.5px; }
.report .pdata b { display: block; color: #5d6a80; font-weight: 500; font-size: 11px; }
.report .hl { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.report .hl div { border: 1px solid #d9dfe9; border-radius: 8px; padding: 8px 10px; }
.report .hl b { font-family: var(--f-display); font-size: 19px; font-weight: 500; display: block; }
.report .hl small { color: #5d6a80; font-size: 11px; }
.report table { border-collapse: collapse; width: 100%; font-size: 12px; }
.report th, .report td { border-bottom: 1px solid #e3e7ef; padding: 4px 6px; text-align: left; }
.report th { background: #eef1f6; font-weight: 600; color: #213863; }
.report td.r, .report th.r { text-align: right; }
.report tr.s td { background: #f5f6f9; font-weight: 700; color: #213863; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; }
.report .rdot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-left: 5px; }
.report .rdot.ok { background: #2f8a5b; } .report .rdot.warn { background: #b7791f; } .report .rdot.bad { background: #c0392b; }
.report .g { color: #2f8a5b; } .report .b { color: #c0392b; }
.report .ed { border: 1px dashed #c8d0de; border-radius: 6px; padding: 8px 10px; min-height: 60px; white-space: pre-wrap; font-size: 13px; }
.report .ed:focus { outline: 2px solid #2c4a7e; }
.report .rchart { height: 200px; position: relative; }
.report .sign { display: flex; justify-content: space-between; font-size: 12px; color: #5d6a80; padding-top: 24px; }
.report .foot { font-size: 10.5px; color: #8a95a8; border-top: 1px solid #e3e7ef; padding-top: 8px; }

dialog { border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--fg); padding: 22px; width: min(640px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(14,22,38,.5); }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--fg); color: var(--bg); padding: 9px 14px; border-radius: 8px; font-size: 13px; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.on { opacity: 1; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; }
  .report .pdata, .report .hl { grid-template-columns: 1fr 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; }
  .side, .topbar, .tabs, .noprint, .toast { display: none !important; }
  .app { display: block; }
  .main { padding: 0; }
  .report { box-shadow: none; max-width: none; border-radius: 0; }
  .report .ed { border: 0; padding: 0; min-height: 0; }
  .report .ed:empty { display: none; }
  .report section { break-inside: avoid; }
  .report .rh, .report th, .report tr.s td, .report .rdot { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .tablewrap { overflow: visible; border: 0; }
  table.sheet { min-width: 0; font-size: 11px; }
  .sheet thead th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* Visita 0, pagos y panel de administración */
.paydot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; background: var(--line); vertical-align: middle; }
.paydot.ok { background: var(--ok); } .paydot.warn { background: #e08a1e; } .paydot.bad { background: var(--bad); } .paydot.na { background: var(--line); }
.paydot.big { width: 14px; height: 14px; }
.plist .paydot { margin-left: auto; box-shadow: 0 0 0 2px rgba(243,236,220,.25); }
.pill .paydot { width: 8px; height: 8px; }
.pill.warn .paydot { background: #e08a1e; }
.wk-cand { background: rgba(157,183,234,.3); } .wk-no { background: rgba(239,125,112,.3); }
.wk-l { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--surface-2); color: var(--fg); font-weight: 600; }
.wk-l.wk-cand { background: var(--accent-soft); color: var(--accent); } .wk-l.wk-no { background: var(--bad-soft); color: var(--bad); } .wk-l.wk-fin { background: var(--ok-soft); color: var(--ok); }
.sadmin { width: 100%; text-align: left; background: rgba(243,236,220,.08); border: 1px solid rgba(243,236,220,.2); color: var(--cream); border-radius: var(--r); padding: 9px 10px; cursor: pointer; font-weight: 600; }
.sadmin[aria-current="true"] { background: var(--cream); color: var(--navy); }
.linkbtn { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 600; cursor: pointer; text-align: left; }
.linkbtn:hover { text-decoration: underline; }
.paychk { display: flex; gap: 6px; align-items: center; white-space: nowrap; font-size: 13px; }
table.admin td { vertical-align: top; padding-block: 9px; }

/* Hoja: el recuadro del valor lleva el color del estado; última visita en naranja tenue */
:root { --last-soft: #fdf3e6; --last-head: #c4761c; --last-line: #f0c48c; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --last-soft: #2e2416; --last-head: #a8641a; --last-line: #6b4a22; } }
:root[data-theme="dark"] { --last-soft: #2e2416; --last-head: #a8641a; --last-line: #6b4a22; }
.cellw .fv.ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 45%, transparent); color: var(--ok); font-weight: 600; }
.cellw .fv.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 45%, transparent); color: var(--warn); font-weight: 600; }
.cellw .fv.bad { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 45%, transparent); color: var(--bad); font-weight: 600; }
.cellw output.fv { border: 1px solid transparent; }
.sheet td.lastcol { background: var(--last-soft); }
.sheet td.lastcol + td.delta { border-left: 2px solid var(--last-line); }
.sheet td.lastcol { border-left: 2px solid var(--last-line); }
.sheet thead th.lastcol { background: var(--last-head); }
.sheet .lastlbl { display: none; }
.sheet th.lastcol .lastlbl { display: inline-block; margin-left: 6px; font-size: 10.5px; letter-spacing: .06em; text-transform: uppercase; background: rgba(255,255,255,.22); padding: 0 6px; border-radius: 99px; }
.sheet tr.sec td { background: var(--surface-2); }
.legend .sw { width: 22px; height: 14px; border-radius: 4px; display: inline-block; border: 1px solid var(--line); }
.legend .sw.ok { background: var(--ok-soft); border-color: var(--ok); } .legend .sw.warn { background: var(--warn-soft); border-color: var(--warn); }
.legend .sw.bad { background: var(--bad-soft); border-color: var(--bad); } .legend .sw.last { background: var(--last-soft); border-color: var(--last-line); }
@media print { .cellw .fv, .sheet td.lastcol, .sheet thead th.lastcol { -webkit-print-color-adjust: exact; print-color-adjust: exact; } }

/* Perfil y pago junto al nombre (solo administración) */
.perfil { display: grid; gap: 6px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; opacity: .9; padding: 0 2px; }
.perfil .seg { background: rgba(243,236,220,.1); width: 100%; display: grid; grid-template-columns: 1fr 1fr; }
.perfil .seg button { color: var(--cream); text-transform: none; letter-spacing: 0; font-size: 12.5px; }
.perfil .seg button[aria-pressed="true"] { background: var(--cream); color: var(--navy); }
.plist .pn { display: flex; align-items: center; gap: 8px; }
.plist .pn .paydot { margin-left: 0; }
h1.pname { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; }
.paypill { font-family: var(--f-body); font-size: 12.5px; font-weight: 600; padding: 3px 10px; }
.pill.warn .paydot { background: #e08a1e; }

/* Envíos de la visita 0 */
.sends { display: grid; gap: 6px; }
.send { display: flex; align-items: center; justify-content: space-between; gap: 10px; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; flex-wrap: wrap; }
.send.done { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 40%, transparent); }
.sendlbl { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; flex: 1; min-width: 200px; }
.sendlbl input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--ok); }
.sendlbl span { display: grid; }
.sendlbl small { color: var(--muted); font-size: 12px; }

/* Filtros por columna del panel de administración */
.admin tr.filtros th { padding-top: 0; padding-bottom: 8px; font-weight: 400; text-transform: none; letter-spacing: 0; }
.admin .colf { width: 100%; min-width: 90px; font: inherit; font-size: 12px; padding: 4px 6px; border: 1px solid var(--line, #ccc); border-radius: 6px; background: var(--surface, #fff); color: inherit; }

/* Nombre del paciente con recuadro del estado de pago (solo administración) */
.payname { display: inline-block; border-radius: 6px; padding: 1px 8px; border: 1px solid transparent; justify-self: start; }
.payname.na { padding: 1px 0; }
.plist .payname.ok { background: color-mix(in srgb, var(--ok) 30%, transparent); border-color: color-mix(in srgb, var(--ok) 70%, transparent); }
.plist .payname.warn { background: color-mix(in srgb, var(--warn) 30%, transparent); border-color: color-mix(in srgb, var(--warn) 70%, transparent); }
.plist .payname.bad { background: color-mix(in srgb, var(--bad) 30%, transparent); border-color: color-mix(in srgb, var(--bad) 70%, transparent); }
.admin .payname { font-weight: 600; }
.admin .payname.ok { background: var(--ok-soft); border-color: color-mix(in srgb, var(--ok) 45%, transparent); }
.admin .payname.warn { background: var(--warn-soft); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.admin .payname.bad { background: var(--bad-soft); border-color: color-mix(in srgb, var(--bad) 45%, transparent); }
[hidden] { display: none !important; }

/* Selector de usuario (simulado) */
.perfil select { width: 100%; margin-top: 4px; font: inherit; font-size: 12px; padding: 6px 8px; border-radius: 8px; border: 1px solid rgba(243,236,220,.25); background: rgba(243,236,220,.08); color: var(--cream); }
.perfil select option { color: #1a2238; }
.perfil select { text-transform: none; letter-spacing: 0; }
a.btn { text-decoration: none; color: inherit; }
#dlg-inv { border: 0; border-radius: 14px; padding: 22px; background: var(--surface); color: var(--fg); }

/* Evolución de un parámetro al hacer clic */
.trend { cursor: pointer; }
.sheet td.pl.trend:hover b, .pill.trend:hover { text-decoration: underline; text-underline-offset: 3px; }
.kpi.trend:hover { box-shadow: 0 0 0 2px var(--accent-soft); }
.sheet td.delta.trend:hover, output.trend:hover { outline: 2px solid var(--accent-soft); outline-offset: 1px; }
.ti { width: 13px; height: 13px; vertical-align: -1px; margin-right: 6px; color: var(--accent); opacity: .55; }
.sheet td.pl.trend:hover .ti { opacity: 1; }
#dlg-trend { border: 0; border-radius: 14px; padding: 22px; width: min(860px, calc(100vw - 32px)); background: var(--surface); color: var(--fg); }
#dlg-trend::backdrop, #dlg-inv::backdrop { background: rgba(10, 18, 34, .45); }
.fvp { display: inline-block; padding: 1px 8px; border-radius: 6px; font-weight: 600; border: 1px solid transparent; }
.fvp.ok { background: var(--ok-soft); color: var(--ok); } .fvp.warn { background: var(--warn-soft); color: var(--warn); } .fvp.bad { background: var(--bad-soft); color: var(--bad); }

/* Página de inicio */
#btn-home { margin-bottom: -4px; }
.home { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; margin-top: 18px; }
.hcard { display: flex; flex-direction: column; }
.hcal { grid-column: 1 / -1; }
.hhead { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 6px; }
.hhead h2 { margin: 0; }
.hstats { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--muted); }
.hstats b { color: var(--fg); font-size: 16px; }
.hlist { display: grid; gap: 4px; }
.hrow { display: flex; justify-content: space-between; align-items: center; gap: 10px; width: 100%; text-align: left; background: var(--surface-2, transparent); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; cursor: pointer; color: inherit; font: inherit; }
.hrow:hover { border-color: var(--accent); }
.hrow.static { cursor: default; }
.hrow.static:hover { border-color: var(--line); }
.qgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.qi { border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; display: grid; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cw { font-size: 11px; font-weight: 600; color: var(--muted); text-align: center; padding: 2px 0; }
.cd { min-height: 86px; border: 1px solid var(--line); border-radius: 8px; padding: 4px 5px; display: flex; flex-direction: column; gap: 2px; align-items: stretch; text-align: left; background: var(--surface); color: inherit; font: inherit; cursor: pointer; overflow: hidden; }
.cd.out { border: 0; background: transparent; cursor: default; }
.cd.past { background: var(--surface-2, var(--surface)); }
.cd.today { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.cd.sel { outline: 2px solid var(--accent); outline-offset: 1px; }
.cd .dn { font-size: 12px; font-weight: 600; color: var(--muted); }
.cd.today .dn { color: var(--accent); }
.ce { font-size: 11px; line-height: 1.3; padding: 1px 5px; border-radius: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.a-Admin { background: var(--accent-soft); color: var(--accent); }
.a-Medicina { background: var(--accent-soft); color: var(--accent); }
.ce.st-prevista { background: transparent !important; border: 1px dashed currentColor; opacity: .8; }
.ce.st-realizada { opacity: .65; }
.sw.st-realizada { background: var(--accent-soft); opacity: .65; }
.sw.st-programada { background: var(--accent); }
.sw.st-prevista { background: transparent; border: 1px dashed var(--muted); }
@media (max-width: 700px) { .cd { min-height: 54px; } .ce { font-size: 0; padding: 0; height: 6px; } .qgrid { grid-template-columns: 1fr; } }

.qi { gap: 1px; }
.qdl { display: flex; gap: 6px; margin-top: 4px; }
.qdl a { font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 5px; border: 1px solid var(--line); color: var(--accent); text-decoration: none; }
.qdl a:hover { border-color: var(--accent); background: var(--accent-soft); }
a.hrow { text-decoration: none; }
.qref { margin: 6px 0 0; padding-left: 18px; display: grid; gap: 3px; }
.cd.past { background: transparent; }
.cd.past .dn { opacity: .6; }

.ce { white-space: normal; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.ce .cwk { font-weight: 700; font-variant-numeric: tabular-nums; }
.pill.wkp { font-weight: 700; font-variant-numeric: tabular-nums; }
.cd { min-height: 96px; }

/* Envío al paciente desde la visita 0 */
#dlg-send { border: 0; border-radius: 14px; padding: 22px; width: min(760px, calc(100vw - 32px)); background: var(--surface); color: var(--fg); }
#dlg-send::backdrop { background: rgba(10, 18, 34, .45); }
#dlg-send h3 { margin: 0 0 6px; font-size: 14px; }
#dlg-send textarea { font-size: 13px; line-height: 1.45; }
.sdgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; margin-top: 10px; }
.sdi { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.sdi label { display: flex; gap: 8px; align-items: center; cursor: pointer; }
.sdi a { font-size: 12px; color: var(--accent); text-decoration: none; white-space: nowrap; }
.sdi a:hover { text-decoration: underline; }

/* Barra lateral: menú de secciones */
.snav { display: grid; gap: 6px; }
.snav button { position: relative; display: flex; gap: 11px; align-items: center; width: 100%; text-align: left; background: rgba(243,236,220,.06); border: 1px solid rgba(243,236,220,.14); color: var(--cream); border-radius: 10px; padding: 9px 11px; cursor: pointer; }
.snav button:hover { background: rgba(243,236,220,.12); }
.snav button[aria-current="true"] { background: var(--cream); color: var(--navy); border-color: var(--cream); }
.snav svg { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; opacity: .85; }
.snav b { display: block; font-weight: 600; font-size: 14px; }
.snav small { display: block; font-size: 11.5px; opacity: .7; }
.nbadge { margin-left: auto; font-style: normal; font-size: 11px; font-weight: 700; min-width: 20px; height: 20px; border-radius: 99px; display: grid; place-items: center; background: var(--warn); color: #fff; padding: 0 6px; }
.srecent { display: grid; gap: 2px; }
.srecent .slabel { font-size: 10.5px; letter-spacing: .12em; text-transform: uppercase; opacity: .6; padding: 4px 6px; }
.srecent button { display: flex; justify-content: space-between; align-items: center; gap: 8px; width: 100%; text-align: left; background: none; border: 0; border-radius: 8px; padding: 6px 8px; color: var(--cream); cursor: pointer; font-size: 13px; }
.srecent button:hover { background: rgba(243,236,220,.08); }
.srecent button[aria-current="true"] { background: rgba(243,236,220,.16); }
.srecent .pn { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.crumb { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font: inherit; letter-spacing: inherit; text-transform: inherit; }
.crumb:hover { text-decoration: underline; }
/* Página de pacientes */
.pgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 12px; }
.pcard { display: grid; gap: 4px; align-content: start; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 13px 14px; cursor: pointer; color: inherit; font: inherit; }
.pcard:hover { border-color: var(--accent); box-shadow: 0 2px 10px rgba(10,18,34,.06); }
.pc-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.pc-top .pn { font-weight: 600; font-size: 15px; }
.pc-st.st-prog { background: var(--accent-soft); color: var(--accent); }
.pc-st.st-pre { background: var(--warn-soft); color: var(--warn); }
.pc-st.st-fin { background: var(--ok-soft); color: var(--ok); }
.pc-bar { height: 5px; border-radius: 99px; background: var(--line); overflow: hidden; margin: 4px 0 2px; }
.pc-bar i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.pc-foot { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; border-top: 1px solid var(--line); padding-top: 6px; margin-top: 4px; }

/* Cuestionarios: revisión y volcado */
#dlg-q { border: 0; border-radius: 14px; padding: 22px; width: min(820px, calc(100vw - 32px)); max-height: calc(100vh - 40px); background: var(--surface); color: var(--fg); }
#dlg-q::backdrop { background: rgba(10, 18, 34, .45); }
.qs { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-top: 12px; }
.qs-head { display: flex; align-items: center; gap: 12px; }
.qs-head h3 { margin: 0; font-size: 16px; flex: 1; }
.qs-score { font-weight: 700; font-size: 18px; font-variant-numeric: tabular-nums; padding: 2px 10px; border-radius: 8px; background: var(--line); }
.qs-score small { font-weight: 500; font-size: 11px; opacity: .75; }
.qs-score.ok { background: var(--ok-soft); color: var(--ok); } .qs-score.warn { background: var(--warn-soft); color: var(--warn); } .qs-score.bad { background: var(--bad-soft); color: var(--bad); }
.qs-int { display: grid; gap: 3px; margin-top: 6px; justify-items: start; }
.qs-alert { color: var(--bad); font-weight: 600; }
.qtab { width: 100%; margin-top: 8px; }
.qtab td { vertical-align: middle; }
.qtab select { width: 100%; min-width: 210px; }
.qtab tr.qmiss select { border-color: var(--warn); background: var(--warn-soft); }
.qtab tr.qmulti select { border-color: var(--warn); }
.qint td { vertical-align: top; min-width: 170px; }
.qcell { background: none; border: 0; padding: 0; cursor: pointer; text-align: left; color: inherit; font: inherit; }
.qcell:hover { text-decoration: underline; text-underline-offset: 3px; }

.pc-kp { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.pc-imp { font-weight: 600; padding: 0 7px; border-radius: 6px; }
.pc-imp small { font-weight: 500; opacity: .75; }
.pc-imp.good { background: var(--ok-soft); color: var(--ok); }
.pc-imp.low { background: var(--warn-soft); color: var(--warn); }
.wk-l.wk-prog { background: var(--ok-soft); color: var(--ok); } .wk-l.wk-pre { background: var(--warn-soft); color: var(--warn); }
.wk-l.wk-fin { background: var(--surface-2); color: var(--muted); }

/* Colores por tipo de visita */
:root { --c-v0: #1d7a76; --c-v0-soft: #dcf1ef; --c-med: #2c4a7e; --c-med-soft: #e3eaf6; --c-nut: #2f7d4f; --c-nut-soft: #e1f2e7; --c-psi: #6d4aa8; --c-psi-soft: #ece5f7; --c-mus: #b8621b; --c-mus-soft: #fbeadb; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --c-v0: #5cc7c2; --c-v0-soft: #123433; --c-med: #9db7ea; --c-med-soft: #22345a; --c-nut: #6fcf97; --c-nut-soft: #173a2a; --c-psi: #b99cf0; --c-psi-soft: #2e2347; --c-mus: #eea067; --c-mus-soft: #3d2715; } }
:root[data-theme="dark"] { --c-v0: #5cc7c2; --c-v0-soft: #123433; --c-med: #9db7ea; --c-med-soft: #22345a; --c-nut: #6fcf97; --c-nut-soft: #173a2a; --c-psi: #b99cf0; --c-psi-soft: #2e2347; --c-mus: #eea067; --c-mus-soft: #3d2715; }
.a-Admin { background: var(--c-v0-soft); color: var(--c-v0); }
.a-Medicina { background: var(--c-med-soft); color: var(--c-med); }
.a-Nutrición { background: var(--c-nut-soft); color: var(--c-nut); }
.a-Psicología { background: var(--c-psi-soft); color: var(--c-psi); }
.a-Musculpt { background: var(--c-mus-soft); color: var(--c-mus); }
.arow { border-left-width: 4px; }
.ab-Admin { border-left-color: var(--c-v0); } .ab-Medicina { border-left-color: var(--c-med); } .ab-Nutrición { border-left-color: var(--c-nut); } .ab-Psicología { border-left-color: var(--c-psi); } .ab-Musculpt { border-left-color: var(--c-mus); }
.arow .pill { font-size: 11.5px; padding: 0 7px; }

/* Pauta de ejercicio */
.exf { display: grid; gap: 6px; }
.exfi { display: flex; gap: 10px; align-items: flex-start; padding: 7px 10px; border-radius: 8px; background: var(--surface-2); font-size: 13.5px; }
.exfi i { flex: none; width: 8px; height: 8px; border-radius: 99px; margin-top: 6px; background: var(--muted); }
.exfi.ok i { background: var(--ok); } .exfi.warn i { background: var(--warn); } .exfi.bad i { background: var(--bad); }
.exgen { margin: 12px 0 0; padding-left: 18px; display: grid; gap: 4px; }
.exgrp { margin-top: 14px; }
.exgrp h3 { font-size: 14px; margin: 0 0 6px; }
.exlist { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 8px; }
.exi { display: flex; gap: 10px; align-items: flex-start; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; }
.exi > div { flex: 1; min-width: 0; }
.exi a { color: inherit; text-decoration: none; }
.exi a:hover b { text-decoration: underline; }
.exvid { flex: none; width: 30px; height: 30px; border-radius: 99px; display: grid; place-items: center; background: var(--accent); color: var(--surface) !important; font-size: 12px; }
#printzone { display: none; }
@media print {
  body.pz .app, body.pz dialog, body.pz #toast { display: none !important; }
  body.pz #printzone { display: block; }
  body.pz { background: #fff; color: #111; }
}
.expdf { font: 11pt/1.45 var(--f-body); color: #111; max-width: 180mm; margin: 0 auto; }
.expdf header { display: flex; align-items: center; gap: 10px; border-bottom: 2px solid #2c4a7e; padding-bottom: 8px; }
.expdf header img { width: 34px; height: 34px; }
.expdf header b { display: block; color: #2c4a7e; }
.expdf header span { font-size: 9pt; color: #555; }
.expdf header .r { margin-left: auto; font-size: 9pt; color: #555; }
.expdf h1 { font-size: 18pt; margin: 14px 0 2px; color: #2c4a7e; }
.expdf .who { margin: 0 0 10px; color: #444; }
.expdf .box { background: #f2f5fa; border-radius: 8px; padding: 8px 12px; }
.expdf .box p { margin: 4px 0; }
.expdf .tip { font-size: 9.5pt; color: #2c4a7e; font-weight: 600; }
.expdf .exgrp { break-inside: avoid; }
.expdf .exlist { grid-template-columns: 1fr 1fr; }
.expdf .exi { border-color: #ccd5e3; break-inside: avoid; }
.expdf .exi a { color: #2c4a7e; text-decoration: underline; }
.expdf .exvid { background: #2c4a7e; color: #fff !important; text-decoration: none !important; }
.expdf .muted { color: #666; }
.expdf footer { margin-top: 16px; border-top: 1px solid #ccd5e3; padding-top: 6px; font-size: 8.5pt; color: #666; }

/* Calendario: entrar en la consulta */
.ce[data-ev] { cursor: pointer; }
.ce[data-ev]:hover { outline: 1.5px solid currentColor; }
.ce.lock { cursor: not-allowed; opacity: .55; }
.ce.lock:hover { outline: none; }
.hrow.lock { cursor: not-allowed; opacity: .6; }
.hrow.lock:hover { border-color: var(--line); }

/* Consulta del día */
.cgrid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(300px, 1fr); gap: 16px; align-items: start; }
@media (max-width: 1000px) { .cgrid { grid-template-columns: 1fr; } }
.csec { border-top: 1px solid var(--line); padding: 8px 0; }
.csec > summary { cursor: pointer; padding: 4px 0; list-style-position: inside; }
.csheet { margin-top: 6px; width: 100%; }
.csheet td.pl { min-width: 260px; }
/* Alertas */
.alist { display: grid; gap: 6px; margin-bottom: 10px; }
.ali { display: flex; gap: 10px; justify-content: space-between; align-items: flex-start; border: 1px solid var(--line); border-left: 4px solid var(--warn); border-radius: 8px; padding: 8px 10px; font-size: 13.5px; }
.ali.alta { border-left-color: var(--bad); background: var(--bad-soft); }
.ali.auto { border-left-color: var(--muted); background: var(--surface-2); }
.ali.auto.alta { border-left-color: var(--bad); background: var(--bad-soft); }
.anew textarea { width: 100%; }
.abadge { display: inline-block; vertical-align: middle; margin-left: 10px; font-size: 13px; font-weight: 700; padding: 2px 9px; border-radius: 99px; background: var(--warn-soft); color: var(--warn); font-family: var(--f-body); }
.abadge.hi { background: var(--bad-soft); color: var(--bad); }
.halerts { border-color: var(--warn); }
.hrow.ahi { border-left: 4px solid var(--bad); }

/* Pago del programa: la tabla cabe en la tarjeta */
.paytbl { width: 100%; table-layout: fixed; }
.paytbl th, .paytbl td { padding: 8px 6px; vertical-align: middle; overflow-wrap: anywhere; }
.paytbl th:nth-child(1) { width: 30%; }
.paytbl th:nth-child(2) { width: 18%; }
.paytbl th:nth-child(3) { width: 16%; }
.paytbl th:nth-child(4) { width: 10%; text-align: center; }
.paytbl td:nth-child(4) { text-align: center; }
.paytbl th:nth-child(5) { width: 26%; }
.paytbl td small { display: block; color: var(--muted); font-size: 12px; line-height: 1.3; }
.paytbl input[type=date] { width: 100%; min-width: 0; box-sizing: border-box; padding-left: 6px; padding-right: 4px; font-size: 13px; }
/* Pago: ajuste fino (fechas e importes sin partir) */
.paytbl { table-layout: auto; }
.paytbl th, .paytbl td { padding: 8px 5px; overflow-wrap: normal; width: auto !important; }
.paytbl td:nth-child(2), .paytbl td:nth-child(3), .paytbl th { white-space: nowrap; }
.paytbl td:nth-child(5) { width: 128px !important; }
.paytbl input[type=date] { width: 100%; min-width: 112px; font-size: 12.5px; }

/* Para el paciente */
.tbadge { display: inline-grid; place-items: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--warn); color: #fff; font-size: 11px; font-weight: 700; margin-left: 4px; }
.pplist { display: grid; gap: 8px; }
.ppi { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.ppi.alta { border-color: var(--warn); background: color-mix(in srgb, var(--warn) 7%, transparent); }
.ppi label { display: flex; gap: 10px; align-items: flex-start; cursor: pointer; flex: 1; }
.ppi label input { margin-top: 3px; }
.ppi label > span { display: grid; gap: 2px; }
.ppi .actions { flex-shrink: 0; }
.pplog { display: grid; gap: 4px; font-size: 13px; }
@media (max-width: 640px) { .ppi { flex-direction: column; } }

.pptags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.pptags .pill { font-size: 11.5px; }
.hrow.ppw { align-items: flex-start; }

/* Versión de equipo (servidor) */
#cloud-gate { position: fixed; inset: 0; z-index: 9000; display: grid; place-items: center; padding: 16px; background: var(--navy, #24365e); }
#cloud-gate[hidden] { display: none; }
.cg-box { width: min(400px, 100%); background: var(--card, #fff); color: var(--fg, #1a2238); border-radius: 16px; padding: 24px; box-shadow: 0 20px 60px rgba(0,0,0,.3); display: grid; gap: 12px; }
.cg-box h2 { margin: 4px 0 0; }
.cg-box form { display: grid; gap: 10px; }
.cg-box input { font: inherit; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--line, #d6dbe6); background: var(--bg, #fff); color: inherit; }
.cg-brand { display: flex; gap: 10px; align-items: center; }
.cg-brand img { width: 40px; height: 40px; border-radius: 8px; }
.cg-brand b { display: block; } .cg-brand small { color: var(--muted); font-size: 12px; }
.cg-msg { margin: 0; font-size: 14px; color: var(--muted); }
.cg-msg.bad { color: var(--bad); }
.cg-foot { margin: 0; font-size: 12.5px; color: var(--muted); }
body.cloud .side .perfil, body.cloud #btn-reset, body.cloud .only-local { display: none !important; }
#cloud-user { display: grid; gap: 6px; padding: 8px 2px 0; border-top: 1px solid rgba(243,236,220,.18); }
.cu-name b { display: block; font-size: 13px; } .cu-name small { font-size: 11.5px; opacity: .75; }
.cu-st { font-size: 11.5px; } .cu-st.ok { color: #8fd19e; } .cu-st.pend { color: #f3c969; } .cu-st.err { color: #f19a8f; }
