:root {
  color-scheme: light;
  --bg: #f4f4f1;
  --surface: #fcfcfb;
  --side: #fcfcfb;
  --ink: #0b0b0b;
  --ink2: #52514e;
  --muted: #898781;
  --line: #e1e0d9;
  --axis: #c3c2b7;
  --hover: #f0efec;
  --accent: #2a78d6;
  --accent-soft: rgba(42, 120, 214, 0.10);
  --accent-line: rgba(42, 120, 214, 0.35);
  --accent-ink: #ffffff;
  --good: #006300;
  --warn: #fab219;
  --warn-bg: #fff4d6;
  --warn-ink: #5c4300;
  --danger: #d03b3b;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.05), 0 4px 14px rgba(11, 11, 11, 0.03);
  /* categórica en orden fijo (validada con scripts/validate_palette.js) */
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --bg: #0d0d0d; --surface: #1a1a19; --side: #151514; --ink: #f0efec; --ink2: #c3c2b7; --muted: #898781;
    --line: #2c2c2a; --axis: #383835; --hover: #242423;
    --accent: #3987e5; --accent-soft: rgba(57, 135, 229, 0.16); --accent-line: rgba(57, 135, 229, 0.45);
    --good: #0ca30c; --warn-bg: #3a2f10; --warn-ink: #f2d27a; --danger: #e66767; --shadow: none;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d0d0d; --surface: #1a1a19; --side: #151514; --ink: #f0efec; --ink2: #c3c2b7; --muted: #898781;
  --line: #2c2c2a; --axis: #383835; --hover: #242423;
  --accent: #3987e5; --accent-soft: rgba(57, 135, 229, 0.16); --accent-line: rgba(57, 135, 229, 0.45);
  --good: #0ca30c; --warn-bg: #3a2f10; --warn-ink: #f2d27a; --danger: #e66767; --shadow: none;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #008300;
}

* { box-sizing: border-box; }
html { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; font-size: 15px; }
body { margin: 0; background: var(--bg); color: var(--ink); }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; font-weight: 600; }
.muted { color: var(--muted); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
svg.i { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- estructura: barra lateral + contenido ---------- */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 14px;
  padding: 16px 12px; background: var(--side); border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 8px; }
.brand strong { display: block; font-size: 15px; line-height: 1.2; }
.brand .muted { font-size: 12px; }
.logo { width: 30px; height: 30px; border-radius: 9px; background: var(--accent); display: inline-block; position: relative; flex: none; }
.logo::after { content: ""; position: absolute; inset: 8px 7px 7px; border-left: 3px solid #fff; border-right: 3px solid #fff; border-radius: 1px; box-shadow: inset 0 -6px 0 -3px #fff; opacity: .95; }
.logo.big { width: 44px; height: 44px; border-radius: 13px; }
.logo.big::after { inset: 12px 10px 10px; border-width: 4px; }
nav { display: grid; gap: 2px; align-content: start; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; color: var(--ink2);
  text-decoration: none; font-size: 14px; position: relative;
}
.nav-item:hover { background: var(--hover); color: var(--ink); }
.nav-item[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item[aria-current="page"]::before { content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.side-foot { border-top: 1px solid var(--line); padding-top: 12px; display: grid; gap: 8px; }
.who { display: flex; align-items: center; gap: 8px; font-size: 14px; padding: 0 6px; }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: inline-grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.side-actions { display: flex; gap: 4px; }

.content { min-width: 0; }
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 24px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 18px; }
.actions { display: flex; align-items: center; gap: 8px; }
main { padding: 22px 24px 40px; max-width: 1560px; outline: none; }

/* ---------- controles ---------- */
.btn {
  font: inherit; font-size: 14px; padding: 7px 13px; border-radius: 9px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--hover); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 3px 9px; font-size: 13px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input, select, textarea {
  font: inherit; font-size: 14px; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; min-width: 0;
}
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; padding: 2px; background: var(--surface); gap: 2px; }
.seg button { font: inherit; font-size: 13px; border: 0; background: transparent; color: var(--ink2); padding: 5px 12px; border-radius: 8px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.chip { font: inherit; font-size: 13px; border: 1px solid var(--line); background: var(--surface); color: var(--ink2); padding: 3px 10px; border-radius: 999px; cursor: pointer; }
.chip:hover { background: var(--hover); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: var(--ink2); }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.page-head h2 { font-size: 22px; }
.page-head p { margin: 4px 0 0; color: var(--ink2); max-width: 78ch; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar input[type="search"], .toolbar select { max-width: 270px; }

/* ---------- tablas ---------- */
.table-wrap { overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; max-height: calc(100vh - 190px); box-shadow: var(--shadow); }
table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 14px; }
th, td { padding: 5px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
th { position: sticky; top: 0; z-index: 2; background: var(--surface); font-size: 12px; font-weight: 600; letter-spacing: .02em; color: var(--ink2); white-space: nowrap; border-bottom: 1px solid var(--axis); }
tbody tr:hover td { background: var(--hover); }
tfoot td { position: sticky; bottom: 0; background: var(--surface); font-weight: 600; border-top: 1px solid var(--axis); border-bottom: 0; }
td input:not([type="checkbox"]), td select { width: 100%; border-color: transparent; background: transparent; }
td input:not([type="checkbox"]):hover, td select:hover { border-color: var(--line); }
td input:not([type="checkbox"]):focus, td select:focus { border-color: var(--accent); background: var(--surface); }
td input[type="number"] { text-align: right; min-width: 90px; }
td input[type="text"] { min-width: 150px; }
td.center { text-align: center; white-space: nowrap; }
.tag { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 999px; background: var(--hover); color: var(--ink2); white-space: nowrap; }
.tag.crm { background: var(--accent-soft); color: var(--accent); }
.empty { padding: 30px; text-align: center; color: var(--muted); }

/* ---------- licencias por puesto ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 14px; }
.mini { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; box-shadow: var(--shadow); }
.mini .l { font-size: 12px; color: var(--ink2); }
.mini .v { font-size: 20px; font-weight: 600; margin-top: 1px; }
.lic { border-collapse: separate; }
.lic th, .lic td { border-bottom: 1px solid var(--line); }
.lic thead th { text-align: center; }
.lic thead tr:nth-child(1) th { height: 34px; top: 0; }
.lic thead tr:nth-child(2) th { top: 34px; height: 34px; font-weight: 500; }
.lic th.grp { background: var(--surface); border-top: 3px solid var(--gc, var(--accent)); color: var(--ink); font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; border-left: 1px solid var(--line); }
.lic th.tool { border-left: 1px solid var(--line); min-width: 148px; }
.lic th.tool.first-in-group, .lic td.first-in-group { border-left: 1px solid var(--line); }
.lic .sticky { position: sticky; left: 0; z-index: 3; background: var(--surface); min-width: 250px; max-width: 250px; text-align: left; box-shadow: 1px 0 0 var(--line); }
.lic thead th.sticky { z-index: 5; }
.lic tbody tr:hover td.sticky { background: var(--hover); }
.lic tr.sec td { position: sticky; left: 0; background: var(--hover); font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--ink2); padding: 6px 12px; }
.lic tr.sec:hover td { background: var(--hover); }
.lic td.cellp { padding: 6px; min-width: 148px; }
.persona { display: flex; align-items: center; gap: 10px; }
.persona .nm { line-height: 1.25; min-width: 0; }
.persona .nm strong { display: block; font-weight: 600; }
.persona .nm span { color: var(--muted); font-size: 13px; }
.persona .tags { display: flex; gap: 4px; margin-top: 3px; flex-wrap: wrap; }
.lcell { position: relative; }
.lcell select { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; border: 0; padding: 0; z-index: 1; }
.pill {
  display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 36px; padding: 5px 9px; border-radius: 10px;
  font-size: 13px; border: 1px solid var(--line); background: var(--surface);
}
.pill .pn { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.pill .pp { font-size: 12px; font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.pill.paid { background: var(--accent-soft); border-color: var(--accent-line); }
.pill.paid .pp { color: var(--accent); }
.pill.free { background: var(--hover); }
.pill.free .pp { color: var(--good); font-weight: 600; }
.pill.none { border-style: dashed; color: var(--muted); justify-content: center; background: transparent; }
.lcell:hover .pill { border-color: var(--accent); }
.lcell select:focus-visible + .pill, .lcell:focus-within .pill { outline: 2px solid var(--accent); outline-offset: 1px; }
.lic tfoot td { text-align: center; font-weight: 600; }
.lic tfoot td.sticky { text-align: left; }

.tool-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.tcard { background: var(--surface); border: 1px solid var(--line); border-top: 3px solid var(--gc, var(--accent)); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); }
.tcard header { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.tcard h3 { font-size: 16px; }
.tcard .grp-tag { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tcard .tot { font-size: 22px; font-weight: 600; margin: 6px 0 2px; }
.tcard .plans { display: grid; gap: 8px; margin-top: 10px; }
.plan { border-top: 1px solid var(--line); padding-top: 8px; }
.plan .row { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.plan .who { color: var(--ink2); font-size: 13px; margin-top: 3px; }
.tcard.off { opacity: .6; }

/* ---------- panel ---------- */
.grid { display: grid; gap: 14px; }
.cols-kpi { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(440px, 1fr)); }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; box-shadow: var(--shadow); min-width: 0; }
.card h3 { font-size: 15px; margin-bottom: 2px; }
.card .sub { color: var(--muted); font-size: 13px; margin-bottom: 14px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }

.assume { display: flex; gap: 18px 26px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.assume .field { display: grid; gap: 5px; }
.assume label, .assume .lbl { font-size: 12px; font-weight: 600; color: var(--ink2); }
.assume .static { padding: 7px 0; font-weight: 600; }
.assume input[type="number"] { width: 92px; text-align: right; }
.stepper { display: inline-flex; align-items: center; gap: 6px; }
.stepper input { width: 64px; text-align: center; font-weight: 600; font-size: 16px; }
.stepper .sbtn { width: 32px; height: 32px; padding: 0; justify-content: center; font-size: 18px; line-height: 1; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }

.hero-card { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 24px; align-items: center; background: linear-gradient(135deg, var(--accent-soft), transparent 70%), var(--surface); }
.hero-card .label { color: var(--ink2); font-size: 14px; }
.hero-card .value { font-size: 54px; font-weight: 600; line-height: 1.05; margin: 6px 0 6px; }
.hero-card .detail { color: var(--ink2); font-size: 14px; }
.hero-split { display: grid; gap: 10px; }
.hero-split .row { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.hero-split .row:last-child { border-bottom: 0; padding-bottom: 0; }
.hero-split .row b { font-variant-numeric: tabular-nums; }

.kpi { display: flex; gap: 12px; align-items: flex-start; }
.kpi .ico { width: 38px; height: 38px; border-radius: 11px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; flex: none; }
.kpi .label { color: var(--ink2); font-size: 13px; }
.kpi .value { font-size: 24px; font-weight: 600; margin-top: 1px; }
.kpi .detail { color: var(--muted); font-size: 12px; margin-top: 2px; }

.alert { background: var(--warn-bg); color: var(--warn-ink); border-radius: 12px; padding: 10px 14px; margin-bottom: 14px; font-size: 14px; }
.alert summary { cursor: pointer; font-weight: 600; }
.alert ul { margin: 8px 0 2px; padding-left: 18px; }

/* barras horizontales: <=24px, extremo de 4px, base cuadrada, valor al final */
.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: minmax(120px, 190px) 1fr; align-items: center; gap: 10px; font-size: 14px; }
.bar-label { display: flex; align-items: center; gap: 8px; color: var(--ink2); min-width: 0; }
.bar-label span.t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.bar-track { display: flex; align-items: center; gap: 8px; min-height: 22px; }
.bar { height: 20px; border-radius: 0 4px 4px 0; min-width: 2px; transition: width .3s; }
.bar-val { color: var(--ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
.bar-pct { color: var(--muted); font-size: 12px; }
.view-toggle { margin-left: auto; flex: none; }

/* medidor */
.meter { height: 12px; border-radius: 6px; background: var(--accent-soft); overflow: hidden; margin: 10px 0 6px; }
.meter > div { height: 100%; border-radius: 6px; background: var(--accent); transition: width .3s; }
.meter.warn { background: color-mix(in srgb, var(--warn) 22%, transparent); }
.meter.warn > div { background: var(--warn); }
.meter.over { background: color-mix(in srgb, var(--danger) 20%, transparent); }
.meter.over > div { background: var(--danger); }
.meter-legend { display: flex; justify-content: space-between; font-size: 13px; color: var(--ink2); }

/* proyección mes a mes */
.tl { display: grid; grid-template-columns: 52px 1fr; gap: 8px; }
.tl-y { position: relative; height: 200px; }
.tl-y span { position: absolute; right: 0; transform: translateY(50%); font-size: 11px; color: var(--muted); white-space: nowrap; }
.tl-plot { position: relative; height: 200px; border-bottom: 1px solid var(--axis); }
.tl-grid { position: absolute; left: 0; right: 0; border-top: 1px solid var(--line); }
.tl-cols { position: absolute; inset: 0; display: flex; gap: 6px; }
.tl-col { position: relative; flex: 1; min-width: 0; }
.tl-bar { position: absolute; bottom: 0; left: 50%; transform: translateX(-50%); width: 100%; max-width: 24px; border-radius: 4px 4px 0 0; background: var(--s1); transition: height .3s; }
.tl-col:hover .tl-bar { filter: brightness(1.12); }
.tl-val { position: absolute; left: 50%; transform: translateX(-50%); font-size: 12px; white-space: nowrap; color: var(--ink); font-weight: 600; }
.tl-col:last-child .tl-val { left: auto; right: 0; transform: none; }
.tl-xrow { display: flex; gap: 6px; margin: 6px 0 0 60px; }
.tl-x { flex: 1; min-width: 0; text-align: center; font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; }

.mini-table table { font-size: 13px; }
.ibar { display: inline-block; height: 8px; border-radius: 0 3px 3px 0; background: var(--s1); vertical-align: middle; }

/* ---------- login / toast / tooltip / diálogo ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(390px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 18px; padding: 30px; display: grid; gap: 12px; box-shadow: var(--shadow); }
.login-card h1 { font-size: 24px; }
.login-card p { margin: 0; }
.login-card label { display: grid; gap: 4px; font-size: 13px; color: var(--ink2); }
.error { color: var(--danger); min-height: 1.2em; font-size: 14px; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 9px 16px; border-radius: 10px; z-index: 50; max-width: 90vw; font-size: 14px; }
.toast.err { background: var(--danger); color: #fff; }
.tip { position: fixed; z-index: 60; pointer-events: none; background: var(--ink); color: var(--bg); padding: 6px 10px; border-radius: 8px; font-size: 13px; max-width: 340px; }
dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--ink); padding: 20px; max-width: min(720px, 94vw); width: 100%; }
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
dialog h3 { margin-bottom: 8px; }
dialog table { margin: 10px 0; }
dialog .row { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }

.settings { display: grid; gap: 14px; max-width: 580px; }
.settings label { display: grid; gap: 4px; font-size: 13px; color: var(--ink2); }
.settings .hint { color: var(--muted); font-size: 12px; }
.log td { font-size: 13px; }

@media (max-width: 980px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { min-width: 0; position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--line); }
  nav { display: flex; flex-wrap: nowrap; overflow-x: auto; order: 3; width: 100%; flex: none; }
  .nav-item { white-space: nowrap; }
  .nav-item[aria-current="page"]::before { display: none; }
  .side-foot { border: 0; padding: 0; margin-left: auto; display: flex; align-items: center; gap: 8px; }
  .topbar { padding: 10px 14px; }
  main { padding: 14px; }
  .hero-card { grid-template-columns: 1fr; }
  .hero-card .value { font-size: 40px; }
  .cols-2 { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 1fr; gap: 2px; }
}
@media print { .sidebar, .topbar, .toolbar, .btn { display: none !important; } .shell { display: block; } .table-wrap { max-height: none; } }
