/* Paleta de la marca (igual que la página web: sitio-web/styles.css).
   Azul marino = estructura, azul = acciones; verde/ámbar/rojo solo para estados (listo / pendiente / alerta). */
:root {
  --navy: #0b2a4a;
  --navy-2: #163b63;
  --bg: #f4f7fa;
  --panel: #ffffff;
  --ink: #142233;
  --ink-2: #4a5b6e;
  --ink-3: #7b8a9a;
  --line: #e1e8ef;
  --line-2: #cdd8e3;
  --hover: #f0f5fa;
  --subtle: #f6f9fb;
  --accent: #1b7fd1;
  --accent-2: #0f5fa3;
  --accent-ink: #ffffff;
  --accent-soft: #eaf4fc;
  --danger: #c0352b;
  --danger-soft: #fdecea;
  --warn: #9a6200;
  --warn-soft: #fff4d6;
  --ok: #1a7f45;
  --ok-soft: #e5f5ec;
  --wa: #1fa855;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(11, 42, 74, .05), 0 6px 18px -12px rgba(11, 42, 74, .16);
  --serif: "Fraunces", Georgia, "Times New Roman", serif;
  --sans: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* Odontograma */
  --od-caries: #d92d20;
  --od-rest: #1f5fd1;
  --od-sell: #12a150;
  --od-frac: #e07a00;
  --od-def: #8b3fd9;
  font-family: var(--sans);
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -.01em; }
h1 { font-family: var(--serif); font-weight: 500; font-size: 26px; letter-spacing: -.015em; }
h2 { font-size: 17px; }
h3 { font-size: 14px; }
a { color: var(--accent); }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--navy); color: #c9d7e6; display: flex; flex-direction: column; padding: 18px 12px; gap: 4px;
  position: sticky; top: 0; height: 100vh; overflow-y: auto; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.2) transparent; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; color: #fff; font-weight: 600; font-size: 15px; line-height: 1.2; }
.brand svg { flex: none; }
.brand small { display: block; font-weight: 500; font-size: 11px; color: #8fa6bf; letter-spacing: .04em; text-transform: uppercase; margin-top: 2px; }
.side a.nav svg { flex: none; opacity: .85; }
.side a.nav.on svg { opacity: 1; }
.side a.nav { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; font-weight: 500; color: inherit; text-decoration: none; }
.side a.nav:hover { background: rgba(255,255,255,.07); }
.side a.nav.on { background: var(--accent); color: #fff; }
.side-cuerpo { flex: 1; display: flex; flex-direction: column; }
.side .navs { display: flex; flex-direction: column; gap: 4px; }
.side .spacer { flex: 1; }
/* Menú en árbol: grupos que se despliegan */
.side .g-h { width: 100%; border: none; background: transparent; color: inherit; font-weight: 500; text-align: left; justify-content: flex-start; }
.side .g-h:hover { background: rgba(255,255,255,.07); }
.side .g-h.dentro { color: #fff; font-weight: 600; }
.side .g-h > span { flex: 1; }
.side .flecha { width: 7px; height: 7px; border-right: 1.8px solid currentColor; border-bottom: 1.8px solid currentColor; transform: rotate(-45deg); opacity: .7; transition: transform .15s; margin-right: 4px; }
.side .grupo.abierto .flecha { transform: rotate(45deg); }
.side .g-hijos { display: none; flex-direction: column; gap: 2px; margin: 2px 0 6px 19px; padding-left: 12px; border-left: 1px solid rgba(255,255,255,.16); }
.side .grupo.abierto .g-hijos { display: flex; }
.side a.sub { display: block; padding: 7px 10px; border-radius: 7px; color: #b5c6d8; text-decoration: none; font-size: 13.5px; }
.side a.sub:hover { background: rgba(255,255,255,.07); color: #fff; }
.side a.sub.on { background: var(--accent); color: #fff; font-weight: 600; }
.menu-btn { display: none; }
button.ok { color: var(--ok); border-color: #b9e3c9; }
button.ok:hover { background: var(--ok-soft); }

/* ---------- Secciones plegables (árbol) ---------- */
.pl-lista { display: flex; flex-direction: column; gap: 8px; }
.pl-h { width: 100%; display: flex; align-items: center; gap: 14px; padding: 13px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); text-align: left; font-weight: 400; white-space: normal; color: var(--ink); text-decoration: none; cursor: pointer; }
.pl-h:hover { border-color: var(--accent); background: var(--panel); }
.pl.abierta > .pl-h { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.pl-ic { width: 38px; height: 38px; border-radius: 10px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; }
.pl-t { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.pl-t b { font-size: 15px; font-weight: 600; }
.pl-t small { color: var(--ink-3); font-size: 13px; line-height: 1.35; }
.pl-n { min-width: 28px; height: 26px; padding: 0 9px; border-radius: 99px; background: var(--subtle); border: 1px solid var(--line); font-weight: 700; display: grid; place-items: center; font-size: 13px; font-variant-numeric: tabular-nums; flex: none; }
.pl-flecha { width: 8px; height: 8px; border-right: 2px solid var(--ink-3); border-bottom: 2px solid var(--ink-3); transform: rotate(45deg); transition: transform .15s; margin: 0 4px 4px; flex: none; }
.pl.abierta > .pl-h .pl-flecha { transform: rotate(-135deg); margin: 4px 4px 0; }
.pl-link .pl-flecha { transform: rotate(-45deg); margin: 0 6px 0 2px; }
.pl-warn .pl-ic { background: var(--warn-soft); color: var(--warn); } .pl-warn .pl-t small { color: var(--warn); } .pl-warn .pl-n { background: var(--warn-soft); border-color: #f1dc9c; color: var(--warn); }
.pl-danger .pl-ic { background: var(--danger-soft); color: var(--danger); } .pl-danger .pl-t small { color: var(--danger); } .pl-danger .pl-n { background: var(--danger-soft); border-color: #f3c7c2; color: var(--danger); }
.pl-ok .pl-ic { background: var(--ok-soft); color: var(--ok); }
/* El detalle cuelga de su fila, con una línea que lo une (como un organigrama) */
.pl-c { margin: 8px 0 6px 19px; padding-left: 16px; border-left: 2px solid var(--line-2); }
.pl-c > .card + .card, .pl-c > .card + details, .pl-c > details + details, .pl-c > details + .card { margin-top: 12px; }
.pl-c > .card:first-child { margin-top: 0; }

/* Carpeta del paciente: estado en una línea */
.estado-pac { display: flex; flex-wrap: wrap; gap: 8px; margin: -4px 0 14px; }
.ep { display: inline-flex; align-items: center; gap: 8px; padding: 7px 12px; border-radius: 10px; background: var(--subtle); border: 1px solid var(--line); color: var(--ink-2); font-size: 13px; }
.ep > span { display: flex; flex-direction: column; line-height: 1.3; }
.ep small { font-size: 12px; opacity: .9; }
.ep svg { width: 16px; height: 16px; flex: none; }
.ep.accent { background: var(--accent-soft); border-color: #cfe3f6; color: var(--accent-2); }
.ep.ok { background: var(--ok-soft); border-color: #b9e3c9; color: var(--ok); }
.ep.warn { background: var(--warn-soft); border-color: #f1dc9c; color: var(--warn); }
.ep.danger { background: var(--danger-soft); border-color: #f3c7c2; color: var(--danger); }
.pachead .meta a { text-decoration: none; font-weight: 600; }

/* Bloques que se abren dentro de una sección */
details.card > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px; padding: 13px 20px; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::after { content: ''; width: 7px; height: 7px; border-right: 2px solid var(--ink-3); border-bottom: 2px solid var(--ink-3); transform: rotate(45deg); margin: 0 2px 3px auto; flex: none; transition: transform .15s; }
details.card[open] > summary::after { transform: rotate(-135deg); margin-top: 6px; margin-bottom: 0; }
details.card[open] > summary { border-bottom: 1px solid var(--line); }
details.plegado > summary { gap: 12px; }
details.plegado > summary .muted { flex: 1; }
.pres-d > summary { align-items: center; }
.pd-t { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.pd-t small { color: var(--ink-3); font-size: 12.5px; }
.pd-r { flex: none; text-align: right; }
.cuenta-res { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.cuenta-res dl.cuenta { flex: 1 1 320px; }
.cuenta-acc { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 20px 14px; }
@container principal (min-width: 721px) { .cuenta-acc { padding: 14px 20px; flex-direction: column; align-items: stretch; } }

/* Plan de pago */
.plan-b { margin: 0 20px 16px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--subtle); }
.plan-b.vacio { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: space-between; }
.plan-b.atrasado { border-color: #f3c7c2; }
.plan-h { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.plan-h .grow { flex: 1; }
.plan-b table, .cob-pres table { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; margin-top: 6px; }
.plan-b .progreso { margin: 8px 0 4px; background: var(--line); }
table.cuotas td, table.cuotas th { padding: 7px 12px; }
table.cuotas tr.cu-pagada td { color: var(--ink-3); }
table.cuotas tr.cu-vencida td.g { color: var(--danger); font-weight: 600; }
table.cuotas tr.cu-hoy td.g { color: var(--warn); font-weight: 600; }
.plan-info { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.plan-info > div { background: var(--subtle); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 2px; }
.plan-info span { font-size: 12px; color: var(--ink-3); }
.plan-info b { font-size: 16px; font-variant-numeric: tabular-nums; }
.f-col { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); font-weight: 500; }
.seg-ancho { display: flex; flex-wrap: wrap; margin-top: 6px; }
.f-col .seg-ancho { margin-top: 2px; }
.seg-ancho button { flex: 1 1 auto; justify-content: center; padding: 9px 12px; }
.cuotas-edit td { vertical-align: middle; }
.cu-cita { font-weight: 600; color: var(--accent-2); }
.plan-suma { margin-top: 10px; font-size: 13px; color: var(--ink-2); }

/* Cerrar cita: asistente de 3 pasos */
.cierre-paso { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.cierre-paso + .cierre-paso { margin-top: 12px; }
.cierre-paso .paso-h { margin-bottom: 10px; }
.cierre-paso .num-paso { width: 24px; height: 24px; font-size: 13px; }
.checks { display: flex; flex-direction: column; gap: 6px; }
.check-fila { display: flex; gap: 10px; align-items: flex-start; padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; }
.check-fila:hover { background: var(--hover); }
.check-fila:has(input:checked) { border-color: var(--ok); background: var(--ok-soft); }
.check-fila input { width: 18px; height: 18px; margin-top: 1px; flex: none; accent-color: var(--ok); }
.check-fila > span { display: flex; flex-direction: column; gap: 1px; }
.check-fila small { color: var(--ink-3); font-size: 12px; }

/* Hoy */
.hoy-buscar { position: relative; margin: -6px 0 14px; max-width: 560px; }
.hoy-buscar .search { max-width: none; }
.hoy-buscar input { padding-top: 11px; padding-bottom: 11px; border-radius: 10px; }
.bp-res { position: absolute; left: 0; right: 0; top: calc(100% + 4px); z-index: 10; background: var(--panel); border: 1px solid var(--line-2); border-radius: 10px; box-shadow: 0 10px 30px -10px rgba(11,42,74,.3); overflow: hidden; }
.bp-res a { display: block; padding: 10px 12px; color: var(--ink); text-decoration: none; border-bottom: 1px solid var(--line); }
.bp-res a:last-child { border-bottom: none; }
.bp-res a:hover { background: var(--hover); }
.fila-hoy { cursor: pointer; }
.fila-tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.fila-acc { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.cobro-fila { align-items: center !important; }
.cobro-fila a { text-decoration: none; color: var(--ink); }
.cobro-der { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.cobro-acc { display: flex; gap: 6px; }

/* Cobranza */
.filtros-cob { margin: 0 0 12px; }
.cob-monto { display: flex; flex-direction: column; align-items: flex-end; flex: none; font-variant-numeric: tabular-nums; }
.cob-monto b { font-size: 15px; }
.cob-monto small { font-size: 12px; color: var(--ink-3); }
.pl-danger .cob-monto b { color: var(--danger); } .pl-warn .cob-monto b { color: var(--warn); }
.cob-datos { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.cob-datos > div { display: flex; flex-direction: column; gap: 2px; }
.cob-datos span { font-size: 12px; color: var(--ink-3); }
.cob-datos small { font-size: 12px; color: var(--ink-3); }
.cob-acc { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0 4px; }
.cob-pres { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.avance { display: flex; align-items: center; gap: 8px; }
.avance .progreso { flex: 1; margin: 0; min-width: 60px; }
.avance small { white-space: nowrap; color: var(--ink-2); }
.gstat.cobro-cita { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.gstat.cobro-cita .grow { flex: 1; min-width: 200px; }
/* Cuestionario de salud */
a.ep { text-decoration: none; }
a.ep:hover { filter: brightness(.97); }
.ep > svg { margin-top: 0 !important; }
.salud-falta { border-color: #f3c7c2; background: linear-gradient(180deg, var(--danger-soft), var(--panel) 70%); }
.salud-falta h2 { color: var(--danger); }
.salud-acc { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.salud-h { display: flex; align-items: flex-start; gap: 10px; }
.salud-h .grow { flex: 1; }
.alertas-salud { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.alertas-salud .tag { font-size: 13px; padding: 4px 10px; border-radius: 8px; }
ol.salud-lista { list-style: none; margin: 0; padding: 4px 0; counter-reset: s; }
ol.salud-lista li { counter-increment: s; display: flex; gap: 12px; align-items: flex-start; padding: 9px 20px; border-bottom: 1px solid var(--line); }
ol.salud-lista li:last-child { border-bottom: none; }
ol.salud-lista li::before { content: counter(s) '.'; color: var(--ink-3); min-width: 20px; font-variant-numeric: tabular-nums; }
ol.salud-lista li.si { background: #fffaf9; }
ol.salud-lista .grow { flex: 1; min-width: 0; }
.salud-det { font-weight: 600; color: var(--ink); margin-top: 3px; }
ol.salud-form { list-style: none; margin: 0; padding: 0; counter-reset: s; }
ol.salud-form > li { counter-increment: s; display: grid; grid-template-columns: 1fr auto; gap: 6px 14px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
ol.salud-form > li.falta { background: var(--danger-soft); margin: 0 -10px; padding: 10px; border-radius: 8px; }
.sf-q::before { content: counter(s) '. '; color: var(--accent); font-weight: 700; }
.sf-sn button { min-width: 54px; justify-content: center; }
.sf-det { grid-column: 1 / -1; }
.h-salud .h-dot { background: var(--danger); }
@media (max-width: 640px) { ol.salud-form > li { grid-template-columns: 1fr; } ol.salud-lista li { padding: 9px 14px; } }
/* ---------- Contabilidad ---------- */
.tipo-grupo + .tipo-grupo { margin-top: 10px; }
.tipo-grupo .sub-h { border: none; padding: 4px 0 8px; }
.tipos { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
.tipo-b { flex-direction: column; align-items: flex-start; gap: 3px; padding: 12px 14px; text-align: left; white-space: normal; border-radius: 10px; font-weight: 400; height: 100%; }
.tipo-b:hover { border-color: var(--accent); background: var(--accent-soft); }
.tipo-b b { font-size: 14px; }
.tipo-b small { color: var(--ink-3); font-size: 12px; line-height: 1.35; }
ul.links { list-style: none; margin: 0; padding: 6px; }
a.fila-link { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--ink); text-decoration: none; }
a.fila-link:hover { background: var(--hover); }
a.fila-link .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
a.fila-link small { color: var(--ink-3); font-size: 12.5px; }
a.fila-link .pl-ic { width: 32px; height: 32px; }
a.fila-link .pl-flecha { transform: rotate(-45deg); }
.ag-bar.periodo { gap: 6px; }
.ag-bar.periodo .chip { padding: 5px 12px; }
.informe { overflow-x: auto; }
table.er { font-variant-numeric: tabular-nums; }
table.er th, table.er td { padding: 7px 16px; border-bottom: none; }
table.er thead th { border-bottom: 1px solid var(--line); white-space: nowrap; }
table.er .num { white-space: nowrap; }
tr.er-s td { padding-top: 16px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--navy); border-bottom: 1px solid var(--line-2); }
tr.er-g td { padding-top: 10px; font-weight: 600; color: var(--ink-2); font-size: 13px; }
tr.er-c td:first-child { padding-left: 30px; color: var(--ink-2); }
tr.er-c[data-cta] { cursor: pointer; }
tr.er-c[data-cta]:hover td { background: var(--hover); }
tr.er-st td { font-weight: 600; border-top: 1px dashed var(--line-2); font-size: 13px; }
tr.er-st td:first-child { padding-left: 30px; }
tr.er-t td { font-weight: 700; border-top: 1px solid var(--line-2); }
tr.er-u td { font-weight: 700; background: var(--subtle); border-top: 1px solid var(--line-2); border-bottom: 1px solid var(--line-2); }
tr.er-final td { background: var(--accent-soft); color: var(--navy); font-size: 15px; }
.nota-er { margin-top: 12px; background: var(--subtle); }
.nota-er p { margin: 6px 0; }
.bal-dos { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.bal-dos .card + .card { margin-top: 16px; }
.bal-tot { display: flex; justify-content: space-between; font-size: 15px; background: var(--accent-soft); margin-top: 16px; color: var(--navy); }
table.proy th, table.proy td { padding: 6px 8px; font-size: 13px; }
.asiento { border-bottom: 1px solid var(--line); padding: 10px 16px 12px; }
.asiento:last-child { border-bottom: none; }
.as-h { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.as-h .grow { flex: 1; min-width: 160px; }
table.as-l td { padding: 3px 8px; border: none; font-size: 13px; }
table.as-l tr.haber td:nth-child(2) { padding-left: 32px; color: var(--ink-2); }
table.as-l td.num { width: 120px; }
table.inv tr.bajo td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
.click-nombre { cursor: pointer; }
.click-nombre:hover b { color: var(--accent); text-decoration: underline; }
.conteo td { vertical-align: middle; }
.pasos-ini .card + .card { margin-top: 0; }
/* Segundo paso al registrar: categorías, con lo que ya se lleva cada una */
.cats .tipo-b { min-height: 96px; }
.cats .tipo-b.otro { border-style: dashed; }
.cat-m { display: flex; flex-direction: column; gap: 5px; width: 100%; margin-top: auto; padding-top: 8px; font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.cat-barra { display: block; height: 4px; border-radius: 2px; background: var(--line); overflow: hidden; }
.cat-barra i { display: block; height: 100%; border-radius: 2px; background: var(--accent); }
.cats-pie { margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap; }
/* Ventas: elegir al paciente que pagó */
.cp-res { display: flex; flex-direction: column; margin-top: 8px; max-height: 300px; overflow-y: auto; }
.cp-res button { flex-direction: column; align-items: flex-start; gap: 1px; text-align: left; border: none; border-radius: 8px; padding: 8px 10px;
  background: none; font-weight: 400; white-space: normal; }
.cp-res button:hover { background: var(--hover); }
table.precios select { min-width: 210px; }
table.precios select[name=moneda] { min-width: 0; }
/* Tipo de cambio */
.tc-card { margin-bottom: 16px; }
.tc-fila { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; }
.tc-actual { font-size: 16px; background: var(--accent-soft); color: var(--navy); padding: 8px 14px; border-radius: 10px; white-space: nowrap; }
/* Ingresos por especialidad (detalle de «Servicios odontológicos») */
tr.er-e td { padding-top: 2px; padding-bottom: 2px; font-size: 12.5px; color: var(--ink-3); }
tr.er-e td:first-child { padding-left: 48px; }
tr.ef-an td { padding-top: 3px; padding-bottom: 3px; font-size: 12.5px; color: var(--ink-3); }
.chips-mat { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 14px; }
.chips-mat .chip { padding: 4px 10px; font-size: 12.5px; }
/* Estados financieros en formato contable */
.ef-doc { padding: 0 0 10px; }
.ef-membrete { text-align: center; padding: 22px 20px 14px; border-bottom: 1px solid var(--line); }
.ef-razon { font-weight: 700; font-size: 15px; letter-spacing: .03em; text-transform: uppercase; color: var(--navy); }
.ef-membrete h2 { margin: 10px 0 2px; font-size: 17px; text-transform: uppercase; letter-spacing: .05em; }
.ef-cuando { font-size: 14px; }
.ef-dato { font-size: 12.5px; color: var(--ink-3); margin-top: 2px; }
table.ef { font-variant-numeric: tabular-nums; width: 100%; }
table.ef th, table.ef td { padding: 6px 14px; border-bottom: none; }
table.ef thead th { border-bottom: 1px solid var(--line); white-space: nowrap; font-size: 12px; }
table.ef .num { white-space: nowrap; text-align: right; }
table.ef .ef-cod { width: 72px; color: var(--ink-3); font-size: 12.5px; white-space: nowrap; }
table.ef .pct { color: var(--ink-3); font-size: 12px; }
table.ef.bc thead th.c { text-align: center; }
.ef-nom.s2 { padding-left: 30px; }
.ef-nom.s3 { padding-left: 48px; }
.ef-nom.s4 { padding-left: 66px; }
tr.ef-g { cursor: pointer; }
tr.ef-g:hover td, tr.ef-cta[data-cta]:hover td { background: var(--hover); }
tr.ef-n1 td { padding-top: 16px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--navy); border-bottom: 1px solid var(--line-2); }
tr.ef-n2 td { padding-top: 10px; font-weight: 700; text-transform: uppercase; font-size: 12.5px; letter-spacing: .03em; }
tr.ef-n3 td { font-weight: 600; font-style: italic; color: var(--ink-2); }
tr.ef-cta td { color: var(--ink-2); }
tr.ef-cta[data-cta] { cursor: pointer; }
.ef-car { display: inline-block; width: 7px; height: 7px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg);
  margin: 0 9px 3px 0; opacity: .55; transition: transform .15s; }
tr.ef-g.cerrado .ef-car { transform: rotate(-45deg); margin-bottom: 1px; }
tr.ef-total td { font-weight: 700; text-transform: uppercase; font-size: 13px; border-top: 1px solid var(--ink-2); border-bottom: 3px double var(--ink-2); }
tr.ef-resultado td { font-weight: 700; text-transform: uppercase; font-size: 13px; background: var(--subtle); border-top: 1px solid var(--line-2); border-bottom: 1px solid var(--line-2); }
tr.ef-resultado:last-child td { background: var(--accent-soft); color: var(--navy); border-bottom: 3px double var(--navy); }
.ef-nota { margin: 12px 16px 0; font-size: 12.5px; color: var(--ink-3); }
.ef-firmas { display: none; }
table.mayor { font-variant-numeric: tabular-nums; }
table.mayor tr.my-h td { padding-top: 16px; font-weight: 700; border-bottom: 1px solid var(--line-2); }
table.mayor tr.my-h a { color: var(--navy); text-decoration: none; }
table.mayor tr.my-ini td { color: var(--ink-3); }
@container principal (max-width: 620px) { table.ef .ef-cod { display: none; } }
@media print {
  .ef-doc { break-inside: auto; }
  .ef-car { display: none; }
  .ef-firmas { display: grid; grid-template-columns: 1fr 1fr; gap: 60px; margin: 72px 40px 10px; break-inside: avoid; }
  .ef-firmas div { border-top: 1px solid #000; padding-top: 6px; text-align: center; font-size: 12px; }
  .ef-firmas span { display: block; font-weight: 600; min-height: 1.2em; }
}
@container principal (max-width: 860px) { .bal-dos { grid-template-columns: minmax(0, 1fr); } }
@media print {
  .side, .pagehead a, .pagehead button, .pagehead .check, .ag-bar, #toast { display: none !important; }
  .shell { display: block; } .main { padding: 0; max-width: none; }
  .card { box-shadow: none; break-inside: avoid; }
  body, :root { background: #fff; }
}
/* Agenda: marca «$» en la cita cuando toca cobrar */
.cita .cobrar { position: absolute; bottom: 3px; right: 4px; width: 16px; height: 16px; border-radius: 50%; background: var(--warn); color: #fff; font-style: normal;
  font-size: 11px; font-weight: 700; display: grid; place-items: center; }
.side .me { border-top: 1px solid rgba(255,255,255,.12); padding: 12px 8px 0; font-size: 13px; }
.side .me b { display: block; color: #fff; font-weight: 600; }
.side .me .rol { display: block; }
.side .me button { margin-top: 8px; }
.main { padding: 24px 32px 48px; max-width: 1240px; width: 100%; min-width: 0; container: principal / inline-size; }
.main .card { overflow-x: auto; } /* una tabla ancha se desliza dentro de su tarjeta, nunca estira la página */
.pagehead { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.pagehead .grow { flex: 1; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 18px 20px; }
.card + .card { margin-top: 16px; }
.cardhead { display: flex; align-items: center; gap: 10px; padding: 14px 20px; border-bottom: 1px solid var(--line); }
.cardhead .grow { flex: 1; }

/* ---------- Controles ---------- */
button, .btn {
  font: inherit; border: 1px solid var(--line-2); background: var(--panel); color: var(--ink);
  padding: 7px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; display: inline-flex; align-items: center; gap: 6px;
  text-decoration: none; white-space: nowrap; transition: background .12s, border-color .12s;
}
button:hover { background: var(--hover); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
button.danger { color: var(--danger); border-color: #f0c3bf; }
button.danger:hover { background: var(--danger-soft); }
button.ghost { border-color: transparent; background: transparent; }
button.ghost:hover { background: var(--hover); }
button.sm { padding: 4px 9px; font-size: 13px; }
button:disabled { opacity: .5; cursor: not-allowed; }
.side button { background: transparent; color: #c9d7e6; border-color: rgba(255,255,255,.2); }
.side button:hover { background: rgba(255,255,255,.08); }

input, select, textarea {
  font: inherit; color: var(--ink); background: #fff; border: 1px solid var(--line-2); border-radius: 6px;
  padding: 8px 11px; width: 100%;
}
textarea { resize: vertical; min-height: 64px; }
input[readonly], textarea[readonly], select:disabled, input:disabled, textarea:disabled { background: var(--subtle); color: var(--ink-2); }
label.f { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-2); font-weight: 500; }
label.f.full, .grid > .full { grid-column: 1 / -1; }
.grid { display: grid; gap: 14px 16px; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.grid.two { grid-template-columns: repeat(2, 1fr); }
fieldset { border: none; padding: 0; margin: 0 0 22px; }
legend { font-weight: 600; font-size: 13px; color: var(--ink); margin-bottom: 10px; padding: 0; text-transform: uppercase; letter-spacing: .04em; }
.search { position: relative; max-width: 420px; flex: 1; }
.search input { padding-left: 34px; }
.search svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--ink-3); }
.actions { display: flex; gap: 8px; justify-content: flex-end; align-items: flex-end; margin-top: 18px; }

/* ---------- Tablas ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: .03em; background: var(--subtle); }
tbody tr:last-child td { border-bottom: none; }
tr.click { cursor: pointer; }
td a { text-decoration: none; }
td a:hover { text-decoration: underline; }
tr.click:hover td { background: #f5f9fd; }
td.acts { text-align: right; white-space: nowrap; }
.empty { padding: 36px 20px; text-align: center; color: var(--ink-3); }

/* ---------- Etiquetas ---------- */
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eef2f6; color: var(--ink-2); }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.danger { background: var(--danger-soft); color: var(--danger); }
.tag.accent { background: var(--accent-soft); color: var(--accent); }
.alerta { display: flex; gap: 10px; align-items: flex-start; background: var(--danger-soft); color: var(--danger); border: 1px solid #f3c7c2; border-radius: var(--radius); padding: 10px 14px; margin-bottom: 16px; }

/* ---------- Paciente ---------- */
.pachead { display: flex; gap: 16px; align-items: center; margin-bottom: 16px; }
.avatar { width: 48px; height: 48px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 600; font-size: 17px; flex: none; }
.pachead .info { flex: 1; min-width: 0; }
.pachead .meta { color: var(--ink-3); margin-top: 3px; display: flex; gap: 14px; flex-wrap: wrap; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 18px; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
.tabs a { padding: 9px 14px; color: var(--ink-2); text-decoration: none; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs a:hover { color: var(--ink); }
.tabs a.on { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 16px; }
.kpi { padding: 14px 18px; }
.kpi .l { font-size: 12px; color: var(--ink-3); }
.kpi .v { font-size: 22px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .v.neg { color: var(--danger); }
.kpi .v.pos { color: var(--ok); }

.kpis.auto { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.kpis > .card + .card { margin-top: 0; } /* en la grilla, todas las tarjetas a la misma altura */

/* ---------- Carpeta del paciente: Resumen ---------- */
.acciones-pac { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.res-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.res-grid .col { min-width: 0; }
.lista-res { list-style: none; margin: 0; padding: 4px 0; }
.lista-res li { display: flex; align-items: flex-start; gap: 10px; padding: 8px 20px; }
.lista-res li + li { border-top: 1px solid var(--line); }
.lista-res .grow { flex: 1; min-width: 0; }
.punto { width: 8px; height: 8px; border-radius: 50%; flex: none; margin-top: 6px; background: var(--ink-3); }
.punto.ok { background: var(--ok); } .punto.warn { background: #d99a00; } .punto.danger { background: var(--danger); } .punto.accent { background: var(--accent); }
.progreso { height: 6px; background: var(--line); border-radius: 99px; margin: 12px 20px 4px; overflow: hidden; }
.progreso span { display: block; height: 100%; background: var(--ok); border-radius: 99px; }
.sub-h { padding: 12px 20px 2px; font-size: 12px; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; border-top: 1px solid var(--line); }
.pie-card { padding: 10px 20px 14px; font-size: 13px; }
dl.cuenta { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; margin: 0; padding: 14px 20px 16px; font-variant-numeric: tabular-nums; }
dl.cuenta dt { color: var(--ink-2); } dl.cuenta dd { margin: 0; text-align: right; }
.mini-arch { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 14px 20px 4px; }
.mini-arch a { aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--subtle); border: 1px solid var(--line); display: grid; place-items: center; color: var(--ink-3); }
.mini-arch img { width: 100%; height: 100%; object-fit: cover; }
.mini-arch .arch-ico svg { width: 24px; height: 24px; }
ul.carpetas { list-style: none; margin: 0; padding: 8px 10px 12px; }
ul.carpetas a { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; }
ul.carpetas a:hover { background: var(--hover); }
ul.carpetas svg { color: var(--accent); flex: none; }
ul.carpetas .grow { flex: 1; }
ul.carpetas .n { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink-2); min-width: 20px; text-align: right; }
ul.carpetas li.vacia a { color: var(--ink-3); } ul.carpetas li.vacia svg { color: var(--line-2); } ul.carpetas li.vacia .n { color: var(--ink-3); font-weight: 500; }
/* Historial: línea de tiempo por mes */
ul.historial { list-style: none; margin: 0; padding: 6px 0 12px; }
ul.historial li.h-mes { padding: 14px 20px 6px; font-size: 12px; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; }
ul.historial li[data-tab] { display: grid; grid-template-columns: 10px 92px minmax(0, 1fr) auto; gap: 12px; align-items: start; padding: 8px 20px; cursor: pointer; position: relative; }
ul.historial li[data-tab]:hover { background: var(--hover); }
.h-dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 4px; background: var(--ink-3); box-shadow: 0 0 0 3px var(--panel); }
.h-cita .h-dot { background: var(--accent); } .h-tratamiento .h-dot { background: var(--navy); } .h-pago .h-dot { background: var(--ok); }
.h-presupuesto .h-dot { background: #7c5cc4; } .h-archivo .h-dot { background: #8ea3b8; } .h-seguimiento .h-dot { background: #d99a00; } .h-alta .h-dot { background: var(--line-2); }
.h-fecha { font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.h-fecha span { display: block; color: var(--ink-3); font-size: 12px; }
.h-tipo { font-size: 11px; font-weight: 600; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; margin-right: 4px; }
.h-extra { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
@container principal (max-width: 860px) {
  .res-grid { grid-template-columns: minmax(0, 1fr); }
}
@container principal (max-width: 560px) {
  ul.historial li[data-tab] { grid-template-columns: 10px minmax(0, 1fr) auto; gap: 2px 12px; padding: 8px 14px; }
  ul.historial .h-fecha { grid-column: 2; grid-row: 1; }
  ul.historial .h-cuerpo { grid-column: 2 / 4; grid-row: 2; }
  ul.historial .h-extra { grid-column: 3; grid-row: 1; }
  ul.historial li.h-mes { padding: 14px 14px 6px; }
  .lista-res li { padding: 8px 14px; }
}
a.kpi.link { color: inherit; text-decoration: none; transition: border-color .12s, box-shadow .12s; }
a.kpi.link:hover { border-color: var(--accent); box-shadow: 0 2px 10px rgba(15, 118, 110, .12); }
.kpi .metodo { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; margin-top: 4px; font-variant-numeric: tabular-nums; }

/* ---------- Inicio / seguimientos ---------- */
.inicio-grid { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 16px; align-items: start; }
.inicio-grid .col > .card + .card { margin-top: 16px; }
.inicio-grid td { vertical-align: middle; }
tr.apagada td { opacity: .5; }
.vencido { color: var(--danger); font-weight: 600; }
.chips { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
label.check { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 13px; cursor: pointer; }
label.check input { width: auto; }
.timeline { list-style: none; margin: 0; padding: 6px 20px 12px; }
.timeline li { position: relative; padding: 10px 0 10px 18px; border-left: 2px solid var(--line); }
.timeline li::before { content: ''; position: absolute; left: -6px; top: 15px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.timeline .tag { margin-left: 4px; }

/* ---------- Archivos ---------- */
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { background: var(--accent-2); }
button.linklike { border: none; background: none; padding: 0; color: var(--accent); font-weight: 600; text-decoration: underline; }
.arch-filtros { padding: 12px 20px 0; margin: 0; }
.chip { border-radius: 999px; padding: 4px 12px; font-size: 13px; font-weight: 600; background: var(--panel); }
.chip span { color: var(--ink-3); font-weight: 500; margin-left: 2px; }
.chip.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent-2); }
.dropzone { margin: 12px 20px 0; border: 2px dashed var(--line-2); border-radius: var(--radius); padding: 18px; text-align: center;
  color: var(--ink-2); display: flex; flex-direction: column; gap: 4px; align-items: center; transition: background .12s, border-color .12s; }
.dropzone.sobre { border-color: var(--accent); background: var(--accent-soft); }
.dropzone.chica { margin: 0; padding: 14px; }
.arch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; padding: 16px 20px 20px; }
.arch { display: flex; flex-direction: column; align-items: stretch; padding: 0; gap: 0; border-radius: 10px; overflow: hidden; text-align: left; white-space: normal; font-weight: 400; }
.arch:hover { border-color: var(--accent); background: var(--panel); box-shadow: 0 4px 14px -6px rgba(11, 42, 74, .25); }
.arch-mini { aspect-ratio: 4 / 3; background: var(--subtle); display: grid; place-items: center; overflow: hidden; border-bottom: 1px solid var(--line); }
.arch-mini img { width: 100%; height: 100%; object-fit: cover; }
.arch-info { padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.arch-info b { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.arch-info span { font-size: 12px; color: var(--ink-3); }
.arch-ico { position: relative; color: var(--ink-3); display: grid; place-items: center; }
.arch-ico span { position: absolute; bottom: 7px; font-size: 8px; font-weight: 700; letter-spacing: .04em; color: var(--accent-2); }
.arch-vacio { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 36px 20px; }
.arch-vacio p { max-width: 520px; margin: 0 0 8px; }
.subidas { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 240px; overflow-y: auto; }
.subidas li { position: relative; display: flex; align-items: center; gap: 8px; padding: 7px 8px 7px 12px; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.subidas li .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.subidas li b { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.subidas li small { color: var(--ink-3); }
.subidas li i { position: absolute; left: 0; bottom: 0; height: 3px; width: 0; background: var(--accent); transition: width .15s; }
.subidas li.listo { border-color: #b9e3c9; background: var(--ok-soft); }
.subidas li.listo i { width: 100% !important; background: var(--ok); }
.subidas li.listo small::after { content: ' · Guardado en Drive ✓'; color: var(--ok); font-weight: 600; }
.subidas li.listo [data-quitar] { display: none; }
.subidas li.fallo { border-color: #f0c3bf; background: var(--danger-soft); }
.subidas li.fallo small { color: var(--danger); }
.visor { position: relative; display: flex; align-items: center; gap: 8px; }
.visor-img { flex: 1; min-height: 240px; max-height: 62vh; display: grid; place-items: center; background: #0b1622; border-radius: 10px; overflow: hidden; }
.visor-img > img { max-width: 100%; max-height: 62vh; object-fit: contain; display: block; }
.visor-doc { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 24px; background: var(--subtle); width: 100%; min-height: 240px; justify-content: center; }
.visor-doc img { max-height: 40vh; max-width: 100%; border: 1px solid var(--line); border-radius: 6px; background: #fff; }
.visor-doc img + .arch-ico { display: none; }
.visor-nav { font-size: 28px; line-height: 1; padding: 6px 12px; border-radius: 999px; }
.visor-meta { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; margin-top: 12px; font-size: 13px; color: var(--ink-2); }
pre.arbol { background: var(--subtle); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; font-size: 12px; color: var(--ink-2); margin: 0; overflow-x: auto; }

/* ---------- Carga rápida de fichas ---------- */
.carga { max-width: 820px; }
.carga .card + .card, .carga .paso + .paso { margin-top: 14px; }
.paso { transition: background .12s, border-color .12s; }
.paso.sobre { border-color: var(--accent); background: var(--accent-soft); }
.paso.apagado { opacity: .55; }
.paso-h { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.paso-h .grow { flex: 1; }
.num-paso { width: 28px; height: 28px; border-radius: 50%; background: var(--navy); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 14px; flex: none; }
.c-botones { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
button.grande { justify-content: center; padding: 13px 18px; font-size: 15px; border-radius: 10px; }
.c-fotos { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; margin-top: 14px; }
.c-fotos:empty { display: none; }
.c-foto { position: relative; aspect-ratio: 3 / 4; border: 1px solid var(--line-2); border-radius: 10px; overflow: hidden; background: var(--subtle); display: grid; place-items: center; }
.c-foto img { width: 100%; height: 100%; object-fit: contain; transition: transform .15s; background: #fff; }
.c-foto .c-n { position: absolute; top: 6px; left: 6px; background: var(--navy); color: #fff; font-size: 12px; font-weight: 700; border-radius: 999px; min-width: 22px; height: 22px; display: grid; place-items: center; padding: 0 6px; }
.c-foto .c-acc { position: absolute; top: 4px; right: 4px; display: flex; gap: 4px; }
.c-foto .c-acc button { background: rgba(255,255,255,.92); padding: 3px 8px; }
.c-foto i { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--accent); width: 0; transition: width .15s; }
.c-foto.listo { border-color: var(--ok); }
.c-foto.listo i { background: var(--ok); }
.c-foto.listo::after { content: '✓'; position: absolute; bottom: 8px; right: 8px; width: 24px; height: 24px; border-radius: 50%; background: var(--ok); color: #fff; display: grid; place-items: center; font-weight: 700; }
.c-foto.fallo { border-color: var(--danger); }
.c-foto .c-err { position: absolute; left: 0; right: 0; bottom: 4px; background: var(--danger); color: #fff; font-size: 11px; padding: 4px 6px; line-height: 1.25; }
.c-barra { position: sticky; bottom: 0; z-index: 5; display: flex; align-items: center; gap: 12px; margin: 14px 0; padding: 12px 16px;
  background: rgba(255,255,255,.96); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 -6px 18px -12px rgba(11,42,74,.25); backdrop-filter: blur(4px); }
.c-barra .grow { flex: 1; color: var(--ink-2); }
.dup { margin-top: 12px; padding: 10px 12px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); font-size: 13px; }
.dup-f { display: flex; align-items: center; gap: 8px; margin-top: 6px; color: var(--ink); }
.dup-f .grow { flex: 1; }

/* ---------- Finanzas: gráficos ---------- */
.fin-dos { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 16px; }
.fin-dos .card + .card { margin-top: 0; }
.fin-dos h3, .card.pad > h3 { margin-bottom: 10px; }
/* Barras verticales: un solo color (azul de la marca), puntas redondeadas, guías tenues */
.vbarras { position: relative; overflow: visible; display: grid; grid-template-columns: 64px 1fr; height: 240px; margin-top: 22px; }
.vb-eje { display: flex; flex-direction: column; justify-content: space-between; align-items: flex-end; padding: 0 8px 22px 0;
  font-size: 11px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.vb-eje span { transform: translateY(-50%); } .vb-eje span:last-child { transform: translateY(50%); }
.vb-area { position: relative; display: flex; align-items: flex-end; gap: 2px; padding-bottom: 22px; border-bottom: 0; }
.vb-grid { position: absolute; left: 0; right: 0; height: 1px; background: var(--line); pointer-events: none; }
.vb-col { flex: 1; height: 100%; position: relative; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; cursor: default; }
.vb-col:hover { background: linear-gradient(to top, transparent 22px, rgba(27,127,209,.05) 22px); }
.vb-bar { position: relative; width: min(46px, 55%); min-height: 2px; background: #9cc6ec; border-radius: 4px 4px 0 0; transition: height .3s; }
.vb-bar.actual { background: var(--accent); }
.vb-val { position: absolute; bottom: calc(100% + 4px); left: 50%; transform: translateX(-50%); font-size: 12px; font-weight: 700; color: var(--ink); white-space: nowrap; }
.vb-mes { position: absolute; bottom: -20px; font-size: 12px; color: var(--ink-2); white-space: nowrap; }
.vb-tip { position: absolute; top: 0; width: 150px; background: var(--navy); color: #fff; font-size: 12px; line-height: 1.4; padding: 8px 10px; border-radius: 8px; pointer-events: none; z-index: 2; }
/* Barras horizontales (desglose) */
.hbarras { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.hbarras li { display: grid; grid-template-columns: minmax(90px, 32%) 1fr auto; align-items: center; gap: 10px; font-size: 13px; }
.hb-l { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hb-b { height: 10px; background: var(--subtle); border-radius: 5px; overflow: hidden; }
.hb-b i { display: block; height: 100%; background: var(--accent); border-radius: 5px; }
.hb-v { font-weight: 700; font-variant-numeric: tabular-nums; color: var(--ink); }

/* ---------- Precios ---------- */
.nuevo-precio { display: flex; gap: 8px; align-items: center; }
.nuevo-precio input[name=nombre] { flex: 1; }
table.precios td { padding: 5px 12px; vertical-align: middle; }
table.precios input[type=number] { text-align: right; }
table.precios tr:not(:hover) input:not(:focus) { border-color: transparent; background: transparent; }

/* ---------- Presupuestos ---------- */
.pres { border-top: 1px solid var(--line); }
.pres:first-child { border-top: none; }
.pres-h { display: flex; align-items: center; gap: 12px; padding: 14px 20px; flex-wrap: wrap; }
.pres-h .grow { flex: 1; }
.pres table th, .pres table td { padding: 7px 20px; }
.pres .tot td { font-weight: 600; border-top: 1px solid var(--line-2); }
.pres .pie-pago td { border-bottom: none; padding-top: 3px; padding-bottom: 3px; font-size: 13px; }
.pres .tot + .pie-pago td { padding-top: 8px; }
.pres .pie-pago:last-child td { padding-bottom: 12px; }
.items-edit td { padding: 5px 4px; border: none; }
.items-edit input { padding: 5px 8px; }

/* ---------- Odontograma ---------- */
.od-wrap { display: grid; grid-template-columns: 1fr 230px; gap: 16px; align-items: start; }
.od-wrap .card + .card { margin-top: 0; }
.od-board { padding: 18px 12px; overflow-x: auto; }
.od-row { display: flex; justify-content: center; gap: 2px; }
.od-half { display: flex; gap: 2px; }
.od-half + .od-half { border-left: 2px solid var(--line-2); padding-left: 6px; margin-left: 4px; }
.od-gap { height: 18px; }
.od-gap.mid { border-top: 1px dashed var(--line-2); margin: 10px 0; height: 8px; }
.tooth { display: flex; flex-direction: column; align-items: center; gap: 2px; width: 48px; }
.tooth .n { font-size: 11px; color: var(--ink-3); font-variant-numeric: tabular-nums; cursor: pointer; padding: 1px 4px; border-radius: 4px; }
.tooth .n:hover { background: var(--hover); color: var(--ink); }
.tooth.sel .n { background: var(--accent); color: #fff; }
.tooth svg { width: 44px; height: 48px; display: block; overflow: visible; }
.tooth svg .s { fill: #fff; stroke: #93a3b3; stroke-width: 1; cursor: pointer; transition: fill .08s; }
.tooth svg .s:hover { fill: var(--accent-soft); }
.tooth.ro svg .s { cursor: default; }
.tooth.ro svg .s:hover { fill: #fff; }
.s.caries { fill: var(--od-caries) !important; }
.s.restauracion { fill: var(--od-rest) !important; }
.s.sellante { fill: var(--od-sell) !important; }
.s.fractura { fill: var(--od-frac) !important; }
.s.restauracion_defectuosa { fill: var(--od-def) !important; }
.tooth.ausente svg .s { fill: #eef2f6 !important; stroke: #c3cfdb; }
.tooth .mk { pointer-events: none; fill: none; stroke-width: 2.4; stroke-linecap: round; }

.od-tools { padding: 14px; position: sticky; top: 16px; }
.od-tools h3 { margin: 4px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); }
.tool { display: flex; align-items: center; gap: 8px; width: 100%; padding: 6px 8px; border: 1px solid transparent; background: none; border-radius: 6px; text-align: left; justify-content: flex-start; }
.tool:hover { background: var(--hover); }
.tool.on { border-color: var(--accent); background: var(--accent-soft); }
.sw { width: 14px; height: 14px; border-radius: 3px; border: 1px solid #93a3b3; flex: none; }
.od-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; padding: 12px 20px; border-top: 1px solid var(--line); font-size: 12px; color: var(--ink-2); }
.od-legend span { display: inline-flex; gap: 6px; align-items: center; }
.od-hint { font-size: 12px; color: var(--ink-3); margin-top: 10px; line-height: 1.45; }

/* ---------- Agenda ---------- */
.ag-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.ag-bar .titulo { display: inline-block; font-size: 16px; font-weight: 600; min-width: 230px; }
.ag-bar .titulo::first-letter { text-transform: uppercase; }
.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 6px; overflow: hidden; }
.seg button { border: none; border-radius: 0; }
.seg button + button { border-left: 1px solid var(--line-2); }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.ag-bar select { width: auto; }
.ag { display: grid; overflow: auto; max-height: calc(100vh - 190px); min-height: 320px; }
.ag-head { display: contents; }
.ag-h { position: sticky; top: 0; z-index: 3; background: var(--subtle); border-bottom: 1px solid var(--line); padding: 8px 6px; text-align: center; font-size: 13px; font-weight: 600; min-width: 130px; }
.ag-h small { display: block; font-weight: 400; color: var(--ink-3); }
.ag-h.hoy { color: var(--accent); }
.ag-h .dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 6px; }
.ag-horas { position: relative; border-right: 1px solid var(--line); }
.ag-horas span { position: absolute; right: 6px; font-size: 11px; color: var(--ink-3); transform: translateY(-50%); font-variant-numeric: tabular-nums; }
.ag-col { position: relative; border-right: 1px solid var(--line); cursor: copy; min-width: 130px; }
.ag-col.ro { cursor: default; }
.ag-col:last-child { border-right: none; }
.ag-col.hoy { background-color: #fafcfe; }
.ag-ahora { position: absolute; left: 0; right: 0; height: 2px; background: var(--danger); z-index: 2; pointer-events: none; }
.ag-ahora::before { content: ''; position: absolute; left: -4px; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); }
.cita {
  position: absolute; border-radius: 5px; padding: 3px 6px; font-size: 12px; line-height: 1.3; overflow: hidden; cursor: pointer;
  background: color-mix(in srgb, var(--c) 14%, white); border-left: 3px solid var(--c); color: var(--ink); z-index: 1;
  box-shadow: 0 0 0 1px #fff; transition: box-shadow .1s;
}
.cita:hover { box-shadow: 0 0 0 1px #fff, 0 2px 8px rgba(0,0,0,.15); z-index: 2; }
.cita b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cita .h { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.cita .m { color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cita.confirmada { background: color-mix(in srgb, var(--c) 26%, white); }
.cita.atendida { opacity: .6; }
.cita.cancelada { opacity: .45; text-decoration: line-through; background: #f1f4f7; border-left-color: #9aa9b8; }
.cita.no_asistio { background: var(--danger-soft); border-left-color: var(--danger); }
.cita .gerr { position: absolute; top: 3px; right: 4px; width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
/* Agenda en lista */
.ag-lista { display: flex; flex-direction: column; }
.ag-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 16px 12px 14px; border: none; border-radius: 0; border-bottom: 1px solid var(--line);
  border-left: 4px solid var(--c); background: var(--panel); text-align: left; white-space: normal; font-weight: 400; position: relative; }
.ag-item:last-child { border-bottom: none; }
.ag-item:hover { background: #f5f9fd; }
.ag-hora { display: flex; flex-direction: column; align-items: flex-start; min-width: 48px; font-variant-numeric: tabular-nums; }
.ag-hora small, .ag-det small { color: var(--ink-3); font-size: 12px; }
.ag-det { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ag-item.cancelada .ag-det b { text-decoration: line-through; color: var(--ink-3); }
.ag-item.cancelada, .ag-item.atendida { opacity: .65; }
.ag-item.no_asistio { background: var(--danger-soft); }
.ag-tags { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
tr.sin-aviso td:first-child { box-shadow: inset 3px 0 0 var(--danger); }
.ag-item .gerr { position: absolute; top: 8px; right: 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }
.pac-res { border: 1px solid var(--line-2); border-radius: 6px; margin-top: 4px; max-height: 190px; overflow-y: auto; }
.pac-res button { display: block; width: 100%; text-align: left; border: none; border-radius: 0; border-bottom: 1px solid var(--line); }
.pac-res button:last-child { border-bottom: none; }
.pac-sel { display: flex; align-items: center; gap: 10px; padding: 7px 10px; border: 1px solid var(--accent); background: var(--accent-soft); border-radius: 6px; }
.pac-sel .grow { flex: 1; }
.gstat { font-size: 12px; padding: 8px 10px; border-radius: 8px; background: var(--subtle); color: var(--ink-2); margin-top: 14px; }
.gstat.err { background: var(--warn-soft); color: var(--warn); }
code.copy { background: #eef2f6; padding: 2px 6px; border-radius: 4px; font-size: 12px; user-select: all; word-break: break-all; }
ol.pasos { padding-left: 20px; line-height: 1.6; margin: 8px 0; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(1200px 600px at 85% -10%, rgba(27,127,209,.35), transparent 60%), linear-gradient(160deg, var(--navy) 0%, var(--navy-2) 100%); }
.login .card { width: 100%; max-width: 380px; padding: 28px; }
.login h1 { margin: 14px 0 4px; }
.login form { display: grid; gap: 14px; margin-top: 20px; }
.login .err { color: var(--danger); font-size: 13px; min-height: 18px; }
.sep-o { display: flex; align-items: center; gap: 10px; color: var(--ink-3); font-size: 12px; margin: 18px 0 14px; }
.sep-o::before, .sep-o::after { content: ''; flex: 1; height: 1px; background: var(--line); }

/* ---------- Modal / toast ---------- */
dialog { border: none; border-radius: 14px; padding: 0; width: min(720px, calc(100vw - 32px)); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(11, 42, 74, .45); backdrop-filter: blur(2px); }
dialog form { padding: 22px 24px; max-height: 85vh; overflow-y: auto; }
dialog h2 { margin-bottom: 16px; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--navy); color: #fff; padding: 10px 18px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; z-index: 100; max-width: 90vw; }
#toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { background: var(--danger); }

@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  /* Menú del celular: barra fija arriba con la sección actual; el botón «☰» despliega el árbol completo */
  .side { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; padding: 8px 12px; gap: 10px; flex-direction: row; height: auto; overflow: visible; }
  .brand { padding: 0; font-size: 14px; flex: 1; min-width: 0; }
  .brand > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .brand svg { width: 28px; height: 28px; }
  .brand small { display: none; }
  .side .spacer { display: none; }
  .menu-btn { display: inline-flex; align-items: center; gap: 8px; background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.22); color: #fff; padding: 7px 10px 7px 12px; max-width: 58%; }
  .menu-btn:hover { background: rgba(255,255,255,.16); }
  .menu-btn > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
  .side-cuerpo { display: none; }
  .side.menu-abierto .side-cuerpo { display: flex; flex-direction: column; position: absolute; left: 0; right: 0; top: 100%; background: var(--navy);
    padding: 8px 12px 14px; max-height: calc(100vh - 52px); overflow-y: auto; box-shadow: 0 18px 30px -12px rgba(0,0,0,.45); }
  .side .me { margin-top: 10px; }
  .side a.nav, .side .g-h { padding: 11px 10px; font-size: 15px; }
  .side a.sub { padding: 10px 10px; font-size: 14.5px; }
  .main { padding: 18px 14px 40px; }
  .od-wrap { grid-template-columns: minmax(0, 1fr); }
  .od-tools { position: static; }
  .kpis, .kpis.auto { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpis > :last-child:nth-child(odd) { grid-column: 1 / -1; }
  .kpi { padding: 12px 14px; }
  .kpi .v { font-size: 19px; }
  .c-botones { grid-template-columns: 1fr; }
  .c-barra { margin: 14px -14px; border-radius: 0; border-left: none; border-right: none; padding: 12px 14px calc(12px + env(safe-area-inset-bottom)); }
  .c-barra button.grande { flex: 1; }
  .c-barra .grow:empty { display: none; }
  .inicio-grid { grid-template-columns: minmax(0, 1fr); }
  .fin-dos { grid-template-columns: minmax(0, 1fr); }
  .vbarras { grid-template-columns: 52px 1fr; }
  .grid.two { grid-template-columns: 1fr; }
}
/* Pantallas táctiles: no se puede arrastrar archivos; queda el botón «Subir archivos». */
@media (hover: none) and (pointer: coarse) {
  #drop { display: none; }
}
/* ---------- Tablas en espacios angostos (celular, tablet, laptop chica) ---------- */
@container principal (max-width: 720px) {
  /* Tablas → filas apiladas tipo tarjeta */
  table.apilar thead { display: none; }
  table.apilar, table.apilar tbody { display: block; width: 100%; }
  table.apilar tr { display: flex; flex-wrap: wrap; align-items: center; gap: 3px 12px; padding: 11px 14px; border-bottom: 1px solid var(--line); }
  table.apilar tbody tr:last-child { border-bottom: none; }
  table.apilar td { display: block; border: none; padding: 0; font-size: 13px; color: var(--ink-2); width: auto !important; }
  table.apilar td.p { flex: 1 1 100%; order: -1; font-size: 14px; color: var(--ink); }
  table.apilar td.g { flex: 1 1 140px; min-width: 0; color: var(--ink); }
  table.apilar td.w { flex: 1 1 100%; color: var(--ink); }
  table.apilar td.num { margin-left: auto; }
  table.apilar td.num + td.num { margin-left: 0; }
  table.apilar td.acts { flex: 1 1 100%; text-align: left; white-space: normal; margin-top: 4px; }
  table.apilar td.acts button { margin: 2px 4px 2px 0; }
  table.apilar td.mo, table.apilar td:empty { display: none; }
  table.apilar td[data-l]::before { content: attr(data-l) ' '; color: var(--ink-3); font-size: 12px; }
  table.apilar tr.tot td { font-size: 15px; }
  .pres table.apilar tr { padding: 8px 14px; }
  .pres table.apilar tr.pie-pago { flex-wrap: nowrap; align-items: baseline; border-bottom: none; padding: 2px 14px; }
  .pres table.apilar tr.tot + tr.pie-pago { padding-top: 8px; }
  .pres table.apilar tr.pie-pago:last-child { padding-bottom: 12px; }
  .pres table.apilar tr.pie-pago td.pl { flex: 1 1 auto; min-width: 0; text-align: right; white-space: normal; }
  .pres table.apilar tr.pie-pago td.pv { flex: none; margin-left: 0; white-space: nowrap; }
  .pres-h { padding: 12px 14px; gap: 8px; }
  table.precios.apilar td.p input { font-weight: 600; }
  table.precios.apilar td.g { flex: 0 1 130px; }
}
/* ---------- Teléfono ---------- */
@media (max-width: 640px) {
  h1 { font-size: 23px; }
  .pagehead { gap: 8px; margin-bottom: 14px; }
  .pagehead .search { order: 5; flex-basis: 100%; max-width: none; }
  .ag-bar { gap: 6px; }
  .ag-bar .titulo { order: -1; flex-basis: 100%; min-width: 0; font-size: 15px; }
  .ag-bar > .grow { display: none; }
  .ag-bar input[type=date] { flex: 1; min-width: 0; }
  .ag-bar select { flex: 1 1 100%; min-width: 0; }
  .ag-bar .seg { flex: 1 1 100%; } .ag-bar .seg button { flex: 1; justify-content: center; }
  .cardhead { padding: 12px 14px; flex-wrap: wrap; }
  .card.pad { padding: 16px 14px; }
  .actions { flex-wrap: wrap; }
  input, select, textarea { font-size: 16px; } /* evita que el iPhone haga zoom al escribir */
  .pl-h { padding: 12px; gap: 10px; }
  .pl-ic { width: 32px; height: 32px; border-radius: 9px; }
  .pl-ic svg { width: 16px; height: 16px; }
  .pl-c { margin-left: 6px; padding-left: 10px; }
  .plan-b { margin: 0 12px 14px; padding: 10px; }
  .plan-info b { font-size: 14px; }
  .cobro-fila { flex-wrap: wrap; }
  .cobro-der { flex: 1 1 100%; justify-content: space-between; padding-left: 18px; }
  .fila-hoy { flex-wrap: wrap; }
  .fila-acc { flex: 1 1 100%; justify-content: flex-start; padding-left: 60px; }
  details.card > summary { padding: 12px 14px; }
  .pres-d > summary { flex-wrap: wrap; }
  .estado-pac .ep { flex: 1 1 100%; }

  /* Editor de presupuesto: cada procedimiento en dos renglones */
  .items-edit thead { display: none; }
  .items-edit, .items-edit tbody { display: block; }
  .items-edit tr { display: grid; grid-template-columns: 64px 1fr 1fr 34px 34px; gap: 6px; align-items: center; padding: 8px 0; border-bottom: 1px dashed var(--line-2); }
  .items-edit td { width: auto !important; padding: 0; }
  .items-edit td:nth-child(2) { grid-column: span 4; }
  .items-edit td:nth-child(4) { grid-column: span 2; }

  /* Ventanas: casi a pantalla completa */
  dialog { width: calc(100vw - 16px); max-height: calc(100dvh - 16px); }
  dialog form { padding: 18px 16px; max-height: calc(100dvh - 16px); }
  .visor-nav { position: absolute; z-index: 2; background: rgba(255,255,255,.9); }
  .visor-nav.ant { left: 6px; } .visor-nav.sig { right: 6px; }
  .arch-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 14px; }
  .dropzone { margin: 12px 14px 0; }
  .arch-filtros { padding: 12px 14px 0; }

  /* Odontograma: más compacto y deslizable */
  .od-board { padding: 12px 6px; }
  .tooth { width: 38px; }
  .tooth svg { width: 34px; height: 38px; }
  .tabs a { padding: 9px 11px; }
}
@media print {
  .side, .tabs, button, .od-tools { display: none !important; }
  .shell { display: block; }
  .main { padding: 0; }
  .card { box-shadow: none; }
}
