/* ============================================================
   Control de Velocidad — Data-Dense Dashboard
   Paleta: azul (#1E40AF / #3B82F6) + acento ámbar (#F59E0B)
   Tipografía: Fira Sans (texto) / Fira Code (datos)
   ============================================================ */
:root {
  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  --primary: #1e40af;
  --primary-600: #1d4ed8;
  --primary-700: #1e3a8a;
  --accent: #3b82f6;
  --cta: #f59e0b;
  --cta-600: #d97706;

  --text: #0f172a;
  --heading: #1e3a8a;
  --muted: #475569;

  --ok: #16a34a;
  --bad: #dc2626;
  --warn: #d97706;
  --out: #94a3b8;

  --ring: rgba(59, 130, 246, .35);
  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
  --shadow: 0 4px 12px rgba(15, 23, 42, .08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, .14);

  --font-body: "Fira Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: "Fira Code", ui-monospace, "Cascadia Code", Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* ---------- Iconos SVG ---------- */
.icon {
  width: 18px;
  height: 18px;
  flex: none;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-sm { width: 15px; height: 15px; }

/* ---------- Sidebar ---------- */
#sidebar {
  width: 384px;
  min-width: 384px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow-y: auto;
  padding: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 4px 14px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.brand-logo {
  width: 42px;
  height: 42px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: #fff;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  box-shadow: var(--shadow);
}
.brand-logo .icon { width: 24px; height: 24px; }
.brand h1 {
  font-size: 17px;
  font-weight: 700;
  margin: 0;
  color: var(--heading);
  letter-spacing: -.01em;
}
.subtitle {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .2s ease, border-color .2s ease;
}
.card:hover { box-shadow: var(--shadow); }

.card h2 {
  font-size: 14px;
  font-weight: 700;
  margin: 0 0 12px;
  color: var(--heading);
  display: flex;
  align-items: center;
  gap: 9px;
}
.card h2 .icon { color: var(--accent); }

.step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #fff;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  flex: none;
}

.hint {
  font-size: 12px;
  color: var(--muted);
  margin: 0 0 10px;
  line-height: 1.45;
}
.hint code, code {
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 5px;
  color: var(--primary-700);
}

/* ---------- Fields ---------- */
.field { margin-bottom: 11px; }
.field label {
  display: block;
  font-size: 12px;
  margin-bottom: 5px;
  color: var(--text);
  font-weight: 600;
}
.field input,
.field select {
  width: 100%;
  padding: 9px 11px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 13.5px;
  font-family: var(--font-body);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.field input::placeholder { color: #94a3b8; }
.field input[type="number"] { font-family: var(--font-mono); }
.field select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
  cursor: pointer;
}
.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
}
.field input:disabled,
.field select:disabled { opacity: .55; cursor: not-allowed; }

.field.check label {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 500;
  cursor: pointer;
  font-size: 12.5px;
  line-height: 1.35;
}
.field.check input {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
  flex: none;
}

.two-col { display: flex; gap: 9px; }
.two-col .field { flex: 1; }

/* ---------- Buttons ---------- */
.btn {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  padding: 9px 13px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-body);
  transition: background .18s ease, border-color .18s ease, color .18s ease, box-shadow .18s ease;
}
.btn:hover { background: var(--surface-3); border-color: var(--border-strong); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }
.btn:active { transform: translateY(.5px); }

.btn.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.btn.primary:hover { background: var(--primary-700); border-color: var(--primary-700); }

.btn.cta {
  background: var(--cta);
  border-color: var(--cta);
  color: #3a2a05;
}
.btn.cta:hover { background: var(--cta-600); border-color: var(--cta-600); color: #fff; }

.btn.danger { background: var(--surface); border-color: #fca5a5; color: var(--bad); }
.btn.danger:hover { background: #fef2f2; }

.btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.btn:disabled:hover { background: var(--surface); }
.btn.primary:disabled:hover { background: var(--primary); }
.btn.full { width: 100%; }
.btn.small { padding: 6px 11px; font-size: 12px; }

.btn-row { display: flex; gap: 9px; margin-bottom: 11px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; }

/* ---------- Dropzone ---------- */
.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--r);
  padding: 22px 14px;
  text-align: center;
  cursor: pointer;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  background: var(--surface-2);
  transition: border-color .18s ease, background .18s ease, color .18s ease;
}
.dropzone .dz-icon { color: var(--accent); margin-bottom: 6px; }
.dropzone .dz-icon .icon { width: 28px; height: 28px; }
.dropzone:hover { border-color: var(--accent); background: #f0f6ff; }
.dropzone.dragover {
  border-color: var(--accent);
  background: #e8f1ff;
  box-shadow: 0 0 0 4px var(--ring) inset;
}
.dropzone .dz-sub { font-size: 11px; color: var(--muted); margin-top: 4px; font-weight: 500; }

.file-name {
  font-size: 12px;
  color: var(--ok);
  font-weight: 600;
  word-break: break-all;
  min-height: 14px;
  margin-top: 8px;
}

.mapping {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* ---------- Estado OSM ---------- */
#osmStatus {
  margin-top: 8px;
  font-size: 11.5px;
  line-height: 1.45;
  padding: 8px 10px;
  border-radius: var(--r-sm);
  background: var(--surface-3);
  border: 1px solid var(--border);
}
#osmStatus:empty { display: none; }
#osmStatus.loading { color: var(--cta-600); background: #fffbeb; border-color: #fde68a; }
#osmStatus.ok { color: var(--ok); background: #f0fdf4; border-color: #bbf7d0; }
#osmStatus.error { color: var(--bad); background: #fef2f2; border-color: #fecaca; }

/* ---------- Animación ---------- */
.anim {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.anim-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 700;
  color: var(--heading);
  margin-bottom: 9px;
}
input[type="range"] {
  width: 100%;
  margin-top: 8px;
  accent-color: var(--primary);
  cursor: pointer;
}
#animInfo { margin-top: 7px; min-height: 16px; font-family: var(--font-mono); font-size: 11.5px; }

/* ---------- Summary / KPI ---------- */
.summary {
  margin-top: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 13px;
  font-size: 13px;
}
.summary-head {
  font-weight: 700;
  color: var(--heading);
  margin-bottom: 2px;
}
.summary-sub { font-size: 11.5px; color: var(--muted); margin-bottom: 11px; line-height: 1.4; }

.kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  margin-bottom: 4px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 10px 11px;
}
.kpi.wide { grid-column: 1 / -1; }
.kpi-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  font-weight: 600;
  margin-bottom: 3px;
}
.kpi-value {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 700;
  color: var(--heading);
  line-height: 1.1;
}
.kpi.bad .kpi-value { color: var(--bad); }
.kpi.ok .kpi-value { color: var(--ok); }
.kpi-value small { font-size: 12px; font-weight: 500; color: var(--muted); }

.summary .danger-text { color: var(--bad); font-weight: 600; }
.summary .ok-text { color: var(--ok); font-weight: 600; }
.summary-warn {
  margin-top: 9px;
  font-size: 11.5px;
  color: var(--bad);
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--r-sm);
  padding: 7px 9px;
}

.foot { margin-top: 6px; padding: 0 4px; }
.foot small { color: var(--muted); font-size: 11px; }

.hidden { display: none !important; }

/* ---------- Map ---------- */
#mapWrap { flex: 1; position: relative; }
#map { width: 100%; height: 100%; }

.legend {
  position: absolute;
  bottom: 18px;
  right: 18px;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 12px 14px;
  font-size: 12px;
  z-index: 1000;
  line-height: 1.85;
  box-shadow: var(--shadow-lg);
  color: var(--text);
  max-width: 240px;
}
.legend .dot {
  display: inline-block;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  margin-right: 7px;
  vertical-align: middle;
}
.dot.tramo { background: var(--accent); border-radius: 2px; width: 16px; height: 4px; }
.dot.ok { background: var(--ok); }
.dot.warn { background: var(--cta); }
.dot.bad { background: var(--bad); }
.dot.out { background: var(--out); }

.route-legend { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.route-title { margin-bottom: 5px; font-weight: 600; color: var(--heading); }
.route-scale { display: flex; height: 10px; border-radius: 4px; overflow: hidden; }
.route-scale span { flex: 1; }
.route-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--muted);
  margin-top: 3px;
}
.route-arrow-note { font-size: 10px; color: var(--muted); margin-top: 5px; }

.legend-toggle { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.legend-toggle label { display: flex; align-items: center; gap: 7px; cursor: pointer; }
.legend-toggle input { accent-color: var(--primary); cursor: pointer; }

/* ---------- Results panel ---------- */
.results-panel {
  position: fixed;
  bottom: 0;
  left: 384px;
  right: 0;
  height: 42vh;
  background: var(--surface);
  border-top: 3px solid var(--primary);
  z-index: 1500;
  display: flex;
  flex-direction: column;
  box-shadow: 0 -12px 32px rgba(15, 23, 42, .18);
}
.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.results-header h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--heading);
  display: flex;
  align-items: center;
  gap: 8px;
}
.table-wrap { overflow: auto; flex: 1; }

table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th, td {
  padding: 9px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  z-index: 1;
  font-weight: 600;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .03em;
}
td { font-variant-numeric: tabular-nums; }
tbody tr { transition: background .12s ease; }
tbody tr:hover { background: var(--surface-3); }
td.speed-bad { color: var(--bad); font-weight: 700; font-family: var(--font-mono); }
tbody tr.clickable { cursor: pointer; }
tbody tr.row-active { background: #e8f1ff !important; box-shadow: inset 3px 0 0 var(--primary); }

/* Badges */
.prio { font-weight: 700; padding: 2px 8px; border-radius: 999px; font-size: 11px; }
.prio.alta { background: #fef2f2; color: var(--bad); border: 1px solid #fecaca; }
.prio.media { background: #fffbeb; color: var(--cta-600); border: 1px solid #fde68a; }
.prio.baja { background: #f0fdf4; color: var(--ok); border: 1px solid #bbf7d0; }
.road-pill {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--muted);
}

/* Leaflet popups */
.leaflet-popup-content { font-size: 13px; font-family: var(--font-body); }
.leaflet-popup-content b { color: var(--heading); }
.leaflet-popup-content code { font-family: var(--font-mono); }

/* ---------- Scrollbars ---------- */
#sidebar::-webkit-scrollbar,
.table-wrap::-webkit-scrollbar { width: 10px; height: 10px; }
#sidebar::-webkit-scrollbar-thumb,
.table-wrap::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
  border: 2px solid var(--surface);
}
#sidebar::-webkit-scrollbar-thumb:hover,
.table-wrap::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  #sidebar { width: 340px; min-width: 340px; }
  .results-panel { left: 340px; }
}
@media (max-width: 760px) {
  #app { flex-direction: column; }
  #sidebar { width: 100%; min-width: 0; max-height: 52vh; }
  .results-panel { left: 0; height: 48vh; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
}

/* ---------- Accesibilidad: movimiento reducido ---------- */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- Login ---------- */
body.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 55%, #3b82f6 100%);
}
.login-wrap { width: 100%; max-width: 440px; }
.login-card {
  background: var(--surface);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
.login-header {
  background: linear-gradient(135deg, #1e3a8a, #1e40af);
  color: #fff;
  padding: 24px 22px 18px;
}
.login-brand { display: flex; align-items: center; gap: 12px; }
.login-brand h1 { margin: 0; font-size: 18px; color: #fff; }
.login-brand p { margin: 2px 0 0; font-size: 12px; opacity: .85; }
.login-header .brand-logo { background: rgba(255,255,255,.15); box-shadow: none; }
.login-lead { margin: 14px 0 0; font-size: 13px; line-height: 1.45; opacity: .9; }
.login-body { padding: 22px; }
.login-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--bad);
  border-radius: var(--r-sm);
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 12px;
}
.login-foot { font-size: 11px; color: var(--muted); text-align: center; margin: 14px 0 0; }
.login-foot a { color: var(--primary-600); font-weight: 600; text-decoration: none; }
.login-foot a:hover { text-decoration: underline; }

/* Barra de usuario en sidebar */
.user-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.user-bar .help-link {
  flex: none;
  text-decoration: none;
}
.user-chip {
  flex: 1;
  font-size: 12px;
  font-weight: 600;
  color: var(--heading);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
