:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-alt: #eef2f6;
  --text: #16202a;
  --muted: #667483;
  --border: #d9e1ea;
  --primary: #123f66;
  --primary-2: #0f5f8f;
  --success: #1f8f5f;
  --info: #2574c7;
  --warning: #c18a14;
  --danger: #bb2d3b;
  --shadow: 0 12px 30px rgba(18, 30, 50, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: linear-gradient(180deg, #eef3f7 0%, #f8fafc 100%);
  color: var(--text);
}

a { color: var(--primary-2); text-decoration: none; }
input, select, textarea, button {
  font: inherit;
}
input, select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.8rem 0.9rem;
  background: var(--surface);
}
textarea { resize: vertical; }
button, .btn {
  border: 0;
  border-radius: 14px;
  padding: 0.8rem 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  cursor: pointer;
}
.btn-primary { background: var(--primary); color: white; }
.btn-secondary { background: var(--surface-alt); color: var(--text); }
.btn-danger { background: var(--danger); color: white; }
.btn-success { background: var(--success); color: white; }
.btn-info { background: var(--info); color: white; }
.btn-warning { background: var(--warning); color: white; }
.btn-large { padding: 1rem 1.1rem; font-weight: 700; }

.topbar {
  padding: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  justify-content: space-between;
  align-items: center;
  background: rgba(255,255,255,0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { font-size: 1.05rem; font-weight: 800; }
.muted { color: var(--muted); font-size: 0.92rem; }
.topnav { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.topnav a {
  padding: 0.55rem 0.8rem;
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--text);
  font-size: 0.92rem;
  white-space: nowrap;
}
.topnav-form {
  margin: 0;
  display: inline-flex;
}
.topnav-link {
  padding: 0.55rem 0.8rem;
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--text);
  font-size: 0.92rem;
  white-space: nowrap;
  -webkit-appearance: none;
  appearance: none;
}
.page-shell {
  width: min(1240px, calc(100% - 1rem));
  margin: 1rem auto 3rem;
}
.grid {
  display: grid;
  gap: 1rem;
}
.grid.cards { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.dashboard-hero-map {
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(0, 1.45fr) minmax(240px, 0.75fr);
  align-items: start;
}
.dashboard-hero-map > .driver-status-panel {
  max-height: clamp(420px, 62vh, 620px);
  overflow: auto;
}
.live-map-panel {
  position: relative;
}
.live-map-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.map-fullscreen-toggle {
  white-space: nowrap;
  padding: 0.65rem 0.9rem;
}
.live-map-panel-header h2,
.panel h2 {
  margin: 0;
  font-size: 0.94rem;
  font-weight: 700;
  line-height: 1.2;
}
.live-map-panel.is-fullscreen {
  position: fixed;
  inset: 1rem;
  z-index: 1000;
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: calc(100vh - 2rem);
}
.live-map-panel.is-fullscreen .route-legend,
.live-map-panel.is-fullscreen .driver-detail-card,
.live-map-panel.is-fullscreen > .muted {
  display: none;
}
.live-map-panel.is-fullscreen .live-map-panel-header {
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  right: 0.75rem;
  z-index: 1001;
  margin: 0;
  padding: 0.55rem 0.7rem;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  box-shadow: 0 12px 28px rgba(18, 30, 50, 0.16);
}
.live-map-panel.is-fullscreen .map-leaflet {
  flex: 1 1 auto;
  min-height: 0;
}
.live-map-panel.is-fullscreen .map-leaflet .leaflet-container {
  height: 100%;
  min-height: 0;
}
.map-fullscreen-active .dashboard-hero-map > .driver-status-panel,
.map-fullscreen-active .dashboard-support-grid {
  display: none;
}
body.map-fullscreen-active {
  overflow: hidden;
}
.route-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin: 0.65rem 0 0.9rem;
}
.route-chip {
  gap: 0.45rem;
  border: 1px solid rgba(18, 30, 50, 0.08);
}
.route-swatch {
  width: 0.9rem;
  height: 0.9rem;
  border-radius: 999px;
  flex: 0 0 auto;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.65);
}
.route-checkpoint-marker {
  height: 21px;
  border: 0;
}
.route-checkpoint-badge {
  min-width: 48px;
  min-height: 18px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.18rem;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: linear-gradient(180deg, rgba(16, 46, 72, 0.92), rgba(10, 28, 44, 0.92));
  box-shadow: 0 10px 20px rgba(18, 30, 50, 0.28);
  padding: 0.08rem 0.36rem;
  white-space: nowrap;
  max-width: 96px;
  backdrop-filter: blur(4px);
}
.route-checkpoint-name {
  color: rgba(255, 255, 255, 0.98);
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  line-height: 1;
  overflow: hidden;
  text-overflow: ellipsis;
}
.route-checkpoint-badge::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--checkpoint-color, var(--primary-2));
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.14);
  flex: 0 0 auto;
}
.dashboard-support-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 0.9fr);
  align-items: start;
}
.card, .auth-card, .panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: var(--shadow);
  padding: 1rem;
}
.card h3, .panel h2, .auth-card h1 { margin-top: 0; }
.stat-value { font-size: 1.8rem; font-weight: 800; line-height: 1; }
.stat-label { color: var(--muted); margin-top: 0.25rem; font-size: 0.92rem; }
.pill {
  display: inline-flex;
  align-items: center;
  padding: 0.3rem 0.6rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
}
.pill.green, .status-green { background: rgba(31,143,95,0.12); color: var(--success); }
.pill.blue, .status-blue { background: rgba(37,116,199,0.12); color: var(--info); }
.pill.yellow, .status-yellow { background: rgba(193,138,20,0.15); color: var(--warning); }
.pill.red, .status-red { background: rgba(187,45,59,0.12); color: var(--danger); }
.message-stack { display: grid; gap: 0.75rem; margin-bottom: 1rem; }
.message { border-radius: 16px; padding: 0.9rem 1rem; background: white; border: 1px solid var(--border); }
.message-success { border-color: rgba(31,143,95,0.25); }
.message-error { border-color: rgba(187,45,59,0.25); }
.message-warning { border-color: rgba(193,138,20,0.25); }
.stack { display: grid; }
.gap-md { gap: 0.9rem; }
.form-grid { display: grid; gap: 0.9rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.form-grid .full { grid-column: 1 / -1; }
.table-wrap { overflow-x: auto; border-radius: 18px; border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; background: var(--surface); }
th, td { padding: 0.8rem; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
th { background: var(--surface-alt); font-size: 0.92rem; }
.map-box {
  position: relative;
  min-height: 220px;
  border-radius: 22px;
  border: 1px solid var(--border);
  background:
    linear-gradient(90deg, rgba(18,63,102,0.05) 1px, transparent 1px) 0 0 / 26px 26px,
    linear-gradient(180deg, rgba(18,63,102,0.05) 1px, transparent 1px) 0 0 / 26px 26px,
    linear-gradient(180deg, #eef4fb, #f8fbfd);
  overflow: hidden;
}
.map-leaflet {
  min-height: clamp(420px, 62vh, 620px);
}
.map-leaflet .leaflet-container {
  width: 100%;
  height: 100%;
  min-height: clamp(420px, 62vh, 620px);
  border-radius: 22px;
}
.driver-tooltip {
  background: transparent;
  color: var(--text);
  border: 0;
  box-shadow: none;
}
.driver-tooltip .leaflet-popup-content-wrapper {
  background: rgba(255, 255, 255, 0.98);
  color: var(--text);
  border-radius: 14px;
  box-shadow: 0 14px 30px rgba(18, 30, 50, 0.22);
  border: 1px solid rgba(18, 63, 102, 0.12);
}
.driver-tooltip .leaflet-popup-content {
  margin: 0.7rem 0.85rem;
  min-width: 190px;
  max-width: 260px;
  color: var(--text);
}
.driver-tooltip .leaflet-popup-tip {
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 14px 30px rgba(18, 30, 50, 0.22);
}
.driver-tooltip strong {
  display: block;
  font-size: 0.92rem;
  margin-bottom: 0.2rem;
}
.driver-tooltip .small {
  color: var(--muted);
  line-height: 1.35;
}
.driver-tooltip .muted {
  color: var(--muted);
}
.driver-hover-tooltip {
  background: rgba(255, 255, 255, 0.98);
  color: var(--text);
  border: 1px solid rgba(18, 63, 102, 0.12);
  border-radius: 14px;
  box-shadow: 0 14px 30px rgba(18, 30, 50, 0.22);
  padding: 0.7rem 0.85rem;
}
.driver-hover-tooltip.leaflet-tooltip-top:before,
.driver-hover-tooltip.leaflet-tooltip-bottom:before,
.driver-hover-tooltip.leaflet-tooltip-left:before,
.driver-hover-tooltip.leaflet-tooltip-right:before {
  border-top-color: rgba(255, 255, 255, 0.98);
  border-bottom-color: rgba(255, 255, 255, 0.98);
  border-left-color: rgba(255, 255, 255, 0.98);
  border-right-color: rgba(255, 255, 255, 0.98);
}
.driver-hover-tooltip strong {
  display: block;
  font-size: 0.92rem;
  margin-bottom: 0.2rem;
}
.driver-hover-tooltip .small {
  color: var(--muted);
  line-height: 1.35;
}
.driver-hover-tooltip .muted {
  color: var(--muted);
}
.car-marker {
  background: rgba(255, 255, 255, 0.98);
  border: 2px solid #ffffff;
  border-radius: 999px;
  box-shadow: 0 8px 18px rgba(18, 30, 50, 0.24);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
}
.car-marker-emoji {
  font-size: 1.55rem;
  line-height: 1;
}
.car-marker-moving { outline: 2px solid rgba(37, 116, 199, 0.18); }
.car-marker-waiting { outline: 2px solid rgba(193, 138, 20, 0.18); }
.car-marker-offline { outline: 2px solid rgba(187, 45, 59, 0.18); }
.car-marker-available { outline: 2px solid rgba(31, 143, 95, 0.18); }
.map-marker-wrap {
  position: absolute;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.map-marker {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid white;
  box-shadow: 0 4px 10px rgba(0,0,0,0.18);
}
.map-marker-emoji {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  font-size: 1.45rem;
  line-height: 1;
}
.map-marker.available { background: var(--success); }
.map-marker.moving { background: var(--info); }
.map-marker.waiting { background: var(--warning); }
.map-marker.offline { background: var(--danger); }
.map-label {
  font-size: 0.74rem;
  white-space: nowrap;
  background: rgba(255,255,255,0.92);
  padding: 0.2rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.controls { display: grid; gap: 0.7rem; }
.button-grid { display: grid; gap: 0.75rem; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.small { font-size: 0.88rem; }
.status-list { display: grid; gap: 0.65rem; }
.driver-detail-card {
  position: absolute;
  top: 4.25rem;
  right: 1rem;
  z-index: 5;
  display: grid;
  gap: 0.35rem;
  width: min(320px, calc(100% - 2rem));
  padding: 0.9rem;
  border: 1px solid rgba(18, 63, 102, 0.12);
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255,255,255,0.98), rgba(238,242,246,0.92));
  box-shadow: 0 12px 26px rgba(18, 30, 50, 0.16);
  pointer-events: none;
}
.driver-detail-card strong {
  font-size: 1.02rem;
}
.driver-detail-card .small,
.driver-detail-card .muted {
  line-height: 1.4;
}
.status-row {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
}
@media (max-width: 640px) {
  .dashboard-hero-map,
  .dashboard-support-grid {
    grid-template-columns: 1fr;
  }
  .live-map-panel {
    padding-bottom: 1rem;
  }
  .driver-detail-card {
    position: static;
    width: auto;
    margin: 0 0 0.85rem;
    pointer-events: auto;
  }
  .map-leaflet,
  .map-leaflet .leaflet-container {
    min-height: 500px;
  }
}
@media (max-width: 720px) {
  .page-shell { width: min(100%, calc(100% - 0.75rem)); }
  .topbar { padding: 0.85rem; }
  .topnav { gap: 0.45rem; }
  .topnav a { padding: 0.5rem 0.7rem; }
  .map-leaflet,
  .map-leaflet .leaflet-container { min-height: 420px; }
}
