:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #18202b;
  --muted: #5d6b7c;
  --line: #e2e7ee;
  --brand: #d71920;
  --brand-ink: #ffffff;
  --s2: #d71920;      /* Tubo Wash */
  --s3: #e3a600;      /* Corregidora */
  --prev: #9aa6b4;    /* periodo de comparacion */
  --good: #1a7f37;
  --bad: #b42318;
  --warn-bg: #fff4e5;
  --radius: 12px;
  --gap: 14px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand); }
button, select, input { font: inherit; }

/* ---------- barra superior ---------- */
.top { position: sticky; top: 0; z-index: 10; background: var(--card); color: var(--ink);
  display: flex; align-items: center; gap: 12px; padding: 0 16px; height: 56px; border-bottom: 3px solid var(--brand); }
.top img { height: 38px; width: auto; display: block; }
.top h1 { font-size: 17px; margin: 0; font-weight: 650; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .user { font-size: 13px; color: var(--muted); }
@media (max-width: 480px) { .top .user { display: none; } }
.top button { background: transparent; color: inherit; border: 1px solid var(--line);
  border-radius: 8px; padding: 4px 10px; cursor: pointer; }

/* ---------- filtros ---------- */
.filtros { background: var(--card); border-bottom: 1px solid var(--line); padding: 10px 16px;
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.chips { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; max-width: 100%; }
.chips::-webkit-scrollbar { display: none; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 5px 12px;
  white-space: nowrap; cursor: pointer; color: var(--ink); }
.chip[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.filtros select, .filtros input[type=date] { border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; background: var(--card); }
.rango { display: none; gap: 6px; align-items: center; }
.rango.on { display: flex; }
.periodo { font-size: 13px; color: var(--muted); width: 100%; }

/* ---------- pestañas ---------- */
.tabs { display: flex; gap: 2px; padding: 0 12px; background: var(--card); border-bottom: 1px solid var(--line);
  overflow-x: auto; scrollbar-width: none; position: sticky; top: 59px; z-index: 9; }
.tabs::-webkit-scrollbar { display: none; }
.tab { border: 0; background: none; padding: 11px 12px; cursor: pointer; color: var(--muted); white-space: nowrap;
  border-bottom: 3px solid transparent; }
.tab[aria-selected="true"] { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }

main { max-width: 1200px; margin: 0 auto; padding: 16px; }
.panel { display: none; }
.panel.on { display: block; }

/* ---------- tarjetas ---------- */
.grid { display: grid; gap: var(--gap); }
.kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 760px) { .kpis { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); } }
.g2 { grid-template-columns: 1fr; }
@media (min-width: 960px) { .g2 { grid-template-columns: 1fr 1fr; } }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; min-width: 0; }
.card h2 { font-size: 15px; margin: 0 0 2px; }
.card .sub { font-size: 12.5px; color: var(--muted); margin: 0 0 10px; }
.mt { margin-top: var(--gap); }

.kpi .lbl { font-size: 12.5px; color: var(--muted); }
.kpi .val small { font-size: 14px; font-weight: 600; color: var(--muted); }
.kpi .val { font-size: 24px; font-weight: 700; margin: 2px 0 4px; font-variant-numeric: tabular-nums; }
.kpi .cmp { font-size: 12.5px; color: var(--muted); display: flex; flex-direction: column; gap: 1px; }
.up { color: var(--good); } .down { color: var(--bad); }
.kpi.alerta { background: var(--warn-bg); }

.chart { position: relative; height: 260px; }
.chart.alto { height: 360px; }

/* ---------- tablas ---------- */
.tabla { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { font-weight: 600; color: var(--muted); font-size: 12.5px; position: sticky; top: 0; background: var(--card); }
td.txt, th.txt { text-align: left; }
tr.alerta td { background: var(--warn-bg); }
tfoot td { font-weight: 650; }

/* ---------- mapa de calor ---------- */
.heat td { text-align: center; font-variant-numeric: tabular-nums; min-width: 38px; }
@media (max-width: 480px) {
  .heat th, .heat td { padding: 6px 3px; min-width: 0; font-size: 12px; }
  .kpi .val { font-size: 21px; }
}
.heat td.h { text-align: left; color: var(--muted); }

.nota { font-size: 12.5px; color: var(--muted); margin-top: 8px; }
.cargando { opacity: .45; pointer-events: none; transition: opacity .15s; }
.error { background: #fdecea; color: var(--bad); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; display: none; }
.error.on { display: block; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; padding: 16px; }
.login { width: 100%; max-width: 360px; }
.login h1 { font-size: 20px; margin: 0 0 4px; }
.login label { display: block; font-size: 13px; color: var(--muted); margin: 12px 0 4px; }
.login input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; }
.btn { width: 100%; margin-top: 16px; padding: 11px; border: 0; border-radius: 8px; background: var(--brand);
  color: var(--brand-ink); font-weight: 600; cursor: pointer; }
.btn[disabled] { opacity: .6; }

/* ---------- pagina publica ---------- */
.hero { background: var(--card); border-bottom: 4px solid var(--brand); padding: 32px 16px; text-align: center; }
.hero img { width: 240px; max-width: 70%; height: auto; }
.hero p { margin: 8px 0 0; color: var(--muted); }
.login .logo { width: 180px; height: auto; display: block; margin: 0 auto 8px; }
.login h1 { text-align: center; }
.login .sub { text-align: center; }

/* ---------- utilidades extra ---------- */
.cab { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 2px; }
.mini { border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 8px;
  padding: 4px 10px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.mini.primario { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.buscar { display: flex; gap: 8px; margin-bottom: 8px; }
.buscar input { flex: 1; min-width: 0; border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
#t-notas tbody tr.fila { cursor: pointer; }
#t-notas tbody tr.fila:hover td { background: #fdf2f2; }
#t-notas td.serv { white-space: normal; min-width: 180px; text-align: left; }
tr.detalle td { background: #f7f9fc; text-align: left; white-space: normal; }
tr.cancelada td { color: var(--muted); text-decoration: line-through; }
.tag { display: inline-block; font-size: 11px; border-radius: 6px; padding: 1px 6px; background: var(--line); color: var(--ink); margin-left: 4px; text-decoration: none; }

/* ---------- por sucursal ---------- */
.porsuc { display: grid; gap: var(--gap); grid-template-columns: 1fr; align-items: center; }
@media (min-width: 860px) { .porsuc { grid-template-columns: 260px 1fr; } }
.chart.pie { height: 240px; }
#t-sucursal td:first-child { color: var(--muted); }
#t-sucursal th.tot, #t-sucursal td.tot { font-weight: 650; }

/* ---------- pronostico ---------- */
.pron { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: thin; }
.dia { flex: 0 0 auto; min-width: 92px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; text-align: center; }
.dia .d { font-size: 12.5px; color: var(--muted); }
.dia .ic { font-size: 26px; line-height: 1.3; }
.dia .t { font-size: 13px; font-variant-numeric: tabular-nums; }
.dia .ll { font-size: 12px; margin-top: 2px; }
.dia.seco { border-color: #b7e1c1; background: #f3fbf5; }
.dia.lluvia { border-color: #bcd3f5; background: #f2f7fe; }
.dia.lluvia .ll { color: #1d4ed8; font-weight: 600; }

/* ---------- mapa ---------- */
.mapa { height: 460px; border-radius: 10px; border: 1px solid var(--line); z-index: 0; }
@media (max-width: 480px) { .mapa { height: 360px; } }
.leyenda { background: #fff; padding: 6px 10px; border-radius: 8px; font-size: 12.5px; line-height: 1.6; box-shadow: 0 1px 4px rgba(0,0,0,.2); }
.leyenda i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }

/* ---------- pie (igual que a57m: logo blanco sobre franja oscura) ---------- */
.pie { display: flex; justify-content: center; padding: 18px 16px 24px; }
.pie a { display: inline-flex; flex-direction: column; align-items: center; gap: 5px;
  background: #1f2937; color: #e5e7eb; border-radius: 10px; padding: 8px 18px 10px;
  text-decoration: none; font-size: 13px; font-weight: 700; }
.pie a:hover { background: #111827; }
.pie-label { font-size: 9px; letter-spacing: .8px; text-transform: uppercase; color: rgba(255,255,255,.55); font-weight: 600; }
.pie img { height: 32px; display: block; }

.login .recordar { display: flex; align-items: center; gap: 8px; margin: 14px 0 0; font-size: 13px; color: var(--ink); cursor: pointer; }
.login .recordar input { width: 18px; height: 18px; margin: 0; accent-color: var(--brand); }
