:root {
  --bg: #eef3f1;
  --surface: #ffffff;
  --surface-soft: #f7faf8;
  --surface-strong: #eef6f3;
  --ink: #17201d;
  --muted: #65736e;
  --line: #dce6e2;
  --primary: #006d77;
  --primary-soft: #d9f0ee;
  --green: #2f9e44;
  --amber: #f08c00;
  --red: #d9480f;
  --purple: #7048e8;
  --blue: #1971c2;
  --shadow: 0 18px 45px rgba(26, 44, 38, 0.12);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: "Segoe UI", Arial, sans-serif;
  line-height: 1.45;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.65;
}

.app-shell {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr) 360px;
  height: 100vh;
  min-height: 720px;
  overflow: hidden;
}

.sidebar,
.detail-panel {
  background: var(--surface);
  border-color: var(--line);
  overflow: auto;
}

.sidebar {
  border-right: 1px solid var(--line);
  padding: 18px;
}

.detail-panel {
  border-left: 1px solid var(--line);
  padding: 18px;
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  overflow: auto;
  padding: 18px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
}

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  color: #fff;
  background: var(--primary);
  border-radius: var(--radius);
  place-items: center;
  box-shadow: 0 10px 24px rgba(0, 109, 119, 0.22);
}

.brand-block h1,
.topbar h2,
.section-heading h3,
.detail-title h2 {
  margin: 0;
  line-height: 1.12;
}

.brand-block h1 {
  font-size: 19px;
}

.brand-block p,
.eyebrow,
.detail-subtitle {
  margin: 0;
  color: var(--muted);
}

.brand-block p {
  font-size: 13px;
}

.eyebrow {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.search-box {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  margin-bottom: 14px;
  padding: 0 12px;
  color: var(--muted);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.search-box input {
  width: 100%;
  min-width: 0;
  color: var(--ink);
  background: transparent;
  border: 0;
  outline: 0;
}

.place-search {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 500;
  display: grid;
  grid-template-columns: 20px minmax(180px, 360px) 40px;
  align-items: center;
  gap: 8px;
  min-height: 46px;
  width: min(470px, calc(100% - 170px));
  padding: 0 6px 0 14px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(220, 230, 226, 0.95);
  border-radius: var(--radius);
  box-shadow: 0 14px 34px rgba(26, 44, 38, 0.18);
}

.place-search input {
  min-width: 0;
  color: var(--ink);
  background: transparent;
  border: 0;
  outline: 0;
}

.quick-places {
  position: absolute;
  top: 68px;
  left: 14px;
  z-index: 500;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  width: min(520px, calc(100% - 28px));
}

.quick-places button {
  min-height: 30px;
  padding: 0 10px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(220, 230, 226, 0.95);
  border-radius: 999px;
  box-shadow: 0 8px 22px rgba(26, 44, 38, 0.11);
}

.view-tabs,
.filter-tabs {
  display: grid;
  gap: 8px;
}

.view-tabs {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 16px;
}

.filter-tabs {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 14px;
}

.view-tab,
.filter-tab,
.action-button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.view-tab {
  gap: 8px;
  padding: 0 10px;
}

.filter-tab {
  padding: 0 9px;
  font-size: 13px;
}

.view-tab:hover,
.filter-tab:hover,
.action-button:hover,
.icon-button:hover {
  border-color: rgba(0, 109, 119, 0.35);
  transform: translateY(-1px);
}

.view-tab.is-active,
.filter-tab.is-active,
.icon-button.is-active {
  color: var(--primary);
  background: var(--primary-soft);
  border-color: rgba(0, 109, 119, 0.28);
}

.fleet-mini {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}

.mini-stat {
  padding: 10px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.mini-stat strong {
  display: block;
  font-size: 20px;
}

.mini-stat span {
  color: var(--muted);
  font-size: 12px;
}

.vehicle-list {
  display: grid;
  gap: 10px;
}

.vehicle-card {
  display: block;
  width: 100%;
  padding: 12px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.vehicle-card.is-selected {
  border-color: var(--primary);
  box-shadow: 0 10px 28px rgba(0, 109, 119, 0.14);
}

.vehicle-card-head,
.vehicle-card-meta,
.vehicle-card-foot,
.topbar,
.topbar-actions,
.section-heading,
.detail-title,
.detail-actions,
.stat-row,
.event-item,
.route-stop,
.map-statusbar,
.endpoint-box {
  display: flex;
  align-items: center;
}

.vehicle-card-head {
  justify-content: space-between;
  gap: 10px;
}

.plate {
  font-weight: 800;
}

.vehicle-card-meta,
.vehicle-card-foot {
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.vehicle-card-foot {
  color: var(--ink);
}

.progress-line {
  height: 6px;
  margin-top: 10px;
  overflow: hidden;
  background: #e7eeea;
  border-radius: 999px;
}

.progress-line span {
  display: block;
  height: 100%;
  background: var(--primary);
  border-radius: inherit;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 26px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 700;
  border-radius: 999px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  white-space: nowrap;
}

.status-pill::before {
  content: "";
  width: 8px;
  height: 8px;
  background: var(--muted);
  border-radius: 50%;
}

.status-pill.running,
.status-pill.ok {
  color: var(--green);
  background: #e8f7ec;
  border-color: #c7ebd0;
}

.status-pill.running::before,
.status-pill.ok::before {
  background: var(--green);
}

.status-pill.idle {
  color: var(--blue);
  background: #e7f1fb;
  border-color: #cfe2f5;
}

.status-pill.idle::before {
  background: var(--blue);
}

.status-pill.stopped {
  color: #5b6470;
  background: #f1f3f5;
  border-color: #dee2e6;
}

.status-pill.stopped::before {
  background: #868e96;
}

.status-pill.alarm,
.status-pill.critical {
  color: var(--red);
  background: #fff0ea;
  border-color: #ffd2c2;
}

.status-pill.alarm::before,
.status-pill.critical::before {
  background: var(--red);
}

.status-pill.offline,
.status-pill.warning {
  color: var(--amber);
  background: #fff4de;
  border-color: #ffe0a3;
}

.status-pill.offline::before,
.status-pill.warning::before {
  background: var(--amber);
}

.topbar {
  justify-content: space-between;
  gap: 18px;
}

.topbar h2 {
  margin-top: 4px;
  font-size: 24px;
}

.topbar-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.icon-button {
  width: 40px;
  padding: 0;
}

.action-button {
  gap: 8px;
  padding: 0 14px;
  font-weight: 700;
}

.action-button.subtle {
  background: var(--surface-soft);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 12px;
}

.metric-card {
  min-width: 0;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 20px rgba(26, 44, 38, 0.06);
}

.metric-card i {
  color: var(--primary);
}

.metric-card strong {
  display: block;
  margin-top: 10px;
  font-size: 26px;
  line-height: 1;
}

.metric-card span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.map-stage {
  position: relative;
  min-height: 470px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

#map {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.leaflet-container {
  font-family: inherit;
}

.map-layer-control {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 500;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  max-width: min(560px, calc(100% - 32px));
}

.basemap-select {
  min-height: 40px;
  padding: 0 36px 0 12px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid rgba(220, 230, 226, 0.95);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(26, 44, 38, 0.12);
  outline: 0;
}

.map-statusbar {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  z-index: 500;
  flex-wrap: wrap;
  gap: 8px;
}

.map-statusbar span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 11px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(220, 230, 226, 0.9);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(26, 44, 38, 0.12);
}

.traffic-legend {
  position: absolute;
  right: 14px;
  bottom: 58px;
  z-index: 500;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: min(470px, calc(100% - 28px));
}

.traffic-legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  padding: 0 10px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(220, 230, 226, 0.9);
  border-radius: 999px;
  box-shadow: 0 8px 22px rgba(26, 44, 38, 0.1);
  font-size: 12px;
  font-weight: 700;
}

.map-sovereignty-label {
  display: grid;
  place-items: center;
  width: 190px;
  color: #3c4043;
  font-family: Arial, "Segoe UI", sans-serif;
  line-height: 1.08;
  pointer-events: auto;
  text-align: center;
  text-shadow:
    0 1px 0 rgba(255, 255, 255, 0.95),
    1px 0 0 rgba(255, 255, 255, 0.95),
    -1px 0 0 rgba(255, 255, 255, 0.95),
    0 -1px 0 rgba(255, 255, 255, 0.95),
    0 2px 5px rgba(255, 255, 255, 0.9);
}

.map-sovereignty-label span {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
  white-space: nowrap;
}

.map-sovereignty-label small {
  margin-top: 2px;
  color: #1a73e8;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  white-space: nowrap;
}

.traffic-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.traffic-dot.free {
  background: var(--green);
}

.traffic-dot.medium {
  background: var(--amber);
}

.traffic-dot.heavy,
.traffic-dot.alarm {
  background: var(--red);
}

.vehicle-icon {
  position: relative;
  display: grid;
  width: 36px;
  height: 36px;
  color: #fff;
  background: var(--primary);
  border: 3px solid #fff;
  border-radius: 50%;
  place-items: center;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.24);
}

.vehicle-icon::after {
  content: "";
  position: absolute;
  top: -7px;
  left: 13px;
  width: 8px;
  height: 12px;
  background: inherit;
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
  transform: rotate(var(--heading));
  transform-origin: 50% 18px;
}

.vehicle-icon.running {
  background: var(--green);
}

.vehicle-icon.idle {
  background: var(--blue);
}

.vehicle-icon.stopped {
  background: #868e96;
}

.vehicle-icon.alarm {
  background: var(--red);
}

.vehicle-icon.offline {
  background: var(--amber);
}

.vehicle-icon.selected {
  outline: 4px solid rgba(0, 109, 119, 0.22);
}

.lower-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.9fr);
  gap: 16px;
}

.operations-panel {
  min-width: 0;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.section-heading {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.section-heading h3 {
  margin-top: 3px;
  font-size: 18px;
}

.chart-wrap {
  min-height: 190px;
}

.trip-table-wrap {
  overflow: auto;
  margin-top: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.endpoint-box {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding: 12px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.endpoint-box span {
  color: var(--primary);
  font-weight: 800;
}

.endpoint-box code {
  min-width: 0;
  overflow: hidden;
  color: var(--ink);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.telemetry-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.telemetry-form label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.telemetry-form input {
  min-width: 0;
  min-height: 38px;
  padding: 0 10px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  outline: 0;
}

.telemetry-form button {
  grid-column: 1 / -1;
}

.event-feed {
  display: grid;
  gap: 10px;
  max-height: 310px;
  overflow: auto;
}

.event-item {
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.event-item.is-ack {
  opacity: 0.62;
}

.event-copy strong {
  display: block;
  font-size: 13px;
}

.event-copy span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.detail-title {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.detail-title h2 {
  font-size: 22px;
}

.detail-actions {
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.detail-actions .action-button {
  flex: 1 1 calc(50% - 8px);
}

.detail-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.detail-section h3 {
  margin: 0 0 12px;
  font-size: 15px;
}

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

.stat-box {
  padding: 12px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.stat-box span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.stat-box strong {
  display: block;
  margin-top: 6px;
  font-size: 20px;
}

.route-list {
  display: grid;
  gap: 8px;
}

.route-stop,
.history-point {
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.route-stop i,
.history-point i {
  color: var(--primary);
}

.history-list {
  display: grid;
  gap: 8px;
}

.history-point {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  align-items: center;
}

.history-point strong {
  color: var(--ink);
  font-size: 12px;
}

.driver-block {
  display: grid;
  gap: 6px;
  padding: 12px;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.driver-block strong {
  font-size: 16px;
}

.driver-block span {
  color: var(--muted);
  font-size: 13px;
}

.empty-state {
  padding: 16px;
  color: var(--muted);
  text-align: center;
  background: var(--surface-soft);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

.toast-stack {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 1000;
  display: grid;
  gap: 10px;
  width: min(360px, calc(100vw - 36px));
}

.toast {
  padding: 12px 14px;
  color: #fff;
  background: var(--ink);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.toast.success {
  background: var(--green);
}

.toast.warning {
  background: var(--amber);
}

.toast.danger {
  background: var(--red);
}

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

  .detail-panel {
    grid-column: 1 / -1;
    max-height: 420px;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .metric-grid {
    grid-template-columns: repeat(3, minmax(140px, 1fr));
  }
}

@media (max-width: 920px) {
  .app-shell {
    display: block;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }

  .sidebar,
  .workspace,
  .detail-panel {
    overflow: visible;
  }

  .sidebar,
  .detail-panel {
    border: 0;
  }

  .workspace {
    padding: 14px;
  }

  .topbar,
  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    justify-content: flex-start;
  }

  .metric-grid,
  .lower-grid,
  .stat-grid {
    grid-template-columns: 1fr;
  }

  .map-stage {
    min-height: 58vh;
  }

  .place-search {
    top: 12px;
    left: 12px;
    width: calc(100% - 24px);
    grid-template-columns: 20px minmax(0, 1fr) 40px;
  }

  .quick-places {
    top: 66px;
    left: 12px;
    width: calc(100% - 24px);
  }

  .map-layer-control {
    top: 112px;
    left: 12px;
    right: 12px;
    justify-content: flex-start;
    max-width: none;
  }

  .traffic-legend {
    right: 12px;
    bottom: 78px;
  }

}

@media (max-width: 560px) {
  .view-tabs,
  .filter-tabs,
  .fleet-mini,
  .telemetry-form {
    grid-template-columns: 1fr;
  }

  .topbar h2 {
    font-size: 20px;
  }

  .detail-actions .action-button {
    flex-basis: 100%;
  }

  .map-statusbar {
    align-items: stretch;
    flex-direction: column;
  }
}
