/* FleetFlow Design System - Inspired by Dribbble references #090909, #240BF8, #B1A99C, #E4E3E4, #544F52, #AD684B */
:root {
  --bg-app: #F2F0EB;
  --bg-app-2: #EDEBE6;
  --bg-dark: #090909;
  --bg-dark-2: #121112;
  --bg-dark-3: #1E1E1E;
  --bg-panel: #FFFFFF;
  --bg-muted: #F6F4F0;
  --bg-input: #F1EFEA;
  --text-primary: #0A090A;
  --text-secondary: #544F52;
  --text-tertiary: #8A8683;
  --text-on-dark: #EDEBE6;
  --text-on-dark-muted: #9A9590;
  --border: #E8E4DF;
  --border-strong: #D6D0C8;
  --border-dark: #2A2A2A;
  --accent: #240BF8;
  --accent-hover: #1C09C7;
  --accent-soft: rgba(36,11,248,0.08);
  --accent-soft-2: rgba(36,11,248,0.12);
  --success: #1A7F4B;
  --success-soft: #E6F4EB;
  --warning: #AD684B;
  --warning-soft: #FBF0E9;
  --danger: #B42318;
  --danger-soft: #FEECEB;
  --shadow-sm: 0 1px 2px rgba(9,9,9,0.04), 0 4px 12px rgba(9,9,9,0.04);
  --shadow-md: 0 8px 24px rgba(9,9,9,0.08);
  --shadow-lg: 0 16px 48px rgba(9,9,9,0.12);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 9999px;
  --sidebar-w: 280px;
  --sidebar-w-collapsed: 72px;
  --header-h: 72px;
  --font-sans: "Inter", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", Menlo, monospace;
  --ease-spring: cubic-bezier(0.32,0.72,0,1);
  --ease-out: cubic-bezier(0.16,1,0.3,1);
}

* { box-sizing: border-box; }
html { font-size: 15px; -webkit-font-smoothing: antialiased; }
body {
  margin:0;
  font-family: var(--font-sans);
  background: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.5;
  overflow-x: hidden;
}

/* Scrollbar */
::-webkit-scrollbar { width:6px; height:6px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 9999px; }
::-webkit-scrollbar-track { background: transparent; }

/* Layout */
.app-shell { display:flex; min-height:100vh; }
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-dark);
  color: var(--text-on-dark);
  display:flex;
  flex-direction:column;
  position:fixed;
  top:0; left:0; bottom:0;
  z-index: 40;
  transition: width 0.3s var(--ease-spring), transform 0.3s var(--ease-spring);
  border-right: 1px solid var(--border-dark);
}
.sidebar.collapsed { width: var(--sidebar-w-collapsed); }
.sidebar-header {
  height: var(--header-h);
  display:flex;
  align-items:center;
  padding:0 20px;
  gap:12px;
  border-bottom:1px solid var(--border-dark);
}
.logo-mark {
  width:32px; height:32px;
  background: var(--accent);
  border-radius: 8px;
  display:grid;
  place-items:center;
  font-weight:800;
  font-size:14px;
  color:white;
  flex-shrink:0;
}
.logo-text { font-weight:700; letter-spacing:-0.02em; font-size:16px; white-space:nowrap; }
.logo-text span { color: var(--text-on-dark-muted); font-weight:400; }
.sidebar.collapsed .logo-text,
.sidebar.collapsed .nav-section-label,
.sidebar.collapsed .nav-label,
.sidebar.collapsed .nav-badge,
.sidebar.collapsed .user-card-meta { display:none; }
.sidebar-nav { flex:1; overflow-y:auto; padding:16px 12px; }
.nav-section { margin-bottom:20px; }
.nav-section-label {
  font-size:10px; letter-spacing:0.12em; text-transform:uppercase;
  color: var(--text-on-dark-muted); padding:8px 12px 8px;
}
.nav-item {
  display:flex; align-items:center; gap:10px;
  height:38px; padding:0 12px;
  border-radius:10px;
  color: var(--text-on-dark-muted);
  text-decoration:none;
  font-size:13.5px; font-weight:450;
  transition: all 0.18s ease;
  position:relative;
}
.nav-item:hover { background: var(--bg-dark-3); color: var(--text-on-dark); }
.nav-item.active { background: var(--bg-dark-3); color:white; }
.nav-item.active::before {
  content:""; position:absolute; left:-12px; top:50%; transform:translateY(-50%);
  width:3px; height:18px; background: var(--accent); border-radius:0 3px 3px 0;
}
.nav-icon { width:18px; height:18px; flex-shrink:0; opacity:0.9; }
.nav-badge {
  margin-left:auto;
  background: var(--accent);
  color:white;
  font-size:11px; font-weight:600;
  padding:2px 7px; border-radius:9999px;
}
.sidebar-footer {
  padding:12px;
  border-top:1px solid var(--border-dark);
}
.user-card {
  display:flex; align-items:center; gap:10px;
  padding:8px 10px; border-radius:10px;
  background: rgba(255,255,255,0.06);
}
.user-avatar { width:36px; height:36px; border-radius:9999px; background:#2A2A2A; display:grid; place-items:center; font-weight:600; font-size:13px; color:white; flex-shrink:0; overflow:hidden; }
.user-avatar img { width:100%; height:100%; object-fit:cover; }
.user-card-meta { line-height:1.2; overflow:hidden; }
.user-card-name { font-size:13px; font-weight:600; white-space:nowrap; overflow:hidden; text-overflow:ellipsis; }
.user-card-role { font-size:11px; color: var(--text-on-dark-muted); }

.main {
  flex:1;
  margin-left: var(--sidebar-w);
  min-width:0;
  transition: margin-left 0.3s var(--ease-spring);
}
.sidebar.collapsed + .main { margin-left: var(--sidebar-w-collapsed); }

.topbar {
  height: var(--header-h);
  background: rgba(242,240,235,0.8);
  backdrop-filter: blur(12px);
  border-bottom:1px solid var(--border);
  position:sticky; top:0; z-index:30;
  display:flex; align-items:center;
  padding:0 24px;
  gap:16px;
}
.topbar-title { flex-shrink:0; }
.topbar-title h1 { margin:0; font-size:20px; font-weight:650; letter-spacing:-0.02em; line-height:1.1; }
.topbar-title p { margin:2px 0 0; font-size:12.5px; color: var(--text-secondary); }

.search-wrap { flex:1; max-width:420px; margin-left:24px; position:relative; }
.search-input {
  width:100%; height:40px;
  background: var(--bg-panel);
  border:1px solid var(--border);
  border-radius:9999px;
  padding:0 16px 0 40px;
  font-size:13.5px;
  outline:none;
  transition: all 0.2s ease;
}
.search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-icon { position:absolute; left:14px; top:50%; transform:translateY(-50%); width:16px; height:16px; color: var(--text-tertiary); }

.topbar-actions { margin-left:auto; display:flex; align-items:center; gap:8px; }
.icon-btn {
  width:40px; height:40px;
  border-radius:9999px;
  border:1px solid var(--border);
  background: var(--bg-panel);
  display:grid; place-items:center;
  cursor:pointer;
  transition: all 0.18s ease;
}
.icon-btn:hover { background: var(--bg-muted); border-color: var(--border-strong); }

.content { padding:24px; max-width:1440px; margin:0 auto; }

/* Buttons */
.btn {
  height:40px; padding:0 18px;
  border-radius:9999px;
  font-size:13.5px; font-weight:600;
  border:1px solid transparent;
  display:inline-flex; align-items:center; justify-content:center; gap:8px;
  cursor:pointer;
  transition: all 0.18s ease;
  text-decoration:none;
  white-space:nowrap;
  line-height:1;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color:white; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--bg-panel); color: var(--text-primary); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg-muted); }
.btn-ghost { background: transparent; color: var(--text-secondary); border-color: transparent; }
.btn-ghost:hover { background: var(--bg-muted); color: var(--text-primary); }
.btn-danger { background: var(--danger); color:white; }
.btn-sm { height:32px; padding:0 14px; font-size:12.5px; }
.btn-lg { height:48px; padding:0 24px; font-size:14px; }
.btn:disabled { opacity:0.5; pointer-events:none; }

/* Cards */
.card {
  background: var(--bg-panel);
  border:1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}
.card-header { padding:16px 20px; border-bottom:1px solid var(--border); display:flex; align-items:center; justify-content:space-between; }
.card-title { font-size:14px; font-weight:650; letter-spacing:-0.01em; }
.card-body { padding:20px; }
.card-hover:hover { box-shadow: var(--shadow-md); border-color: var(--border-strong); transform: translateY(-1px); transition: all 0.2s var(--ease-out); }

/* KPI Cards */
.kpi-grid { display:grid; grid-template-columns: repeat(4, 1fr); gap:16px; margin-bottom:24px; }
.kpi-card { padding:18px 20px; }
.kpi-label { font-size:11px; letter-spacing:0.06em; text-transform:uppercase; color: var(--text-tertiary); font-weight:600; margin-bottom:8px; }
.kpi-value { font-size:26px; font-weight:700; letter-spacing:-0.03em; line-height:1; }
.kpi-delta { margin-top:8px; font-size:12px; display:flex; align-items:center; gap:4px; }
.kpi-delta.up { color: var(--success); }
.kpi-delta.down { color: var(--danger); }

/* Tables */
.table-wrap { overflow:auto; border-radius: var(--radius-md); border:1px solid var(--border); background: var(--bg-panel); }
.table { width:100%; border-collapse:collapse; }
.table th {
  text-align:left;
  font-size:11px; letter-spacing:0.06em; text-transform:uppercase;
  color: var(--text-tertiary); font-weight:600;
  padding:14px 16px;
  background: var(--bg-muted);
  border-bottom:1px solid var(--border);
  white-space:nowrap;
}
.table td { padding:14px 16px; border-bottom:1px solid var(--border); font-size:13.5px; vertical-align:middle; }
.table tr:last-child td { border-bottom:none; }
.table tr:hover td { background: #FBF9F6; }

/* Pills */
.pill {
  display:inline-flex; align-items:center; gap:6px;
  height:24px; padding:0 10px;
  border-radius:9999px;
  font-size:11.5px; font-weight:600;
  letter-spacing:0.01em;
  white-space:nowrap;
}
.pill-dot { width:6px; height:6px; border-radius:9999px; }
.pill-draft { background:#F2F0EB; color: var(--text-secondary); } .pill-draft .pill-dot{ background: var(--text-tertiary); }
.pill-pending { background:#EFE9FF; color:#3D1DD3; } .pill-pending .pill-dot{ background: var(--accent); }
.pill-confirmed { background: var(--accent-soft); color: var(--accent); } .pill-confirmed .pill-dot{ background: var(--accent); }
.pill-assigned { background:#E8E6FF; color:#2A11EF; } .pill-assigned .pill-dot{ background:#2A11EF; }
.pill-in_transit { background:#DBEAFE; color:#1E40AF; } .pill-in_transit .pill-dot{ background:#3B82F6; }
.pill-delayed { background: var(--warning-soft); color: var(--warning); } .pill-delayed .pill-dot{ background: var(--warning); }
.pill-delivered { background: var(--success-soft); color: var(--success); } .pill-delivered .pill-dot{ background: var(--success); }
.pill-cancelled { background:#F2F0EB; color: var(--text-tertiary); text-decoration:line-through; }

/* Forms */
.form-group { margin-bottom:16px; }
.form-label { display:block; font-size:12.5px; font-weight:600; margin-bottom:6px; color: var(--text-primary); }
.form-input, .form-select, .form-textarea {
  width:100%;
  background: var(--bg-panel);
  border:1px solid var(--border);
  border-radius:10px;
  padding:0 14px;
  font-size:13.5px;
  outline:none;
  transition: all 0.18s ease;
}
.form-input, .form-select { height:40px; }
.form-textarea { padding:12px 14px; min-height:80px; resize:vertical; }
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--accent); box-shadow:0 0 0 3px var(--accent-soft); }
.form-hint { font-size:11.5px; color: var(--text-tertiary); margin-top:4px; }
.form-error { font-size:11.5px; color: var(--danger); margin-top:4px; }

/* Map */
.map-container {
  background: #E9E5DE;
  border:1px solid var(--border);
  border-radius: var(--radius-md);
  overflow:hidden;
  position:relative;
  height:480px;
}
.map-container .leaflet-container {
  width:100%; height:100%;
  border-radius: var(--radius-md);
  z-index:1;
}
.map-placeholder {
  width:100%; height:100%;
  background: radial-gradient(circle at 30% 30%, #F2EEE8 0%, #E9E5DE 40%, #DDD8CF 100%);
  position:relative;
  overflow:hidden;
}
.map-grid {
  position:absolute; inset:0;
  background-image:
    linear-gradient(rgba(0,0,0,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0,0,0,0.03) 1px, transparent 1px);
  background-size: 40px 40px;
}
.route-line {
  position:absolute;
  height:3px;
  background: var(--border-strong);
  border-radius:9999px;
  transform-origin:left center;
}
.route-line.proposed {
  background: var(--accent);
  height:4px;
  box-shadow: 0 0 12px rgba(36,11,248,0.35);
}
.route-marker {
  position:absolute;
  width:32px; height:32px;
  background: var(--bg-dark);
  border:3px solid white;
  border-radius:9999px;
  box-shadow: var(--shadow-md);
  display:grid; place-items:center;
  color:white; font-size:11px; font-weight:700;
}
#reroute-map, #dashboard-reroute-map {
  min-height:280px;
  background:#E9E5DE;
  border-radius: var(--radius-md);
}

/* Timeline */
.timeline { position:relative; padding-left:28px; }
.timeline::before { content:""; position:absolute; left:7px; top:4px; bottom:4px; width:2px; background: var(--border); border-radius:9999px; }
.timeline-item { position:relative; padding-bottom:20px; }
.timeline-item:last-child { padding-bottom:0; }
.timeline-dot {
  position:absolute; left:-28px; top:2px;
  width:16px; height:16px;
  border-radius:9999px;
  background: var(--bg-panel);
  border:2px solid var(--border-strong);
  display:grid; place-items:center;
}
.timeline-dot.active { background: var(--accent); border-color: var(--accent); box-shadow:0 0 0 4px var(--accent-soft); }
.timeline-dot.delayed { background: var(--warning); border-color: var(--warning); }
.timeline-dot.completed { background: var(--success); border-color: var(--success); }
.timeline-content { }
.timeline-title { font-size:13px; font-weight:600; }
.timeline-desc { font-size:12.5px; color: var(--text-secondary); margin-top:2px; }
.timeline-time { font-size:11px; color: var(--text-tertiary); font-family: var(--font-mono); margin-top:4px; }

/* AI Agent Panel */
.ai-panel {
  background: linear-gradient(180deg, #FFFFFF 0%, #FBF9F7 100%);
  border:1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow:hidden;
}
.ai-panel-header {
  padding:16px 20px;
  border-bottom:1px solid var(--border);
  display:flex; align-items:center; gap:12px;
}
.ai-avatar {
  width:36px; height:36px;
  border-radius:10px;
  background: var(--bg-dark);
  display:grid; place-items:center;
  color:white;
}
.ai-status {
  width:8px; height:8px;
  border-radius:9999px;
  background: var(--success);
  box-shadow:0 0 0 3px var(--success-soft);
  animation: pulse 2s infinite;
}
@keyframes pulse { 0%{ box-shadow:0 0 0 0 var(--success-soft);} 70%{ box-shadow:0 0 0 6px rgba(26,127,75,0);} 100%{ box-shadow:0 0 0 0 rgba(26,127,75,0);} }
.ai-thinking { display:flex; gap:4px; align-items:center; }
.ai-thinking-dot { width:4px; height:4px; background: var(--text-tertiary); border-radius:9999px; animation: thinking 1.4s infinite; }
.ai-thinking-dot:nth-child(2){ animation-delay:0.2s; } .ai-thinking-dot:nth-child(3){ animation-delay:0.4s; }
@keyframes thinking { 0%,80%,100%{ transform:scale(0.6); opacity:0.4; } 40%{ transform:scale(1); opacity:1; } }

/* Extraction */
.extraction-grid { display:grid; grid-template-columns: repeat(2, 1fr); gap:12px; }
.extraction-field {
  background: var(--bg-panel);
  border:1px solid var(--border);
  border-radius:10px;
  padding:12px;
  position:relative;
}
.extraction-field.confidence-high { border-color: rgba(26,127,75,0.25); background: #FBFFFD; }
.extraction-field.confidence-medium { border-color: rgba(173,104,75,0.3); background: #FFFCF8; }
.extraction-field.confidence-low { border-color: rgba(180,35,24,0.25); background: #FFFBFB; }
.extraction-label { font-size:10px; letter-spacing:0.08em; text-transform:uppercase; color: var(--text-tertiary); font-weight:600; }
.extraction-value { font-size:13.5px; font-weight:600; margin-top:4px; }
.confidence-badge { position:absolute; top:8px; right:8px; font-size:10px; padding:2px 6px; border-radius:9999px; font-weight:600; }
.conf-high { background: var(--success-soft); color: var(--success); }
.conf-med { background: var(--warning-soft); color: var(--warning); }
.conf-low { background: var(--danger-soft); color: var(--danger); }

/* Drawer & Modal */
.drawer {
  position:fixed; top:0; right:0; bottom:0;
  width:440px; max-width:100vw;
  background: var(--bg-panel);
  border-left:1px solid var(--border);
  box-shadow: var(--shadow-lg);
  z-index:60;
  transform: translateX(100%);
  transition: transform 0.36s var(--ease-spring);
  display:flex; flex-direction:column;
}
.drawer.open { transform: translateX(0); }
.drawer-header { height:64px; padding:0 20px; border-bottom:1px solid var(--border); display:flex; align-items:center; justify-content:space-between; flex-shrink:0; }
.drawer-body { flex:1; overflow:auto; padding:20px; }
.drawer-footer { padding:16px 20px; border-top:1px solid var(--border); display:flex; gap:10px; justify-content:flex-end; background: var(--bg-muted); }

.modal-overlay {
  position:fixed; inset:0;
  background: rgba(9,9,9,0.45);
  backdrop-filter: blur(8px);
  z-index:70;
  display:none;
  place-items:center;
  padding:20px;
}
.modal-overlay.open { display:grid; }
.modal {
  width:100%; max-width:560px;
  background: var(--bg-panel);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow:hidden;
  animation: modalIn 0.32s var(--ease-spring);
}
@keyframes modalIn { from{ transform: translateY(12px) scale(0.98); opacity:0; } to{ transform: translateY(0) scale(1); opacity:1; } }
.modal-header { padding:20px 24px 0; }
.modal-title { font-size:18px; font-weight:700; letter-spacing:-0.02em; }
.modal-desc { font-size:13.5px; color: var(--text-secondary); margin-top:6px; }
.modal-body { padding:20px 24px; }
.modal-footer { padding:16px 24px; background: var(--bg-muted); border-top:1px solid var(--border); display:flex; gap:10px; justify-content:flex-end; }

/* Toast */
.toast-container { position:fixed; bottom:20px; right:20px; z-index:80; display:flex; flex-direction:column; gap:10px; }
.toast {
  width:360px; max-width:90vw;
  background: var(--bg-panel);
  border:1px solid var(--border);
  border-radius:14px;
  box-shadow: var(--shadow-lg);
  padding:14px 16px;
  display:flex; gap:12px;
  animation: toastIn 0.28s var(--ease-spring);
}
@keyframes toastIn { from{ transform: translateY(12px); opacity:0; } to{ transform: translateY(0); opacity:1; } }
.toast-icon { width:32px; height:32px; border-radius:9999px; display:grid; place-items:center; flex-shrink:0; }
.toast-success .toast-icon { background: var(--success-soft); color: var(--success); }
.toast-error .toast-icon { background: var(--danger-soft); color: var(--danger); }
.toast-title { font-size:13px; font-weight:600; }
.toast-msg { font-size:12.5px; color: var(--text-secondary); margin-top:2px; }

/* Skeletons */
.skeleton { background: linear-gradient(90deg, #EDEBE6 25%, #F5F3F0 50%, #EDEBE6 75%); background-size:200% 100%; animation: shimmer 1.2s infinite; border-radius:8px; }
@keyframes shimmer { 0%{ background-position:200% 0; } 100%{ background-position:-200% 0; } }

/* Utilities */
.grid-2 { display:grid; grid-template-columns: repeat(2, 1fr); gap:16px; }
.grid-3 { display:grid; grid-template-columns: repeat(3, 1fr); gap:16px; }
.flex { display:flex; }
.items-center { align-items:center; }
.justify-between { justify-content:space-between; }
.gap-2 { gap:8px; } .gap-3 { gap:12px; } .gap-4 { gap:16px; }
.mt-4 { margin-top:16px; } .mt-6 { margin-top:24px; } .mb-4 { margin-bottom:16px; }
.text-sm { font-size:12.5px; } .text-xs { font-size:11px; }
.text-muted { color: var(--text-secondary); }
.text-mono { font-family: var(--font-mono); }
.hidden { display:none !important; }
.divider { height:1px; background: var(--border); margin:16px 0; }

/* Responsive */
@media (max-width: 1024px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-3 { grid-template-columns:1fr; }
  .sidebar { transform: translateX(-100%); width: var(--sidebar-w); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left:0 !important; }
  .topbar { padding:0 16px; }
  .content { padding:16px; }
  .search-wrap { display:none; }
}
@media (max-width: 640px) {
  .kpi-grid { grid-template-columns:1fr; }
  .drawer { width:100vw; }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration:0.01ms !important; transition-duration:0.01ms !important; }
}

/* Focus */
:focus-visible { outline:2px solid var(--accent); outline-offset:2px; }

/* Leaflet overrides */
.leaflet-container { font-family: var(--font-sans); }
