:root {
  --brand: #e4002b;
  --brand-hover: #c20025;
  --bg: #ffffff;
  --surface: #ffffff;
  --subtle: #f7f7f8;
  --border: #e6e6e9;
  --border-strong: #d4d4d8;
  --text: #18181b;
  --text-2: #52525b;
  --muted: #8a8a93;
  --track: #eeeef0;
  /* Paleta de estado (fija): siempre acompañada de etiqueta */
  --on: #0ca30c;
  --just-off: #fab219;
  --off-days: #ec835a;
  --off-weeks: #d03b3b;
  --dark: #7a2230;
  --ok-ink: #0a7a0a;
  --bad-ink: #b42323;
  --radius: 12px;
  --font: "Segoe UI Variable Text", "Segoe UI", "Inter", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { background: var(--bg); }
body { margin: 0; color: var(--text); font-family: var(--font); font-size: 13.5px; line-height: 1.5;
  -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; }
.hidden { display: none !important; }
a { color: var(--brand); }

/* ---------- Encabezado ---------- */
.appbar { position: sticky; top: 0; z-index: 50; background: #fff; }
.appbar-inner { max-width: 1600px; margin: 0 auto; padding: 12px 28px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.stripes { height: 5px; background: repeating-linear-gradient(90deg, var(--brand) 0 18px, #fff 18px 30px);
  border-bottom: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 14px; }
.brand-logo { height: 34px; width: auto; display: block; }
.brand-text { border-left: 1px solid var(--border); padding-left: 14px; }
.brand-title { font-size: 17px; font-weight: 700; letter-spacing: -.015em; line-height: 1.2; }
.brand-sub { font-size: 12px; color: var(--muted); }
.spacer { flex: 1; }
.updated { display: flex; align-items: center; gap: 10px; padding: 6px 12px; border: 1px solid var(--border);
  border-radius: 10px; background: var(--subtle); }
.updated .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--on); flex: none; }
.updated.late .dot { background: var(--just-off); }
.updated-main { font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; line-height: 1.3; }
.updated-sub { font-size: 11.5px; color: var(--muted); line-height: 1.3; }

.btn, select, .search { height: 36px; border: 1px solid var(--border-strong); background: #fff; border-radius: 8px;
  font-size: 13px; color: var(--text); }
.btn { display: inline-flex; align-items: center; gap: 7px; padding: 0 14px; font-weight: 550; cursor: pointer; }
.btn:hover { background: var(--subtle); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--brand-hover); }
.btn-ghost { border-color: transparent; color: var(--brand); }
select { padding: 0 30px 0 11px; font: inherit; font-size: 13px; appearance: none; cursor: pointer; max-width: 230px;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='m4 6 4 4 4-4' fill='none' stroke='%2352525b' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 10px center / 12px; }
select:focus, .btn:focus-visible, input:focus { outline: 2px solid color-mix(in srgb, var(--brand) 35%, transparent); outline-offset: 1px; }

.menu { position: relative; }
.menu-list { position: absolute; right: 0; top: calc(100% + 6px); width: 300px; background: #fff; border: 1px solid var(--border);
  border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.12); padding: 6px; z-index: 60; }
.menu-list button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 9px 11px;
  border-radius: 7px; cursor: pointer; }
.menu-list button:hover { background: var(--subtle); }
.menu-list b { display: block; font-size: 13px; font-weight: 600; }
.menu-list span { display: block; font-size: 12px; color: var(--muted); }

/* ---------- Layout ---------- */
.wrap { max-width: 1600px; margin: 0 auto; padding: 22px 28px 60px; display: flex; flex-direction: column; gap: 18px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; min-width: 0; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
h2 { margin: 0; font-size: 15px; font-weight: 650; letter-spacing: -.01em; }
.card-sub { margin: 2px 0 0; font-size: 12.5px; color: var(--muted); }
.h-count { font-weight: 500; color: var(--muted); font-size: 13px; margin-left: 4px; }
.alert { padding: 11px 14px; border-radius: 10px; font-size: 13px; font-weight: 500; }
.alert-err { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warn { background: #fffbeb; color: #854d0e; border: 1px solid #fde68a; }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: 1.15fr 1fr 1fr 1.3fr; gap: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px;
  text-align: left; min-width: 0; }
.kpi-click { cursor: pointer; transition: border-color .12s, box-shadow .12s; }
.kpi-click:hover { border-color: var(--border-strong); box-shadow: 0 2px 8px rgba(0,0,0,.05); }
.kpi-click.active { border-color: var(--text); box-shadow: inset 0 0 0 1px var(--text); }
.kpi-label { font-size: 12px; font-weight: 600; color: var(--text-2); text-transform: uppercase; letter-spacing: .06em;
  display: flex; align-items: center; gap: 8px; }
.kpi-value { font-size: 40px; font-weight: 750; letter-spacing: -.035em; line-height: 1.1; margin-top: 8px;
  font-variant-numeric: tabular-nums; }
.kpi-value.ok { color: var(--ok-ink); }
.kpi-value.bad { color: var(--bad-ink); }
.kpi-sub { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.kpi-inline { font-size: 12px; color: var(--text); letter-spacing: 0; text-transform: none; margin-left: auto;
  font-weight: 700; font-variant-numeric: tabular-nums; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.kpi-gauge { display: flex; align-items: center; gap: 18px; }
.gauge { width: 104px; height: 104px; transform: rotate(-90deg); flex: none; }
.gauge circle { fill: none; stroke-width: 12; }
.g-track { stroke: color-mix(in srgb, var(--off-weeks) 22%, #fff); }
.g-on { stroke: var(--on); stroke-linecap: round; transition: stroke-dasharray .8s cubic-bezier(.2,.8,.2,1); }
.kpi-stores .kpi-label { margin-bottom: 10px; }
.sc-bar { display: flex; height: 8px; gap: 2px; margin-bottom: 8px; }
.sc-bar span:first-child { border-radius: 4px 0 0 4px; }
.sc-bar span:last-child { border-radius: 0 4px 4px 0; }
.sc-rows { display: flex; flex-direction: column; }
.sc-row { display: grid; grid-template-columns: 12px 1fr auto; align-items: center; gap: 9px; border: 0; background: none;
  padding: 4px 6px; margin: 0 -6px; border-radius: 6px; cursor: pointer; text-align: left; font-size: 13px; color: var(--text-2); }
.sc-row:hover { background: var(--subtle); }
.sc-row.active { background: var(--subtle); color: var(--text); box-shadow: inset 2px 0 0 var(--text); }
.sc-row b { color: var(--text); font-variant-numeric: tabular-nums; }
.sq { width: 11px; height: 11px; border-radius: 3px; display: inline-block; }

/* ---------- Estados ---------- */
.tierbar { display: flex; height: 36px; gap: 2px; border-radius: 8px; overflow: hidden; }
.seg-t { min-width: 4px; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 600;
  font-size: 12.5px; cursor: pointer; white-space: nowrap; overflow: hidden; transition: flex-grow .8s, opacity .15s;
  font-variant-numeric: tabular-nums; }
.seg-t.dim { opacity: .25; }
.tierlegend { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.tl { display: inline-flex; align-items: center; gap: 8px; height: 32px; padding: 0 12px; border: 1px solid var(--border);
  border-radius: 8px; background: #fff; cursor: pointer; font-size: 13px; color: var(--text-2); }
.tl:hover { border-color: var(--border-strong); }
.tl.active { border-color: var(--text); color: var(--text); box-shadow: inset 0 0 0 1px var(--text); }
.tl b { color: var(--text); font-variant-numeric: tabular-nums; }

.t-on { background: var(--on); }
.t-just_off { background: var(--just-off); }
.t-off_days { background: var(--off-days); }
.t-off_weeks { background: var(--off-weeks); }
.t-dark { background: var(--dark) repeating-linear-gradient(45deg, transparent 0 3px, rgba(255,255,255,.3) 3px 4px); }
.seg-t.t-just_off, .seg-t.t-off_days { color: #3b2400; }

/* ---------- Barra de filtros ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; position: sticky; top: 70px; z-index: 40;
  background: rgba(255,255,255,.96); backdrop-filter: blur(6px); padding: 10px 0; margin: -6px 0;
  border-bottom: 1px solid transparent; }
.toolbar.stuck { border-bottom-color: var(--border); }
.search { display: inline-flex; align-items: center; gap: 8px; padding: 0 11px; width: 260px; color: var(--muted); }
.search input { border: 0; outline: 0; font: inherit; font-size: 13px; width: 100%; color: var(--text); background: none; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; height: 36px; padding: 3px; gap: 3px; background: var(--subtle); }
.seg button { border: 0; background: none; color: var(--text-2); padding: 0 12px; cursor: pointer; font-weight: 550; font-size: 13px; border-radius: 5px; }
.seg button.active { background: #fff; color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.1); }
.count { margin-left: auto; font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* ---------- Mapa ---------- */
.legend-mini { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); }
.legend-mini span { display: inline-flex; align-items: center; gap: 6px; }
.stores { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 10px; }
.store { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px 12px; background: #fff; position: relative; }
.store::before { content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0; background: var(--on); }
.store.partial::before { background: var(--just-off); }
.store.all_off::before { background: var(--off-weeks); }
.store-h { margin-bottom: 8px; min-width: 0; }
.store-n { font-weight: 600; font-size: 12.5px; line-height: 1.3; display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.store-n .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sid { flex: none; font-size: 12px; font-weight: 700; color: #fff; background: var(--text);
  border-radius: 5px; padding: 1px 7px; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.store-c { font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: 2px; }
.store-c .x { color: var(--bad-ink); font-weight: 600; }
.screens { display: flex; flex-wrap: wrap; gap: 4px; }
/* Cuadros de pantalla: tonos con contraste ≥ 4.5:1 para leer P1, P2… en cualquier estado */
.scr { min-width: 34px; max-width: 150px; height: 24px; line-height: 24px; padding: 0 6px; border-radius: 5px;
  text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  font-size: 11px; font-weight: 700; letter-spacing: .01em; cursor: default; }
.scr.t-on, .legend-mini .t-on { background: #0b7d0b; color: #fff; }
.scr.t-just_off, .legend-mini .t-just_off { background: #fab219; color: #1a1000; }
.scr.t-off_days, .legend-mini .t-off_days { background: #ec835a; color: #1a0800; }
.scr.t-off_weeks, .legend-mini .t-off_weeks { background: #b42323; color: #fff; }
.scr.t-dark, .legend-mini .t-dark { background: #6b1a28; color: #fff; }
.scr:hover, .px:hover { outline: 2px solid var(--text); outline-offset: 1px; }
.wall { display: grid; grid-template-columns: repeat(auto-fill, 13px); gap: 3px; }
.px { width: 13px; height: 13px; border-radius: 3px; }
.changed { animation: flash 1.2s 3; }
@keyframes flash { 50% { box-shadow: 0 0 0 3px var(--text); } }
@media (prefers-reduced-motion: reduce) { .changed { animation: none; outline: 2px solid var(--text); } }
.more { text-align: center; margin-top: 14px; }
.empty { padding: 34px; text-align: center; color: var(--muted); }

/* ---------- Desgloses ---------- */
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.hist { display: flex; align-items: flex-end; gap: 6px; height: 200px; padding-top: 18px; }
.hcol { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 0; }
.hbar { width: 100%; max-width: 38px; border-radius: 4px 4px 0 0; min-height: 2px; transition: height .8s; }
.hval { font-size: 11.5px; font-weight: 600; font-variant-numeric: tabular-nums; margin-bottom: 4px; }
.hlbl { font-size: 11px; color: var(--muted); margin-top: 6px; white-space: nowrap; }
.brow { display: grid; grid-template-columns: minmax(0, 150px) 1fr 48px; align-items: center; gap: 12px;
  padding: 6px 8px; margin: 0 -8px; border-radius: 6px; cursor: pointer; }
.brow:hover { background: var(--subtle); }
.brow.active { background: var(--subtle); box-shadow: inset 2px 0 0 var(--text); }
.brow .k { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brow .k small { color: var(--muted); margin-left: 5px; font-size: 11.5px; }
.brow .bar { display: flex; height: 10px; gap: 2px; }
.brow .bar span:first-child { border-radius: 3px 0 0 3px; }
.brow .bar span:last-child { border-radius: 0 3px 3px 0; }
.brow .bar span:only-child { border-radius: 3px; }
.brow .p { font-size: 12.5px; font-weight: 650; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Tabla ---------- */
.table-wrap { overflow-x: auto; margin: 0 -20px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-2); font-weight: 600;
  padding: 9px 12px; background: var(--subtle); border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
  cursor: pointer; white-space: nowrap; user-select: none; }
th:first-child, td:first-child { padding-left: 20px; }
th.sorted::after { content: " ↓"; }
th.sorted.asc::after { content: " ↑"; }
td { padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody tr:hover td { background: #fafafa; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
td.mono { font-family: var(--mono); font-size: 12px; color: var(--text-2); }
.badge { display: inline-flex; align-items: center; gap: 7px; font-weight: 550; }
.badge i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

/* ---------- Tooltip / toast / pie ---------- */
.tip { position: fixed; z-index: 100; pointer-events: none; background: #fff; color: var(--text); border: 1px solid var(--border);
  padding: 11px 13px; border-radius: 10px; font-size: 12.5px; min-width: 240px; max-width: 330px; box-shadow: 0 10px 30px rgba(0,0,0,.14); }
.tip-title { font-weight: 650; font-size: 13px; }
.tip-status { display: flex; align-items: center; gap: 7px; font-weight: 600; margin: 4px 0 8px; }
.tip-status i { width: 9px; height: 9px; border-radius: 50%; }
.tip .row { display: flex; justify-content: space-between; gap: 16px; padding: 2px 0; }
.tip .row span:first-child { color: var(--muted); }
.tip .row span:last-child { font-variant-numeric: tabular-nums; text-align: right; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 100; background: var(--text); color: #fff; padding: 12px 16px;
  border-radius: 10px; font-weight: 500; box-shadow: 0 10px 30px rgba(0,0,0,.2); display: flex; gap: 14px; }
.toast i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.foot { text-align: center; font-size: 12px; color: var(--muted); padding-top: 6px; }

/* ---------- Modo TV ---------- */
body.tv .toolbar, body.tv #off-sec, body.tv .appbar .btn:not(#tv), body.tv .menu { display: none !important; }
body.tv .wrap, body.tv .appbar-inner { max-width: none; }
body.tv .kpi-value { font-size: 56px; }

@media (max-width: 1250px) {
  .kpis { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 1000px) { .appbar { position: static; } .toolbar { top: 0; } }
@media (max-width: 760px) {
  .wrap { padding: 14px 16px 50px; }
  .appbar-inner { padding: 10px 16px; }
  .brand-sub, .updated-sub { display: none; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .kpi-gauge, .kpi-stores { grid-column: 1 / -1; }
  .kpi-value { font-size: 30px; }
  .toolbar { position: static; }
  .search { width: 100%; }
  select { max-width: none; flex: 1; }
  .count { margin-left: 0; }
}
