/* ============ Tema ============ */
:root {
  --fondo: #f3f1ec;
  --panel: #ffffff;
  --panel-2: #f8f6f1;
  --borde: #e2ddd2;
  --texto: #1f1d1a;
  --texto-2: #6b665c;
  --acento: #c8811a;
  --ok: #2f9e6b;
  --mal: #d0473c;
  --rejilla: rgba(0, 0, 0, .07);
  --sombra: 0 1px 2px rgba(40, 30, 10, .06), 0 4px 16px rgba(40, 30, 10, .05);
  --l2500: #d98b19;
  --l2000: #1f8f8a;
  --l1500: #d0573f;
  --l1200: #5b62c9;
  --radio: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fondo: #121315; --panel: #1b1d20; --panel-2: #222529; --borde: #2e3237;
    --texto: #ecebe7; --texto-2: #9a9890; --acento: #f0a434;
    --rejilla: rgba(255, 255, 255, .07); --sombra: none;
    --l2500: #f0a434; --l2000: #36b8b0; --l1500: #ef7a62; --l1200: #8b91f0;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --fondo: #121315; --panel: #1b1d20; --panel-2: #222529; --borde: #2e3237;
  --texto: #ecebe7; --texto-2: #9a9890; --acento: #f0a434;
  --rejilla: rgba(255, 255, 255, .07); --sombra: none;
  --l2500: #f0a434; --l2000: #36b8b0; --l1500: #ef7a62; --l1200: #8b91f0;
  color-scheme: dark;
}

/* ============ Base ============ */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--fondo);
  color: var(--texto);
  font: 15px/1.45 "Barlow", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { margin: 0; font-family: "Barlow Condensed", "Barlow", sans-serif; letter-spacing: .01em; }
.num { font-family: "Barlow Condensed", sans-serif; font-variant-numeric: tabular-nums; }
main { max-width: 1440px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }

/* ============ Barra superior ============ */
.barra {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 16px; background: var(--panel); border-bottom: 1px solid var(--borde);
  position: sticky; top: 0; z-index: 10;
}
.marca { display: flex; align-items: center; gap: 12px; }
.marca svg { width: 34px; height: 34px; fill: none; stroke: var(--acento); stroke-width: 2.6; stroke-linecap: round; }
.marca h1 { font-size: 22px; font-weight: 700; line-height: 1; }
.marca p { margin: 2px 0 0; font-size: 13px; color: var(--texto-2); }
.barra-der { display: flex; align-items: center; gap: 14px; }
.reloj { text-align: right; line-height: 1.1; }
.reloj span { font: 600 22px "Barlow Condensed", sans-serif; font-variant-numeric: tabular-nums; }
.reloj small { display: block; color: var(--texto-2); font-size: 12px; }
.icono {
  width: 36px; height: 36px; display: grid; place-items: center; border-radius: 10px;
  border: 1px solid var(--borde); background: var(--panel-2);
}
.icono svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icono:hover, .boton:hover { border-color: var(--acento); }

/* ============ Tarjetas de línea ============ */
.lineas { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.linea {
  --c: var(--acento);
  text-align: left; background: var(--panel); border: 1px solid var(--borde); border-radius: var(--radio);
  padding: 14px 16px 12px; box-shadow: var(--sombra); position: relative; overflow: hidden;
  transition: opacity .2s, transform .15s;
}
.linea::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--c); }
.linea:hover { transform: translateY(-1px); }
.linea.oculta { opacity: .42; }
.linea .cab { display: flex; justify-content: space-between; align-items: center; }
.linea h3 { font-size: 19px; font-weight: 700; }
.estado { font-size: 12px; display: inline-flex; align-items: center; gap: 6px; color: var(--texto-2); }
.estado::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 22%, transparent); }
.estado.mal::before { background: var(--mal); box-shadow: 0 0 0 3px color-mix(in srgb, var(--mal) 22%, transparent); }
.linea .total { font-size: 34px; font-weight: 600; line-height: 1.05; margin: 6px 0 2px; }
.linea .total small { font-size: 14px; color: var(--texto-2); font-family: "Barlow", sans-serif; font-weight: 500; margin-left: 4px; }
.linea .datos { display: flex; gap: 14px; font-size: 13px; color: var(--texto-2); flex-wrap: wrap; }
.linea .datos b { color: var(--texto); font-weight: 600; }
.meta { margin-top: 10px; height: 6px; border-radius: 6px; background: var(--panel-2); overflow: hidden; }
.meta i { display: block; height: 100%; background: var(--c); border-radius: 6px; transition: width .5s; }
.meta-txt { font-size: 12px; color: var(--texto-2); margin-top: 4px; }

/* ============ Controles ============ */
.controles {
  display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center;
  background: var(--panel); border: 1px solid var(--borde); border-radius: var(--radio); padding: 12px 16px;
}
.grupo { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.rotulo { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--texto-2); font-weight: 600; }
.chips, .segmento { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button, .segmento button, .boton {
  border: 1px solid var(--borde); background: var(--panel-2); padding: 6px 12px; border-radius: 999px; font-size: 14px; font-weight: 500;
}
.segmento { gap: 0; background: var(--panel-2); border: 1px solid var(--borde); border-radius: 10px; padding: 3px; }
.segmento button { border: 0; background: none; border-radius: 7px; padding: 5px 12px; }
.chips button.activo, .segmento button.activo { background: var(--texto); color: var(--panel); border-color: var(--texto); }
.boton { border-radius: 10px; }
.rango { display: flex; align-items: center; gap: 6px; color: var(--texto-2); }
.rango input { background: var(--panel-2); border: 1px solid var(--borde); border-radius: 10px; padding: 5px 8px; }

/* ============ KPIs ============ */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.kpi { background: var(--panel); border: 1px solid var(--borde); border-radius: var(--radio); padding: 14px 16px; box-shadow: var(--sombra); min-width: 0; }
.kpi h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--texto-2); font-weight: 600; font-family: "Barlow", sans-serif; }
.kpi .num { font-size: 32px; font-weight: 600; margin: 4px 0 0; line-height: 1.1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi small { color: var(--texto-2); font-size: 13px; }
.sube { color: var(--ok); font-weight: 600; }
.baja { color: var(--mal); font-weight: 600; }

/* ============ Tarjetas de gráfica ============ */
.tarjeta { background: var(--panel); border: 1px solid var(--borde); border-radius: var(--radio); padding: 16px; box-shadow: var(--sombra); min-width: 0; position: relative; }
.tarjeta-cab { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.tarjeta h2 { font-size: 20px; font-weight: 600; }
.sub { color: var(--texto-2); font-size: 13px; }
.acciones { display: flex; gap: 8px; align-items: center; }
.ayuda { margin: 0 0 8px; font-size: 12.5px; color: var(--texto-2); }
.lienzo { position: relative; height: 280px; }
.lienzo.alto { height: 420px; }
.fila { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 16px; }
.vacio { position: absolute; inset: 120px 16px auto; text-align: center; color: var(--texto-2); }
.migas { display: flex; gap: 6px; flex-wrap: wrap; font-size: 13px; color: var(--texto-2); margin-top: 2px; }
.migas button { border: 0; background: none; padding: 0; color: var(--acento); text-decoration: underline; text-underline-offset: 2px; }
.principal:fullscreen { padding: 24px; display: flex; flex-direction: column; }
.principal:fullscreen .lienzo { flex: 1; height: auto; }

/* ============ Tabla ============ */
.tabla-env { overflow: auto; max-height: 420px; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; font-size: 14px; }
th, td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--borde); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th { position: sticky; top: 0; background: var(--panel); font-weight: 600; color: var(--texto-2); font-size: 12.5px; text-transform: uppercase; letter-spacing: .05em; }
thead th i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }
tfoot td { font-weight: 700; border-top: 2px solid var(--borde); position: sticky; bottom: 0; background: var(--panel); }
tbody tr:hover { background: var(--panel-2); }
tbody tr.clic { cursor: pointer; }

.pie { text-align: center; color: var(--texto-2); font-size: 12.5px; padding: 8px 16px 24px; }
.cargando main { opacity: .65; transition: opacity .2s; }

/* ============ Responsive ============ */
@media (max-width: 1100px) {
  .lineas, .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fila { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
  main { padding: 12px 16px; gap: 12px; }
  .lineas, .kpis { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
  .linea { padding: 12px 12px 10px; }
  .linea .total { font-size: 26px; }
  .kpi .num { font-size: 24px; }
  .lienzo.alto { height: 320px; }
  .marca p, .reloj small { display: none; }
  .ayuda { display: none; }
}
