/* =========================================================
   Dashboard de reparto · estilos
   ========================================================= */

:root {
  --bg: #f3f5fa;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #2563eb;
  --accent-soft: #dbe7ff;

  --c-envios: #2563eb;
  --c-recogidas: #f59e0b;
  --c-valijas: #ec4899;
  --c-paradas: #10b981;
  --c-ratio: #8b5cf6;
  --c-aviso: #ef4444;

  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 16px rgba(15, 23, 42, .05);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --card: #111a2e;
    --text: #e6ebf5;
    --muted: #93a1ba;
    --border: #22304a;
    --accent: #5b8def;
    --accent-soft: #1b2b4d;

    --c-envios: #5b8def;
    --c-recogidas: #fbbf24;
    --c-valijas: #f472b6;
    --c-paradas: #34d399;
    --c-ratio: #a78bfa;
    --c-aviso: #f87171;

    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px rgba(0, 0, 0, .25);
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 var(--font);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible, button:focus-visible, select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

h1, h2 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.65rem; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; }
code { background: var(--accent-soft); padding: 2px 6px; border-radius: 6px; font-size: .9em; }

.skip {
  position: absolute; left: -999px; top: 8px; z-index: 100;
  background: var(--accent); color: #fff; padding: 8px 14px; border-radius: 8px;
}
.skip:focus { left: 8px; }

/* ---------- Barra superior ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar__inner {
  max-width: 1320px; margin: 0 auto; padding: 10px 24px;
  display: flex; align-items: center; gap: 24px;
}
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand svg { color: var(--accent); }
.topbar__nav { display: flex; gap: 4px; flex: 1; }
.topbar__nav a {
  padding: 6px 12px; border-radius: 8px; color: var(--muted); font-weight: 500;
}
.topbar__nav a.activo, .topbar__nav a:hover { background: var(--accent-soft); color: var(--accent); text-decoration: none; }

.filtro { display: flex; align-items: center; gap: 8px; }
.filtro label { color: var(--muted); font-size: .85rem; }
select {
  font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 28px 6px 10px;
}

/* ---------- Estructura ---------- */
.contenedor { width: 100%; max-width: 1320px; margin: 0 auto; padding: 24px; flex: 1; }
.pie { border-top: 1px solid var(--border); color: var(--muted); font-size: .85rem; }
.pie .contenedor { flex: none; padding-top: 16px; padding-bottom: 16px; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.sub { margin: 4px 0 0; color: var(--muted); }
.titulo-fecha::first-letter { text-transform: uppercase; }
.migas { margin-bottom: 8px; font-size: .9rem; }
.paginacion { display: flex; gap: 8px; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: .9rem; cursor: pointer;
  padding: 8px 14px; border-radius: 10px; border: 1px solid var(--accent);
  background: var(--accent); color: #fff;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn--ghost { background: transparent; color: var(--accent); border-color: var(--border); }
.btn--ghost:hover { background: var(--accent-soft); filter: none; }

/* ---------- Tarjetas ---------- */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px;
  min-width: 0;
}
.card__head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card__head small { display: block; color: var(--muted); font-size: .82rem; margin-top: 2px; }

.vacio { text-align: center; padding: 48px 24px; }
.vacio p { color: var(--muted); }

/* ---------- KPIs ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 20px; }
.kpis--6 { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.kpi {
  --k: var(--border);
  background: var(--card); border: 1px solid var(--border); border-left: 4px solid var(--k);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px;
  display: flex; flex-direction: column; gap: 2px;
}
.kpi--envios { --k: var(--c-envios); }
.kpi--recogidas { --k: var(--c-recogidas); }
.kpi--valijas { --k: var(--c-valijas); }
.kpi--paradas { --k: var(--c-paradas); }
.kpi--aviso { --k: var(--c-aviso); }
.kpi__etiqueta { color: var(--muted); font-size: .82rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.kpi__valor { font-size: 1.9rem; line-height: 1.15; font-variant-numeric: tabular-nums; }
.kpi__nota { color: var(--muted); font-size: .82rem; }

/* ---------- Rejillas ---------- */
.grid-main { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 20px; margin-bottom: 20px; align-items: start; }
.col-graficos { display: grid; gap: 20px; min-width: 0; }
.graficos-2col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.col-lateral { position: sticky; top: 76px; }
.grid-vacio { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 20px; align-items: start; }
.grid-tablas { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.grid-tablas__col { display: grid; gap: 20px; min-width: 0; }

.chart-box { position: relative; height: 320px; }
.chart-box--sm { height: 280px; }

/* ---------- Tablas ---------- */
.tabla-scroll { overflow: auto; max-height: 560px; border-radius: 10px; }
.tabla { width: 100%; border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
.tabla th, .tabla td { padding: 8px 12px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.tabla thead th {
  position: sticky; top: 0; z-index: 2; background: var(--card);
  color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em;
  border-bottom: 2px solid var(--border);
}
.tabla tbody tr:hover { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.tabla tfoot th, .tabla tfoot td { font-weight: 700; border-top: 2px solid var(--border); border-bottom: 0; background: var(--card); }
.tabla .num { text-align: right; }
.tabla .total { font-weight: 700; }
.tabla .dir { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.tabla th[scope="row"] { font-weight: 600; }

.tabla-pivote .sticky { position: sticky; left: 0; z-index: 1; background: var(--card); }
.tabla-pivote thead .sticky { z-index: 3; }
.tabla-pivote th, .tabla-pivote td { padding: 7px 10px; }
.heat { background: color-mix(in srgb, var(--c-paradas) calc(var(--i, 0) * 65%), transparent); }
.heat--vacio { color: var(--muted); }

.barra { display: inline-block; vertical-align: middle; width: 110px; height: 8px; border-radius: 99px; background: var(--border); overflow: hidden; }
.barra span { display: block; height: 100%; background: var(--c-paradas); border-radius: 99px; }
.barra__txt { margin-left: 8px; color: var(--muted); }

/* ---------- Calendario ---------- */
.calendario__cab { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.calendario__mes { font-weight: 700; text-transform: capitalize; }
.cal-btn {
  width: 32px; height: 32px; display: inline-grid; place-items: center;
  border: 1px solid var(--border); background: transparent; color: var(--text);
  border-radius: 8px; cursor: pointer; font-size: 1rem;
}
.cal-btn:hover { background: var(--accent-soft); }
.calendario__grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.calendario__dow { text-align: center; color: var(--muted); font-size: .75rem; font-weight: 600; padding: 4px 0; }
.cal-dia {
  position: relative; aspect-ratio: 1; display: grid; place-items: center;
  border-radius: 10px; font-size: .88rem; color: var(--muted); border: 1px solid transparent;
  font-variant-numeric: tabular-nums;
}
.cal-dia--datos { color: var(--text); font-weight: 600; background: var(--accent-soft); cursor: pointer; }
.cal-dia--datos::after {
  content: ""; position: absolute; bottom: 5px; width: 5px; height: 5px; border-radius: 50%; background: var(--accent);
}
.cal-dia--datos:hover { text-decoration: none; border-color: var(--accent); }
.cal-dia--sel { background: var(--accent); color: #fff; }
.cal-dia--sel::after { background: #fff; }
.cal-dia--hoy { border-color: var(--muted); }
.calendario__pie { margin-top: 12px; display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.calendario__pie .btn { padding: 5px 10px; font-size: .82rem; }

.leyenda { list-style: none; display: flex; gap: 16px; padding: 0; margin: 12px 0 0; color: var(--muted); font-size: .8rem; }
.leyenda li { display: inline-flex; align-items: center; gap: 6px; }
.punto { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.punto--datos { background: var(--accent-soft); border: 1px solid var(--accent); }
.punto--sel { background: var(--accent); }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .grid-main, .grid-vacio, .grid-tablas { grid-template-columns: minmax(0, 1fr); }
  .col-lateral { position: static; order: -1; }
}
@media (max-width: 720px) {
  .contenedor { padding: 16px; }
  .topbar__inner { padding: 10px 16px; gap: 12px; flex-wrap: wrap; }
  .graficos-2col { grid-template-columns: minmax(0, 1fr); }
  h1 { font-size: 1.35rem; }
  .kpi__valor { font-size: 1.6rem; }
}

@media print {
  .topbar, .col-lateral, .btn, .skip { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; }
}
