:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-strong: #f8fafc;
  --rail: #111827;
  --rail-soft: #1f2937;
  --text: #111827;
  --muted: #64748b;
  --line: #dbe3ee;
  --line-strong: #c7d2e3;
  --green: #16a34a;
  --blue: #2563eb;
  --amber: #d97706;
  --red: #dc2626;
  --shadow: 0 18px 42px rgba(15, 23, 42, 0.11);
  --soft-shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  min-height: 100vh;
  overflow: hidden;
  font-family: "Manrope", sans-serif;
  color: var(--text);
  background: var(--bg);
}

.shell {
  display: grid;
  grid-template-columns: 286px minmax(0, 1fr);
  grid-template-rows: auto 1fr;
  width: 100%;
  min-height: 100vh;
}

.hero {
  grid-column: 1;
  grid-row: 1;
  display: grid;
  gap: 18px;
  padding: 22px;
  color: #f8fafc;
  background: linear-gradient(180deg, #111827, #0f172a);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.brand {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 52px;
  height: 52px;
  object-fit: contain;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  padding: 7px;
}

.eyebrow {
  margin: 0 0 6px;
  color: #86efac;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 800;
}

h1,
h2 {
  margin: 0;
  font-family: "Space Grotesk", sans-serif;
}

h1 {
  font-size: 22px;
  line-height: 1.1;
}

h2 {
  font-size: 25px;
  letter-spacing: 0;
}

.hero-copy p {
  margin: 0 0 12px;
  color: #cbd5e1;
  font-size: 13px;
  line-height: 1.55;
}

.hero-actions,
.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.hero-actions .button,
.action-row .button {
  flex: 1 1 auto;
}

.app-nav {
  grid-column: 1;
  grid-row: 2;
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 6px 14px 22px;
  overflow-y: auto;
  background: linear-gradient(180deg, #111827, #0f172a);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.app-nav button {
  position: relative;
  width: 100%;
  min-height: 44px;
  padding: 0 12px 0 16px;
  border: 0;
  border-radius: 8px;
  color: #cbd5e1;
  background: transparent;
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-nav button:hover {
  background: rgba(255, 255, 255, 0.07);
  color: #ffffff;
}

.app-nav button.is-active {
  color: #052e16;
  background: #86efac;
  box-shadow: 0 10px 22px rgba(134, 239, 172, 0.18);
}

.app-nav button.is-active::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 10px;
  bottom: 10px;
  width: 3px;
  border-radius: 999px;
  background: #052e16;
}

.grid {
  grid-column: 2;
  grid-row: 1 / 3;
  display: block;
  min-width: 0;
  height: 100vh;
  overflow-y: auto;
  padding: 28px;
}

.panel {
  width: min(1060px, 100%);
  min-height: calc(100vh - 56px);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(248, 250, 252, 0.96)),
    var(--surface);
  box-shadow: var(--shadow);
}

.panel:not([hidden]) {
  display: block;
}

[hidden] {
  display: none !important;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding-bottom: 18px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 999px;
  color: #1e293b;
  background: #e2e8f0;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.stack {
  display: grid;
  gap: 14px;
}

.stack.small {
  gap: 10px;
}

label span,
.metric-label,
.data-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

input,
select {
  width: 100%;
  min-height: 48px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
  font: inherit;
}

input:focus,
select:focus {
  outline: 3px solid rgba(37, 99, 235, 0.16);
  border-color: rgba(37, 99, 235, 0.55);
}

.button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--text);
  background: #eef2f7;
  font: inherit;
  font-weight: 800;
  text-decoration: none;
  cursor: pointer;
  box-shadow: var(--soft-shadow);
}

.button:hover:not(:disabled) {
  filter: brightness(0.98);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.button.primary {
  color: #ffffff;
  background: var(--green);
}

.button.ghost {
  color: #0f172a;
  background: #ffffff;
  border-color: var(--line);
  box-shadow: none;
}

.button.danger {
  color: #ffffff;
  background: var(--red);
}

.button.subtle {
  color: #0f172a;
  background: #e2e8f0;
}

.button.compact {
  min-height: 34px;
  padding: 0 12px;
  font-size: 12px;
  white-space: nowrap;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.compact-row {
  margin-bottom: 10px;
}

.callout,
.empty-state {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--muted);
  line-height: 1.55;
}

.callout:not(.subtle) {
  color: var(--text);
  background: #ecfdf5;
  border-color: #bbf7d0;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metrics article,
.data-grid article {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.03);
}

.metrics article:nth-child(2n) {
  border-color: #bfdbfe;
  background: #eff6ff;
}

.metrics article:nth-child(3n) {
  border-color: #fed7aa;
  background: #fff7ed;
}

.metrics strong {
  display: block;
  min-height: 25px;
  overflow-wrap: anywhere;
  font-family: "Space Grotesk", sans-serif;
  font-size: 22px;
}

.compact-metrics strong {
  font-size: 16px;
}

.data-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.data-value {
  overflow-wrap: anywhere;
  font-size: 15px;
  font-weight: 800;
}

.summary-list,
.table-list,
.stop-list,
.log-output {
  display: grid;
  gap: 10px;
}

.summary-row,
.table-row,
.log-line,
.route-plan-card {
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--muted);
  line-height: 1.5;
}

.table-row:hover,
.summary-row:hover,
.stop-row:hover {
  border-color: var(--line-strong);
  background: #ffffff;
}

.success-row {
  background: #ecfdf5;
  border-color: #bbf7d0;
}

.table-row {
  cursor: pointer;
}

.table-row strong,
.stop-row strong {
  display: block;
  color: var(--text);
  margin-bottom: 5px;
}

.stop-row {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
}

.stop-row > span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  color: #052e16;
  background: #bbf7d0;
  font-weight: 900;
}

.stop-row small {
  display: block;
  color: var(--muted);
}

code {
  padding: 2px 7px;
  border-radius: 999px;
  color: #0f172a;
  background: #e2e8f0;
}

#adminMap,
#driverMap {
  width: 100%;
  height: min(58vh, 520px);
  min-height: 340px;
  margin-bottom: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.stack-control {
  display: block;
  margin-bottom: 12px;
}

.poi-marker {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  color: #ffffff;
  border: 2px solid rgba(255, 255, 255, 0.9);
  font-size: 13px;
  font-weight: 900;
  box-shadow: 0 10px 20px rgba(15, 23, 42, 0.24);
}

.ai-brief,
.route-plan-list {
  display: grid;
  gap: 12px;
}

.route-plan-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 4px;
}

.route-plan-card small,
.route-plan-head span {
  color: var(--muted);
}

.route-plan-card ol {
  margin: 10px 0 0;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.55;
}

.ai-score {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.ai-score strong {
  color: var(--green);
  font-family: "Space Grotesk", sans-serif;
  font-size: 44px;
}

.ai-score span {
  color: var(--muted);
  font-weight: 800;
}

.ai-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.ai-list li {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-strong);
  color: var(--muted);
}

.vehicle-marker {
  position: relative;
  width: 92px;
  height: 44px;
  pointer-events: auto;
}

.vehicle-marker-pulse {
  position: absolute;
  left: 33px;
  bottom: 0;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  background: rgba(22, 163, 74, 0.22);
  border: 1px solid rgba(22, 163, 74, 0.5);
  animation: livePulse 1.8s ease-out infinite;
}

.vehicle-marker-body {
  position: absolute;
  left: 0;
  top: 0;
  display: grid;
  grid-template-columns: 12px 1fr;
  grid-template-rows: auto auto;
  column-gap: 7px;
  min-width: 92px;
  padding: 8px 10px;
  border: 2px solid rgba(255, 255, 255, 0.88);
  border-radius: 8px 8px 8px 2px;
  color: #052e16;
  background: #86efac;
  box-shadow: 0 12px 24px rgba(15, 23, 42, 0.3);
  transform: translateY(-8px);
}

.vehicle-marker-window {
  grid-row: 1 / 3;
  width: 12px;
  height: 20px;
  border-radius: 3px;
  background: rgba(5, 46, 22, 0.22);
  align-self: center;
}

.vehicle-marker strong,
.vehicle-marker small {
  display: block;
  line-height: 1.1;
  white-space: nowrap;
}

.vehicle-marker strong {
  max-width: 58px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 11px;
  font-weight: 900;
}

.vehicle-marker small {
  font-size: 10px;
  font-weight: 800;
  opacity: 0.78;
}

@keyframes livePulse {
  0% {
    transform: scale(0.6);
    opacity: 0.9;
  }

  100% {
    transform: scale(1.9);
    opacity: 0;
  }
}

@media (max-width: 920px) {
  :root {
    --mobile-rail: clamp(76px, 22vw, 94px);
  }

  .shell {
    display: grid;
    grid-template-columns: var(--mobile-rail) minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
    height: 100vh;
    min-height: 100vh;
  }

  .hero {
    position: relative;
    z-index: 20;
    grid-column: 1 / -1;
    grid-row: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 14px;
    border-right: 0;
  }

  .brand {
    grid-template-columns: 42px minmax(0, 1fr);
  }

  .brand-mark {
    width: 42px;
    height: 42px;
    border-radius: 8px;
  }

  .hero-copy {
    display: none;
  }

  h1 {
    font-size: 18px;
  }

  .app-nav {
    position: relative;
    top: auto;
    z-index: 15;
    grid-column: 1;
    grid-row: 2;
    display: grid;
    align-content: start;
    gap: 6px;
    height: 100%;
    min-height: 0;
    padding: 10px 6px;
    overflow-y: auto;
    overflow-x: hidden;
    border-top: 0;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
  }

  .app-nav button {
    width: 100%;
    min-width: 0;
    min-height: 52px;
    padding: 0 6px;
    font-size: 11px;
    line-height: 1.1;
    text-align: center;
    border: 1px solid rgba(255, 255, 255, 0.06);
    background: rgba(255, 255, 255, 0.035);
  }

  .app-nav button.is-active::before {
    display: none;
  }

  .app-nav button.is-active {
    border-color: rgba(134, 239, 172, 0.72);
    box-shadow: inset 3px 0 0 #052e16, 0 8px 18px rgba(0, 0, 0, 0.14);
  }

  .grid {
    grid-column: 2;
    grid-row: 2;
    height: 100%;
    min-height: 0;
    padding: 10px 10px 14px;
    overflow-y: auto;
    overflow-x: hidden;
  }

  .panel {
    width: 100%;
    min-height: 100%;
    padding: 14px;
    border-radius: 10px;
  }

  .panel-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 14px;
    padding-bottom: 14px;
  }

  .metrics,
  .data-grid,
  .action-grid {
    grid-template-columns: 1fr;
  }

  #adminMap,
  #driverMap {
    height: min(52vh, 420px);
    min-height: 280px;
  }
}
