/* ═══════════════════════════ TOKENS ═══════════════════════════ */
:root {
  --bg:        #0f1410;
  --surface:   #171e18;
  --border:    #243027;
  --border-2:  #2f3e32;
  --text:      #dde8de;
  --muted:     #617065;
  --accent:    #4ade80;   /* verde señal - nuestro único color vibrante */
  --accent-dim:#1a3d23;
  --warn:      #fbbf24;
  --warn-dim:  #3d2e06;
  --crit:      #f87171;
  --crit-dim:  #3b1010;
  --info:      #67e8f9;
  --info-dim:  #0a2b30;
  --ok:        #4ade80;
  --ok-dim:    #1a3d23;
  --ff-display:'Syne', sans-serif;
  --ff-body:   'DM Sans', sans-serif;
  --ff-mono:   'DM Mono', monospace;
  --r:         10px;
  --r-sm:      6px;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--ff-body);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
a { color: var(--accent); }

/* ═══════════════════════════ LAYOUT ═══════════════════════════ */
.shell { max-width: 1200px; margin: 0 auto; padding: 0 20px 80px; }

/* ═══════════════════════════ TOP BAR ═══════════════════════════ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: rgba(15,20,16,.92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 100;
}
.brand {
  font-family: var(--ff-display);
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -.01em;
  color: var(--text);
  white-space: nowrap;
}
.brand span { color: var(--accent); }
.sync-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--ff-mono);
  font-size: 10.5px;
  color: var(--muted);
  white-space: nowrap;
}
.sync-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--muted);
  transition: .3s;
}
.sync-dot.live { background: var(--accent); box-shadow: 0 0 6px var(--accent); animation: pulse 2s infinite; }
.sync-dot.loading { background: var(--warn); animation: pulse 0.6s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.btn-reload {
  background: var(--surface);
  border: 1px solid var(--border-2);
  color: var(--text);
  padding: 6px 12px;
  border-radius: var(--r-sm);
  font-family: var(--ff-mono);
  font-size: 11px;
  cursor: pointer;
  transition: .15s;
  white-space: nowrap;
}
.btn-reload:hover { border-color: var(--accent); color: var(--accent); }

/* ═══════════════════════════ PAGE HEADER ═══════════════════════ */
.page-head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 16px;
  align-items: end;
  padding: 32px 0 24px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}
.eyebrow {
  font-family: var(--ff-mono);
  font-size: 10.5px;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}
.page-title {
  font-family: var(--ff-display);
  font-size: clamp(26px, 5vw, 42px);
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: -.02em;
}
.page-title em { color: var(--accent); font-style: normal; }
.meta-pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.pill {
  font-family: var(--ff-mono);
  font-size: 10.5px;
  padding: 3px 9px;
  border-radius: 20px;
  border: 1px solid var(--border-2);
  color: var(--muted);
}
.pill.green { border-color: var(--accent); color: var(--accent); }

/* ═══════════════════════════ DATE NAV ═══════════════════════════ */
.date-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 14px 16px;
  margin-bottom: 20px;
}
.nav-arrows { display: flex; gap: 4px; }
.arrow-btn {
  background: transparent;
  border: 1px solid var(--border-2);
  color: var(--text);
  width: 32px; height: 32px;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 15px;
  display: flex; align-items: center; justify-content: center;
  transition: .15s;
}
.arrow-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.arrow-btn:disabled { opacity: .3; cursor: not-allowed; }
.date-label-wrap { flex: 1 1 160px; }
.date-dow {
  font-family: var(--ff-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--muted);
  display: block;
  margin-bottom: 2px;
}
.date-label-text {
  font-family: var(--ff-display);
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
}
input[type="date"] {
  background: var(--bg);
  border: 1px solid var(--border-2);
  color: var(--text);
  border-radius: var(--r-sm);
  padding: 7px 10px;
  font-family: var(--ff-mono);
  font-size: 12px;
  color-scheme: dark;
  flex: 1 1 140px;
  max-width: 180px;
}
.btn-latest {
  background: var(--accent);
  color: #081a0e;
  border: none;
  border-radius: var(--r-sm);
  padding: 7px 14px;
  font-family: var(--ff-mono);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: .15s;
  white-space: nowrap;
  margin-left: auto;
}
.btn-latest:hover { background: #86efac; }

/* ═══════════════════════════ DAY STRIP ═══════════════════════════ */
.day-strip-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 14px 16px 10px;
  margin-bottom: 24px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.day-strip-inner {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  min-width: min-content;
}
.ds-label {
  font-family: var(--ff-mono);
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin-right: 10px;
  align-self: center;
  white-space: nowrap;
}
.ds-day {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  min-width: 24px;
  padding: 2px;
  border-radius: 4px;
  transition: .15s;
}
.ds-day:hover .ds-bar { border-color: var(--accent); }
.ds-day.active .ds-bar { background: var(--accent); border-color: var(--accent); }
.ds-bar {
  width: 14px;
  border-radius: 3px 3px 1px 1px;
  background: var(--border-2);
  border: 1px solid var(--border-2);
  transition: .15s;
}
.ds-lbl {
  font-family: var(--ff-mono);
  font-size: 8px;
  color: var(--muted);
  white-space: nowrap;
  text-align: center;
}
.ds-day.active .ds-lbl { color: var(--accent); font-weight: 600; }

/* ═══════════════════════════ KPIs ═══════════════════════════════ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 18px 16px 14px;
  position: relative;
  overflow: hidden;
}
.kpi::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 2px;
  background: var(--border-2);
}
.kpi.c-ok::after   { background: var(--ok); }
.kpi.c-warn::after { background: var(--warn); }
.kpi.c-crit::after { background: var(--crit); }
.kpi.c-info::after { background: var(--info); }
.kpi-label {
  font-family: var(--ff-mono);
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin-bottom: 10px;
}
.kpi-value {
  font-family: var(--ff-display);
  font-size: 34px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -.02em;
}
.kpi.c-ok   .kpi-value { color: var(--ok); }
.kpi.c-warn .kpi-value { color: var(--warn); }
.kpi.c-crit .kpi-value { color: var(--crit); }
.kpi.c-info .kpi-value { color: var(--info); }
.kpi-sub {
  font-size: 11.5px;
  color: var(--muted);
  margin-top: 6px;
  line-height: 1.3;
}

/* ═══════════════════════════ SECTION TITLE ═══════════════════════ */
.sec {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 28px 0 14px;
  font-family: var(--ff-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--muted);
}
.sec::after { content: ''; flex: 1; height: 1px; background: var(--border); }

/* ═══════════════════════════ ROUTE ═══════════════════════════════ */
.route-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 18px 18px 14px;
}
.route-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
}
.route-track {
  display: flex;
  align-items: flex-start;
  position: relative;
  min-width: min-content;
  padding: 0 6px;
}
.route-track::before {
  content: '';
  position: absolute;
  top: 14px;
  left: 20px; right: 20px;
  height: 1px;
  background: var(--border-2);
}
.route-stop {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 110px;
  flex-shrink: 0;
  cursor: default;
  padding: 0 4px;
}
.route-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--ok);
  border: 2px solid var(--bg);
  box-shadow: 0 0 0 1px var(--ok);
  margin-bottom: 8px;
  z-index: 1;
  position: relative;
  transition: .15s;
}
.route-stop.has-alert .route-dot {
  background: var(--crit);
  box-shadow: 0 0 0 1px var(--crit);
}
.route-time {
  font-family: var(--ff-mono);
  font-size: 9.5px;
  color: var(--muted);
  margin-bottom: 4px;
}
.route-name {
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  line-height: 1.3;
  color: var(--text);
  max-width: 100%;
  word-break: break-word;
}
.route-alert-tag {
  font-family: var(--ff-mono);
  font-size: 9px;
  color: var(--crit);
  text-align: center;
  margin-top: 3px;
}
.route-empty {
  padding: 24px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

/* ═══════════════════════════ CHARTS ═══════════════════════════════ */
.charts-row {
  display: grid;
  grid-template-columns: 3fr 2fr;
  gap: 14px;
  margin-bottom: 24px;
}
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 18px 18px 16px;
}
.chart-card h3 {
  font-family: var(--ff-display);
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 14px;
  color: var(--text);
}
.chart-wrap { height: 220px; position: relative; }
.legend { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }
.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--ff-mono);
  font-size: 10.5px;
  color: var(--muted);
}
.legend-dot {
  width: 8px; height: 8px;
  border-radius: 2px;
  flex-shrink: 0;
}

/* ═══════════════════════════ REPORT PANEL ═══════════════════════ */
.report-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
  margin-bottom: 24px;
}
.report-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.report-head h3 {
  font-family: var(--ff-display);
  font-size: 14px;
  font-weight: 700;
  flex: 1 1 160px;
}
.report-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.report-controls select,
.report-controls input[type="date"] {
  background: var(--surface);
  border: 1px solid var(--border-2);
  color: var(--text);
  border-radius: var(--r-sm);
  padding: 7px 10px;
  font-family: var(--ff-mono);
  font-size: 11px;
  color-scheme: dark;
  max-width: 170px;
}
.report-controls select option { background: var(--surface); }
.btn-gen {
  background: var(--accent);
  color: #081a0e;
  border: none;
  border-radius: var(--r-sm);
  padding: 7px 14px;
  font-family: var(--ff-mono);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: .15s;
  white-space: nowrap;
}
.btn-gen:hover { background: #86efac; }
.btn-dl {
  background: transparent;
  border: 1px solid var(--border-2);
  color: var(--muted);
  border-radius: var(--r-sm);
  padding: 7px 14px;
  font-family: var(--ff-mono);
  font-size: 11px;
  cursor: pointer;
  transition: .15s;
  white-space: nowrap;
}
.btn-dl:hover { border-color: var(--accent); color: var(--accent); }
.report-body {
  padding: 18px;
  font-family: var(--ff-mono);
  font-size: 12px;
  line-height: 1.8;
  color: var(--muted);
  white-space: pre-wrap;
  min-height: 60px;
  max-height: 340px;
  overflow-y: auto;
}
.report-body.has-content { color: var(--text); }

/* ═══════════════════════════ TABLE ═══════════════════════════════ */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
thead th {
  background: var(--bg);
  text-align: left;
  padding: 11px 14px;
  font-family: var(--ff-mono);
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  position: sticky;
  top: 0;
}
tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: rgba(74,222,128,.04); }
tbody td { padding: 12px 14px; vertical-align: top; }
.td-local b { display: block; font-size: 13px; font-weight: 600; overflow-wrap: break-word; }
.td-pos { font-family: var(--ff-mono); font-size: 10px; color: var(--muted); }
.td-merch {
  font-family: var(--ff-mono);
  font-size: 11px;
  background: var(--bg);
  border: 1px solid var(--border-2);
  border-radius: 20px;
  padding: 2px 9px;
  white-space: nowrap;
  display: inline-block;
}
.td-time { font-family: var(--ff-mono); font-size: 12px; white-space: nowrap; }
.td-dur { font-family: var(--ff-mono); font-size: 10.5px; color: var(--muted); white-space: nowrap; }
.badges { display: flex; flex-wrap: wrap; gap: 4px; }
.badge {
  font-family: var(--ff-mono);
  font-size: 9.5px;
  padding: 2px 7px;
  border-radius: 4px;
  white-space: nowrap;
}
.badge-ok   { background: var(--ok-dim);   color: var(--ok);   border: 1px solid #26503a; }
.badge-crit { background: var(--crit-dim); color: var(--crit); border: 1px solid #5a2020; }
.td-obs { font-size: 12px; color: var(--muted); line-height: 1.4; overflow-wrap: break-word; max-width: 240px; }
.foto-link { font-family: var(--ff-mono); font-size: 11px; color: var(--accent); text-decoration: none; }
.foto-link:hover { color: var(--info); }
.no-foto { font-family: var(--ff-mono); font-size: 10.5px; color: var(--border-2); }

.empty-state { padding: 60px 20px; text-align: center; }
.empty-title { font-family: var(--ff-display); font-size: 18px; font-weight: 700; color: var(--text); margin-bottom: 6px; }
.empty-sub { font-size: 13px; color: var(--muted); }

/* ═══════════════════════════ LOADING ═══════════════════════════ */
.loader {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 999;
}
.loader.hidden { display: none; }
.loader-ring {
  width: 36px; height: 36px;
  border: 2px solid var(--border-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
.loader-text { font-family: var(--ff-mono); font-size: 12px; color: var(--muted); }
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══════════════════════════ ERROR ════════════════════════════ */
.error-bar {
  display: none;
  background: var(--crit-dim);
  border: 1px solid var(--crit);
  border-radius: var(--r-sm);
  padding: 10px 16px;
  font-family: var(--ff-mono);
  font-size: 12px;
  color: var(--crit);
  margin-bottom: 16px;
  align-items: center;
  gap: 10px;
}
.error-bar.visible { display: flex; }

/* ═══════════════════════════ RESPONSIVE ═══════════════════════ */
@media (max-width: 860px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .charts-row { grid-template-columns: 1fr; }
  .page-head { grid-template-columns: 1fr; }
}

@media (max-width: 600px) {
  .shell { padding: 0 14px 60px; }
  .topbar { padding: 12px 14px; }
  .brand { font-size: 14px; }
  .page-head { padding: 22px 0 18px; margin-bottom: 18px; }
  .eyebrow { font-size: 9.5px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 18px; }
  .kpi { padding: 14px 12px 12px; }
  .kpi-value { font-size: 26px; }
  .kpi-label { font-size: 9px; }
  .kpi-sub { font-size: 10.5px; }
  .date-nav { padding: 12px; gap: 8px; }
  .date-label-text { font-size: 15px; }
  .btn-latest { margin-left: 0; width: 100%; text-align: center; order: 10; }
  input[type="date"] { max-width: 100%; flex: 1 1 100%; }
  .route-stop { width: 90px; }
  .route-name { font-size: 10px; }
  .chart-wrap { height: 180px; }
  .report-head { flex-direction: column; align-items: flex-start; }
  .report-controls { width: 100%; }
  .report-controls select,
  .report-controls input[type="date"] { max-width: 100%; flex: 1 1 100%; }
  .btn-gen, .btn-dl { flex: 1; text-align: center; }
  /* mobile card table */
  table, thead, tbody, th, td, tr { display: block; }
  thead { display: none; }
  tbody tr { border-bottom: 6px solid var(--bg); padding: 10px 0; }
  tbody td { border: none; padding: 4px 14px; max-width: 100%; }
  tbody td::before {
    content: attr(data-label);
    display: block;
    font-family: var(--ff-mono);
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
    margin-bottom: 3px;
  }
  .td-obs { max-width: 100%; }
}

@media (max-width: 380px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .kpi-value { font-size: 22px; }
}