:root {
  color-scheme: light;
  --page: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f1f2f5;
  --ink: #16181d;
  --ink-2: #6b7080;
  --line: #e4e6eb;
  --axis: #c3c7d0;
  --accent: #257de0;
  --accent-soft: #e9f2fd;
  --pos: #257de0;
  --neg: #ec4647;
  --pos-text: #0b7a33;
  --neg-text: #c22c2d;
  --good-bg: #eaf6ee;
  --bad-bg: #fdeeee;
  --spark: #257de0;
  --warn-bg: #fff6e0;
  --warn-line: #f2c35b;
  --err-bg: #fdecec;
  --err-line: #ec9a9a;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  --font: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--page); color: var(--ink); font: 14px/1.45 var(--font); }
button, input, select { font: inherit; color: inherit; }
a { color: inherit; }
svg { stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Estructura ---------- */
.app { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 18px;
  background: var(--surface); border-right: 1px solid var(--line); padding: 16px 12px;
}
.side-brand { display: flex; gap: 10px; align-items: center; padding: 2px 6px 6px; }
.side-brand b { display: block; font-size: 15px; }
.side-brand small { display: block; color: var(--ink-2); font-size: 12px; }
.logo {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-weight: 700;
}
.side-nav { display: grid; gap: 2px; flex: 1; align-content: start; }
.tab, .side-link {
  display: flex; gap: 10px; align-items: center; width: 100%; border: 0; background: none; cursor: pointer;
  padding: 8px 10px; border-radius: 8px; color: var(--ink-2); text-align: left; white-space: nowrap;
}
.tab svg, .side-link svg { width: 18px; height: 18px; flex: none; }
.tab:hover, .side-link:hover { background: var(--surface-2); color: var(--ink); }
.tab[aria-selected="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.side-settings { margin-top: 12px; }

.main-col { min-width: 0; }
.top {
  position: sticky; top: 0; z-index: 6; background: rgba(255, 255, 255, .92); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line); padding: 10px max(24px, calc((100% - 1280px) / 2 + 24px));
  display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center;
}
.crumbs { margin-right: auto; }
.crumb { color: var(--ink-2); font-size: 13px; }
.crumb b { color: var(--ink); font-size: 14px; }
.status { color: var(--ink-2); font-size: 12px; white-space: nowrap; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.inline-label { display: flex; gap: 8px; align-items: center; color: var(--ink-2); font-size: 13px; }

main { max-width: 1280px; margin: 0 auto; padding: 20px 24px 56px; display: grid; gap: 20px; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; align-items: center; gap: 8px; padding: 8px 12px; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .side-brand { padding: 0 8px 0 0; }
  .side-brand small { display: none; }
  .side-nav { display: flex; flex: none; }
  .side-settings { margin-top: 0; }
  .tab, .side-link { width: auto; }
  .top { position: static; padding: 10px 14px; }
  main { padding: 14px 14px 48px; }
}

/* ---------- Controles ---------- */
select, input[type="date"], input[type="number"], input[type="text"], input[type="password"] {
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-height: 36px;
}
input[type="number"] { width: 110px; }
.btn {
  display: inline-flex; gap: 6px; align-items: center; justify-content: center;
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px; padding: 7px 12px; cursor: pointer; min-height: 36px;
}
.btn svg { width: 16px; height: 16px; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { background: #1f6cc4; }
.btn.small { padding: 3px 8px; min-height: 28px; font-size: 13px; }
.btn:disabled { opacity: .6; cursor: default; }

.datepick { position: relative; }
.picker { font-weight: 500; }
.picker .chev { width: 14px; height: 14px; color: var(--ink-2); }
.pop {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 10; width: 340px; max-width: calc(100vw - 28px);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(16, 24, 40, .14); padding: 12px; display: grid; gap: 12px;
}
.pop[hidden] { display: none; }
.presets { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.presets button {
  border: 0; background: none; text-align: left; padding: 7px 10px; border-radius: 8px; cursor: pointer; color: var(--ink);
}
.presets button:hover { background: var(--surface-2); }
.presets button.on { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.custom { display: flex; gap: 8px; align-items: end; border-top: 1px solid var(--line); padding-top: 12px; flex-wrap: wrap; }
.custom input { width: 130px; }

/* ---------- Secciones y tarjetas ---------- */
.section { display: grid; gap: 12px; }
.section-head { display: flex; gap: 8px; align-items: center; }
.section-head svg { width: 18px; height: 18px; color: var(--ink-2); }
.section-head h2 { margin: 0; font-size: 17px; font-weight: 650; }
.section-head .sub { color: var(--ink-2); font-size: 13px; margin-left: 4px; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 1100px) { .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 520px) { .metrics { grid-template-columns: 1fr; } }
.metric {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px 16px 10px; min-width: 0; display: flex; flex-direction: column;
}
.metric.featured.pos-bg { background: var(--good-bg); border-color: #cfe9d7; }
.metric.featured.neg-bg { background: var(--bad-bg); border-color: #f3d0d0; }
.m-head { display: flex; gap: 6px; align-items: center; color: var(--ink-2); font-size: 13px; }
.m-head svg { width: 15px; height: 15px; flex: none; }
.m-head .label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.delta { margin-left: auto; font-size: 12px; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.delta.good { color: var(--pos-text); }
.delta.bad { color: var(--neg-text); }
.delta.flat { color: var(--ink-2); }
.m-value { font-size: 26px; font-weight: 650; letter-spacing: -.01em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.m-note { color: var(--ink-2); font-size: 12px; margin-top: 1px; }
.m-foot { margin-top: auto; }

.spark { position: relative; height: 52px; margin-top: 8px; cursor: crosshair; }
.spark svg { display: block; width: 100%; height: 100%; overflow: visible; }
.spark .line { stroke: var(--spark); stroke-width: 2; vector-effect: non-scaling-stroke; }
.spark .area { fill: var(--spark); opacity: .08; stroke: none; }
.spark .zero { stroke: var(--axis); stroke-width: 1; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }
.spark .dot {
  position: absolute; width: 9px; height: 9px; margin: -4.5px 0 0 -4.5px; border-radius: 50%;
  background: var(--spark); box-shadow: 0 0 0 2px var(--surface); display: none; pointer-events: none;
}
.spark .vline { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--axis); display: none; pointer-events: none; }
.spark .stip {
  position: absolute; bottom: calc(100% + 6px); transform: translateX(-50%); pointer-events: none; display: none; z-index: 4;
  background: var(--ink); color: #fff; border-radius: 6px; padding: 4px 8px; font-size: 12px; white-space: nowrap;
}
.spark .stip b { font-weight: 600; margin-left: 6px; font-variant-numeric: tabular-nums; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.card h2 { margin: 0 0 4px; font-size: 15px; }
.card .sub { margin: 0 0 12px; color: var(--ink-2); font-size: 13px; }
.card-head { display: flex; gap: 8px 12px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; }

/* Teselas de otras pestañas */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.tile .label { color: var(--ink-2); font-size: 13px; }
.tile .value { font-size: 24px; font-weight: 650; margin-top: 2px; }
.tile .note { color: var(--ink-2); font-size: 12px; margin-top: 2px; }
.tile.hero .value { font-size: 28px; }

.pos { color: var(--pos-text); }
.neg { color: var(--neg-text); }
.muted { color: var(--ink-2); }

.table-wrap { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th { color: var(--ink-2); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
th:first-child, td:first-child, .left { text-align: left; }
tbody tr:hover td { background: #fafbfc; }
tr.total td { font-weight: 700; border-bottom: 0; border-top: 2px solid var(--line); }
td .flag { font-size: 11px; color: var(--ink-2); margin-left: 4px; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; background: var(--surface-2); color: var(--ink-2); }
.badge.alta { background: var(--accent-soft); color: var(--accent); }
.badge.renovacion { background: var(--good-bg); color: var(--pos-text); }

.alert { border-radius: var(--radius); padding: 10px 14px; border: 1px solid var(--warn-line); background: var(--warn-bg); }
.alert.error { border-color: var(--err-line); background: var(--err-bg); }
.alert ul { margin: 4px 0 0; padding-left: 18px; }

.chart { position: relative; }
.chart svg { display: block; width: 100%; height: 260px; overflow: visible; stroke: none; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .base { stroke: var(--axis); stroke-width: 1; }
.chart text { fill: var(--ink-2); font-size: 11px; font-variant-numeric: tabular-nums; stroke: none; }
.chart .bar-pos { fill: var(--pos); }
.chart .bar-neg { fill: var(--neg); }
.chart .hit { fill: transparent; cursor: default; }
.chart .hl.on { fill: var(--surface-2); }
.legend { display: flex; gap: 16px; color: var(--ink-2); font-size: 13px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.tip {
  position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; font-size: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.12); min-width: 170px; display: none; z-index: 3;
}
.tip b { display: block; margin-bottom: 4px; color: var(--ink); }
.tip div { display: flex; justify-content: space-between; gap: 12px; color: var(--ink-2); }
.tip div span:last-child { color: var(--ink); font-variant-numeric: tabular-nums; }

.settings { display: grid; gap: 16px; }
.field-row { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: end; }
.field { display: grid; gap: 4px; }
.field label { color: var(--ink-2); font-size: 13px; }
.group-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; display: grid; gap: 12px; }
.product-list { display: grid; gap: 4px; max-height: 220px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; padding: 8px; }
.product-list label { display: flex; gap: 8px; align-items: center; }
.cost-rows { display: grid; gap: 6px; }
.cost-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.cost-row input { width: 90px; }

.demo-banner { background: var(--accent-soft); color: var(--accent); text-align: center; padding: 6px; font-size: 13px; }
.empty { color: var(--ink-2); padding: 24px 0; text-align: center; }
.loading { color: var(--ink-2); padding: 48px 0; text-align: center; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login form { width: 100%; max-width: 340px; display: grid; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); }
.login h1 { margin: 0; font-size: 20px; }
.login input { width: 100%; }
.login .err { color: var(--neg-text); min-height: 1.4em; font-size: 13px; }
