:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #f8faf9;
  --border: #dde4e1;
  --border-strong: #c3cdc9;
  --text: #17201d;
  --text-2: #55635e;
  --text-3: #7d8a85;
  --accent: #0f766e;
  --accent-hover: color-mix(in srgb, var(--accent) 82%, black);
  --accent-soft: color-mix(in srgb, var(--accent) 12%, white);
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn: #b45309;
  --warn-soft: #fdf3e2;
  --ok: #157f3b;
  --ok-soft: #e6f4ea;
  --info: #1d4ed8;
  --info-soft: #e8eefc;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 20, .06), 0 1px 3px rgba(16, 24, 20, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 20, .18);
  --sidebar: 228px;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body { line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 22px; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
.muted { color: var(--text-2); }
.small { font-size: 12.5px; }
.mono { font-variant-numeric: tabular-nums; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-wrap; }
.hidden { display: none !important; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.stack > * + * { margin-top: 12px; }

/* ---------- layout ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar { background: #0d2b27; color: #cfe3de; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; color: #fff; font-weight: 600; font-size: 16px; }
.brand img { width: 30px; height: 30px; }
.brand small { display: block; font-weight: 400; color: #8fb3ab; font-size: 12px; }
.nav { padding: 6px 10px; flex: 1; overflow-y: auto; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 6px; color: #cfe3de; font-weight: 500; margin-bottom: 2px; }
.nav a:hover { background: rgba(255,255,255,.07); text-decoration: none; color: #fff; }
.nav a.active { background: #13443d; color: #fff; }
.nav a svg { width: 18px; height: 18px; flex: none; opacity: .9; }
.nav .badge { margin-left: auto; background: #f59e0b; color: #1f1500; border-radius: 10px; padding: 0 7px; font-size: 11.5px; font-weight: 600; }
.nav-sep { height: 1px; background: rgba(255,255,255,.08); margin: 10px 6px; }
.sidebar-foot { padding: 12px 16px 16px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12.5px; }
.sidebar-foot .who { color: #fff; font-weight: 600; }
.sidebar-foot button { margin-top: 8px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; background: rgba(244,246,245,.92); backdrop-filter: blur(6px); border-bottom: 1px solid var(--border); padding: 10px 24px; display: flex; gap: 12px; align-items: center; }
.topbar .menu-btn { display: none; }
.gsearch { position: relative; flex: 1; max-width: 520px; }
.gsearch input { padding-left: 34px; background: var(--surface); }
.gsearch svg { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); width: 16px; color: var(--text-3); }
.gsearch .dropdown { position: absolute; left: 0; right: 0; top: calc(100% + 4px); }
.content { padding: 22px 24px 48px; max-width: 1400px; width: 100%; }
.page-head { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .sub { color: var(--text-2); margin-top: 2px; }

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-h { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; }
.card-b { padding: 16px; }
.card-b.flush { padding: 0; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g-dash { grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { padding: 14px 16px; }
.kpi .label { color: var(--text-2); font-size: 12.5px; font-weight: 500; }
.kpi .value { font-size: 26px; font-weight: 600; margin-top: 2px; font-variant-numeric: tabular-nums; }
.kpi .hint { color: var(--text-3); font-size: 12px; }
.kpi.link { cursor: pointer; }
.kpi.link:hover { border-color: var(--accent); }

/* ---------- forms ---------- */
label { display: block; font-weight: 500; font-size: 12.5px; color: var(--text-2); margin-bottom: 4px; }
input, select, textarea { width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 6px; padding: 7px 10px; min-height: 36px; }
textarea { resize: vertical; min-height: 72px; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(15,118,110,.15); }
input[type=checkbox] { width: 16px; height: 16px; min-height: 0; accent-color: var(--accent); margin: 0; }
input[type=color] { padding: 2px; width: 48px; }
.check { display: inline-flex; align-items: center; gap: 7px; font-weight: 500; color: var(--text); font-size: 13.5px; margin: 0; cursor: pointer; }
.fields { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 12px 14px; }
.f12 { grid-column: span 12; } .f8 { grid-column: span 8; } .f6 { grid-column: span 6; } .f4 { grid-column: span 4; } .f3 { grid-column: span 3; } .f2 { grid-column: span 2; }
.help { color: var(--text-3); font-size: 12px; margin-top: 4px; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); font-weight: 600; margin: 18px 0 10px; }
.section-title:first-child { margin-top: 0; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 500; border-radius: 6px; padding: 7px 14px; min-height: 36px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap; text-decoration: none !important; }
.btn:hover { background: var(--surface-2); border-color: var(--text-3); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); border-color: #f0b8b2; }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: rgba(0,0,0,.05); }
.btn.sm { padding: 3px 9px; min-height: 28px; font-size: 12.5px; }
.btn svg { width: 16px; height: 16px; }
.btn.wa { color: #128c4b; border-color: #a7dcbc; }
.btn.wa:hover { background: #e9f8ef; }
.sidebar .btn { background: transparent; color: #cfe3de; border-color: rgba(255,255,255,.2); width: 100%; }
.sidebar .btn:hover { background: rgba(255,255,255,.07); }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 6px 12px; font: inherit; cursor: pointer; color: var(--text-2); border-right: 1px solid var(--border); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--text-2); background: var(--surface-2); position: sticky; top: 0; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #f1f7f5; }
tr.void td { color: var(--text-3); text-decoration: line-through; }
.pager { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); color: var(--text-2); }

/* ---------- tags ---------- */
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 10px; background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border); white-space: nowrap; }
.tag.warn { background: var(--warn-soft); color: var(--warn); border-color: #f5d9ab; }
.tag.danger { background: var(--danger-soft); color: var(--danger); border-color: #f4c0ba; }
.tag.ok { background: var(--ok-soft); color: var(--ok); border-color: #b9e0c6; }
.tag.info { background: var(--info-soft); color: var(--info); border-color: #c4d3f7; }
.tag.accent { background: var(--accent-soft); color: var(--accent); border-color: #b5ddd6; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.st-pendiente { background: var(--surface-2); color: var(--text-2); }
.st-confirmada { background: var(--info-soft); color: var(--info); border-color: #c4d3f7; }
.st-atendida { background: var(--ok-soft); color: var(--ok); border-color: #b9e0c6; }
.st-no_presentado { background: var(--danger-soft); color: var(--danger); border-color: #f4c0ba; }
.st-cancelada { background: #f1f1f1; color: #888; text-decoration: line-through; }

/* ---------- lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 11px 16px; border-bottom: 1px solid var(--border); display: flex; gap: 12px; align-items: center; }
.list > li:last-child { border-bottom: 0; }
.list .time { font-weight: 600; font-variant-numeric: tabular-nums; width: 46px; flex: none; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 600; }
.empty { padding: 28px 16px; text-align: center; color: var(--text-2); }
.empty strong { display: block; color: var(--text); margin-bottom: 4px; }

/* ---------- líneas de factura ---------- */
.lines { border: 1px solid var(--border); border-radius: 6px; padding: 6px; background: var(--surface-2); }
.line { display: grid; grid-template-columns: minmax(0, 1fr) 64px 96px 88px 92px 34px; gap: 6px; align-items: center; margin-bottom: 6px; }
.line:last-child { margin-bottom: 0; }
.line.head { font-size: 12px; color: var(--text-2); font-weight: 600; padding: 0 2px; }
.line input, .line select { min-height: 32px; padding: 5px 8px; }
@media (max-width: 860px) {
  .line { grid-template-columns: 1fr 1fr 1fr; }
  .line > :first-child { grid-column: 1 / -1; }
  .line.head { display: none; }
}

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 14px; font: inherit; font-weight: 500; color: var(--text-2); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button:hover { color: var(--text); }
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tabs .count { font-size: 11px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 0 6px; margin-left: 4px; }

/* ---------- patient header ---------- */
.phead { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 16px; }
.avatar { width: 52px; height: 52px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 18px; flex: none; }
.phead .meta { color: var(--text-2); display: flex; gap: 14px; flex-wrap: wrap; margin-top: 4px; font-size: 13px; }
.alert-box { border: 1px solid #f4c0ba; background: var(--danger-soft); color: var(--danger); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; font-weight: 500; }
.legacy { background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: var(--radius); padding: 12px 14px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline > li { position: relative; padding: 0 0 18px 22px; border-left: 2px solid var(--border); margin-left: 6px; }
.timeline > li::before { content: ""; position: absolute; left: -7px; top: 3px; width: 12px; height: 12px; border-radius: 50%; background: var(--surface); border: 2px solid var(--accent); }
.timeline > li:last-child { border-left-color: transparent; }
.timeline .vhead { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.timeline dl { margin: 0; display: grid; grid-template-columns: 130px 1fr; gap: 4px 12px; }
.timeline dt { color: var(--text-3); font-size: 12.5px; }
.timeline dd { margin: 0; white-space: pre-wrap; }

/* ---------- agenda ---------- */
.agenda-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.agenda { display: grid; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; max-height: calc(100vh - 190px); position: relative; }
.ag-head { position: sticky; top: 0; z-index: 3; background: var(--surface-2); border-bottom: 1px solid var(--border); padding: 8px 6px; text-align: center; font-weight: 600; font-size: 13px; }
.ag-head.today { color: var(--accent); }
.ag-head small { display: block; font-weight: 400; color: var(--text-3); }
.ag-corner { position: sticky; top: 0; left: 0; z-index: 4; background: var(--surface-2); border-bottom: 1px solid var(--border); }
.ag-time { position: sticky; left: 0; z-index: 2; background: var(--surface); font-size: 11.5px; color: var(--text-3); text-align: right; padding: 0 6px; border-right: 1px solid var(--border); transform: translateY(-7px); }
.ag-col { position: relative; border-left: 1px solid var(--border); }
.ag-col.today { background: #fbfefd; }
.ag-col.closed { background: repeating-linear-gradient(135deg, #f6f7f7, #f6f7f7 6px, #eef0ef 6px, #eef0ef 12px); }
.ag-slot { border-bottom: 1px dotted #e6ebe9; cursor: pointer; }
.ag-slot.hour { border-bottom: 1px solid #e1e7e4; }
.ag-slot:hover { background: var(--accent-soft); }
.ag-ev { position: absolute; left: 3px; right: 3px; border-radius: 5px; padding: 3px 6px; font-size: 12px; line-height: 1.25; overflow: hidden; cursor: pointer; background: #e3f2ef; border-left: 4px solid var(--accent); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.ag-ev:hover { z-index: 5; box-shadow: var(--shadow-lg); }
.ag-ev b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ag-ev .t { color: var(--text-2); font-size: 11px; }
.ag-ev.cancelada, .ag-ev.no_presentado { opacity: .5; text-decoration: line-through; }
.ag-ev.atendida { background: #edf7f0; }
.ag-ev .flags { position: absolute; top: 3px; right: 5px; font-size: 10px; font-weight: 700; color: var(--warn); }
.now-line { position: absolute; left: 0; right: 0; height: 2px; background: #e11d48; z-index: 4; pointer-events: none; }
.now-line::before { content: ""; position: absolute; left: -4px; top: -3px; width: 8px; height: 8px; border-radius: 50%; background: #e11d48; }

/* ---------- dropdown / picker ---------- */
.dropdown { background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius); box-shadow: var(--shadow-lg); max-height: 340px; overflow-y: auto; z-index: 50; }
.dropdown .opt { padding: 8px 12px; cursor: pointer; border-bottom: 1px solid var(--border); }
.dropdown .opt:last-child { border-bottom: 0; }
.dropdown .opt:hover, .dropdown .opt.sel { background: var(--accent-soft); }
.dropdown .opt small { color: var(--text-2); display: block; }
.picker { position: relative; }
.picker .dropdown { position: absolute; left: 0; right: 0; top: calc(100% + 2px); }
.picked { display: flex; align-items: center; gap: 8px; border: 1px solid var(--border-strong); border-radius: 6px; padding: 6px 10px; background: var(--accent-soft); }

/* ---------- modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(10, 25, 22, .45); display: grid; place-items: center; padding: 16px; z-index: 100; animation: fade .12s ease-out; }
.modal { background: var(--surface); border-radius: 10px; box-shadow: var(--shadow-lg); width: 100%; max-width: 620px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; animation: pop .14s ease-out; }
.modal.wide { max-width: 860px; }
.modal-h { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.modal-b { padding: 18px 20px; overflow-y: auto; }
.modal-f { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.99); } }

/* ---------- toasts ---------- */
#toasts { position: fixed; bottom: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #17201d; color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow-lg); max-width: 380px; animation: pop .15s ease-out; }
.toast.err { background: var(--danger); }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(160deg, #0d2b27 0%, #13443d 55%, #e3f2ef 55.1%); }
.auth .card { width: 100%; max-width: 400px; padding: 28px; }
.auth .brand-big { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.auth .brand-big img { width: 44px; }
.err-msg { color: var(--danger); background: var(--danger-soft); border-radius: 6px; padding: 8px 10px; font-size: 13px; }

/* ---------- charts ---------- */
.bars { display: grid; grid-template-columns: repeat(12, 1fr); gap: 6px; align-items: end; height: 170px; padding-top: 10px; }
.bars .b { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bars .b span { width: 100%; max-width: 34px; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
.bars .b small { color: var(--text-3); font-size: 11px; margin-top: 4px; }
.bars .b em { font-style: normal; font-size: 11px; color: var(--text-2); margin-bottom: 3px; font-variant-numeric: tabular-nums; }
.hbar { display: grid; grid-template-columns: 160px 1fr 50px; gap: 10px; align-items: center; margin-bottom: 7px; font-size: 13px; }
.hbar .track { background: var(--surface-2); border-radius: 4px; height: 12px; overflow: hidden; }
.hbar .fill { height: 100%; background: var(--accent); border-radius: 4px; }
.hbar .lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- print ---------- */
#print-root { display: none; }
@media print {
  body > *:not(#print-root) { display: none !important; }
  #print-root { display: block; color: #000; font-size: 12px; }
  .print-doc { padding: 10mm; }
  .print-doc h1 { font-size: 18px; }
  .print-doc table td, .print-doc table th { border-bottom: 1px solid #ccc; background: none; }
  .print-head { display: flex; justify-content: space-between; border-bottom: 2px solid #0f766e; padding-bottom: 8px; margin-bottom: 14px; }
  .print-box { border: 1px solid #bbb; padding: 8px 10px; margin-bottom: 10px; white-space: pre-wrap; break-inside: avoid; }
  .print-box b { display: block; font-size: 11px; text-transform: uppercase; color: #444; margin-bottom: 2px; }
}

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .g-dash, .g3 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; z-index: 90; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  .topbar { padding: 10px 16px; }
  .topbar .menu-btn { display: inline-flex; }
  .content { padding: 16px 16px 40px; }
  .g2 { grid-template-columns: 1fr; }
  .fields > * { grid-column: span 12 !important; }
  .timeline dl { grid-template-columns: 1fr; }
  .hbar { grid-template-columns: 110px 1fr 40px; }
  .hide-sm { display: none; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- modo prueba ---------- */
.sandbox-banner { position: sticky; top: 0; z-index: 25; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 8px 24px; background: #f59e0b; color: #1f1500; font-size: 13px; }
.sandbox-banner b { background: #1f1500; color: #fbbf24; padding: 2px 8px; border-radius: 4px; letter-spacing: .05em; }
.sandbox-banner span { flex: 1; min-width: 200px; }
.sandbox-banner .btn { background: #fff7e6; border-color: #b45309; }
body.sandbox .topbar { top: 37px; background: rgba(255, 247, 230, .95); }
body.sandbox .sidebar { border-top: 5px solid #f59e0b; }
body.sandbox .auth { background: linear-gradient(160deg, #78350f 0%, #b45309 55%, #fff7e6 55.1%); }
@media (max-width: 860px) { body.sandbox .topbar { top: 0; } .sandbox-banner { position: static; padding: 8px 16px; } }
.support-banner { background: #c7d2fe; color: #1e1b4b; }
.support-banner b { background: #1e1b4b; color: #c7d2fe; }

/* v2.3: agendas múltiples y fichas por especialidad */
.f1 { grid-column: span 1; } .f5 { grid-column: span 5; }
.ag-slot.off { background: repeating-linear-gradient(135deg, transparent, transparent 6px, rgba(0,0,0,.03) 6px, rgba(0,0,0,.03) 12px); }
.ag-head .ag-name { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.auth .linkish { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }

/* v2.4: diseño adaptable (monitor, tableta y móvil) e idiomas */
.grid > *, .fields > * { min-width: 0; }
.lang-sel { width: auto; min-height: 30px; padding: 3px 8px; font-size: 12.5px; color: var(--text-2); background: transparent; }
.lang-sel.sm { border-color: transparent; }
.card-h { flex-wrap: wrap; }
.modal-h h2 { min-width: 0; overflow-wrap: anywhere; }
/* Tableta: menú lateral más estrecho */
@media (max-width: 1180px) and (min-width: 861px) {
  :root { --sidebar: 200px; }
  .content { padding: 18px 18px 40px; }
  .fields > .f2, .fields > .f3 { grid-column: span 4; }
  .fields > .f4 { grid-column: span 6; }
  .fields > .f8 { grid-column: span 12; }
  .kpis { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
}
/* Móvil y tableta vertical */
@media (max-width: 860px) {
  .g2, .g3, .g-dash { grid-template-columns: minmax(0, 1fr); }
  .sidebar { width: min(280px, 86vw); }
  body.menu-open::after { content: ""; position: fixed; inset: 0; background: rgba(10, 25, 22, .35); z-index: 80; }
  .topbar { gap: 8px; }
  .gsearch { max-width: none; }
  .page-head { align-items: flex-start; }
  .page-head h1 { font-size: 20px; }
  .page-head > .spacer { display: none; }
  .page-head > .row, .page-head > .btn, .page-head > select { flex: 1 1 auto; }
  .card-h { padding: 12px 14px; }
  .card-b { padding: 14px; }
  th, td { padding: 8px 10px; }
  .table-wrap td { white-space: nowrap; }
  .table-wrap td.pre, .table-wrap td .pre { white-space: pre-wrap; min-width: 220px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi .value { font-size: 22px; }
  .tabs { margin-left: -16px; margin-right: -16px; padding: 0 8px; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .modal-bg { padding: 0; place-items: end center; }
  .modal { max-width: none !important; border-radius: 14px 14px 0 0; max-height: 94dvh; }
  .modal-h { padding: 14px 16px; }
  .modal-b { padding: 14px 16px; }
  .modal-f { padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); }
  .modal-f .btn { flex: 1 1 auto; }
  #toasts { left: 12px; right: 12px; bottom: 12px; }
  .toast { max-width: none; }
  .agenda { max-height: calc(100dvh - 210px); }
  .hbar { grid-template-columns: 96px 1fr 40px; }
  .bars { gap: 3px; }
  .bars .b em { font-size: 9.5px; }
  .timeline dl { grid-template-columns: 1fr; }
  .list > li { flex-wrap: wrap; }
}
@media (max-width: 480px) {
  .content { padding: 12px 12px 32px; }
  .tabs { margin-left: -12px; margin-right: -12px; }
  .auth .card { padding: 20px; }
  .kpi { padding: 12px; }
  .seg button { padding: 6px 9px; }
  .line { grid-template-columns: 1fr 1fr; }
  .line > :first-child { grid-column: 1 / -1; }
}
/* Pantallas táctiles: objetivos más grandes y sin zoom automático en iOS */
@media (pointer: coarse) {
  input, select, textarea { font-size: 16px; min-height: 42px; }
  input[type=checkbox] { width: 20px; height: 20px; min-height: 0; }
  .btn { min-height: 42px; }
  .btn.sm { min-height: 34px; }
  .nav a { padding: 12px 10px; }
  .tabs button { padding: 12px 14px; }
}
