/* FreightOS Design System
   Transport operations console with a dense, industrial feel */

:root {
  --primary: #08111f;
  --secondary: #142033;
  --accent: #1d4ed8;
  --accent-2: #0f766e;
  --success: #16a34a;
  --warning: #d97706;
  --danger: #dc2626;
  --info: #0891b2;
  --bg: #eef3f9;
  --bg-2: #f7f9fc;
  --card: rgba(255, 255, 255, 0.92);
  --card-solid: #ffffff;
  --border: #d8e0ea;
  --border-strong: #c3ceda;
  --text: #0f172a;
  --muted: #64748b;
  --shadow: 0 18px 40px rgba(15, 23, 42, 0.08);
  --shadow-soft: 0 8px 24px rgba(15, 23, 42, 0.05);
  --radius: 0;
  --font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(29, 78, 216, 0.09), transparent 26%),
    radial-gradient(circle at right 15%, rgba(15, 118, 110, 0.08), transparent 22%),
    linear-gradient(180deg, #f8fbff 0%, var(--bg) 48%, #edf2f8 100%);
  overflow: hidden;
}

a { color: inherit; }

img, svg, video, canvas { display: block; max-width: 100%; }

button, input, select, textarea {
  font: inherit;
}

::selection {
  background: rgba(29, 78, 216, 0.16);
  color: var(--text);
}

/* Scrollbars */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(100, 116, 139, 0.4) transparent;
}

*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: rgba(100, 116, 139, 0.34);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background: rgba(100, 116, 139, 0.55); }

/* Layout */
.app-wrapper {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: 258px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  color: #e2e8f0;
  background:
    linear-gradient(180deg, rgba(8, 17, 31, 0.99), rgba(13, 23, 42, 0.98)),
    linear-gradient(135deg, #08111f, #111f34);
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: 18px 0 36px rgba(8, 15, 27, 0.1);
}

.sidebar-brand {
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar-brand .logo {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 800;
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #0ea5e9);
  box-shadow: 0 8px 20px rgba(37, 99, 235, 0.35);
}

.sidebar-brand h1 {
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.sidebar-brand h1 span { color: #60a5fa; }

.sidebar-brand .sub {
  margin-top: 2px;
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #94a3b8;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 10px 8px 12px;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  margin: 2px 0;
  color: #cbd5e1;
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.01em;
  border-left: 2px solid transparent;
  transition: transform 0.12s ease, background-color 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.sidebar-nav a:hover {
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
  transform: translateX(2px);
}

.sidebar-nav a.active {
  background: rgba(37, 99, 235, 0.16);
  border-left-color: #60a5fa;
  color: #dbeafe;
}

.sidebar-nav a i {
  width: 18px;
  text-align: center;
  font-size: 13px;
  opacity: 0.95;
}

.sidebar-group {
  margin-bottom: 12px;
}

.sidebar-group-title {
  padding: 12px 14px 4px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #64748b;
  display: flex;
  align-items: center;
  gap: 6px;
  border-top: 1px solid rgba(255, 255, 255, 0.04);
}

.sidebar-group:first-child .sidebar-group-title {
  border-top: none;
  padding-top: 4px;
}

.sidebar-nav a .nav-badge {
  margin-left: auto;
  padding: 2px 7px;
  font-size: 10px;
  font-weight: 700;
  border-radius: 99px;
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.sidebar-nav a .nav-badge.info {
  background: rgba(59, 130, 246, 0.2);
  color: #93c5fd;
  border-color: rgba(59, 130, 246, 0.3);
}

.sidebar-footer {
  padding: 15px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar-footer .avatar {
  width: 34px;
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  background: linear-gradient(135deg, #0f766e, #2563eb);
}

.sidebar-footer .info { font-size: 12px; min-width: 0; }
.sidebar-footer .info .name {
  font-weight: 700;
  color: #f8fafc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-footer .info .role {
  color: #94a3b8;
  font-size: 11px;
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.top-nav {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid rgba(195, 206, 218, 0.9);
}

.top-nav .page-title h2 {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.top-nav .page-title p {
  margin-top: 2px;
  font-size: 12px;
  color: var(--muted);
}

.top-nav .actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* Surface */
.card,
.stat-card,
.login-box,
.modal-box {
  background: var(--card);
  border: 1px solid rgba(216, 224, 234, 0.95);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(10px);
}

.card {
  padding: 20px;
  border-radius: var(--radius);
}

/* Admin ↔ driver handoff panel */
.handoff-panel {
  padding: 0;
  border: 1px solid #f2c76e;
  border-left: 4px solid var(--warning);
  background: linear-gradient(100deg, #fffaf0, #ffffff);
  box-shadow: var(--shadow-soft);
}
.handoff-panel-head { display:flex; align-items:center; justify-content:space-between; gap:16px; padding:16px 18px; border-bottom:1px solid #f7dfad; }
.handoff-panel .eyebrow { color:#a16207; font-size:10px; font-weight:800; letter-spacing:.12em; text-transform:uppercase; }
.handoff-panel h3 { margin-top:3px; font-size:16px; }
.handoff-list { display:grid; }
.handoff-item { display:flex; align-items:center; justify-content:space-between; gap:16px; padding:13px 18px; border-bottom:1px solid #f7ead0; }
.handoff-item:last-child { border-bottom:0; }
.handoff-item > div { min-width:0; }
.handoff-item strong { display:block; font-size:13px; }
.handoff-item span { display:block; margin-top:3px; color:var(--muted); font-size:12px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
@media (max-width: 640px) { .handoff-panel-head, .handoff-item { align-items:flex-start; flex-direction:column; } .handoff-item span { white-space:normal; } }

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
}

.card-header h3 {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #475569;
}

/* Typography helpers */
.label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.value {
  margin-top: 6px;
  font-size: 30px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.05em;
}

.sub {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.font-mono { font-family: "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", monospace; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.required { color: var(--danger); }

/* Grids */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  padding: 20px;
  position: relative;
  overflow: hidden;
}

.stat-card::after {
  content: "";
  position: absolute;
  inset: auto -20px -22px auto;
  width: 110px;
  height: 110px;
  background: radial-gradient(circle, rgba(37, 99, 235, 0.1), transparent 70%);
  pointer-events: none;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

/* Tables */
.table-container {
  overflow-x: auto;
  border: 1px solid rgba(216, 224, 234, 0.6);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: rgba(255, 255, 255, 0.62);
}

thead th {
  padding: 12px 12px;
  text-align: left;
  white-space: nowrap;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #64748b;
  background: rgba(248, 250, 252, 0.95);
  border-bottom: 1px solid var(--border);
}

tbody td {
  padding: 10px 12px;
  border-bottom: 1px solid #e6edf5;
  vertical-align: middle;
}

tbody tr:hover { background: rgba(241, 245, 249, 0.85); }
tbody tr:last-child td { border-bottom: none; }

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 22px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  border: 1px solid transparent;
}

.badge-success {
  background: rgba(22, 163, 74, 0.12);
  color: #166534;
  border-color: rgba(22, 163, 74, 0.18);
}

.badge-warning {
  background: rgba(217, 119, 6, 0.12);
  color: #92400e;
  border-color: rgba(217, 119, 6, 0.18);
}

.badge-danger {
  background: rgba(220, 38, 38, 0.12);
  color: #991b1b;
  border-color: rgba(220, 38, 38, 0.18);
}

.badge-info {
  background: rgba(8, 145, 178, 0.12);
  color: #155e75;
  border-color: rgba(8, 145, 178, 0.18);
}

.badge-secondary {
  background: rgba(100, 116, 139, 0.12);
  color: #475569;
  border-color: rgba(100, 116, 139, 0.18);
}

/* Forms */
.form-group { margin-bottom: 14px; }

.form-group label {
  display: block;
  margin-bottom: 5px;
  font-size: 12px;
  font-weight: 700;
  color: #334155;
}

.form-control {
  width: 100%;
  min-height: 38px;
  padding: 9px 12px;
  color: var(--text);
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color 0.12s ease, box-shadow 0.12s ease, transform 0.12s ease;
}

.form-control:focus {
  outline: none;
  border-color: rgba(37, 99, 235, 0.75);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.form-control::placeholder { color: #94a3b8; }

select.form-control { padding-right: 36px; }

textarea.form-control {
  min-height: 84px;
  resize: vertical;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-row .full { grid-column: 1 / -1; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 8px 16px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease, background-color 0.12s ease, border-color 0.12s ease;
  user-select: none;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 18px rgba(15, 23, 42, 0.08);
}

.btn:active {
  transform: translateY(0);
  box-shadow: none;
}

.btn-primary {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #fff;
  box-shadow: 0 10px 18px rgba(37, 99, 235, 0.18);
}

.btn-secondary {
  background: #334155;
  color: #fff;
}

.btn-success {
  background: linear-gradient(135deg, #16a34a, #15803d);
  color: #fff;
}

.btn-danger {
  background: linear-gradient(135deg, #dc2626, #b91c1c);
  color: #fff;
}

.btn-warning {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #1f2937;
}

.btn-info {
  background: linear-gradient(135deg, #0ea5e9, #0284c7);
  color: #fff;
}

.btn-sm {
  min-height: 30px;
  padding: 5px 10px;
  font-size: 12px;
}

.btn-icon {
  min-height: 34px;
  width: 34px;
  padding: 0;
  background: rgba(255, 255, 255, 0.8);
  border: 1px solid var(--border);
  color: #475569;
}

.btn-icon:hover {
  background: #fff;
  color: var(--text);
}

.btn-ghost {
  background: transparent;
  border: 1px solid transparent;
  color: var(--accent);
  padding: 0;
  min-height: auto;
  box-shadow: none;
}

.btn-ghost:hover {
  transform: none;
  box-shadow: none;
  text-decoration: underline;
}

/* Alerts */
.alert {
  padding: 12px 14px;
  margin-bottom: 16px;
  border-radius: var(--radius);
  border: 1px solid;
  font-size: 13px;
  font-weight: 600;
}

.alert-success {
  background: rgba(220, 252, 231, 0.9);
  border-color: rgba(134, 239, 172, 0.95);
  color: #166534;
}

.alert-danger {
  background: rgba(254, 226, 226, 0.9);
  border-color: rgba(252, 165, 165, 0.95);
  color: #991b1b;
}

/* Modals */
.modal-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(2, 6, 23, 0.58);
  backdrop-filter: blur(4px);
  z-index: 1000;
}

.modal-overlay.open { display: flex; }

.modal-box {
  width: min(100%, 560px);
  max-height: 88vh;
  overflow-y: auto;
  padding: 22px;
  background: #fff;
  box-shadow: var(--shadow);
}

.modal-box h3 {
  margin-bottom: 16px;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

/* Page blocks */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.page-header h3 {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #475569;
}

.dispatch-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid #e5ebf3;
}

.dispatch-row:last-child { border-bottom: none; }

.dispatch-info strong {
  display: inline-block;
  margin-bottom: 2px;
  font-size: 14px;
}

.map-marker {
  background: transparent !important;
  border: none !important;
}

/* Misc utilities */
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.mt-2 { margin-top: 8px; }
.mt-6 { margin-top: 24px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }

/* Login */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at top, rgba(37, 99, 235, 0.24), transparent 28%),
    radial-gradient(circle at bottom right, rgba(15, 118, 110, 0.16), transparent 26%),
    linear-gradient(180deg, #08111f 0%, #0f172a 45%, #111827 100%);
}

.login-page::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    linear-gradient(120deg, rgba(255, 255, 255, 0.045) 0 1px, transparent 1px 100%),
    linear-gradient(0deg, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 100%);
  background-size: 72px 72px;
  mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.6), transparent 95%);
  pointer-events: none;
}

.login-box {
  width: 100%;
  max-width: 420px;
  padding: 34px 32px;
  position: relative;
  z-index: 1;
  background: rgba(255, 255, 255, 0.96);
}

.login-box .login-logo {
  width: 52px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  font-size: 20px;
  font-weight: 900;
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #0ea5e9);
  box-shadow: 0 14px 30px rgba(37, 99, 235, 0.26);
}

.login-box h1 {
  margin-bottom: 4px;
  font-size: 26px;
  font-weight: 900;
  letter-spacing: -0.04em;
}

.login-box h1 span { color: var(--accent); }

.login-box .subtitle {
  margin-bottom: 24px;
  color: var(--muted);
  font-size: 13px;
}

/* Dashboard / page blocks */
.card.mb-6,
.stat-grid.mb-6 {
  margin-bottom: 24px;
}

.dispatch-info {
  min-width: 0;
}

.dispatch-info span {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#dispatchMap {
  border-top: 1px solid var(--border);
  background: #dbeafe;
}

.card > #dispatchMap,
.card > #nowMap {
  border-radius: 0;
}

/* Responsive */
@media (max-width: 1100px) {
  .sidebar { width: 232px; }
  .content { padding: 20px; }
  .grid-2,
  .grid-3 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  body { overflow: auto; }
  .app-wrapper { height: auto; min-height: 100vh; flex-direction: column; }
  .sidebar {
    width: 100%;
    position: sticky;
    top: 0;
    z-index: 20;
  }
  .sidebar-nav {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 12px;
  }
  .sidebar-nav a {
    white-space: nowrap;
    border-left: none;
    border-radius: 999px;
    padding-inline: 12px;
  }
  .sidebar-nav a.active {
    border-left: none;
    background: rgba(37, 99, 235, 0.22);
  }
  .main-content { min-height: 0; }
}

@media (max-width: 720px) {
  .top-nav,
  .page-header,
  .card-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .form-row {
    grid-template-columns: 1fr;
  }
  .stat-grid {
    grid-template-columns: 1fr;
  }
  .content {
    padding: 16px;
  }
  .card {
    padding: 16px;
  }
  .login-box {
    padding: 28px 22px;
  }
  .dispatch-row {
    flex-direction: column;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
