/* Layout: barra superior fija, filtros en una fila que se envuelve, pestañas, paneles en rejilla de 12 columnas que colapsan a 1 en móvil */
:root {
  --bg: #eef1f4;
  --panel: #ffffff;
  --panel-2: #f6f8fa;
  --ink: #15202b;
  --ink-2: #4a5866;
  --muted: #6f7c89;
  --line: #dbe1e7;
  --line-2: #e9edf1;
  --accent: #1f5a92;
  --accent-2: #e2702f;
  --accent-soft: #e3edf7;
  --on-accent: #ffffff;
  --s-fijo: #2a78d6;
  --s-var: #eb6834;
  --s-3: #1baf7a;
  --s-gray: #6f7c89; --s-violet: #6250d6; --s-yellow: #c98500; --s-magenta: #d55181;
  --target: #15202b;
  --good: #1b7f4c; --good-bg: #e2f3ea;
  --warn: #a8670a; --warn-bg: #fbf0dc;
  --bad: #c0392b;  --bad-bg: #fbe6e3;
  --info: #1f5a92; --info-bg: #e3edf7;
  --shadow: 0 1px 2px rgba(21,32,43,.06), 0 4px 16px rgba(21,32,43,.05);
  --f-display: "Saira Semi Condensed", "Arial Narrow", "Roboto Condensed", system-ui, sans-serif;
  --f-body: "Archivo", "Segoe UI", system-ui, -apple-system, sans-serif;
  --r: 10px;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #0e1318; --panel: #161d24; --panel-2: #1b232b; --ink: #e5eaef; --ink-2: #b4bfca; --muted: #8b98a5;
  --line: #2a343e; --line-2: #222b34; --accent: #5ea0e6; --accent-2: #ef8a4f; --accent-soft: #1b2f44; --on-accent: #0b1520;
  --s-fijo: #3987e5; --s-var: #d95926; --s-3: #199e70; --s-gray: #9aa6b2; --s-violet: #9085e9; --s-yellow: #e0a325; --s-magenta: #e87ba4; --target: #e5eaef;
  --good: #4cc185; --good-bg: #13301f; --warn: #e3a547; --warn-bg: #352712; --bad: #ef7466; --bad-bg: #3a1a17; --info: #7cb4ee; --info-bg: #17293b;
  --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
} }
:root[data-theme="dark"] {
  --bg: #0e1318; --panel: #161d24; --panel-2: #1b232b; --ink: #e5eaef; --ink-2: #b4bfca; --muted: #8b98a5;
  --line: #2a343e; --line-2: #222b34; --accent: #5ea0e6; --accent-2: #ef8a4f; --accent-soft: #1b2f44; --on-accent: #0b1520;
  --s-fijo: #3987e5; --s-var: #d95926; --s-3: #199e70; --s-gray: #9aa6b2; --s-violet: #9085e9; --s-yellow: #e0a325; --s-magenta: #e87ba4; --target: #e5eaef;
  --good: #4cc185; --good-bg: #13301f; --warn: #e3a547; --warn-bg: #352712; --bad: #ef7466; --bad-bg: #3a1a17; --info: #7cb4ee; --info-bg: #17293b;
  --shadow: 0 1px 2px rgba(0,0,0,.3); color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; }
img { max-width: 100%; }
body { background: var(--bg); color: var(--ink); font-family: var(--f-body); font-size: 14px; line-height: 1.45; }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--f-display); margin: 0; text-wrap: balance; letter-spacing: .01em; }
h2 { font-size: 1.15rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
.num, td.n, .kpi-value { font-variant-numeric: tabular-nums; }

.topbar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 30; background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar-in, .wrap { max-width: 1440px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.topbar-in { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-block: 10px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 34px; height: 34px; flex: none; }
.brand-name { font-family: var(--f-display); font-weight: 700; font-size: 1.25rem; line-height: 1.1; }
.brand-sub { color: var(--muted); font-size: .8rem; overflow-wrap: anywhere; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); padding: 7px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; font-size: .875rem; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: .8rem; }
.btn:focus-visible, button:focus-visible, input:focus-visible, label.btn:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }

.wrap { padding-block: 14px 28px; display: flex; flex-direction: column; gap: 14px; }
.demo-banner { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; background: var(--warn-bg); color: var(--ink); border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent); padding: 10px 14px; border-radius: var(--r); }
.demo-banner span { flex: 1 1 320px; color: var(--ink-2); }

/* filtros */
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.fchip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 5px 12px; cursor: pointer; font-size: .82rem; max-width: 100%; }
.fchip .fl { color: var(--muted); }
.fchip .fv { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }
.fchip.on { border-color: var(--accent); background: var(--accent-soft); }
.fchip .caret { color: var(--muted); font-size: .7rem; }
.fdate { display: inline-flex; align-items: center; gap: 6px; font-size: .82rem; color: var(--muted); background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 3px 6px 3px 12px; }
.fdate input { border: 0; background: transparent; padding: 2px 4px; font-size: .82rem; }
.flink { background: none; border: 0; color: var(--accent); cursor: pointer; font-weight: 600; font-size: .82rem; padding: 5px 6px; }

.popover { position: fixed; z-index: 60; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); box-shadow: 0 10px 30px rgba(0,0,0,.18); width: min(340px, calc(100vw - 24px)); max-height: min(440px, 70vh); display: flex; flex-direction: column; }
.pop-h { padding: 10px; border-bottom: 1px solid var(--line-2); display: flex; flex-direction: column; gap: 8px; }
.pop-h input[type=search] { width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; background: var(--panel-2); }
.pop-acts { display: flex; gap: 10px; font-size: .8rem; }
.pop-acts button { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font-weight: 600; }
.pop-list { overflow: auto; padding: 4px 0; }
.pop-item { display: flex; align-items: flex-start; gap: 8px; padding: 5px 12px; cursor: pointer; font-size: .84rem; }
.pop-item:hover { background: var(--panel-2); }
.pop-item input { margin-top: 3px; }
.pop-f { padding: 8px 10px; border-top: 1px solid var(--line-2); display: flex; justify-content: flex-end; gap: 8px; }

/* pestañas */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.tabs button { background: none; border: 0; padding: 10px 14px; cursor: pointer; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent-2); }
.tabs button:hover { color: var(--ink); }
.tab-panel { display: flex; flex-direction: column; gap: 14px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; min-width: 0; }
.panel-h { display: flex; align-items: baseline; justify-content: space-between; gap: 8px 12px; flex-wrap: wrap; margin-bottom: 10px; }
.hint, .note { color: var(--muted); font-size: .8rem; }
.note { margin: 6px 0 0; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.grid-a { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: 14px; }
.resumen-grid { grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); }
@media (max-width: 980px) { .grid-2, .grid-3, .grid-a, .resumen-grid { grid-template-columns: minmax(0, 1fr); } }

/* KPIs */
.kpi-groups { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 1100px) { .kpi-groups { grid-template-columns: minmax(0, 1fr); } }
.kgroup { background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 12px 14px 14px; }
.kgroup-t { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; margin-bottom: 8px; }
.kgrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0; }
.kpi { padding: 10px 10px 10px 0; border-top: 1px solid var(--line-2); min-width: 0; }
.kpi:nth-child(-n+2) { border-top: 0; }
.kpi:nth-child(2n) { padding-left: 12px; border-left: 1px solid var(--line-2); padding-right: 0; }
.kpi-label { font-size: .8rem; color: var(--ink-2); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.kpi-value { font-family: var(--f-display); font-weight: 600; font-size: 1.7rem; line-height: 1.15; margin-top: 2px; letter-spacing: -.005em; }
.kpi-sub { font-size: .76rem; color: var(--muted); margin-top: 2px; }
.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0; background: var(--panel); border: 1px solid var(--line); border-radius: var(--r); padding: 4px 16px; }
.kpi-row .kpi { border-top: 0; padding: 10px 12px 10px 0; border-left: 0 !important; padding-left: 0 !important; }
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: .68rem; font-weight: 700; padding: 1px 7px; border-radius: 999px; letter-spacing: .02em; }
.pill.good { background: var(--good-bg); color: var(--good); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }

/* insights */
.insights { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.insights li { display: grid; grid-template-columns: 4px minmax(0, 1fr); gap: 10px; padding: 8px 10px 8px 0; background: var(--panel-2); border-radius: 8px; overflow: hidden; }
.insights .sev { border-radius: 0 3px 3px 0; }
.insights .sev.bad { background: var(--bad); } .insights .sev.warn { background: var(--warn); } .insights .sev.good { background: var(--good); } .insights .sev.info { background: var(--info); }
.insights .it { font-weight: 600; font-size: .88rem; }
.insights .ix { color: var(--ink-2); font-size: .82rem; margin-top: 2px; }
.insights .ia { margin-top: 4px; }
.insights .ia button { background: none; border: 0; padding: 0; color: var(--accent); font-weight: 600; cursor: pointer; font-size: .8rem; }

/* charts */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .ax text, .chart text { fill: var(--muted); font-size: 11px; font-family: var(--f-body); }
.chart .grid line { stroke: var(--line-2); }
.chart .base { stroke: var(--line); }
.chart .tgt { stroke: var(--target); stroke-dasharray: 4 4; stroke-width: 1.2; opacity: .55; }
.chart .tgt-l { fill: var(--ink-2); font-size: 10.5px; }
.chart .hover-band { fill: var(--ink); opacity: .05; }
.chart .empty { fill: var(--muted); font-size: 13px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .8rem; color: var(--ink-2); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.legend i.dash { height: 0; border-top: 2px dashed var(--target); border-radius: 0; width: 14px; opacity: .6; vertical-align: 3px; }
.tooltip { position: fixed; z-index: 70; pointer-events: none; background: var(--ink); color: var(--bg); border-radius: 8px; padding: 8px 10px; font-size: .8rem; line-height: 1.4; max-width: 280px; box-shadow: 0 6px 20px rgba(0,0,0,.25); }
.tooltip b { font-weight: 700; }
.tooltip .tr { display: flex; justify-content: space-between; gap: 14px; }
.tooltip .tr i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }

/* horizontal bars */
.hbars { display: flex; flex-direction: column; gap: 6px; }
.hb { display: grid; grid-template-columns: minmax(90px, 38%) minmax(0, 1fr); gap: 10px; align-items: center; font-size: .8rem; cursor: default; }
.hb.click { cursor: pointer; }
.hb.click:hover .hb-l { color: var(--accent); }
.hb-l { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }
.hb-t { position: relative; height: 20px; display: flex; align-items: center; gap: 8px; }
.hb-b { height: 14px; border-radius: 0 4px 4px 0; background: var(--s-fijo); min-width: 2px; }
.hb-b.over { background: var(--s-var); }
.hb-v { font-variant-numeric: tabular-nums; color: var(--ink); font-weight: 600; white-space: nowrap; }
.hb-tgt { position: absolute; top: -2px; bottom: -2px; border-left: 1.5px dashed var(--target); opacity: .5; }

/* segmented chips */
.seg-row { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; padding: 4px 0; }
.seg-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; min-width: 92px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; min-width: 0; }
.chips button { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 4px 11px; cursor: pointer; font-size: .8rem; }
.chips button[aria-pressed="true"] { background: var(--ink); color: var(--panel); border-color: var(--ink); }

/* tablas */
.table-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.table-tools input[type=search] { border: 1px solid var(--line); border-radius: 8px; padding: 5px 10px; background: var(--panel-2); min-width: 0; width: 210px; max-width: 100%; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: .82rem; color: var(--ink-2); }
.table-wrap { overflow: auto; max-height: 560px; border: 1px solid var(--line-2); border-radius: 8px; }
table.data { border-collapse: separate; border-spacing: 0; width: 100%; font-size: .8rem; }
table.data th { position: sticky; top: 0; background: var(--panel-2); text-align: right; font-weight: 600; color: var(--ink-2); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; cursor: pointer; user-select: none; z-index: 1; }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data th.sorted::after { content: " ▾"; color: var(--accent-2); }
table.data th.sorted.asc::after { content: " ▴"; }
table.data td { padding: 6px 10px; border-bottom: 1px solid var(--line-2); text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.data td:first-child { max-width: 320px; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
table.data tr.click { cursor: pointer; }
table.data tbody tr:hover td { background: var(--panel-2); }
table.data td.good { color: var(--good); font-weight: 600; } table.data td.bad { color: var(--bad); font-weight: 600; } table.data td.warn { color: var(--warn); font-weight: 600; }
table.data tfoot td { font-weight: 700; background: var(--panel-2); position: sticky; bottom: 0; border-top: 1px solid var(--line); }
.cellbar { display: inline-block; height: 6px; border-radius: 3px; background: var(--s-fijo); opacity: .55; margin-left: 8px; vertical-align: middle; }

/* registro bar */
.regbar { display: flex; height: 26px; border-radius: 6px; overflow: hidden; gap: 2px; }
.regbar div { min-width: 2px; }
.reglegend { display: flex; flex-wrap: wrap; gap: 6px 18px; margin-top: 10px; font-size: .82rem; color: var(--ink-2); }
.reglegend b { color: var(--ink); font-variant-numeric: tabular-nums; }
.reglegend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

/* prose */
.prose { max-width: 900px; }
.prose h2 { margin: 18px 0 6px; } .prose h2:first-child { margin-top: 0; }
.prose p, .prose li { color: var(--ink-2); max-width: 75ch; }
.prose dl { display: grid; grid-template-columns: minmax(150px, 220px) minmax(0, 1fr); gap: 8px 18px; margin: 8px 0; }
.prose dt { font-weight: 600; color: var(--ink); }
.prose dd { margin: 0; color: var(--ink-2); }
.prose code { font-size: .82em; background: var(--panel-2); border: 1px solid var(--line-2); padding: 0 4px; border-radius: 4px; overflow-wrap: anywhere; }
@media (max-width: 600px) { .prose dl { grid-template-columns: minmax(0, 1fr); } .prose dd { margin-bottom: 6px; } }

/* modal / loading / toast */
.modal, .loading, .dropzone { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; background: rgba(10,16,22,.45); padding: 16px; }
.modal[hidden], .loading[hidden], .dropzone[hidden] { display: none !important; }
.modal-card, .loading-card { background: var(--panel); border-radius: 12px; padding: 20px; width: min(480px, 100%); box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.goals-form { display: grid; grid-template-columns: minmax(0, 1fr) 120px; gap: 10px 14px; align-items: center; margin: 14px 0; }
.goals-form label { font-size: .88rem; }
.goals-form input { width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; background: var(--panel-2); text-align: right; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.loading-title { font-family: var(--f-display); font-size: 1.2rem; font-weight: 600; }
.progress { height: 8px; background: var(--line-2); border-radius: 4px; overflow: hidden; margin: 14px 0 8px; }
.progress-bar { height: 100%; width: 0; background: var(--accent-2); transition: width .2s; }
.loading-msg { color: var(--muted); font-size: .82rem; min-height: 1.2em; }
.dropzone > div { border: 2px dashed var(--on-accent); color: #fff; font-family: var(--f-display); font-size: 1.5rem; padding: 40px 60px; border-radius: 16px; }
.toast { position: fixed; z-index: 90; left: 50%; transform: translateX(-50%); bottom: calc(20px + env(safe-area-inset-bottom, 0px)); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; font-size: .85rem; max-width: calc(100vw - 32px); }
.toast.err { background: var(--bad); color: #fff; }
.foot { color: var(--muted); font-size: .76rem; text-align: center; padding-top: 6px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media (max-width: 520px) { .kgrid { grid-template-columns: minmax(0, 1fr); } .kpi:nth-child(2n) { padding-left: 0; border-left: 0; } .kpi:nth-child(2) { border-top: 1px solid var(--line-2); } .kpi-value { font-size: 1.5rem; } .seg-label { min-width: 0; } }
.resumen-grid > .panel { display: flex; flex-direction: column; }
.resumen-grid #ch-week { flex: 1 1 auto; min-height: 260px; }
table.data th.txt, table.data td.txt { text-align: left; }
.chart .tgt-l { paint-order: stroke; stroke: var(--panel); stroke-width: 3px; stroke-linejoin: round; }
#q-kpis { grid-template-columns: repeat(4, minmax(0, 1fr)); }
#trip-kpis { grid-template-columns: repeat(6, minmax(0, 1fr)); }
@media (max-width: 1100px) { #trip-kpis { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 760px) { #q-kpis, #trip-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* ===== Páginas PHP ===== */
a.brand { color: inherit; text-decoration: none; }
.top-actions { align-items: center; }
.navlink { color: var(--ink-2); text-decoration: none; font-weight: 600; font-size: .88rem; padding: 6px 10px; border-radius: 8px; }
.navlink:hover { background: var(--panel-2); color: var(--ink); }
.navlink.on { color: var(--ink); background: var(--accent-soft); }
.who { color: var(--muted); font-size: .82rem; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
form.inline { display: inline-flex; align-items: center; gap: 6px; margin: 0; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.wrap.narrow { max-width: 1100px; }
.tabs-row { display: flex; align-items: flex-end; gap: 10px; border-bottom: 1px solid var(--line); }
.tabs-row .tabs { border-bottom: 0; flex: 1; min-width: 0; }
.tabs-row #btn-goals { margin-bottom: 6px; }
#main { position: relative; display: flex; flex-direction: column; gap: 14px; }
#main.loading-data .tab-panel { opacity: .55; transition: opacity .15s; }
.busy-bar { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 60px); z-index: 5; height: 3px; border-radius: 2px; background: linear-gradient(90deg, transparent, var(--accent-2), transparent); background-size: 40% 100%; background-repeat: no-repeat; animation: busy 1s linear infinite; }
@keyframes busy { from { background-position: -40% 0; } to { background-position: 140% 0; } }
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-right, 0px)) 24px max(16px, env(safe-area-inset-left, 0px)); }
.auth-card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; width: min(400px, 100%); box-shadow: var(--shadow); }
.auth-card.wide { width: min(620px, 100%); }
.auth-card h1 { font-size: 1.5rem; margin: 14px 0 10px; }
.auth-brand { display: flex; align-items: center; gap: 10px; font-family: var(--f-display); font-weight: 700; font-size: 1.15rem; }
.form-stack { display: flex; flex-direction: column; gap: 6px; }
.form-stack label, .form-grid label { font-size: .85rem; color: var(--ink-2); font-weight: 600; }
.form-stack input, .form-grid input, .form-row input, .form-row select, td select, .in-sm { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: var(--panel-2); width: 100%; }
.form-stack .btn { margin-top: 12px; padding: 10px; }
.form-grid fieldset { border: 1px solid var(--line-2); border-radius: 10px; padding: 12px 14px 14px; margin: 0 0 14px; display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 8px 12px; align-items: center; }
.form-grid legend { font-weight: 700; padding: 0 6px; }
@media (max-width: 520px) { .form-grid fieldset { grid-template-columns: minmax(0, 1fr); } }
.form-row { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.form-row label { display: flex; flex-direction: column; gap: 4px; font-size: .82rem; color: var(--ink-2); font-weight: 600; flex: 1 1 160px; }
td select { width: auto; padding: 4px 8px; }
.in-sm { width: 150px; padding: 4px 8px; }
.errmsg, .okmsg { padding: 9px 12px; border-radius: 8px; font-size: .88rem; margin: 8px 0; }
.errmsg { background: var(--bad-bg); color: var(--bad); }
.okmsg { background: var(--good-bg); color: var(--good); }
.upload-box { border: 2px dashed var(--line); border-radius: 12px; padding: 28px 16px; display: flex; gap: 12px; align-items: center; justify-content: center; flex-wrap: wrap; margin: 12px 0; background: var(--panel-2); }
.upload-box.over { border-color: var(--accent); background: var(--accent-soft); }
.modes { border: 0; padding: 0; margin: 6px 0 0; display: flex; flex-direction: column; gap: 8px; }
.modes legend { font-weight: 700; margin-bottom: 6px; }
.radio { display: grid; grid-template-columns: 20px minmax(0, 1fr); gap: 6px; font-size: .86rem; color: var(--ink-2); cursor: pointer; }
.radio input { margin-top: 3px; }
.import-status { margin-top: 16px; padding: 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); }

/* ===== v2: pulido visual y exportaciones ===== */
.topbar { box-shadow: 0 1px 0 var(--line), 0 6px 18px rgba(21,32,43,.04); border-bottom: 0; }
.tabs-actions { display: flex; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.tabs-actions .btn svg { margin-right: 2px; }
.period-line { margin: -4px 0 0; font-size: .8rem; color: var(--muted); }
.period-line b { color: var(--ink-2); font-weight: 600; }
.panel { box-shadow: var(--shadow); }
.panel-h .hint { margin-left: auto; }
.panel-h h2, .panel-h h3 { margin-right: auto; }
.panel-h .hint + .xl-btn { margin-left: 4px; }
.xl-btn { display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--line); background: var(--panel); color: var(--ink-2); font: 600 .74rem/1 var(--f-body); padding: 5px 9px 5px 7px; border-radius: 7px; cursor: pointer; white-space: nowrap; }
.xl-btn svg { width: 13px; height: 13px; color: var(--good); }
.xl-btn:hover { border-color: var(--good); color: var(--ink); background: var(--good-bg); }
.xl-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.kgroup { box-shadow: var(--shadow); padding: 14px 16px 12px; }
.kgroup-t { display: flex; align-items: center; gap: 8px; }
.kgroup-t::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: var(--accent-2); }
.kpi { padding-bottom: 12px; }
.kpi-main { display: block; }
.kpi-main .kpi-value { white-space: nowrap; font-size: clamp(1.35rem, 1.1rem + .7vw, 1.7rem); }
.spark { display: block; width: 100%; height: 20px; margin: 4px 0 2px; overflow: visible; }
.spark-line { fill: none; stroke: var(--s-fijo); stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.spark-area { fill: var(--s-fijo); opacity: .10; }
.spark-dot { fill: var(--s-fijo); stroke: var(--panel); stroke-width: 1.2; }
.kpi-delta { font-size: .72rem; color: var(--muted); margin-top: 4px; }
.kpi-delta span { font-weight: 700; padding: 1px 6px; border-radius: 999px; margin-right: 2px; font-variant-numeric: tabular-nums; }
.kpi-delta.neutral span { background: var(--panel-2); color: var(--ink-2); }
.kpi-delta.up-good span { background: var(--good-bg); color: var(--good); }
.kpi-delta.up-bad span { background: var(--bad-bg); color: var(--bad); }
.hb { grid-template-columns: minmax(110px, 40%) minmax(0, 1fr); }
.hb-l { display: flex; align-items: center; gap: 8px; font-size: .78rem; text-transform: none; }
.hb-rank { flex: none; width: 20px; height: 20px; border-radius: 6px; display: inline-grid; place-items: center; background: var(--panel-2); color: var(--muted); font-size: .68rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.hb:nth-child(-n+3) .hb-rank { background: var(--accent-soft); color: var(--accent); }
.hb-b { height: 16px; border-radius: 0 5px 5px 0; }
.hb { padding: 2px 0; border-radius: 6px; }
.hb.click:hover { background: var(--panel-2); }
table.data tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--panel-2) 45%, transparent); }
table.data th { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; }
.tabs button { font-size: .9rem; }
.tabs button[aria-selected="true"] { border-bottom-width: 3px; }
td.acts { white-space: nowrap; }
@media (min-width: 900px) {
  .filters { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 62px); z-index: 20; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(6px); padding: 8px 0; margin: -8px 0; }
}
.hb-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 700px) { .tabs-row { flex-direction: column; align-items: stretch; gap: 0; } .tabs-actions { margin: 6px 0; } }

/* ===== Gráfico combinado ===== */
.chart .ax-title { fill: var(--muted); font-size: 10.5px; font-weight: 600; letter-spacing: .02em; }
.chart .dl-in { fill: #fff; font-size: 9.5px; font-weight: 700; paint-order: stroke; stroke: rgba(0,0,0,.18); stroke-width: 2px; }
.chart .dl-out { fill: var(--ink); font-size: 9.5px; font-weight: 600; }
.chart .dl-line { font-size: 9.5px; font-weight: 700; }
.chart .dl-pill { fill: var(--panel); stroke: var(--line); stroke-width: 1; opacity: .95; }
.combo-tools { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: flex-start; padding: 10px 0 12px; border-top: 1px solid var(--line-2); border-bottom: 1px solid var(--line-2); margin-bottom: 10px; }
.combo-tools .ct { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.combo-tools .ct-l { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: var(--panel); padding: 5px 11px; font-size: .8rem; cursor: pointer; color: var(--ink-2); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--panel); }
.mchips { display: flex; flex-wrap: wrap; gap: 5px; max-width: 520px; }
.mchips button { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 3px 10px 3px 7px; font-size: .78rem; cursor: pointer; color: var(--ink-2); }
.mchips button i { width: 10px; height: 10px; border-radius: 3px; background: var(--line); }
.mchips button.line i { height: 3px; border-radius: 2px; width: 14px; }
.mchips button[aria-pressed="true"] { border-color: var(--ink-2); color: var(--ink); font-weight: 600; background: var(--panel-2); }
.presets { display: flex; flex-wrap: wrap; gap: 6px; }
.presets button { border: 1px dashed var(--line); background: transparent; border-radius: 8px; padding: 4px 10px; font-size: .78rem; cursor: pointer; color: var(--accent); font-weight: 600; }
.presets button[aria-pressed="true"] { border-style: solid; background: var(--accent-soft); }
.combo-note { font-size: .76rem; color: var(--muted); margin-top: 6px; }
.legend i.lnk { height: 3px; width: 16px; border-radius: 2px; vertical-align: 3px; }
.combo-custom { flex-basis: 100%; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; padding-top: 4px; }
.combo-custom .mchips { max-width: none; }
@media (max-width: 800px) { .combo-custom { grid-template-columns: minmax(0, 1fr); } }
