/* Commercial Intelligence · panel
   Tokens de color de la guía de visualización (paleta validada, claro y oscuro). */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-wash: rgba(42, 120, 214, 0.10);
  --good-text: #006300;
  --bad-text: #b42b2b;
  --warn-bg: #fff6e0;
  --warn-ink: #6b4a00;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --o1: #86b6ef; --o2: #5598e7; --o3: #2a78d6; --o4: #1c5cab; --o5: #104281;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 4px 16px rgba(11, 11, 11, 0.04);
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
    --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835;
    --border: rgba(255, 255, 255, 0.10); --accent: #3987e5; --accent-wash: rgba(57, 135, 229, 0.14);
    --good-text: #0ca30c; --bad-text: #e66767; --warn-bg: #2e2612; --warn-ink: #f3cf7a;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --o1: #184f95; --o2: #256abf; --o3: #3987e5; --o4: #6da7ec; --o5: #9ec5f4;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
  --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781; --grid: #2c2c2a; --axis: #383835;
  --border: rgba(255, 255, 255, 0.10); --accent: #3987e5; --accent-wash: rgba(57, 135, 229, 0.14);
  --good-text: #0ca30c; --bad-text: #e66767; --warn-bg: #2e2612; --warn-ink: #f3cf7a;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
  --o1: #184f95; --o2: #256abf; --o3: #3987e5; --o4: #6da7ec; --o5: #9ec5f4;
  --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--page); color: var(--ink); font: 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.ink2 { color: var(--ink-2); }
.hidden { display: none !important; }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login form { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 32px 28px; box-shadow: var(--shadow); }
.login h1 { font-size: 20px; margin: 0 0 4px; letter-spacing: -0.01em; }
.login p { margin: 0 0 24px; color: var(--ink-2); }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 13px; color: var(--ink-2); }
.field input { height: 40px; border: 1px solid var(--border); border-radius: 8px; padding: 0 12px; background: var(--surface); }
.btn { height: 40px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); padding: 0 14px; }
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; width: 100%; font-weight: 600; }
.btn-primary:hover { filter: brightness(1.05); background: var(--accent); }
.error { color: var(--bad-text); font-size: 13px; min-height: 20px; margin: 4px 0 8px; }

/* ---------- estructura ---------- */
.shell { max-width: 1280px; margin: 0 auto; padding: 0 24px 64px; }
header.top { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 20px 0 12px; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--accent); display: grid; place-items: center; flex: none; }
.brand b { font-size: 15px; letter-spacing: -0.01em; }
.brand span { color: var(--muted); font-size: 13px; }
.top-actions { display: flex; gap: 8px; align-items: center; }
.icon-btn { width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); display: grid; place-items: center; }
.icon-btn:hover { background: var(--surface-2); }

.filters { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--page) 92%, transparent);
  backdrop-filter: blur(8px); display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 10px 0 14px;
  border-bottom: 1px solid var(--border); margin-bottom: 20px; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 2px; flex-wrap: wrap; }
.seg button { border: 0; background: transparent; height: 30px; padding: 0 11px; border-radius: 7px; color: var(--ink-2); white-space: nowrap; }
.seg button[aria-pressed="true"] { background: var(--accent-wash); color: var(--ink); font-weight: 600; }
.seg button:hover:not([aria-pressed="true"]) { background: var(--surface-2); }
.dates { display: inline-flex; gap: 6px; align-items: center; }
.dates input, .filters select { height: 34px; border: 1px solid var(--border); border-radius: 8px; padding: 0 8px; background: var(--surface); }
.filters .spacer { flex: 1; }
.period-label { color: var(--ink-2); font-size: 13px; }

.banner { display: flex; gap: 10px; align-items: flex-start; background: var(--warn-bg); color: var(--warn-ink);
  border-radius: 10px; padding: 10px 14px; margin-bottom: 20px; font-size: 13px; }
.banner ul { margin: 0; padding-left: 18px; }

section.block { margin-bottom: 28px; }
.block-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.block-head h2 { font-size: 16px; margin: 0; letter-spacing: -0.01em; }
.block-head p { margin: 0; color: var(--muted); font-size: 13px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 18px 20px; }

/* ---------- cifras ---------- */
.kpis { display: grid; grid-template-columns: minmax(260px, 1.3fr) repeat(4, minmax(0, 1fr)); gap: 12px; }
.kpis .rest { display: contents; }
.hero { grid-row: span 2; display: flex; flex-direction: column; justify-content: space-between; }
.hero .value { font-size: 44px; font-weight: 650; letter-spacing: -0.02em; line-height: 1.1; margin: 8px 0 6px; }
.tile .label, .hero .label { color: var(--ink-2); font-size: 13px; }
.tile .value { font-size: 24px; font-weight: 600; letter-spacing: -0.01em; margin: 4px 0 2px; }
.delta { font-size: 12.5px; display: inline-flex; align-items: center; gap: 4px; }
.delta.good { color: var(--good-text); }
.delta.bad { color: var(--bad-text); }
.delta.flat { color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); }

/* ---------- recorrido ---------- */
.journey { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.stage h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 10px; font-weight: 600; }
.stage dl { margin: 0; display: grid; gap: 7px; }
.stage .row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.stage dt { color: var(--ink-2); font-size: 13px; }
.stage dd { margin: 0; font-weight: 600; text-align: right; white-space: nowrap; }
.stage dd small { display: block; font-weight: 400; }
.stage .key { border-top: 1px solid var(--grid); padding-top: 9px; margin-top: 4px; }

.funnel { display: grid; gap: 4px; }
.funnel-row { display: grid; grid-template-columns: 200px 1fr 150px; gap: 14px; align-items: center; min-height: 40px; }
.funnel-row .name { color: var(--ink-2); font-size: 13px; }
.funnel-row .track { position: relative; height: 24px; }
.funnel-row .bar { position: absolute; left: 0; top: 0; height: 24px; border-radius: 0 4px 4px 0; min-width: 2px; }
.funnel-row .val { font-weight: 600; }
.funnel-drop { grid-column: 2 / 4; font-size: 12px; color: var(--muted); padding: 0 0 2px; display: flex; gap: 6px; align-items: center; }
.funnel-drop b { color: var(--bad-text); font-weight: 600; }

.outcomes { display: grid; gap: 16px; }
.stack-row .stack-label { display: flex; justify-content: space-between; margin-bottom: 6px; font-size: 13px; color: var(--ink-2); }
.stack { display: flex; gap: 2px; height: 24px; }
.stack span { display: block; height: 100%; min-width: 2px; }
.stack span:first-child { border-radius: 4px 0 0 4px; }
.stack span:last-child { border-radius: 0 4px 4px 0; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12.5px; color: var(--ink-2); }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.multiples { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.mini h4 { margin: 0; font-size: 13px; color: var(--ink-2); font-weight: 500; }
.mini .now { font-size: 18px; font-weight: 600; margin: 2px 0 6px; }
.mini svg { display: block; width: 100%; height: 110px; overflow: visible; }

/* ---------- tablas ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 9px 12px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--grid); }
th:first-child, td:first-child { text-align: left; white-space: normal; min-width: 180px; }
th { color: var(--muted); font-weight: 500; font-size: 12px; position: sticky; top: 0; background: var(--surface); }
th button { border: 0; background: none; padding: 0; color: inherit; font: inherit; }
th button[aria-sort] { color: var(--ink); font-weight: 600; }
tbody tr:hover { background: var(--surface-2); }
td .sub { display: block; color: var(--muted); font-size: 12px; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 99px; background: var(--surface-2); color: var(--ink-2); margin-left: 6px; }

.tooltip { position: fixed; z-index: 50; pointer-events: none; background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 12.5px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12); max-width: 260px; }
.tooltip b { display: block; margin-bottom: 2px; }
.notes { font-size: 12.5px; color: var(--muted); display: grid; gap: 4px; margin-top: 8px; }
.loading { opacity: 0.55; transition: opacity 0.2s; }

dialog { border: 1px solid var(--border); border-radius: 14px; background: var(--surface); color: var(--ink); padding: 24px; width: min(380px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
dialog h3 { margin: 0 0 16px; font-size: 16px; }
dialog .actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }
dialog .actions .btn-primary { width: auto; }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero { grid-column: 1 / -1; grid-row: auto; }
  .journey { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .multiples { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .shell { padding: 0 16px 48px; }
  .journey, .grid-2, .multiples { grid-template-columns: 1fr; }
  .funnel-row { grid-template-columns: 1fr; gap: 4px; }
  .funnel-drop { grid-column: 1; }
  .hero .value { font-size: 36px; }
  .brand span { display: none; }
}
@media (prefers-reduced-motion: no-preference) {
  .funnel-row .bar, .stack span { transition: width 0.35s cubic-bezier(0.2, 0.8, 0.2, 1); }
}
@media print {
  .filters, .top-actions { display: none; }
  .card { box-shadow: none; }
}
