:root {
  --bg: #08111f;
  --bg-soft: #0d1728;
  --panel: rgba(11, 20, 37, 0.88);
  --panel-strong: #111c31;
  --accent: #49d3ff;
  --accent-2: #8b5cf6;
  --text: #eef4ff;
  --muted: #96a5c0;
  --good: #34d399;
  --warn: #fbbf24;
  --bad: #f87171;
  --border: rgba(150, 165, 192, 0.16);
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
  --input-bg: rgba(5, 11, 20, 0.72);
}

body[data-theme="light"] {
  --bg: #eef3fb;
  --bg-soft: #e2eaf6;
  --panel: rgba(255, 255, 255, 0.9);
  --panel-strong: #ffffff;
  --text: #16233b;
  --muted: #5c6b84;
  --border: rgba(22, 35, 59, 0.14);
  --shadow: 0 16px 40px rgba(30, 45, 75, 0.14);
  --input-bg: rgba(255, 255, 255, 0.8);
}

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

html,
body {
  min-height: 100%;
  font-family: "Segoe UI", "Trebuchet MS", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

body {
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(73, 211, 255, 0.16), transparent 28%),
    radial-gradient(circle at top right, rgba(139, 92, 246, 0.14), transparent 22%),
    linear-gradient(180deg, #09101c 0%, #07101d 100%);
  transition: background 0.4s ease, color 0.4s ease;
}

body[data-theme="light"] {
  background:
    radial-gradient(circle at top left, rgba(73, 211, 255, 0.16), transparent 30%),
    linear-gradient(180deg, #eef3fb 0%, #e6edf8 100%);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding: 14px 20px;
  background: linear-gradient(180deg, rgba(13, 21, 38, 0.96), rgba(10, 18, 33, 0.88));
  border-bottom: 1px solid var(--border);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
}

body[data-theme="light"] .topbar {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(244, 248, 253, 0.9));
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  border: none;
  background: transparent;
  color: inherit;
  padding: 0;
  cursor: pointer;
  text-align: left;
  border-radius: 14px;
  transition: background 0.2s ease, transform 0.15s ease;
}

.brand:hover {
  background: rgba(255, 255, 255, 0.04);
}

.brand:active {
  transform: scale(0.99);
}

.brand .badge {
  transition: box-shadow 0.2s ease;
}

.brand:hover .badge {
  box-shadow: 0 4px 22px rgba(73, 211, 255, 0.55);
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #8fe7ff 52%, #d8e7ff);
  color: #07101d;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.08em;
  box-shadow: 0 4px 14px rgba(73, 211, 255, 0.28);
}

.brand-text h1 {
  font-size: 18px;
  font-weight: 750;
  line-height: 1.2;
}

.subtitle {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-top: 3px;
}

.topbar-actions {
  display: flex;
  gap: 10px;
}

.status-panel {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.2;
}

.stat-value {
  font-size: 18px;
  font-weight: 750;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.conn {
  font-size: 12px;
  font-weight: 650;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
}

.conn-live {
  color: var(--good);
  border-color: rgba(52, 211, 153, 0.45);
}

.conn-idle {
  color: var(--warn);
  border-color: rgba(251, 191, 36, 0.45);
}

.conn-down {
  color: var(--bad);
  border-color: rgba(248, 113, 113, 0.45);
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  padding: 14px 20px 0;
}

.kpi-card {
  padding: 16px 18px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(16, 25, 43, 0.88), rgba(10, 17, 31, 0.88));
  box-shadow: var(--shadow);
  cursor: pointer;
  user-select: none;
  transition: border-color 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
}

.kpi-card:hover {
  border-color: rgba(73, 211, 255, 0.35);
  transform: translateY(-2px);
}

.kpi-card:active {
  transform: scale(0.98);
}

.kpi-card.active {
  border-color: rgba(73, 211, 255, 0.7);
  box-shadow: 0 0 0 3px rgba(73, 211, 255, 0.18), var(--shadow);
}

body[data-theme="light"] .kpi-card {
  background: linear-gradient(180deg, #ffffff, #f2f6fc);
}

.kpi-card.accent {
  background: linear-gradient(135deg, rgba(73, 211, 255, 0.16), rgba(139, 92, 246, 0.18));
}

.kpi-label {
  display: block;
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.kpi-card strong {
  display: block;
  margin-top: 10px;
  font-size: 30px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.kpi-card strong.flash {
  animation: kpiFlash 0.7s ease-out;
}

@keyframes kpiFlash {
  0% {
    transform: scale(1.28);
    color: var(--accent);
  }
  100% {
    transform: scale(1);
  }
}

.kpi-card span:last-child {
  display: block;
  margin-top: 8px;
  font-size: 12px;
  color: var(--muted);
}

.workspace {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 320px;
  gap: 14px;
  padding: 14px 20px 0;
  flex: 1;
  min-height: 0;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
}

.map-stage {
  position: relative;
  min-width: 0;
  min-height: 0;
  border-radius: 24px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(17, 28, 49, 0.9), rgba(8, 17, 31, 0.95));
  box-shadow: var(--shadow);
}

.map-clock {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 1000;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(8, 17, 31, 0.78);
  color: var(--accent);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.panel {
  border: 1px solid var(--border);
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(15, 24, 42, 0.92), rgba(9, 16, 29, 0.92));
  box-shadow: var(--shadow);
  overflow: hidden;
}

body[data-theme="light"] .panel {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(243, 247, 252, 0.96));
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 16px 0;
}

.panel-head h2 {
  font-size: 14px;
  letter-spacing: 0.02em;
}

.panel-pill {
  display: inline-flex;
  align-items: center;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.ghost-btn {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border-radius: 999px;
  padding: 7px 12px;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease, color 0.2s ease;
}

.ghost-btn:hover {
  border-color: rgba(73, 211, 255, 0.35);
}

.ghost-btn.active {
  background: rgba(73, 211, 255, 0.14);
  border-color: rgba(73, 211, 255, 0.55);
  color: var(--accent);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 16px 0;
}

.field span {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.field input,
.field select {
  width: 100%;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--input-bg);
  color: var(--text);
  padding: 11px 12px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.field input:focus,
.field select:focus {
  border-color: rgba(73, 211, 255, 0.55);
  box-shadow: 0 0 0 3px rgba(73, 211, 255, 0.12);
}

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

.stack-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 16px 16px;
  overflow: auto;
  max-height: 340px;
}

.stack-item {
  display: grid;
  gap: 5px;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease, transform 0.15s ease;
  text-align: left;
  color: inherit;
  width: 100%;
}

.stack-item:hover,
.stack-item.active {
  border-color: rgba(73, 211, 255, 0.35);
  background: rgba(73, 211, 255, 0.08);
}

.stack-item:active {
  transform: scale(0.99);
}

.stack-item-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  font-weight: 700;
}

.stack-item-subtitle,
.stack-item-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.stack-item-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 11px;
  border: 1px solid var(--border);
  color: var(--muted);
}

.stack-item-badge.good {
  color: var(--good);
  border-color: rgba(52, 211, 153, 0.35);
}

.stack-item-badge.warn {
  color: var(--warn);
  border-color: rgba(251, 191, 36, 0.35);
}

.stack-item-badge.bad {
  color: var(--bad);
  border-color: rgba(248, 113, 113, 0.35);
}

.stack-item-badge.live {
  color: var(--accent);
  border-color: rgba(73, 211, 255, 0.45);
}

/* activity feed */
.activity-item {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  animation: slideIn 0.35s ease-out;
}

.activity-item.arrived {
  border-color: rgba(52, 211, 153, 0.3);
}

.activity-item.departed {
  border-color: rgba(73, 211, 255, 0.3);
}

.activity-item.slow {
  border-color: rgba(251, 191, 36, 0.3);
}

.activity-item.brake {
  border-color: rgba(248, 113, 113, 0.35);
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.activity-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
}

.activity-head time {
  color: var(--muted);
  font-weight: 500;
  font-size: 11px;
  white-space: nowrap;
}

.activity-body {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

/* arrivals board */
.arrival-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 11px 13px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
}

.arrival-eta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 46px;
  padding: 6px 9px;
  border-radius: 999px;
  background: rgba(73, 211, 255, 0.14);
  color: var(--accent);
  font-size: 12px;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.arrival-eta.due {
  background: rgba(52, 211, 153, 0.16);
  color: var(--good);
  animation: duePulse 1.2s ease-in-out infinite;
}

@keyframes duePulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(52, 211, 153, 0.35);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(52, 211, 153, 0);
  }
}

.arrival-main {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.arrival-route {
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.arrival-stop {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.arrival-plate {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.empty-state {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  padding: 16px;
}

.detail-body {
  padding: 12px 16px 16px;
}

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

.detail-chip {
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
}

.detail-chip span {
  display: block;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 4px;
}

.detail-chip strong {
  font-size: 14px;
}

.detail-activity {
  margin-top: 14px;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
}

.detail-activity h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 10px;
}

.detail-activity p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.detail-activity p.good {
  color: var(--good);
}

.detail-activity p.warn {
  color: var(--warn);
}

.detail-activity p.bad {
  color: var(--bad);
}

#sparkline {
  width: 100%;
  height: 54px;
  display: block;
  margin-bottom: 10px;
}

#map {
  width: 100%;
  height: 100%;
  min-height: 640px;
  z-index: 1;
}

.leaflet-control-zoom a {
  background: #091323;
  color: #eaf3ff;
  border-color: rgba(150, 165, 192, 0.24);
}

.leaflet-popup-content-wrapper {
  border-radius: 12px;
  background: #ffffff;
}

.leaflet-popup-content {
  margin: 13px 16px;
}

.popup-card {
  font-size: 12px;
  line-height: 1.55;
  color: #0f172a;
  min-width: 170px;
}

.popup-card .plate {
  font-size: 14px;
  font-weight: 700;
  color: #0f766e;
}

.popup-card .status-pill {
  display: inline-flex;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-left: 6px;
}

/* ---------------------------------------------------------- bus markers */
.vehicle-marker {
  background: transparent;
  border: none;
}

.vehicle-marker.filtered-out {
  display: none;
}

.bus-icon {
  position: relative;
  width: 34px;
  height: 34px;
  transition: transform 0.9s linear;
}

.bus-icon svg {
  display: block;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.45));
}

.bus-icon.selected::after {
  content: "";
  position: absolute;
  inset: -7px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  animation: duePulse 1.4s ease-in-out infinite;
}

.bus-icon.stale {
  opacity: 0.5;
}

.bus-icon .speed-tag {
  position: absolute;
  top: 32px;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 9px;
  font-weight: 700;
  color: #06202a;
  background: rgba(73, 211, 255, 0.92);
  border-radius: 999px;
  padding: 1px 6px;
  letter-spacing: 0.03em;
}

.route-line {
  filter: drop-shadow(0 0 6px rgba(73, 211, 255, 0.45));
}

.route-start-marker {
  background: transparent;
  border: none;
}

.route-start-pin,
.route-end-pin {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #fff;
  background: var(--rc, #49d3ff);
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}

.route-start-pin::after {
  content: "START";
  position: absolute;
  top: -14px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 7px;
  letter-spacing: 0.12em;
  color: var(--rc, #49d3ff);
  background: rgba(8, 17, 31, 0.85);
  border-radius: 999px;
  padding: 1px 5px;
  white-space: nowrap;
}

.route-end-pin {
  font-size: 8px;
  background: rgba(8, 17, 31, 0.9);
  color: var(--rc, #49d3ff);
}

.route-glow {
  opacity: 0.35;
  filter: blur(2px);
}

/* ------------------------------------------------------- mobile menu */
.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 44px;
  height: 44px;
  padding: 11px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  border-radius: 12px;
  cursor: pointer;
  flex: none;
}

.hamburger-bar {
  display: block;
  height: 2px;
  border-radius: 999px;
  background: var(--text);
  transition: transform 0.25s ease, opacity 0.25s ease;
}

.hamburger.open .hamburger-bar:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
}

.hamburger.open .hamburger-bar:nth-child(2) {
  opacity: 0;
}

.hamburger.open .hamburger-bar:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
}

.menu-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(4, 9, 17, 0.6);
  -webkit-backdrop-filter: blur(3px);
  backdrop-filter: blur(3px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.menu-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.mobile-menu {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 2001;
  width: min(320px, 86vw);
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px;
  background: linear-gradient(180deg, rgba(13, 21, 38, 0.98), rgba(9, 16, 29, 0.98));
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow);
  transform: translateX(105%);
  transition: transform 0.32s cubic-bezier(0.22, 1, 0.36, 1);
  overflow-y: auto;
}

body[data-theme="light"] .mobile-menu {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.99), rgba(244, 248, 253, 0.99));
}

.mobile-menu.open {
  transform: translateX(0);
}

.mobile-menu-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mobile-menu-head .badge {
  width: 40px;
  height: 40px;
  font-size: 11px;
}

.menu-title {
  font-size: 15px;
  font-weight: 750;
  letter-spacing: 0.02em;
}

.menu-close {
  margin-left: auto;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border-radius: 12px;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.menu-close:hover {
  border-color: rgba(73, 211, 255, 0.35);
}

.mobile-menu-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mobile-menu-list .menu-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-size: 14px;
  font-weight: 650;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease, transform 0.15s ease;
}

.mobile-menu-list .menu-link:hover,
.mobile-menu-list .menu-link:focus-visible {
  background: rgba(73, 211, 255, 0.08);
  border-color: rgba(73, 211, 255, 0.3);
  outline: none;
}

.mobile-menu-list .menu-link:active {
  transform: scale(0.99);
}

.mobile-menu-list .menu-link::after {
  content: "›";
  color: var(--muted);
  font-size: 18px;
}

.mobile-menu-actions {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mobile-menu-actions .ghost-btn {
  text-align: center;
  text-decoration: none;
  padding: 12px 14px;
}

#mapStage,
#searchPanel,
#fleetPanel,
#alertsPanel,
#activityPanel,
#detailPanel,
#arrivalsPanel,
#sessionsPanel {
  scroll-margin-top: 16px;
}

.footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 10px 20px 14px;
  font-size: 11px;
  color: var(--muted);
  background: transparent;
  border-top: 1px solid var(--border);
}

@media (max-width: 1280px) {
  .workspace {
    grid-template-columns: 300px minmax(0, 1fr);
  }

  .detail-sidebar {
    grid-column: 1 / -1;
  }
}

@media (max-width: 960px) {
  .kpi-row,
  .workspace {
    grid-template-columns: 1fr;
  }

  .status-panel,
  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .hamburger {
    display: flex;
    margin-left: auto;
  }

  .map-stage,
  #map {
    min-height: 520px;
  }
}
