:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --ink: #1d2433;
  --muted: #6b7385;
  --line: #e3e6ec;
  --accent: #1f4e79;
  --accent-soft: #e8eff7;
  --pos: #137a4b;
  --neg: #b42318;
  --warn: #9a6700;
  --warn-soft: #fff6dd;
  --radius: 8px;
  --side: 220px;
  font-size: 14px;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; color: var(--ink); background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
h1 { font-size: 22px; margin: 0; font-weight: 600; }
h2 { font-size: 16px; margin: 0 0 12px; font-weight: 600; }
h3 { font-size: 14px; margin: 0 0 8px; font-weight: 600; }
small, .muted { color: var(--muted); }
.num, td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

/* layout */
.shell { display: flex; min-height: 100vh; }
.side { width: var(--side); background: #17263a; color: #cfd8e6; display: flex; flex-direction: column; position: fixed; inset: 0 auto 0 0; }
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand b { color: #fff; display: block; }
.brand small { color: #93a3ba; }
.logo { background: #fff; color: #17263a; font-weight: 700; border-radius: 6px; width: 34px; height: 34px; display: grid; place-items: center; }
nav { display: flex; flex-direction: column; padding: 10px 8px; gap: 2px; flex: 1; }
nav a { color: #cfd8e6; padding: 9px 12px; border-radius: 6px; }
nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
nav a.active { background: rgba(255,255,255,.12); color: #fff; font-weight: 600; }
.me { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,.08); }
.me div:first-child { color: #fff; }
.me small { color: #93a3ba; text-transform: capitalize; }
.me-actions { margin-top: 6px; font-size: 12px; }
.me-actions a { color: #9fc3ea; }
.view { margin-left: var(--side); padding: 24px 28px 60px; flex: 1; min-width: 0; }

.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.crumbs { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.card.flush { padding: 0; }
.card.flush > h2 { padding: 14px 18px 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 1100px) { .grid2 { grid-template-columns: 1fr; } }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi .lbl { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.kpi .val { font-size: 21px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .val small { font-size: 12px; font-weight: 400; }
.kpi.main { background: var(--accent); color: #fff; border-color: var(--accent); }
.kpi.main .lbl { color: #c9d9ea; }

/* composición */
.stack { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--line); margin: 6px 0 10px; }
.stack span { height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 13px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }

/* tablas */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .02em; background: #fafbfc; position: sticky; top: 0; }
tbody tr:hover { background: #f8fafc; }
tr.click { cursor: pointer; }
tr.sub td { background: #fafbfc; font-size: 13px; color: var(--muted); }
tfoot td { font-weight: 600; border-top: 2px solid var(--line); border-bottom: 0; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

.tag { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; background: var(--accent-soft); color: var(--accent); white-space: nowrap; }
.tag.gray { background: #eef0f3; color: var(--muted); }
.tag.warn { background: var(--warn-soft); color: var(--warn); }
.tag.in { background: #e6f4ec; color: var(--pos); }
.tag.out { background: #fdecea; color: var(--neg); }

.alert { background: var(--warn-soft); color: var(--warn); border: 1px solid #f1dfa6; border-radius: var(--radius); padding: 10px 14px; margin-bottom: 16px; }
.info { background: var(--accent-soft); color: var(--accent); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 12px; font-size: 13px; }

/* tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { background: none; border: 0; padding: 9px 14px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; font: inherit; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

/* formularios */
button, .btn { font: inherit; border: 1px solid var(--line); background: #fff; color: var(--ink); border-radius: 6px; padding: 7px 14px; cursor: pointer; }
button:hover, .btn:hover { background: #f3f5f8; text-decoration: none; }
.btn-primary, button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover, button.primary:hover { background: #183f63; }
button.danger { color: var(--neg); }
button.link { border: 0; background: none; color: var(--accent); padding: 0; }
button.sm { padding: 3px 9px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; border: 1px solid #cfd4dc; border-radius: 6px; padding: 7px 10px; background: #fff; color: var(--ink); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #b7cde4; border-color: var(--accent); }
input.num { text-align: right; }
textarea { min-height: 60px; resize: vertical; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.form { display: grid; grid-template-columns: repeat(12, 1fr); gap: 12px 14px; }
.f { grid-column: span 6; }
.f.s3 { grid-column: span 3; } .f.s4 { grid-column: span 4; } .f.s8 { grid-column: span 8; } .f.s12 { grid-column: span 12; }
@media (max-width: 700px) { .f, .f.s3, .f.s4, .f.s8 { grid-column: span 12; } }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink); }
.check input { width: auto; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filters > div { min-width: 150px; }
.inline-pair { display: flex; gap: 6px; }
.inline-pair select { width: 90px; flex: none; }

.summary-box { background: #f8fafc; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.summary-box .row { display: flex; justify-content: space-between; padding: 3px 0; }
.summary-box .row.total { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 8px; font-weight: 600; font-size: 15px; }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 36, .45); display: grid; place-items: start center; padding: 6vh 16px; z-index: 50; overflow-y: auto; }
.modal { background: #fff; border-radius: 10px; width: min(760px, 100%); box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal.wide { width: min(980px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; }
.modal-body { padding: 18px 20px; }
.modal-foot { display: flex; justify-content: space-between; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); background: #fafbfc; border-radius: 0 0 10px 10px; }
.modal-foot .right { display: flex; gap: 8px; margin-left: auto; }
.x { border: 0; background: none; font-size: 22px; line-height: 1; color: var(--muted); padding: 0 4px; }
.err { color: var(--neg); background: #fdecea; border-radius: 6px; padding: 8px 12px; margin-bottom: 12px; }
.ok { color: #1e6b3a; background: #e6f4ea; border-radius: 6px; padding: 8px 12px; margin-bottom: 12px; }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, #17263a, #1f4e79); }
.auth-card { background: #fff; padding: 30px; border-radius: 12px; width: min(380px, 92vw); box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.auth-card h1 { margin-bottom: 4px; }
.auth-card form > div { margin-top: 14px; }
.auth-card button { width: 100%; margin-top: 20px; padding: 10px; }

.toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 80; }
.toast { background: #17263a; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: 0 8px 20px rgba(0,0,0,.2); max-width: 420px; }
.toast.error { background: var(--neg); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.px-box { padding: 12px 16px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; color: #93a3ba; }
.px-box button { margin-top: 8px; width: 100%; background: rgba(255,255,255,.08); color: #fff; border-color: rgba(255,255,255,.15); font-size: 13px; }
.px-box button:hover { background: rgba(255,255,255,.16); }
.px-err { color: #f3b8b2; }
.yahoo-box { background: #f8fafc; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; }
.yahoo-box small { display: block; margin-top: 6px; }
small.stale { color: var(--warn); font-weight: 600; }

.sub-box { background: #f8fafc; border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.f.s2 { grid-column: span 2; }
.tag.short { background: #f3e8fd; color: #6a2c91; }

.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.perf-kpis .val { font-size: 19px; }
.chart-legend { display: flex; gap: 16px; font-size: 13px; margin-bottom: 6px; color: var(--ink); }
.chart-legend i, .ch-tip i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.ch-grid { stroke: #eceef2; stroke-width: 1; }
.ch-lbl { font-size: 11px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.ch-cross { stroke: #9aa3b2; stroke-width: 1; }
.ch-tip { position: absolute; background: #fff; border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; font-size: 12px;
  box-shadow: 0 6px 18px rgba(0,0,0,.12); pointer-events: none; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ch-tip b { display: block; margin-bottom: 4px; }
a.sm-btn { padding: 3px 9px; font-size: 12px; }
/* informe */
.report-bar { display: flex; gap: 16px; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.report { max-width: 1050px; }
.rep-head { display: flex; justify-content: space-between; align-items: flex-end; border-bottom: 2px solid var(--accent); padding-bottom: 12px; margin-bottom: 16px; }
.brand-r { display: flex; gap: 10px; align-items: center; }
.brand-r .logo { background: var(--accent); color: #fff; }
.rep-client { text-align: right; }
.rep-sec { margin: 22px 0 10px; }
body.report-mode .side { display: none; }
body.report-mode .view { margin-left: 0; padding: 24px 32px; }
@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; font-size: 11px; }
  .no-print, .side, .toasts, #modal-root { display: none !important; }
  .view { margin: 0 !important; padding: 0 !important; }
  .card, .kpi { box-shadow: none; break-inside: avoid; }
  .rep-keep, tr { break-inside: avoid; }
  .rep-sec { break-after: avoid; }
  th { position: static; white-space: normal; }
  .tbl-wrap { overflow: visible; }
  table { font-size: 8.5px; }
  th, td { padding: 4px 5px; }
  th { font-size: 7.5px; }
  .card { padding: 10px 12px; margin-bottom: 10px; }
  .card.flush > h2 { padding: 10px 12px 0; }
  h2 { font-size: 13px; }
  .kpi .val { font-size: 16px; }
  .grid2 { grid-template-columns: 1fr 1fr !important; gap: 10px; }
  .report { max-width: none; }
  button.link { display: none; }
  .kpi.main { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .stack span, .legend i, .chart-legend i, .tag, .brand-r .logo { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .ch-tip, .ch-cross, .ch-dot { display: none; }
}

.sim-op { border-bottom: 1px dashed var(--line); padding-bottom: 10px; margin-bottom: 10px; }
.f.s1 { grid-column: span 1; }
.steps { display: flex; gap: 18px; margin-bottom: 14px; font-size: 13px; color: var(--muted); }
.steps .on { color: var(--accent); font-weight: 600; }
.steps .done { color: var(--pos); }
table.mini { font-size: 12px; }
table.mini th, table.mini td { padding: 5px 8px; white-space: nowrap; }
tr.muted td { color: var(--muted); }

.grid2 > * { min-width: 0; }

tr.hl td { background: var(--accent-soft); }
.sens-grid { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 16px; align-items: start; }
@media (max-width: 1100px) { .sens-grid { grid-template-columns: 1fr; } }

.back-btn { border: 0; background: none; color: var(--accent); padding: 0; margin-bottom: 6px; font-size: 13px; cursor: pointer; }
.back-btn:hover { text-decoration: underline; background: none; }

.slider-box { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line); }
.slider-box input[type=range] { width: 100%; padding: 0; border: 0; accent-color: var(--accent); }
#sens-slider-lbl { font-size: 14px; margin-top: 4px; }
.scenario-banner { background: var(--accent-soft); color: var(--ink); border-left: 4px solid var(--accent); border-radius: 6px;
  padding: 10px 14px; margin-bottom: 14px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
#sim-res.loading { opacity: .5; pointer-events: none; transition: opacity .15s; }
table.tgt input { padding: 4px 8px; }

.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 1200px) { .grid3 { grid-template-columns: 1fr; } }
@media print { .grid3 { grid-template-columns: 1fr 1fr 1fr !important; gap: 10px; } }
.op-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.op-btn { text-align: left; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.op-btn small { color: var(--muted); }
.op-btn:hover { border-color: var(--accent); background: var(--accent-soft); }

table.pos-cons th, table.pos-cons td { padding: 7px 8px; }
table.pos-cons td:nth-child(3) small { white-space: nowrap; }
