/* Design system portado de ~/dev/allstate (app/globals.css + componentes shadcn).
   Mismos tokens, mismas escalas; sin Tailwind para no meter build step. */

:root {
  /* Superficies pastel cálido */
  --background: #faf8f5;
  --foreground: #2c2a28;
  --card: #ffffff;

  /* Sage primary */
  --primary: #4a7670;
  --primary-foreground: #ffffff;

  --secondary: #ede9e3;
  --muted: #efede8;
  --muted-foreground: #6e6862;
  --accent: #e2eae6;
  --accent-foreground: #3d5e58;

  /* Terracota destructive */
  --destructive: #b25e48;

  --border: #e2ded7;
  --ring: #4a7670;
  --radius: 0.5rem;
  --radius-sm: calc(var(--radius) * 0.6);
  --radius-md: calc(var(--radius) * 0.8);

  /* Tokens de status — pares bg/fg auditados a >=4.5:1 */
  --status-success-bg: #dcede3;  --status-success-fg: #3d6e55;
  --status-warning-bg: #f5e4c0;  --status-warning-fg: #7a5a20;
  --status-info-bg: #dde3f0;     --status-info-fg: #3d4d70;
  --status-pending-bg: #ece9e3;  --status-pending-fg: #6e6862;
  --status-danger-bg: #f5d9d2;   --status-danger-fg: #7a3525;

  /* Sidebar, un punto más cálido que las cards para separar */
  --sidebar: #f5f1ea;
  --sidebar-accent: #e2eae6;
  --sidebar-accent-foreground: #3d5e58;
  --sidebar-border: #e2ded7;
  --sidebar-width: 16rem;

  --font-sans: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-display: Fraunces, "Iowan Old Style", Georgia, serif;
  --font-mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --positive: #2f7d5c;
}

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

body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--foreground);
  background-color: var(--background);
  /* Wash cálido para que la crema tenga profundidad y no se sienta plana. */
  background-image:
    radial-gradient(circle at 20% 0%, rgba(74, 118, 112, 0.025), transparent 40%),
    radial-gradient(circle at 100% 100%, rgba(228, 182, 112, 0.03), transparent 50%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}

td, th { font-variant-numeric: tabular-nums; }

/* Dinero / IDs / fechas dentro de datos */
.money {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

/* ------------------------------------------------------------------ shell */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--sidebar);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 1rem 1rem 0.875rem;
  border-bottom: 1px solid var(--sidebar-border);
}

.brand-mark {
  width: 2rem; height: 2rem;
  border-radius: var(--radius-md);
  background: var(--primary);
  color: var(--primary-foreground);
  display: grid; place-items: center;
  flex-shrink: 0;
}

.brand-name { font-weight: 600; font-size: 0.875rem; line-height: 1.2; }
.brand-sub { color: var(--muted-foreground); font-size: 0.75rem; }

.sidebar-group { padding: 0.75rem 0.5rem 0; }

.sidebar-group-label {
  color: var(--muted-foreground);
  font-size: 0.6875rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0 0.5rem 0.375rem;
}

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.4375rem 0.5rem;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--foreground);
  font: inherit;
  font-size: 0.875rem;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.sidebar-item:hover { background: var(--secondary); }

.sidebar-item[aria-current="page"] {
  background: var(--sidebar-accent);
  color: var(--sidebar-accent-foreground);
  font-weight: 500;
}

.sidebar-item.is-disabled { color: var(--muted-foreground); cursor: default; }
.sidebar-item.is-disabled:hover { background: transparent; }
.sidebar-item.is-disabled .icon { opacity: 0.7; }

/* Badge "Próximamente": empujado al borde derecho del item, discreto. */
.badge.soon {
  margin-left: auto;
  padding: 0.0625rem 0.375rem;
  font-size: 0.625rem;
  font-weight: 500;
  letter-spacing: 0;
}

.sidebar-footer {
  margin-top: auto;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--sidebar-border);
  color: var(--muted-foreground);
  font-size: 0.75rem;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ----------------------------------------------------------- page header */
.page-header {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--background);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted-foreground);
  font-size: 0.875rem;
}

.breadcrumbs a { color: inherit; text-decoration: none; }
.breadcrumbs a:hover { color: var(--foreground); }
.breadcrumbs .current { color: var(--foreground); }
.breadcrumbs .sep { opacity: 0.5; }

.page-title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.page-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.page-description { margin: 0.25rem 0 0; color: var(--muted-foreground); font-size: 0.875rem; }

/* Estado del feed: pill sutil que aclara que los loads son el piloto. */
.feed-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4375rem;
  align-self: flex-start;
  padding: 0.3125rem 0.625rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  color: var(--foreground);
  font-size: 0.75rem;
  line-height: 1.2;
  cursor: default;
}

.feed-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 999px;
  background: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent);
  flex-shrink: 0;
  animation: feed-pulse 2.4s ease-in-out infinite;
}

@keyframes feed-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.feed-muted { color: var(--muted-foreground); }

@media (prefers-reduced-motion: reduce) {
  .feed-dot { animation: none; }
}

.content { padding: 1.5rem; display: flex; flex-direction: column; gap: 1rem; }

/* ----------------------------------------------------------------- cards */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 1rem 1rem 0.5rem;
}

.card-title { font-size: 0.9375rem; font-weight: 600; letter-spacing: -0.01em; }
.card-content { padding: 0.75rem 1rem 1rem; }

.stat-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}

@media (min-width: 640px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1100px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }

.stat-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1rem 0.5rem;
  color: var(--muted-foreground);
}

.stat-title {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-value {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.75rem;
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.stat-value.is-positive { color: var(--positive); }
.stat-value.is-destructive { color: var(--destructive); }
.stat-sub { margin: 0.375rem 0 0; color: var(--muted-foreground); font-size: 0.75rem; }

/* ---------------------------------------------------------------- badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.125rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.tone-success { background: var(--status-success-bg); color: var(--status-success-fg); border-color: color-mix(in srgb, var(--status-success-fg) 22%, transparent); }
.tone-warning { background: var(--status-warning-bg); color: var(--status-warning-fg); border-color: color-mix(in srgb, var(--status-warning-fg) 22%, transparent); }
.tone-info    { background: var(--status-info-bg);    color: var(--status-info-fg);    border-color: color-mix(in srgb, var(--status-info-fg) 22%, transparent); }
.tone-pending { background: var(--status-pending-bg); color: var(--status-pending-fg); border-color: color-mix(in srgb, var(--status-pending-fg) 22%, transparent); }
.tone-danger  { background: var(--status-danger-bg);  color: var(--status-danger-fg);  border-color: color-mix(in srgb, var(--status-danger-fg) 22%, transparent); }
.tone-neutral { background: var(--muted); color: var(--muted-foreground); border-color: var(--border); }
.badge-outline { background: transparent; color: var(--foreground); }

/* ---------------------------------------------------------------- tabla */
.table-wrap { border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }

thead th {
  text-align: left;
  font-weight: 500;
  color: var(--muted-foreground);
  padding: 0.625rem 0.75rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td { padding: 0.75rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--muted); }

.num { text-align: right; }
.load-name { font-weight: 500; }
.subtle { color: var(--muted-foreground); font-size: 0.8125rem; }

.route-cell { display: inline-flex; align-items: center; gap: 0.375rem; flex-wrap: wrap; }
.route-arrow { color: var(--muted-foreground); }

.margin-negative { color: var(--destructive); font-weight: 500; }
.margin-positive { color: var(--positive); font-weight: 500; }

.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }

.search {
  flex: 1;
  min-width: 16rem;
  max-width: 24rem;
  padding: 0.4375rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--card);
  font: inherit;
  font-size: 0.875rem;
}

.search:focus-visible { outline: 2px solid var(--ring); outline-offset: -1px; }
.toolbar-count { margin-left: auto; color: var(--muted-foreground); font-size: 0.875rem; }

.empty { padding: 3rem 1rem; text-align: center; color: var(--muted-foreground); }

/* --------------------------------------------------------------- detalle */
.detail-grid { display: grid; gap: 1rem; grid-template-columns: 1fr; align-items: start; }

@media (min-width: 1100px) {
  .detail-grid { grid-template-columns: 2fr 1fr; }
}

.detail-col { display: flex; flex-direction: column; gap: 1rem; min-width: 0; }

dl.fields { display: grid; gap: 0.75rem; margin: 0; }
dl.fields.two-col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field { display: grid; gap: 0.125rem; min-width: 0; }

.field dt {
  color: var(--muted-foreground);
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.field dd { margin: 0; font-size: 0.875rem; overflow-wrap: anywhere; }

.money-row { display: flex; align-items: center; justify-content: space-between; font-size: 0.875rem; padding: 0.125rem 0; }
.money-total { border-top: 1px solid var(--border); margin-top: 0.5rem; padding-top: 0.75rem; font-weight: 600; }

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  color: var(--muted-foreground);
  font-size: 0.875rem;
  text-decoration: none;
}

.back-link:hover { color: var(--foreground); }

/* ------------------------------------------------------- stops timeline */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; display: flex; gap: 0.75rem; padding-bottom: 1.5rem; }
.timeline li:last-child { padding-bottom: 0; }

.timeline li:not(:last-child)::before {
  content: "";
  position: absolute;
  top: 2rem;
  left: 1rem;
  margin-left: -0.5px;
  width: 1px;
  height: 100%;
  background: var(--border);
}

.stop-node {
  position: relative;
  z-index: 1;
  width: 2rem; height: 2rem;
  flex-shrink: 0;
  border-radius: 999px;
  border: 1px solid;
  display: grid;
  place-items: center;
}

.stop-pickup { background: #e8f2fa; color: #2b6a94; border-color: rgba(43, 106, 148, 0.4); }
.stop-delivery { background: #e3f2e9; color: #2f7d5c; border-color: rgba(47, 125, 92, 0.4); }

.stop-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.25rem; }
.stop-kicker { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }

.stop-type {
  color: var(--muted-foreground);
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stop-name { font-weight: 500; line-height: 1.3; }
.stop-line { color: var(--muted-foreground); font-size: 0.875rem; margin: 0; }
.stop-meta { display: inline-flex; align-items: center; gap: 0.375rem; color: var(--muted-foreground); font-size: 0.875rem; }

.instructions {
  margin: 0.25rem 0 0;
  padding: 0.625rem 0.75rem;
  background: var(--muted);
  border-radius: var(--radius-md);
  color: var(--foreground);
  font-size: 0.8125rem;
  line-height: 1.5;
  white-space: pre-wrap;
}

.icon { width: 1rem; height: 1rem; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 0.875rem; height: 0.875rem; }

/* --------------------------------------------------------------- roadmap */
.roadmap { margin-top: 0.5rem; }

.roadmap-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
}

.roadmap-title {
  color: var(--muted-foreground);
  font-size: 0.6875rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.roadmap-sub { color: var(--muted-foreground); font-size: 0.8125rem; }

.roadmap-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: 1fr;
}

@media (min-width: 640px) { .roadmap-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1100px) { .roadmap-grid { grid-template-columns: repeat(4, 1fr); } }

/* Cards apagadas: se leen como visión, un escalón por debajo de la data real. */
.roadmap-card {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  padding: 0.875rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--card) 55%, transparent);
}

.roadmap-icon {
  display: grid;
  place-items: center;
  width: 1.875rem;
  height: 1.875rem;
  flex-shrink: 0;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: var(--accent-foreground);
}

.roadmap-icon .icon { width: 0.9375rem; height: 0.9375rem; }
.roadmap-name { margin: 0; font-size: 0.8125rem; font-weight: 600; letter-spacing: -0.01em; }
.roadmap-desc { margin: 0.1875rem 0 0; color: var(--muted-foreground); font-size: 0.75rem; line-height: 1.4; }

.hidden { display: none !important; }

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; overflow-x: auto; }
  .sidebar-group, .sidebar-footer, .sidebar-group-label { display: none; }
  .sidebar-brand { border-bottom: 0; }
  .content, .page-header { padding-left: 1rem; padding-right: 1rem; }
  dl.fields.two-col { grid-template-columns: 1fr; }
}

/* ----------------------------------------------------------- access gate */
/* Data real de cliente detrás de un código. Mismos tokens que el dashboard
   para que no se sienta una pantalla pegada de otro lado. */
.gate {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: var(--background);
}

.gate-card {
  width: 100%;
  max-width: 22rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 2rem 1.75rem;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgb(44 42 40 / 0.05), 0 8px 24px rgb(44 42 40 / 0.06);
}

.gate-card .brand-mark { margin-bottom: 0.25rem; }

.gate-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.375rem;
  font-weight: 500;
}

.gate-sub {
  margin: 0 0 0.75rem;
  color: var(--muted-foreground);
  font-size: 0.875rem;
  line-height: 1.5;
}

.gate-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--muted-foreground);
}

.gate-input {
  flex: none;
  min-width: 0;
  max-width: none;
  width: 100%;
  font-family: var(--font-mono);
  letter-spacing: 0.08em;
}

.gate-button {
  margin-top: 0.5rem;
  padding: 0.5rem 0.75rem;
  border: 0;
  border-radius: var(--radius-md);
  background: var(--primary);
  color: var(--primary-foreground);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
}

.gate-button:hover:not(:disabled) { background: #3f6560; }
.gate-button:disabled { opacity: 0.6; cursor: progress; }
.gate-button:focus-visible { outline: 2px solid var(--ring); outline-offset: 2px; }

.gate-error {
  margin: 0.25rem 0 0;
  padding: 0.5rem 0.625rem;
  border-radius: var(--radius-sm);
  background: var(--status-danger-bg);
  color: var(--status-danger-fg);
  font-size: 0.8125rem;
}

/* -------------------------------------------------- margin intelligence */
.stat-grid { grid-template-columns: 1fr; }
@media (min-width: 640px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1100px) { .stat-grid { grid-template-columns: repeat(5, 1fr); } }

.stat-value.is-negative { color: var(--destructive); }

.panel { padding: 1rem 1.25rem 1.25rem; }

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.panel-title {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.0625rem;
  font-weight: 500;
}

.panel-sub {
  margin: 0.25rem 0 0;
  max-width: 46rem;
  color: var(--muted-foreground);
  font-size: 0.8125rem;
  line-height: 1.5;
}

/* Botones segmentados */
.seg {
  display: inline-flex;
  padding: 2px;
  gap: 2px;
  background: var(--muted);
  border-radius: var(--radius-md);
}

.seg-btn {
  padding: 0.3125rem 0.625rem;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted-foreground);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
}

.seg-btn:hover { color: var(--foreground); }
.seg-btn.is-active { background: var(--card); color: var(--foreground); box-shadow: 0 1px 2px rgb(44 42 40 / 0.08); }
.seg-btn:focus-visible { outline: 2px solid var(--ring); outline-offset: 1px; }

/* Gráficos */
.chart-scroll { overflow-x: auto; }
.chart { display: block; width: 100%; min-width: 34rem; height: auto; }

.chart-caption {
  margin: 1.25rem 0 0.25rem;
  color: var(--muted-foreground);
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* El texto usa tokens de texto, nunca el color de la serie. */
.axis-text { fill: var(--muted-foreground); font-size: 11px; font-family: var(--font-sans); }
.bar-cap { fill: var(--foreground); font-size: 11px; font-weight: 500; font-family: var(--font-mono); }
.row-label { fill: var(--foreground); font-size: 12px; font-family: var(--font-sans); }
.row-value { fill: var(--foreground); font-size: 12px; font-family: var(--font-mono); }
.col-head {
  fill: var(--muted-foreground);
  font-size: 10px;
  font-family: var(--font-sans);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
  font-size: 0.8125rem;
  color: var(--muted-foreground);
}

.legend-item { display: inline-flex; align-items: center; gap: 0.4375rem; color: var(--foreground); }
.legend-item i { width: 10px; height: 10px; border-radius: 3px; }
.legend-note { margin-left: auto; font-size: 0.75rem; }

/* Tooltip compartido */
.chart-tip {
  position: fixed;
  z-index: 40;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  max-width: 20rem;
  padding: 0.5rem 0.625rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--card);
  box-shadow: 0 4px 16px rgb(44 42 40 / 0.12);
  font-size: 0.8125rem;
  pointer-events: none;
}

.chart-tip strong { font-weight: 600; }
.tip-row { display: flex; align-items: center; gap: 0.4375rem; color: var(--muted-foreground); }
.tip-row i { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.tip-total { margin-top: 0.125rem; padding-top: 0.25rem; border-top: 1px solid var(--border); }

/* Drill-down de negativos */
.neg-group { border-bottom: 1px solid var(--border); }
.neg-group:last-child { border-bottom: 0; }

.neg-group summary {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.25rem;
  cursor: pointer;
  list-style: none;
}

.neg-group summary::-webkit-details-marker { display: none; }
.neg-group summary:hover { background: var(--muted); }
.neg-group summary:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; }

.neg-name {
  flex: 1 1 12rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.875rem;
}

.neg-bar { flex: 0 1 8rem; height: 6px; border-radius: 3px; background: var(--muted); overflow: hidden; }
.neg-bar > span { display: block; height: 100%; border-radius: 3px; background: var(--destructive); }

.neg-total { flex: none; min-width: 6rem; text-align: right; font-size: 0.875rem; }
.neg-group .table-wrap { margin: 0 0 0.75rem; }

@media (max-width: 720px) {
  .neg-bar { display: none; }
  .legend-note { margin-left: 0; flex-basis: 100%; }
}

/* Utilidades de tabla que faltaban para las vistas nuevas. */
.mono { font-family: var(--font-mono); font-size: 0.8125rem; }
.dates { color: var(--muted-foreground); font-size: 0.8125rem; white-space: nowrap; }

tfoot td {
  border-top: 1px solid var(--border);
  font-weight: 600;
  background: var(--muted);
}

/* Filas con barra (slippage). Es una tabla con barra inline: el rango de valores
   abarca dos órdenes de magnitud, así que el número hace el trabajo fino y la
   barra da la proporción de un vistazo. */
.bar-rows { display: flex; flex-direction: column; }

.bar-row {
  display: grid;
  grid-template-columns: minmax(9rem, 1.4fr) minmax(4rem, 2fr) minmax(7rem, auto);
  align-items: center;
  gap: 0.875rem;
  padding: 0.5rem 0.25rem;
  border-bottom: 1px solid var(--border);
}

.bar-row:last-child { border-bottom: 0; }
.bar-row:hover { background: var(--muted); }

.bar-label { min-width: 0; display: flex; flex-direction: column; gap: 0.125rem; }

.bar-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.875rem;
}

.bar-sub {
  color: var(--muted-foreground);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

.bar-track { height: 14px; background: var(--muted); border-radius: 3px; overflow: hidden; }

/* Extremo de dato redondeado, base cuadrada: la barra crece desde una sola línea. */
.bar-fill { display: block; height: 100%; border-radius: 0 4px 4px 0; }

.bar-values { display: flex; flex-direction: column; align-items: flex-end; gap: 0.125rem; }

.bar-value {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 720px) {
  .bar-row { grid-template-columns: 1fr auto; }
  .bar-track { grid-column: 1 / -1; order: 3; }
}

/* 10 columnas no entran en pantallas angostas: en vez de aplastarlas, la tabla
   toma su ancho natural y el scroll ocurre dentro de .table-wrap (el body nunca
   scrollea en horizontal). */
#view-loads table { min-width: 58rem; }
.neg-group table { min-width: 46rem; }

/* Fila de totales/agregados que no es una entidad propia (ej. loads sin rep). */
.row-muted td { background: var(--muted); }

#view-customers table, #view-carriers table { min-width: 52rem; }

/* Los KPI de customers y carriers son 4, no 5. */
@media (min-width: 1100px) {
  #cust-kpis, #carrier-kpis { grid-template-columns: repeat(4, 1fr); }
}

/* Marca de referencia dentro de la barra (margen de la cartera). */
.bar-track { position: relative; }

.bar-mark {
  position: absolute;
  top: -2px;
  bottom: -2px;
  width: 2px;
  background: var(--foreground);
  opacity: 0.45;
}

.legend-mark {
  width: 2px !important;
  height: 12px !important;
  border-radius: 0 !important;
  background: var(--foreground);
  opacity: 0.45;
}

/* ------------------------------------------------------ tracking simulado */
.track-row {
  display: grid;
  grid-template-columns: minmax(11rem, 1.6fr) minmax(6rem, 1.4fr) minmax(7rem, auto);
  align-items: center;
  gap: 1rem;
  padding: 0.625rem 0.25rem;
  border-bottom: 1px solid var(--border);
  color: inherit;
  text-decoration: none;
}

.track-row:last-child { border-bottom: 0; }
.track-row:hover { background: var(--muted); }
.track-row:focus-visible { outline: 2px solid var(--ring); outline-offset: -2px; }

.track-main { min-width: 0; display: flex; flex-direction: column; gap: 0.125rem; }
.track-head { display: flex; align-items: center; gap: 0.5rem; }
.track-progress { display: flex; flex-direction: column; gap: 0.25rem; }
.track-eta { display: flex; flex-direction: column; align-items: flex-end; gap: 0.125rem; }

.track-summary {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr));
  padding-bottom: 1rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

/* Timeline de pings: reusa .timeline, con nodos chicos en vez de los stop-node. */
.timeline-item { align-items: flex-start; padding-bottom: 1.125rem !important; }

.timeline-dot {
  position: relative;
  z-index: 1;
  width: 0.75rem;
  height: 0.75rem;
  margin: 0.3125rem 0.625rem 0 0.625rem;
  flex-shrink: 0;
  border-radius: 999px;
  background: var(--card);
  border: 2px solid var(--primary);
}

.timeline-item.is-pickup .timeline-dot { background: var(--primary); }
.timeline-item.is-delivery .timeline-dot { border-color: var(--positive); background: var(--positive); }
.timeline-item.is-pending .timeline-dot { border-color: var(--border); border-style: dashed; }
.timeline-item.is-pending { opacity: 0.7; }
.timeline-item:not(:last-child)::before { left: 1.125rem; top: 1.25rem; }

.timeline-city { margin: 0 0 0.125rem; font-size: 0.875rem; font-weight: 500; }
.lane { font-size: 0.8125rem; white-space: nowrap; }

/* 62rem, no 74rem: los 74 incluían la columna de lane (nowrap, "Nogales, AZ →
   Hunts Point, NY"), que está apagada por SHOW_SIMULATED_LANES. Dejarla en 74
   forzaba scroll horizontal sobre espacio vacío. Si el lane vuelve, vuelve a 74. */
#view-loads table { min-width: 62rem; }
#view-loads tbody tr[data-load] { cursor: pointer; }
#view-loads tbody tr[data-load]:hover { background: var(--muted); }

@media (max-width: 720px) {
  .track-row { grid-template-columns: 1fr auto; }
  .track-progress { grid-column: 1 / -1; order: 3; }
}

/* --------------------------------------------------------- plan de trabajo */
/* Las fases se leen como compromiso, no como wishlist: cada una con su ventana
   de semanas y entregables concretos. La ya entregada se distingue con el borde
   sólido y el acento; las próximas quedan un escalón por debajo. */
.phase {
  padding: 0.875rem 1rem;
  border: 1px dashed var(--border);
  border-left: 3px solid var(--border);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--card) 55%, transparent);
}

.phase + .phase { margin-top: 0.625rem; }

.phase.is-done {
  border-style: solid;
  border-left-color: var(--primary);
  background: var(--card);
}

.phase-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.375rem;
}

.phase-when {
  color: var(--muted-foreground);
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-variant-numeric: tabular-nums;
}

.phase-name { font-size: 0.9375rem; font-weight: 600; letter-spacing: -0.01em; }

.phase-goal {
  margin: 0 0 0.5rem;
  color: var(--muted-foreground);
  font-size: 0.8125rem;
  line-height: 1.55;
}

.phase-items { margin: 0; padding-left: 1.125rem; display: grid; gap: 0.25rem; }
.phase-items li { font-size: 0.8125rem; line-height: 1.5; }

/* ------------------------------------------------- KPI grid: breakpoints
   Consolidado acá porque las fases anteriores fueron apilando reglas de
   .stat-grid y el cascade quedó difícil de leer. Estas son las definitivas.

   NO VERIFICADO POR ENCIMA DE ~1035px CSS: el viewport del entorno donde se
   desarrolló esto está topeado ahí, así que los saltos a 3 y 5 columnas se
   calcularon en vez de mirarse. El criterio es que ninguna card baje de ~190px,
   que es lo que necesita "1,704 loads cerrados" para no cortarse:

     ancho de contenido = viewport - 256 (sidebar) - 48 (padding)
     5 cards: 5*190 + 4*16 de gap = 1014  ->  viewport >= 1318, se usa 1360
     4 cards: 4*190 + 3*16        =  808  ->  viewport >= 1112, se usa 1150
     3 cards: 3*190 + 2*16        =  602  ->  viewport >=  906, se usa 1000

   Los saltos van con margen sobre el mínimo a propósito: si el cálculo se queda
   corto, el error es una columna de menos —que se ve bien— y no una card con el
   texto cortado en la pantalla de la reunión. */
.stat-grid { grid-template-columns: 1fr; }

@media (min-width: 640px)  { .stat-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1000px) { .stat-grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1360px) { .stat-grid { grid-template-columns: repeat(5, 1fr); } }

/* Customers y Carriers tienen 4 KPIs, no 5. */
#cust-kpis, #carrier-kpis { grid-template-columns: 1fr; }

@media (min-width: 640px)  { #cust-kpis, #carrier-kpis { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1150px) { #cust-kpis, #carrier-kpis { grid-template-columns: repeat(4, 1fr); } }

/* El mensaje de "sin resultados" vive dentro de una tabla con min-width y scroll
   horizontal: sin esto queda a la izquierda del área visible cuando el usuario
   venía scrolleado y se lee cortado. Sticky lo mantiene siempre a la vista. */
/* Sin auto-margins a propósito: centrarlo lo empuja al medio de los 74rem de la
   tabla y el sticky deja de servir, porque solo actúa cuando el elemento quedaría
   a la izquierda del borde visible. Anclado a la izquierda se ve siempre. */
.table-wrap .empty {
  position: sticky;
  left: 0;
  width: min(100vw - 6rem, 34rem);
  text-align: left;
}

/* ========================================================== LIVE TRACKING
   Vista sobre la Agents API de SPI. Mismos tokens que el resto; los nombres
   van con prefijo spi- para no cruzarse con ningún selector existente. */

/* Franja de titular. Tres cifras, no cuatro cards: el peso visual está repartido
   a propósito para que la tercera domine —es el hallazgo que motiva la vista, no
   un KPI más de una fila homogénea. */
.spi-headline {
  display: grid;
  gap: 1px;
  grid-template-columns: 1fr;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

@media (min-width: 900px) {
  .spi-headline { grid-template-columns: 1fr 1fr 1.35fr; }
}

.spi-figure {
  background: var(--card);
  padding: 1.125rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.spi-figure-label {
  color: var(--muted-foreground);
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.spi-figure-value {
  margin: 0;
  font-family: var(--font-display);
  font-size: 2.5rem;
  font-weight: 500;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.spi-figure-note { color: var(--muted-foreground); font-size: 0.8125rem; }

/* La cifra líder: fondo terracota lavado y tipo más grande. Es el único lugar de
   la vista donde se gasta color fuerte; el resto queda callado. */
.spi-figure.is-lead {
  background: color-mix(in srgb, var(--status-danger-bg) 55%, var(--card));
  box-shadow: inset 3px 0 0 var(--destructive);
}

.spi-figure.is-lead .spi-figure-value { font-size: 3.5rem; color: var(--status-danger-fg); }
.spi-figure.is-lead .spi-figure-label { color: var(--status-danger-fg); }
.spi-figure.is-lead .spi-figure-note { color: color-mix(in srgb, var(--status-danger-fg) 80%, transparent); }

/* Línea de ETA: dato de la fuente, no un KPI. Va discreta, bajo la franja. */
.spi-eta-note {
  margin: 0;
  padding: 0.625rem 0.875rem;
  border: 1px dashed var(--border);
  border-radius: var(--radius-md);
  background: var(--muted);
  color: var(--muted-foreground);
  font-size: 0.8125rem;
}

.spi-eta-note strong { color: var(--foreground); font-weight: 600; }

/* ------------------------------------------------------------ tabla live */
.spi-table { min-width: 62rem; }
.spi-table tbody tr.spi-row:hover { background: var(--muted); }

/* Franja de severidad a la izquierda de cada fila: deja leer el orden de la
   tabla sin depender solo del chip, que está al final de una fila ancha. */
.spi-table tbody tr.spi-row td:first-child { box-shadow: inset 3px 0 0 var(--sev-color, transparent); }

.spi-sev-critical { --sev-color: var(--destructive); }
.spi-sev-high     { --sev-color: #c07a30; }
.spi-sev-medium   { --sev-color: #3d4d70; }
.spi-sev-ok       { --sev-color: transparent; }

.spi-load-cell { display: flex; align-items: center; gap: 0.5rem; }
/* El número de load no se parte: "SPT-692406" en dos líneas se lee como dos datos. */
.spi-load-cell .mono { white-space: nowrap; }

.spi-toggle {
  width: 1.25rem;
  height: 1.25rem;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--muted-foreground);
  font-size: 0.6875rem;
  line-height: 1;
}

.spi-row[aria-expanded="true"] .spi-toggle {
  background: var(--accent);
  color: var(--accent-foreground);
  border-color: var(--accent-foreground);
}

.spi-stale { color: var(--destructive); font-weight: 500; }
.spi-none { color: var(--muted-foreground); }

/* Fila expandida: detalle de contacto y comentarios del carrier. */
.spi-detail-row > td { background: var(--muted); padding: 0; }
.spi-detail-row.hidden { display: none; }

.spi-detail {
  display: grid;
  gap: 1rem 2rem;
  grid-template-columns: 1fr;
  padding: 1rem 1.25rem 1.125rem 2rem;
}

@media (min-width: 800px) { .spi-detail { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.spi-detail dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 0.375rem 0.875rem; }
.spi-detail dt { color: var(--muted-foreground); font-size: 0.8125rem; }
.spi-detail dd { margin: 0; font-size: 0.8125rem; }

.spi-comment { margin: 0; }
.spi-comment-label {
  display: block;
  color: var(--muted-foreground);
  font-size: 0.6875rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}

.spi-comment-body {
  margin: 0;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.55;
  color: var(--foreground);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.625rem;
  max-height: 9rem;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Separador entre los 17 con problema y los 8 que están reportando bien. */
.spi-divider-row > td {
  background: var(--secondary);
  padding: 0.4375rem 0.75rem;
  color: var(--muted-foreground);
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.spi-divider-row { cursor: default; }
.spi-divider-row:hover > td { background: var(--secondary); }

/* -------------------------------------------------------------- mapa */
/* La altura no es decorativa. Los datos van de lat 18.5 a 49.9 y de lng -122.8 a
   -69.8, que en Mercator es una caja de proporción ~1.36:1. fitBounds ajusta por el
   lado más apretado: en un contenedor bajo y ancho manda el alto, el zoom baja y
   Norteamérica queda flotando entre dos océanos vacíos. A 40rem la proporción del
   contenedor se acerca a la de los datos y el encuadre aprovecha el ancho. */
.spi-map {
  height: 40rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--muted);
}

/* Leaflet inyecta su propia tipografía y fondo. Las clases van en el propio div del
   mapa, no en un hijo: por eso .spi-map.leaflet-container y no un descendiente. */
.spi-map.leaflet-container { font-family: var(--font-sans); background: var(--muted); }
.spi-map .leaflet-popup-content { font-size: 0.8125rem; margin: 0.625rem 0.75rem; }
.spi-map .leaflet-popup-content-wrapper { border-radius: var(--radius-md); }
.spi-map .leaflet-control-attribution { font-size: 0.625rem; background: rgba(255, 255, 255, 0.8); }

.spi-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 0.625rem;
  color: var(--muted-foreground);
  font-size: 0.75rem;
}

.spi-legend-item { display: inline-flex; align-items: center; gap: 0.375rem; }

.spi-legend i {
  width: 0.625rem;
  height: 0.625rem;
  border-radius: 50%;
  display: inline-block;
}

.spi-dot-hist { background: rgba(74, 118, 112, 0.45); }
.spi-dot-live { background: var(--destructive); box-shadow: 0 0 0 2px rgba(178, 94, 72, 0.25); }

@media (prefers-reduced-motion: reduce) {
  .spi-map.leaflet-fade-anim .leaflet-tile { transition: none; }
  .spi-map .leaflet-zoom-anim .leaflet-zoom-animated { transition: none; }
}

/* -------------------------------------- indicador de frescura (Live Tracking)
   Modificadores sobre .feed-pill. El punto base —sage con pulso— lo sigue usando
   Margin Intelligence, así que acá solo se sobrescribe por estado. */

/* Sincronizado hace poco: verde y con pulso. El pulso es lo que comunica "vivo";
   por eso los otros dos estados lo apagan en vez de cambiarle solo el color. */
.feed-pill.is-live .feed-dot {
  background: var(--positive);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--positive) 20%, transparent);
}

/* Sincronización vieja: ámbar y quieto. Los datos siguen siendo reales, pero
   dejaron de llegar cuando deberían. */
.feed-pill.is-stale .feed-dot {
  background: #c07a30;
  box-shadow: 0 0 0 3px rgba(192, 122, 48, 0.2);
  animation: none;
}

.feed-pill.is-stale { border-color: color-mix(in srgb, #c07a30 35%, var(--border)); }

/* Respaldo: gris y quieto. No es un error —la plataforma responde igual— pero lo
   que se ve no viene de la base sino del snapshot que viaja en el bundle. */
.feed-pill.is-fallback .feed-dot {
  background: var(--muted-foreground);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--muted-foreground) 18%, transparent);
  animation: none;
}

.feed-pill.is-fallback { color: var(--muted-foreground); }
