/* Boreal · tokens de la guía de dataviz (paleta validada) */
:root {
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, .10);
  --s1: #2a78d6;  /* azul */
  --s2: #1baf7a;  /* aqua */
  --s3: #eda100;  /* amarillo */
  --s4: #008300;  /* verde */
  --ref: #898781; /* serie de contexto (campaña anterior) */
  --good: #006300;
  --chip-bg: #f0efec;
}
@media (prefers-color-scheme: dark) {
  :root {
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, .10);
    --s1: #3987e5;
    --s2: #199e70;
    --s3: #c98500;
    --s4: #008300;
    --good: #0ca30c;
    --chip-bg: #262624;
  }
}

@font-face {
  font-family: "Inter";
  src: url("fonts/inter.woff2") format("woff2");
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: "Space Grotesk";
  src: url("fonts/space-grotesk.woff2") format("woff2");
  font-weight: 300 700;
  font-display: swap;
}

* { box-sizing: border-box; }
:root { --aurora: linear-gradient(90deg, #2a78d6, #1baf7a); }
body {
  margin: 0;
  background: var(--page);
  /* leve resplandor boreal en la parte alta de la página */
  background-image: radial-gradient(1100px 380px at 50% -120px,
    color-mix(in srgb, var(--s1) 9%, transparent),
    color-mix(in srgb, var(--s2) 4%, transparent) 55%, transparent 75%);
  background-repeat: no-repeat;
  color: var(--ink);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}
h1, h2, h3, .nav a, .seg button, .badge-demo, .chip { font-family: "Space Grotesk", "Inter", system-ui, sans-serif; }

/* ── Cabecera ─────────────────────────────────────── */
header.top {
  position: relative;
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  padding: 14px 28px;
  border-bottom: 1px solid var(--grid);
  background: var(--surface);
}
header.top::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: var(--aurora);
}
.brand {
  display: flex; align-items: center; gap: 12px; margin-right: auto;
  text-decoration: none; color: inherit;
}
.marca { width: 42px; height: 42px; flex: none; }
.marca .crease { stroke: var(--surface); }
.brand h1 { font-size: 18px; margin: 0; letter-spacing: .17em; font-weight: 700; }
.brand p { margin: 0; font-size: 12px; color: var(--muted); }

.nav { display: flex; gap: 4px; }
.nav a {
  display: flex; align-items: center; gap: 7px;
  padding: 8px 14px; border-radius: 9px;
  color: var(--ink-2); text-decoration: none; font-size: 13.5px;
}
.nav a:hover { background: var(--chip-bg); }
.nav a.on { background: var(--chip-bg); color: var(--ink); font-weight: 650; }
.nav a:focus-visible { outline: 2px solid var(--s1); }
.live-dot {
  width: 7px; height: 7px; border-radius: 50%; flex: none; display: inline-block;
  background: var(--s2);
  animation: latido 2s infinite;
}
@keyframes latido {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--s2) 55%, transparent); }
  70% { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}
@media (prefers-reduced-motion: reduce) { .live-dot { animation: none; } }

.toolbar { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar-hint { font-size: 12px; color: var(--muted); margin-left: auto; }
.seg { display: flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button {
  border: 0; background: transparent; color: var(--ink-2);
  padding: 7px 14px; font: inherit; font-size: 13.5px; cursor: pointer;
}
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--chip-bg); color: var(--ink); font-weight: 600; }
.seg button:focus-visible { outline: 2px solid var(--s1); outline-offset: -2px; }

.badge-demo {
  font-size: 11px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted); border: 1px dashed var(--baseline);
  padding: 5px 10px; border-radius: 6px;
}
.autor { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.autor a { color: var(--ink-2); text-decoration: none; border-bottom: 1px solid var(--baseline); }
.autor a:hover, .autor a:focus-visible { color: var(--ink); border-bottom-color: var(--ink); }

/* ── KPIs ─────────────────────────────────────────── */
main { max-width: 1200px; margin: 0 auto; padding: 24px 28px 48px; }
.kpis {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px; margin-bottom: 14px;
}
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px 18px 14px;
  box-shadow: 0 1px 3px color-mix(in srgb, var(--ink) 4%, transparent);
}
.tile .k {
  font-size: 11.5px; letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted); font-weight: 600;
  font-family: "Space Grotesk", sans-serif;
  display: flex; align-items: center; gap: 7px;
}
.tile .k svg { width: 15px; height: 15px; stroke: var(--muted); flex: none; }
.tile .v {
  font-size: 30px; font-weight: 700; letter-spacing: -.01em; margin-top: 4px;
  font-family: "Space Grotesk", sans-serif;
}
.tile .d { font-size: 13px; color: var(--ink-2); margin-top: 2px; }
.tile .d .up { color: var(--good); font-weight: 650; }
.tile .d .down { color: var(--ink-2); font-weight: 650; }

/* Estados de carga */
.tile.skeleton {
  min-height: 92px;
  background: linear-gradient(100deg, var(--chip-bg) 40%, var(--border) 50%, var(--chip-bg) 60%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
  border-color: transparent;
}
@keyframes shimmer { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .tile.skeleton { animation: none; } }
.skeleton-msg { color: var(--muted); font-size: 13.5px; margin: 0 0 14px; }
.error-banner {
  background: var(--chip-bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 18px 20px; margin-bottom: 14px; display: flex; align-items: center; gap: 16px;
}
.error-banner button {
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  border-radius: 8px; padding: 8px 16px; font: inherit; font-weight: 600; cursor: pointer;
}

/* ── Tarjetas y gráficos ──────────────────────────── */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 18px 20px;
  min-width: 0;
  box-shadow: 0 1px 3px color-mix(in srgb, var(--ink) 4%, transparent);
}
.card.wide { grid-column: 1 / -1; }
.card h2 { font-size: 15.5px; margin: 0 0 12px; font-weight: 600; letter-spacing: .01em; }
.card h2 .sub { font-family: "Inter", sans-serif; }
.card h2 .sub { font-weight: 450; color: var(--muted); font-size: 13px; margin-left: 6px; }
.plot { position: relative; height: 280px; }
.card.wide .plot { height: 300px; }

/* ── Tabla ────────────────────────────────────────── */
.tabla-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13.5px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--grid); }
th { font-size: 11.5px; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }

/* ── Chat ─────────────────────────────────────────── */
.card.chat { display: flex; flex-direction: column; }
.chat-log {
  flex: 1; min-height: 170px; max-height: 240px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 8px; padding: 4px 2px; margin-bottom: 10px;
}
.msg { padding: 8px 12px; border-radius: 10px; max-width: 92%; white-space: pre-wrap; font-size: 14px; }
.msg.bot { background: var(--chip-bg); align-self: flex-start; }
.msg.yo { background: var(--s1); color: #fff; align-self: flex-end; }
.msg.pensando span {
  display: inline-block; width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted); margin-right: 4px;
  animation: puntito 1.2s infinite ease-in-out;
}
.msg.pensando span:nth-child(2) { animation-delay: .2s; }
.msg.pensando span:nth-child(3) { animation-delay: .4s; }
@keyframes puntito { 0%, 60%, 100% { opacity: .3; } 30% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .msg.pensando span { animation: none; } }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
.chips button {
  border: 1px solid var(--border); background: transparent; color: var(--ink-2);
  border-radius: 99px; padding: 5px 12px; font: inherit; font-size: 12.5px; cursor: pointer;
}
.chips button:hover { background: var(--chip-bg); }
#chat-form { display: flex; gap: 8px; }
#chat-in {
  flex: 1; border: 1px solid var(--border); border-radius: 8px;
  background: var(--page); color: var(--ink); padding: 9px 12px; font: inherit;
  font-size: 16px; /* <16px dispara el zoom automático de iOS Safari */
  min-width: 0;
}
#chat-in:disabled, #chat-form button:disabled, .chips button:disabled { opacity: .55; cursor: default; }
#chat-in:focus-visible { outline: 2px solid var(--s1); }
#chat-form button {
  border: 0; border-radius: 8px; background: var(--s1); color: #fff;
  padding: 9px 16px; font: inherit; font-weight: 600; cursor: pointer;
}
.nota { font-size: 12px; color: var(--muted); margin: 8px 0 0; }

footer { max-width: 1200px; margin: 0 auto; padding: 0 28px 40px; color: var(--muted); font-size: 12.5px; }
footer code { background: var(--chip-bg); padding: 1px 5px; border-radius: 4px; }

/* ── Hero (dashboard) ─────────────────────────────── */
.hero {
  position: relative; border-radius: 14px; overflow: hidden;
  min-height: 210px; display: flex; align-items: flex-end;
  margin-bottom: 16px;
  border: 1px solid var(--border);
}
.hero img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: center 40%; }
.hero::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(100deg, rgba(10, 12, 14, .78) 0%, rgba(10, 12, 14, .45) 45%, rgba(10, 12, 14, .05) 75%);
}
.hero-texto { position: relative; z-index: 1; padding: 22px 26px; color: #f6f5f1; max-width: 60ch; }
.hero-texto .overline {
  font-family: "Space Grotesk", sans-serif; font-size: 11px; font-weight: 600;
  letter-spacing: .22em; text-transform: uppercase; margin: 0 0 6px;
  background: var(--aurora); -webkit-background-clip: text; background-clip: text; color: transparent;
  filter: brightness(1.5);
}
.hero-texto h2 {
  font-family: "Space Grotesk", sans-serif; font-size: clamp(20px, 3vw, 28px);
  font-weight: 700; margin: 0 0 4px; letter-spacing: -.01em; line-height: 1.2;
}
.hero-texto p:not(.overline) { margin: 0; font-size: 13.5px; color: rgba(246, 245, 241, .82); }

/* ── Flota con foto (centro de control) ───────────── */
.flota-card { display: grid; grid-template-columns: 1fr 265px; gap: 20px; align-items: start; }
.flota-foto { margin: 0; }
.flota-foto img {
  width: 100%; aspect-ratio: 4 / 3.4; object-fit: cover; display: block;
  border-radius: 10px;
}
.flota-foto figcaption { font-size: 12px; color: var(--muted); margin-top: 7px; }

/* ── Cierre (footer con CTA) ──────────────────────── */
footer .cierre {
  position: relative; border-radius: 14px; overflow: hidden;
  background: #16211e; color: #f4f3ef;
  margin-bottom: 16px;
}
.cierre-fondo {
  position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover;
  object-position: right center; opacity: .85;
  mask-image: linear-gradient(90deg, transparent 25%, #000 65%);
  -webkit-mask-image: linear-gradient(90deg, transparent 25%, #000 65%);
}
.cierre-texto { position: relative; z-index: 1; padding: 30px 34px; max-width: 56ch; }
.cierre-texto .marca { width: 34px; height: 34px; color: #f4f3ef; margin-bottom: 10px; }
.cierre-texto .marca .crease { stroke: #16211e; }
.cierre-titulo {
  font-family: "Space Grotesk", sans-serif; font-size: 22px; font-weight: 700;
  margin: 0 0 8px; letter-spacing: -.01em; line-height: 1.25;
}
.cierre-sub { margin: 0 0 16px; font-size: 13.5px; color: rgba(244, 243, 239, .75); }
.cierre-cta { display: flex; gap: 10px; flex-wrap: wrap; }
.btn {
  display: inline-block; padding: 9px 18px; border-radius: 9px;
  font-family: "Space Grotesk", sans-serif; font-size: 13.5px; font-weight: 600;
  text-decoration: none; color: #fff;
  background: linear-gradient(120deg, #2a78d6, #1e9d72);
}
.btn:hover { filter: brightness(1.1); }
.btn.sec { background: transparent; border: 1px solid rgba(244, 243, 239, .35); color: #f4f3ef; }
.btn.sec:hover { background: rgba(244, 243, 239, .1); filter: none; }
.btn:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
footer .legal { margin: 0; }

/* ── La gama (packshot) ───────────────────────────── */
.card.gama { display: grid; grid-template-columns: 1.2fr 1fr; padding: 0; overflow: hidden; }
.gama img { width: 100%; height: 100%; object-fit: cover; display: block; min-height: 260px; }
.gama-info { padding: 22px 26px; align-self: center; }
.gama-info p { color: var(--ink-2); font-size: 14px; margin: 0 0 14px; }
.gama-chips {
  list-style: none; margin: 0 0 12px; padding: 0;
  display: grid; grid-template-columns: 1fr 1fr; gap: 7px 18px; font-size: 13.5px;
}
.gama-chips i {
  width: 11px; height: 11px; border-radius: 3px; display: inline-block;
  background: var(--c); margin-right: 9px; vertical-align: -1px;
}

/* ── Centro de control ────────────────────────────── */
.live-bar { display: flex; gap: 20px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.live-intro { margin: 0; max-width: 62ch; color: var(--ink-2); font-size: 14px; }
.sim-reloj {
  margin-left: auto; display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 16px; white-space: nowrap;
}
.sim-reloj b { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; letter-spacing: .02em; }
.sim-dia { font-size: 12px; color: var(--muted); }
.sim-dia b { font-size: 12px; color: var(--ink-2); }

.live-grid { grid-template-columns: 1.7fr 1fr; }
.mapa-wrap { position: relative; }
#mapa { width: 100%; height: auto; display: block; }
#silueta { fill: var(--chip-bg); stroke: var(--grid); stroke-width: 1.5; }
.ruta-linea { fill: none; stroke: var(--baseline); stroke-dasharray: 2 8; stroke-width: 2; stroke-linecap: round; opacity: .85; }
.ciudad circle { fill: var(--baseline); }
.ciudad text { fill: var(--muted); font-size: 17px; text-anchor: middle; }
.ciudad.hub circle { fill: var(--s2); stroke: var(--surface); stroke-width: 2.5; }
.ciudad.hub text { fill: var(--ink-2); font-weight: 650; }
.camion { transition: transform 3.8s linear; cursor: default; }
.camion circle { fill: var(--s1); stroke: var(--surface); stroke-width: 2.5; }
.camion text {
  fill: #fff; font-size: 12px; font-weight: 700;
  text-anchor: middle; dominant-baseline: central;
}
.camion.descarga circle { fill: var(--s2); }
.camion.incidencia circle { fill: var(--s3); animation: alerta 1s infinite; }
.camion.vuelta circle { opacity: .7; }
@keyframes alerta { 50% { stroke: var(--s3); } }
@media (prefers-reduced-motion: reduce) { .camion { transition: none; } }

.mapa-leyenda { display: flex; gap: 16px; flex-wrap: wrap; }
.mapa-leyenda .ley { display: inline-flex; align-items: center; gap: 6px; }
.mapa-leyenda .dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.mapa-leyenda .dot.ruta { background: var(--s1); }
.mapa-leyenda .dot.descarga { background: var(--s2); }
.mapa-leyenda .dot.incidencia { background: var(--s3); }
.mapa-leyenda .dot.hub { background: var(--s2); outline: 2px solid var(--baseline); outline-offset: 1px; }

.feed-card { display: flex; flex-direction: column; }
#feed {
  list-style: none; margin: 0; padding: 0; flex: 1;
  max-height: 560px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 5px; font-size: 13.5px;
}
.ev {
  display: flex; gap: 10px; padding: 6px 10px; border-radius: 7px;
  border-left: 3px solid var(--baseline); background: transparent;
  color: var(--ink-2);
}
.ev .t { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; font-size: 12.5px; padding-top: 1px; }
.ev.pedido { border-left-color: var(--s1); }
.ev.entrega { border-left-color: var(--good); }
.ev.tueste { border-left-color: var(--s2); }
.ev.incidencia { border-left-color: var(--s3); background: var(--chip-bg); }
.ev.nuevo { animation: evin .5s ease-out; }
@keyframes evin { from { opacity: 0; translate: 0 -8px; } }
@media (prefers-reduced-motion: reduce) { .ev.nuevo { animation: none; } }

/* ── Agente de operaciones ────────────────────────── */
.caso {
  border: 1px solid var(--border); border-radius: 10px;
  padding: 13px 16px; margin-bottom: 12px;
  background: color-mix(in srgb, var(--chip-bg) 45%, transparent);
}
.caso:last-child { margin-bottom: 0; }
.caso-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13.5px; }
.caso-meta { color: var(--ink-2); }
.caso-head .t { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12.5px; }
.caso-razon { font-size: 13.5px; color: var(--ink-2); margin: 10px 0 9px; max-width: 90ch; }
.pensando-dots span {
  display: inline-block; width: 5px; height: 5px; border-radius: 50%;
  background: var(--muted); margin-left: 4px;
  animation: puntito 1.2s infinite ease-in-out;
}
.pensando-dots span:nth-child(2) { animation-delay: .2s; }
.pensando-dots span:nth-child(3) { animation-delay: .4s; }
.caso-acciones {
  list-style: none; margin: 0 0 10px; padding: 0;
  display: flex; flex-direction: column; gap: 6px; font-size: 13.5px;
}
.caso-acciones li { display: flex; gap: 9px; align-items: baseline; }
.acc {
  flex: none; font-family: "Space Grotesk", sans-serif;
  font-size: 10px; font-weight: 600; letter-spacing: .09em; text-transform: uppercase;
  padding: 2px 9px; border-radius: 99px;
  background: var(--chip-bg); border: 1px solid var(--border); color: var(--ink-2);
  min-width: 68px; text-align: center;
}
.acc.aviso { color: var(--s1); }
.acc.eta { color: var(--s3); }
.acc.prioridad { color: var(--s2); }
.acc.escalado { color: var(--s3); border-color: var(--s3); }
.acc.ok { color: var(--good); }
.caso-resumen { font-size: 13.5px; margin: 0; color: var(--good); font-weight: 600; }
.caso-resumen .firma { color: var(--muted); font-weight: 450; }

.chip {
  display: inline-block; padding: 3px 11px; border-radius: 99px;
  background: var(--chip-bg); font-size: 12px; font-weight: 600; white-space: nowrap;
}
.chip.ruta { color: var(--s1); }
.chip.descarga { color: var(--s2); }
.chip.incidencia { color: var(--s3); }
.chip.vuelta, .chip.carga, .chip.fin { color: var(--muted); }
.ruta-txt { color: var(--ink-2); }
.tile .v .de { color: var(--muted); font-size: 60%; font-weight: 450; }

@media (max-width: 860px) {
  body { overflow-x: clip; }
  .grid { grid-template-columns: 1fr; }
  header.top { padding: 12px 16px; gap: 10px 14px; }
  .brand p { display: none; }
  .badge-demo { display: none; }
  .nav { order: 2; }
  main { padding: 16px 16px 40px; }
  .seg { flex-wrap: wrap; }
  .seg button { flex: 1 1 auto; }
  .toolbar-hint { display: none; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tile .v { font-size: clamp(21px, 5.5vw, 30px); white-space: nowrap; }
  .plot { height: 220px; }
  .card.wide .plot { height: 240px; }
  /* Móvil: lo importante primero — semanal y asistente IA arriba */
  .card.wide { order: -2; }
  .card.chat { order: -1; }
  /* La gama al final, en columna */
  .card.gama { order: 5; grid-template-columns: 1fr; }
  .gama img { min-height: 0; max-height: 260px; }
  .hero { min-height: 150px; }
  .flota-card { grid-template-columns: 1fr; }
  .flota-foto { display: none; }
  .cierre-texto { padding: 24px 20px; }
  .cierre-fondo { mask-image: linear-gradient(180deg, transparent 40%, #000 85%); -webkit-mask-image: linear-gradient(180deg, transparent 40%, #000 85%); opacity: .5; }
  /* Centro de control en columna: mapa → feed → flota */
  .live-grid { grid-template-columns: 1fr; }
  .live-grid .card.wide { order: 2; }
  .sim-reloj { margin-left: 0; width: 100%; justify-content: center; }
  #feed { max-height: 340px; }
  .ciudad text { font-size: 26px; }
  .camion circle { r: 15; }
  .camion text { font-size: 16px; }
}

/* Tablas en pantallas estrechas: solo columnas esenciales */
@media (max-width: 600px) {
  #tb-clientes th:nth-child(2), #tb-clientes td:nth-child(2),
  #tb-clientes th:nth-child(4), #tb-clientes td:nth-child(4),
  #tb-flota th:nth-child(2), #tb-flota td:nth-child(2) { display: none; }
}

/* Zonas táctiles ≥44px en dispositivos de dedo */
@media (pointer: coarse) {
  .seg button { padding: 11px 14px; }
  .chips button { padding: 9px 14px; font-size: 13.5px; }
  #chat-form button, #chat-in { padding-top: 12px; padding-bottom: 12px; }
}
