/* =========================================================================
   BRUMA · Ventas TUBV — sistema visual
   Escala de espaciado de 8 px · una sola retícula · tipografía tabular
   ========================================================================= */
:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --border: #e3e6ea;
  --border-strong: #cfd4da;
  --text: #15181c;
  --text-2: #4a5059;
  --muted: #6f7680;
  --accent: #5b1f3a;          /* vino BRUMA */
  --accent-soft: #f6ecf1;
  --accent-ink: #ffffff;
  --good: #1a7f37; --good-bg: #e9f6ee;
  --warn: #8a5a00; --warn-bg: #fff5dc;
  --bad: #b42318;  --bad-bg: #fdeceb;
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --grid: #eceef1;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .06);
  --radius: 10px;
  --gap: 24px;
  --maxw: 1440px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1113; --surface: #171a1d; --surface-2: #1f2327; --border: #2a2f35; --border-strong: #3a4048;
    --text: #eef0f2; --text-2: #c2c7ce; --muted: #8b929b;
    --accent: #c2577f; --accent-soft: #2a1820;
    --good: #4cc26a; --good-bg: #13291a; --warn: #e0a72e; --warn-bg: #2d2610; --bad: #f07070; --bad-bg: #331818;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --grid: #23272c; --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1113; --surface: #171a1d; --surface-2: #1f2327; --border: #2a2f35; --border-strong: #3a4048;
  --text: #eef0f2; --text-2: #c2c7ce; --muted: #8b929b;
  --accent: #c2577f; --accent-soft: #2a1820;
  --good: #4cc26a; --good-bg: #13291a; --warn: #e0a72e; --warn-bg: #2d2610; --bad: #f07070; --bad-bg: #331818;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --grid: #23272c; --shadow: none;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "tnum" 1, "cv11" 1;
}
h1, h2, h3, p { margin: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.err { color: var(--bad); }

/* ---------- Barra superior ---------- */
.topbar { position: sticky; top: 0; z-index: 10; background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner {
  max-width: var(--maxw); margin: 0 auto; padding: 0 var(--gap); height: 64px;
  display: flex; align-items: center; gap: 40px;
}
.brand { display: flex; align-items: center; gap: 12px; flex: none; }
.brand-mark {
  width: 36px; height: 36px; flex: none; border-radius: 8px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-weight: 700; font-size: 17px; letter-spacing: -.02em;
}
.brand-title { font-weight: 700; font-size: 15px; letter-spacing: .08em; line-height: 1.2; }
.brand-sub { color: var(--muted); font-size: 12px; line-height: 1.2; }

.tabs { display: flex; gap: 4px; height: 64px; flex: none; }
.tab {
  height: 100%; border: 0; background: none; padding: 0 16px; cursor: pointer;
  font: inherit; font-weight: 500; color: var(--text-2);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.topbar-right { display: flex; align-items: center; justify-content: flex-end; gap: 16px; margin-left: auto; flex: none; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.status::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--border-strong); }
.status.ok::before { background: var(--good); }
.status.warn::before { background: var(--warn); }
.user-menu { display: flex; align-items: center; gap: 8px; padding-left: 16px; border-left: 1px solid var(--border); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent);
  display: grid; place-items: center; font-weight: 600; font-size: 12px; flex: none;
}
.user-text { line-height: 1.2; margin-right: 4px; }
.user-name { font-weight: 600; font-size: 13px; white-space: nowrap; }
.user-role { color: var(--muted); font-size: 12px; }

/* ---------- Contenido ---------- */
main { max-width: var(--maxw); margin: 0 auto; padding: 32px var(--gap) 120px; }
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: var(--gap); flex-wrap: wrap;
  margin-bottom: var(--gap);
}
.page-head h1 { font-size: 24px; font-weight: 600; letter-spacing: -.01em; line-height: 1.25; }
.page-sub { color: var(--muted); margin-top: 4px; }

.toolbar { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 500; color: var(--text-2); }
input, select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 8px; padding: 0 12px; height: 38px; min-width: 0;
}
input:focus, select:focus, .btn:focus-visible, .tab:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent); outline-offset: 1px;
}
.btn {
  height: 38px; padding: 0 16px; border-radius: 8px; cursor: pointer; white-space: nowrap;
  font: inherit; font-weight: 600; font-size: 13px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.sm { height: 32px; padding: 0 10px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: progress; }

/* ---------- KPIs: retícula fija de 4 columnas ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: var(--gap); }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px; display: flex; flex-direction: column; min-height: 124px;
}
.kpi-label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.kpi-value { font-size: 28px; font-weight: 600; letter-spacing: -.02em; line-height: 1.15; margin-top: 10px; }
.kpi-sub { color: var(--muted); font-size: 12.5px; margin-top: auto; padding-top: 8px; }
.kpi.accent .kpi-label { color: var(--accent); }

/* ---------- Tarjetas ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
  margin-bottom: var(--gap); min-width: 0; overflow: hidden;
}
.card-pad { padding: 20px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.card-head h3 { font-size: 15px; font-weight: 600; line-height: 1.3; }
.card-head p { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.card-body { padding: 20px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--gap); }
.grid-2 > .card { margin-bottom: var(--gap); display: flex; flex-direction: column; }
.grid-2 > .card > .card-body { flex: 1; }
.chart-wrap { position: relative; height: 320px; }
.chart-wrap.is-empty canvas { display: none; }
.chart-wrap.is-empty::after {
  content: 'Sin datos en este periodo. Carga los PDFs del día en “Cargar reportes”.';
  position: absolute; inset: 0; display: grid; place-items: center; padding: 16px; text-align: center;
  color: var(--muted); background: var(--surface-2); border-radius: 8px;
}

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.tbl th, .tbl td { padding: 10px 16px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--grid); }
.tbl th {
  background: var(--surface-2); color: var(--text-2); font-size: 11.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em; position: sticky; top: 0;
}
.tbl th:first-child, .tbl td:first-child, .tbl th.l, .tbl td.l { text-align: left; }
.tbl th:first-child, .tbl td:first-child { padding-left: 20px; }
.tbl th:last-child, .tbl td:last-child { padding-right: 20px; }
.tbl td:first-child { font-weight: 500; }
.tbl tbody tr:hover td, .tbl tr:hover td { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.tbl tr.total td { font-weight: 700; background: var(--surface-2); border-top: 1px solid var(--border-strong); border-bottom: 0; }
.tbl th.grp { text-align: center; border-bottom: 1px solid var(--border); background: var(--surface); color: var(--text); }
.tbl th.sep, .tbl td.sep { border-left: 1px solid var(--border); }
.tbl td.zero { color: var(--muted); }
.tbl td.empty { text-align: center; color: var(--muted); padding: 40px 20px; font-weight: 400; }
.tbl td .btn { margin-left: 4px; }
.tbl select { height: 32px; padding: 0 8px; }

/* ---------- Cobertura ---------- */
.cobertura { display: grid; gap: 6px; font-size: 11px; overflow-x: auto; }
.cob-row { display: grid; grid-template-columns: 120px repeat(31, minmax(20px, 1fr)); gap: 4px; align-items: center; }
.cob-cell { height: 24px; border-radius: 4px; background: var(--surface-2); display: grid; place-items: center; color: var(--muted); }
.cob-cell.ok { background: var(--good-bg); color: var(--good); font-weight: 700; }
.cob-cell.fut { opacity: .4; }
.cob-name { color: var(--text-2); font-weight: 600; font-size: 12px; }
.cob-day { text-align: center; color: var(--muted); }

/* ---------- Carga ---------- */
.dropzone {
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius); padding: 48px 24px; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 8px; cursor: pointer; background: var(--surface-2);
}
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.dz-icon { font-size: 28px; color: var(--accent); }
.dz-title { font-weight: 600; font-size: 16px; }
.dropzone .btn { margin-top: 8px; }

.reg { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; }
.reg-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 16px; }
.reg-title { font-weight: 600; font-size: 15px; margin-right: auto; }
.chip { font-size: 12px; font-weight: 500; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); }
.chip.ok { background: var(--good-bg); color: var(--good); }
.chip.miss { background: var(--bad-bg); color: var(--bad); }
.reg-kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.reg-kpis div { background: var(--surface-2); border-radius: 8px; padding: 12px 14px; }
.reg-kpis b { display: block; font-size: 17px; font-weight: 600; }
.reg-kpis span { font-size: 12px; color: var(--muted); }
.avisos { margin: 0 0 8px; padding: 0; list-style: none; }
.avisos li { background: var(--warn-bg); color: var(--warn); border-radius: 8px; padding: 8px 12px; margin-bottom: 6px; font-size: 13px; }
.avisos li.okmsg { background: var(--good-bg); color: var(--good); }
details summary { cursor: pointer; color: var(--text-2); font-size: 13px; font-weight: 500; margin: 8px 0; }

.save-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; gap: 12px; align-items: center; justify-content: flex-end;
  padding: 12px max(var(--gap), calc((100vw - var(--maxw)) / 2 + var(--gap)));
  background: var(--surface); border-top: 1px solid var(--border); box-shadow: 0 -4px 12px rgba(16, 24, 40, .06);
}
.toast {
  position: fixed; bottom: 84px; left: 50%; transform: translateX(-50%); z-index: 30;
  background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 8px; max-width: 90vw; font-size: 13px;
}
.empty { color: var(--muted); text-align: center; padding: 32px 16px; }

/* ---------- Login y modales ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px;
  background: color-mix(in srgb, var(--bg) 94%, transparent);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 32px; display: flex; flex-direction: column; gap: 14px;
  box-shadow: 0 12px 32px rgba(16, 24, 40, .10);
}
.login-card h2 { font-size: 20px; font-weight: 600; margin-top: 4px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 500; color: var(--text-2); }
.login-card .err { min-height: 18px; font-size: 13px; }
.login-card .btn.primary { height: 42px; }
.row-btns { display: flex; gap: 8px; justify-content: flex-end; }
.badge { font-size: 12px; font-weight: 500; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); color: var(--text-2); }
.badge.on { background: var(--good-bg); color: var(--good); }
.badge.off { background: var(--bad-bg); color: var(--bad); }
.form-row .field { flex: 1 1 180px; }
.form-row .field input, .form-row .field select { width: 100%; }

/* ---------- Responsivo ---------- */
@media (max-width: 1280px) {
  .status { font-size: 0; gap: 0; } /* solo el punto de estado; el texto queda en el title */
}
@media (max-width: 1100px) {
  .topbar-inner { flex-wrap: wrap; height: auto; padding-top: 10px; row-gap: 0; column-gap: 16px; }
  .tabs { order: 3; width: 100%; height: 48px; overflow-x: auto; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
  .reg-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  :root { --gap: 16px; }
  main { padding-top: 20px; }
  .user-text, .status { display: none; }
  .user-menu { padding-left: 8px; border-left: 0; }
  .page-head h1 { font-size: 20px; }
  .toolbar { width: 100%; }
  .toolbar .field { flex: 1 1 140px; }
  .toolbar .field input, .toolbar .field select { width: 100%; }
  .kpis { gap: 12px; }
  .kpi { padding: 16px; min-height: 108px; }
  .kpi-label { min-height: 2.9em; font-size: 11px; } /* misma altura de etiqueta = montos alineados */
  .kpi-value { font-size: 22px; }
  .chart-wrap { height: 260px; }
}
.tbl th.fecha-h { vertical-align: bottom; }
#t-diario tr:nth-child(2) th:first-child { text-align: right; padding-left: 16px; }
