/* ============================================================
   TDS Sweep Edition — Design System
   Trackfast Spider-Man blue/red, dark-mode-first for dispatchers
   ============================================================ */

:root {
  /* Trackfast brand */
  --tf-blue:       #1E40AF;
  --tf-blue-600:   #2563EB;
  --tf-blue-700:   #1D4ED8;
  --tf-blue-900:   #172554;
  --tf-red:        #DC2626;
  --tf-red-600:    #EF4444;
  --tf-red-700:    #B91C1C;

  /* Semantic */
  --c-bg:          #0B0F1A;
  --c-panel:       #0F172A;
  --c-panel-2:     #1E293B;
  --c-panel-3:     #334155;
  --c-border:      #1E293B;
  --c-border-2:    #334155;
  --c-text:        #E2E8F0;
  --c-text-dim:    #94A3B8;
  --c-text-muted:  #64748B;

  --c-primary:     var(--tf-blue);
  --c-primary-hi:  var(--tf-blue-600);
  --c-accent:      var(--tf-red);
  --c-accent-hi:   var(--tf-red-600);

  --c-ok:          #10B981;
  --c-warn:        #F59E0B;
  --c-err:         #EF4444;
  --c-info:        #38BDF8;

  /* Status colors (street sweep lifecycle) */
  --s-not-swept:   #EF4444;     /* red */
  --s-in-progress: #F59E0B;     /* amber */
  --s-completed:   #10B981;     /* green */
  --s-verified:    #3B82F6;     /* blue */
  --s-skipped:     #64748B;     /* slate */

  --radius-sm: 4px;
  --radius:    8px;
  --radius-lg: 12px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow:    0 4px 12px rgba(0,0,0,.4);
  --shadow-lg: 0 12px 32px rgba(0,0,0,.5);

  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", Menlo, Consolas, monospace;
}

[data-theme="light"] {
  --c-bg:         #F8FAFC;
  --c-panel:      #FFFFFF;
  --c-panel-2:    #F1F5F9;
  --c-panel-3:    #E2E8F0;
  --c-border:     #E2E8F0;
  --c-border-2:   #CBD5E1;
  --c-text:       #0F172A;
  --c-text-dim:   #475569;
  --c-text-muted: #64748B;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--c-primary-hi); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0 0 .5em; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
h4 { font-size: .95rem; color: var(--c-text-dim); text-transform: uppercase; letter-spacing: .05em; }

/* ---------- Layout ---------- */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-rows: 56px 1fr;
  grid-template-areas:
    "sidebar topbar"
    "sidebar main";
  min-height: 100vh;
}
.app.collapsed { grid-template-columns: 64px 1fr; }

.sidebar {
  grid-area: sidebar;
  background: linear-gradient(180deg, #0A0E1A 0%, #0F172A 100%);
  border-right: 1px solid var(--c-border);
  padding: 0;
  overflow-y: auto;
}
.sidebar .brand {
  padding: 16px;
  display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid var(--c-border);
}
.sidebar .brand .logo {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--tf-blue) 0%, var(--tf-red) 100%);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; color: white; font-size: 16px;
  box-shadow: 0 0 12px rgba(30, 64, 175, .4);
}
.sidebar .brand .name { font-weight: 700; font-size: 15px; }
.sidebar .brand .name small { display: block; color: var(--c-text-dim); font-weight: 400; font-size: 11px; }

.nav-section { padding: 12px 0; }
.nav-section .label {
  padding: 6px 16px; font-size: 10px; text-transform: uppercase;
  color: var(--c-text-muted); letter-spacing: .08em;
}
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px; color: var(--c-text-dim);
  border-left: 3px solid transparent;
  font-size: 13px;
}
.nav a:hover { color: var(--c-text); background: rgba(255,255,255,.03); text-decoration: none; }
.nav a.active {
  color: white;
  background: linear-gradient(90deg, rgba(30, 64, 175, .15) 0%, transparent 100%);
  border-left-color: var(--tf-red);
}
.nav a .icon { width: 18px; text-align: center; opacity: .9; }

.topbar {
  grid-area: topbar;
  background: var(--c-panel);
  border-bottom: 1px solid var(--c-border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
}
.topbar .page-title { font-weight: 600; }
.topbar .right { display: flex; align-items: center; gap: 12px; }
.topbar .user {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  border-radius: var(--radius);
  background: var(--c-panel-2);
  font-size: 13px;
}
.topbar .user .avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg, var(--tf-blue) 0%, var(--tf-red) 100%);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: white; font-size: 12px;
}

.main { grid-area: main; padding: 20px; overflow-x: hidden; }

/* ---------- Cards ---------- */
.card {
  background: var(--c-panel);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}
.card.flush { padding: 0; }
.card-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--c-border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-body { padding: 16px; }

/* KPI tiles */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.kpi {
  background: var(--c-panel);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  position: relative;
  overflow: hidden;
}
.kpi::before {
  content: ''; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: linear-gradient(90deg, var(--tf-blue) 0%, var(--tf-red) 100%);
}
.kpi .label { font-size: 11px; text-transform: uppercase; color: var(--c-text-muted); letter-spacing: .08em; }
.kpi .value { font-size: 1.6rem; font-weight: 700; margin-top: 4px; }
.kpi .delta { font-size: 11px; margin-top: 2px; }
.kpi .delta.up   { color: var(--c-ok); }
.kpi .delta.down { color: var(--c-err); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--c-border-2);
  border-radius: var(--radius);
  background: var(--c-panel-2);
  color: var(--c-text);
  cursor: pointer;
  font-size: 13px; font-weight: 500;
  text-decoration: none;
  transition: all .15s ease;
}
.btn:hover { background: var(--c-panel-3); text-decoration: none; }
.btn-primary { background: var(--tf-blue); border-color: var(--tf-blue); color: #fff; }
.btn-primary:hover { background: var(--tf-blue-700); }
.btn-accent { background: var(--tf-red); border-color: var(--tf-red); color: #fff; }
.btn-accent:hover { background: var(--tf-red-700); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }

/* ---------- Forms ---------- */
label { display: block; font-size: 12px; color: var(--c-text-dim); margin-bottom: 4px; font-weight: 500; }
input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  background: var(--c-panel-2);
  color: var(--c-text);
  border: 1px solid var(--c-border-2);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: inherit;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--c-primary-hi);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .2);
}
.form-row { display: grid; gap: 12px; margin-bottom: 12px; }
.form-grid-2 { grid-template-columns: 1fr 1fr; }
.form-grid-3 { grid-template-columns: 1fr 1fr 1fr; }

/* ---------- Tables ---------- */
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--c-panel);
  border-radius: var(--radius);
  overflow: hidden;
}
.table th, .table td {
  padding: 10px 12px;
  text-align: left;
  font-size: 13px;
  border-bottom: 1px solid var(--c-border);
}
.table th {
  background: var(--c-panel-2);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  color: var(--c-text-dim);
  letter-spacing: .05em;
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: rgba(255,255,255,.02); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  font-size: 11px; font-weight: 600;
  border-radius: 999px;
  background: var(--c-panel-3);
  color: var(--c-text);
}
.badge-ok    { background: rgba(16,185,129,.15); color: #34D399; }
.badge-warn  { background: rgba(245,158,11,.15); color: #FBBF24; }
.badge-err   { background: rgba(239,68,68,.15); color: #F87171; }
.badge-info  { background: rgba(56,189,248,.15); color: #38BDF8; }
.badge-primary{background: rgba(30,64,175,.2); color: #93C5FD; }
.badge-accent{ background: rgba(220,38,38,.15); color: #FCA5A5; }

/* Status dots */
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.available       { background: var(--c-ok); }
.dot.on_route        { background: var(--c-info); }
.dot.en_route_to_dump{ background: var(--c-warn); }
.dot.at_dump_site    { background: var(--c-warn); }
.dot.refueling       { background: var(--c-warn); }
.dot.watering_up     { background: #60A5FA; }
.dot.out_of_service  { background: var(--c-err); }
.dot.in_maintenance  { background: var(--c-err); }
.dot.in_transit      { background: var(--c-info); }
.dot.shop_hold       { background: #A855F7; }

/* ---------- Auth pages ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 20%, rgba(30,64,175,.15) 0%, transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(220,38,38,.1) 0%, transparent 50%),
    #0A0E1A;
}
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--c-panel);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-lg);
}
.auth-card .brand-stack {
  text-align: center;
  margin-bottom: 24px;
}
.auth-card .big-logo {
  width: 64px; height: 64px;
  background: linear-gradient(135deg, var(--tf-blue) 0%, var(--tf-red) 100%);
  border-radius: 16px;
  margin: 0 auto 16px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; color: white; font-size: 28px;
  box-shadow: 0 0 32px rgba(30, 64, 175, .4);
}

/* ---------- Map ---------- */
.map-wrap {
  height: calc(100vh - 160px);
  min-height: 500px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--c-border);
}
#map { width: 100%; height: 100%; background: #0A0E1A; }

.leaflet-container { background: #0A0E1A !important; font-family: var(--font-sans); }

/* ---------- Alerts ---------- */
.alert {
  padding: 12px 14px; border-radius: var(--radius);
  border: 1px solid;
  font-size: 13px;
  margin-bottom: 12px;
}
.alert-info  { background: rgba(56,189,248,.08); border-color: rgba(56,189,248,.3); color: #7DD3FC; }
.alert-err   { background: rgba(239,68,68,.08); border-color: rgba(239,68,68,.3); color: #FCA5A5; }
.alert-ok    { background: rgba(16,185,129,.08); border-color: rgba(16,185,129,.3); color: #6EE7B7; }
.alert-warn  { background: rgba(245,158,11,.08); border-color: rgba(245,158,11,.3); color: #FCD34D; }

/* ---------- Utilities ---------- */
.row { display: flex; gap: 12px; }
.col { flex: 1; }
.mt-1{margin-top:4px}.mt-2{margin-top:8px}.mt-3{margin-top:12px}.mt-4{margin-top:16px}.mt-5{margin-top:24px}
.mb-1{margin-bottom:4px}.mb-2{margin-bottom:8px}.mb-3{margin-bottom:12px}.mb-4{margin-bottom:16px}.mb-5{margin-bottom:24px}
.p-0{padding:0}.p-2{padding:8px}.p-3{padding:12px}.p-4{padding:16px}
.text-dim{color:var(--c-text-dim)}.text-muted{color:var(--c-text-muted)}
.text-right{text-align:right}.text-center{text-align:center}
.flex{display:flex}.flex-wrap{flex-wrap:wrap}.items-center{align-items:center}.justify-between{justify-content:space-between}
.gap-1{gap:4px}.gap-2{gap:8px}.gap-3{gap:12px}
.w-full{width:100%}
.hidden{display:none !important}
.mono{font-family:var(--font-mono)}
.font-bold{font-weight:700}
.font-semibold{font-weight:600}
.text-xs{font-size:11px}.text-sm{font-size:12px}.text-lg{font-size:16px}.text-xl{font-size:20px}.text-2xl{font-size:24px}

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--c-bg); }
::-webkit-scrollbar-thumb { background: var(--c-border-2); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--c-panel-3); }

/* Responsive */
@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-areas: "topbar" "main";
  }
  .sidebar { display: none; }
  .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
  .map-wrap { height: 60vh; }
}
