:root {
  --sidebar: #111827;
  --sidebar-hover: #1f2937;
  --bg: #f8fafc;
  --panel: #ffffff;
  --border: #e5e7eb;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #2563eb;
  --green: #16a34a;
  --blue: #2563eb;
  --purple: #7c3aed;
  --amber: #d97706;
  --red: #dc2626;
  --emerald: #059669;
  --gray: #9ca3af;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.muted { color: var(--muted); }

/* ── Sidebar ─────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: 240px;
  background: var(--sidebar);
  color: #e5e7eb;
  display: flex;
  flex-direction: column;
  z-index: 30;
}
.sidebar-brand {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 1px;
  padding: 22px 24px;
  color: #fff;
}
.sidebar-brand-sub {
  font-size: 11px;
  font-weight: 600;
  color: #60a5fa;
  margin-left: 6px;
  text-transform: uppercase;
  letter-spacing: 2px;
}
.sidebar-nav { flex: 1; padding: 8px 12px; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: 8px;
  color: #cbd5e1;
  font-weight: 500;
  margin-bottom: 2px;
}
.nav-link:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.nav-link.active { background: var(--primary); color: #fff; }
.nav-icon { width: 18px; text-align: center; opacity: .9; }
.sidebar-footer { padding: 16px; border-top: 1px solid #1f2937; }
.sidebar-admin-name { font-weight: 600; color: #fff; }
.sidebar-admin-role { font-size: 12px; color: var(--gray); text-transform: capitalize; }
.sidebar-logout { display: inline-block; margin-top: 10px; color: #f87171; font-size: 13px; }

/* ── Content ─────────────────────────────────── */
.content { margin-left: 240px; min-height: 100vh; }
.topbar {
  position: sticky;
  top: 0;
  height: 60px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 24px;
  z-index: 20;
}
.topbar-breadcrumb { color: var(--muted); }
.topbar-breadcrumb strong { color: var(--text); }
.topbar-toggle { display: none; background: none; border: none; font-size: 20px; cursor: pointer; }
.main { padding: 24px; }

/* ── Stat cards ──────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  border-left: 4px solid var(--gray);
}
.stat-card--green  { border-left-color: var(--green); }
.stat-card--blue   { border-left-color: var(--blue); }
.stat-card--purple { border-left-color: var(--purple); }
.stat-card--amber  { border-left-color: var(--amber); }
.stat-label { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.stat-value { font-size: 30px; font-weight: 700; }

/* ── Panels & tables ─────────────────────────── */
.panel {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 24px;
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.panel-title { margin: 0; font-size: 16px; font-weight: 600; }
.panel-hint { color: var(--muted); font-size: 12px; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px 20px; text-align: left; }
.table th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.table tbody tr { border-bottom: 1px solid #f1f5f9; }
.table tbody tr:hover { background: #f8fafc; }
.empty { color: var(--muted); text-align: center; padding: 24px; }
.route { max-width: 320px; color: var(--muted); }

/* ── Badges ──────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  text-transform: capitalize;
  background: #e5e7eb;
  color: #374151;
}
.badge-active      { background: #dcfce7; color: #166534; }
.badge-online      { background: #d1fae5; color: #065f46; }
.badge-pending     { background: #fef3c7; color: #92400e; }
.badge-suspended   { background: #fee2e2; color: #991b1b; }
.badge-offline     { background: #f3f4f6; color: #4b5563; }
.badge-searching   { background: #dbeafe; color: #1e40af; }
.badge-requested   { background: #dbeafe; color: #1e40af; }
.badge-accepted       { background: #e0e7ff; color: #3730a3; }
.badge-driver_arrived { background: #ede9fe; color: #5b21b6; }
.badge-in_progress    { background: #dbeafe; color: #1e40af; }
.badge-completed      { background: #dcfce7; color: #166534; }
.badge-cancelled      { background: #f3f4f6; color: #4b5563; }
.badge-no_driver      { background: #fee2e2; color: #991b1b; }

/* ── Filters / search ────────────────────────── */
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.filter-btn {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
}
.filter-btn:hover { border-color: var(--primary); color: var(--primary); }
.filter-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.search-input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
  min-width: 220px;
}

/* ── Buttons ─────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-ghost { background: #f3f4f6; color: #374151; }
.btn-danger { background: var(--red); color: #fff; }
.btn-full { width: 100%; }
.btn:disabled { opacity: .6; cursor: not-allowed; }
.btn-pill {
  border: none;
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  margin-right: 6px;
  color: #fff;
}
.btn-pill--green { background: var(--green); }
.btn-pill--red { background: var(--red); }
.btn-pill:hover { filter: brightness(.95); }

/* ── Detail views ────────────────────────────── */
.back-link { display: inline-block; margin-bottom: 16px; color: var(--muted); }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.detail-list { margin: 0; padding: 8px 20px 20px; }
.detail-list > div { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; border-bottom: 1px solid #f1f5f9; }
.detail-list dt { color: var(--muted); }
.detail-list dd { margin: 0; text-align: right; font-weight: 500; }

/* ── Forms ───────────────────────────────────── */
.form-group { margin-bottom: 16px; text-align: left; }
.form-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: #374151; }
.form-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 11px 14px;
  font-size: 15px;
}
.form-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.form-alert {
  background: #fee2e2;
  color: #991b1b;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 14px;
}

/* ── Login page ──────────────────────────────── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #111827, #1e3a8a);
}
.login-card {
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 20px 40px rgba(0,0,0,.2);
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}
.login-brand { font-size: 26px; font-weight: 800; letter-spacing: 1px; margin-bottom: 6px; }
.login-title { font-size: 18px; margin: 12px 0 4px; }
.login-subtitle { color: var(--muted); margin: 0 0 24px; font-size: 14px; }

/* ── Modal ───────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 360px;
}
.modal-message { margin: 0 0 20px; font-size: 15px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ── Live / SSE indicators ───────────────────── */
.stats-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.stats-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.sse-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--green);
  background: #dcfce7;
  border-radius: 999px;
  padding: 3px 10px;
  transition: background .3s, color .3s;
}
.sse-chip--off {
  color: var(--muted);
  background: #f3f4f6;
}
.live-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--green);
  flex-shrink: 0;
  animation: live-pulse 2s ease-in-out infinite;
}
.sse-chip--off .live-dot {
  background: var(--gray);
  animation: none;
}
@keyframes live-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .35; }
}

@keyframes stat-flash {
  0%   { color: var(--primary); }
  100% { color: inherit; }
}
.stat-value.flash { animation: stat-flash .5s ease-out; }

/* ── Responsive ──────────────────────────────── */
@media (max-width: 860px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .detail-grid { grid-template-columns: 1fr; }
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: translateX(0); }
  .content { margin-left: 0; }
  .topbar-toggle { display: inline-block; }
}

/* ── Tarifas ─────────────────────────────────────────────────────────── */

.pricing-sim-form,
.pricing-settings {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 20px;
}

.pricing-sim-form .form-group,
.pricing-settings .form-group {
  margin-bottom: 0;
}

.cell-input {
  padding: 6px 8px;
  font-size: 13px;
}

/* A deactivated row is still editable — it is dimmed, not hidden, because
   reactivating it is the whole point of keeping it on screen. */
.row-inactive {
  opacity: 0.55;
}

/* The traffic grid is 24 columns wide, so it gets its own compact scale and
   scrolls horizontally inside .table-wrap on narrow screens. */
.traffic-grid {
  font-size: 12px;
}

.traffic-grid th,
.traffic-grid td {
  padding: 2px;
  text-align: center;
}

.traffic-grid th:first-child {
  text-align: left;
  padding-right: 8px;
  white-space: nowrap;
}

.traffic-cell {
  width: 46px;
  padding: 3px 2px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 3px;
  background: transparent;
  color: inherit;
  font-size: 11px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.traffic-cell:focus {
  outline: 2px solid var(--accent, #4a9eff);
  outline-offset: -1px;
}

/* Hide the number spinners: 168 of them would dominate the grid. */
.traffic-cell::-webkit-inner-spin-button,
.traffic-cell::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.traffic-observed {
  color: #4ade80;
  font-size: 9px;
  vertical-align: super;
}

.form-alert--error {
  border-color: #ef4444;
  color: #fca5a5;
}

/* ── Cobranzas ───────────────────────────────────────────────────────── */

.ledger-summary,
.ledger-policy {
  display: flex;
  flex-wrap: wrap;
  gap: 24px;
  margin-bottom: 20px;
}

.ledger-stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ledger-stat-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.6;
}

.ledger-stat-value {
  font-size: 20px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Over-limit rows are tinted rather than badged: the point is to spot them
   while scanning the column of amounts, not to read a label. */
.ledger-over {
  background: rgba(220, 80, 40, 0.10);
}

.ledger-flag {
  font-size: 11px;
  color: #fca5a5;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* A reversed entry stays in the book but reads as struck out, so the history
   is visible without being mistaken for a live charge. */
.ledger-reversed td {
  opacity: 0.45;
  text-decoration: line-through;
}

.ledger-credit {
  color: #4ade80;
}

.ledger-reason {
  flex: 1 1 260px;
}

/* ── Verificaciones de identidad ─────────────────── */
.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 .375rem;
  margin-left: auto;
  border-radius: 999px;
  background: #d93025;
  color: #fff;
  font-size: .6875rem;
  font-weight: 700;
}
.kyc-card {
  border: 1px solid var(--border, #e3e5e8);
  border-radius: 10px;
  padding: 1rem;
  margin-bottom: 1rem;
  background: #fff;
}
.kyc-card-name { font-size: 1rem; font-weight: 700; }
.kyc-card-meta { font-size: .8125rem; color: #5f6368; margin-top: .2rem; }
.kyc-card-reason { font-size: .8125rem; color: #b3261e; margin-top: .35rem; }
.kyc-shots {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  margin: .875rem 0;
}
.kyc-shot { width: 200px; }
.kyc-shot img {
  width: 200px; height: 140px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid #e3e5e8;
  display: block;
}
.kyc-shot-missing {
  width: 200px; height: 140px;
  border-radius: 8px;
  border: 1px dashed #c9ccd1;
  display: flex; align-items: center; justify-content: center;
  color: #9aa0a6;
  font-size: .8125rem;
}
.kyc-shot figcaption { font-size: .75rem; color: #5f6368; margin-top: .25rem; }
.kyc-card-actions {
  display: flex;
  align-items: center;
  gap: .5rem;
  flex-wrap: wrap;
}
.kyc-reason { flex: 1; min-width: 220px; }

/* ---- KYC: revisión automática ---- */
.kyc-ai-settings { margin: .75rem 0 1rem; padding: .75rem 1rem; border: 1px solid #e0e3e7; border-radius: 8px; background: #fafbfc; }
.kyc-ai-settings summary { cursor: pointer; font-weight: 600; }
.kyc-ai-form { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end; margin-top: .5rem; }
.kyc-ai-field { display: flex; flex-direction: column; gap: .25rem; font-size: .8125rem; color: #5f6368; }
.kyc-ai-field small { color: #80868b; }
.kyc-ai { margin: .5rem 0; padding: .6rem .8rem; border-radius: 6px; font-size: .8125rem; border-left: 4px solid #9aa0a6; background: #f1f3f4; }
.kyc-ai--approve { border-left-color: #1e8e3e; background: #e6f4ea; }
.kyc-ai--review  { border-left-color: #f9ab00; background: #fef7e0; }
.kyc-ai--reject  { border-left-color: #d93025; background: #fce8e6; }
.kyc-ai--muted   { color: #80868b; }
.kyc-ai-head { display: flex; flex-wrap: wrap; gap: .75rem; align-items: baseline; }
.kyc-ai-reason { margin: .3rem 0 0; }
.kyc-ai-data { margin: .3rem 0 0; display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
