:root {
  color-scheme: light;
  --bg: #f5f7f4;
  --surface: #ffffff;
  --surface-strong: #eef4f1;
  --ink: #1d2c2a;
  --muted: #65716f;
  --line: #d8e1dd;
  --primary: #0f766e;
  --primary-strong: #0b5f59;
  --primary-soft: #dff3ef;
  --accent: #f5b82e;
  --danger: #cf3f3f;
  --info: #3b82f6;
  --shadow: 0 16px 45px rgba(27, 45, 43, 0.08);
  --radius: 8px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  letter-spacing: 0;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(15, 118, 110, 0.08), rgba(245, 247, 244, 0) 280px),
    var(--bg);
}

.auth-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 18px;
}

.auth-card {
  width: min(760px, 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

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

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

.auth-form {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px clamp(16px, 3vw, 36px) 12px;
}

.user-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.user-chip {
  max-width: 220px;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-block {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 12px;
}

.brand-mark {
  display: grid;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 50%;
  background: var(--primary);
  color: #ffffff;
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.25rem, 2vw, 1.8rem);
  line-height: 1.1;
}

h2 {
  font-size: 1rem;
  line-height: 1.2;
}

.brand-block p,
.muted,
.status-line {
  color: var(--muted);
}

.brand-block p {
  margin-top: 3px;
  font-size: 0.9rem;
}

.tabs {
  display: flex;
  gap: 6px;
  margin: 0 clamp(16px, 3vw, 36px);
  padding: 6px;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.8) inset;
}

.tab-button,
.button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  transition: 160ms ease;
}

.tab-button {
  flex: 1 0 auto;
  gap: 8px;
  padding: 9px 14px;
  color: var(--muted);
  background: transparent;
  white-space: nowrap;
}

.tab-button.active {
  color: var(--ink);
  background: #ffffff;
  border-color: var(--line);
  box-shadow: 0 8px 22px rgba(31, 49, 46, 0.08);
}

.button-icon {
  display: inline-grid;
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  place-items: center;
  font-weight: 850;
  line-height: 1;
}

.app-main {
  padding: 16px clamp(16px, 3vw, 36px) 34px;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.decision-grid,
.graphs-grid {
  display: grid;
  grid-template-columns: minmax(300px, 390px) minmax(0, 1fr);
  gap: 16px;
}

.graphs-grid {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.surface,
.settings-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.surface {
  padding: 16px;
}

.full-surface {
  min-height: 70vh;
}

.surface-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.stacked-title {
  align-items: flex-start;
  flex-wrap: wrap;
}

.map-title,
.dashboard-title {
  flex-wrap: wrap;
}

.field,
.inline-field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
}

.inline-field {
  min-width: 150px;
}

.field + .field,
.button-row,
.metric-strip {
  margin-top: 13px;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 11px;
  background: #ffffff;
  color: var(--ink);
  outline: none;
}

input:focus,
select:focus,
.button:focus-visible,
.tab-button:focus-visible,
.icon-button:focus-visible {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.18);
}

input[type="range"] {
  height: 42px;
  padding: 0;
  accent-color: var(--primary);
}

.range-row,
.button-row,
.filter-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.range-row output {
  min-width: 54px;
  color: var(--ink);
  font-weight: 750;
  text-align: right;
}

.button-row .button {
  flex: 1;
}

.button {
  gap: 8px;
  padding: 0 13px;
  font-weight: 750;
}

.button.primary {
  color: #ffffff;
  background: var(--primary);
  border-color: var(--primary);
}

.button.primary:hover {
  background: var(--primary-strong);
}

.button.secondary {
  color: var(--ink);
  background: #ffffff;
  border-color: var(--line);
}

.button.secondary:hover,
.icon-button:hover {
  background: var(--surface-strong);
}

.button.wide {
  width: 100%;
  margin-top: 12px;
}

.button.small {
  min-height: 34px;
  padding: 0 10px;
  font-size: 0.82rem;
}

.button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.icon-button {
  width: 38px;
  height: 38px;
  padding: 0;
  color: var(--ink);
  background: #ffffff;
  border-color: var(--line);
}

.pill {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  color: var(--primary-strong);
  background: var(--primary-soft);
  font-size: 0.78rem;
  font-weight: 800;
}

.status-line {
  min-height: 22px;
  margin-top: 12px;
  font-size: 0.88rem;
}

.metric-strip,
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}

.metric,
.kpi {
  min-height: 78px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

.metric span,
.kpi span {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.metric strong,
.kpi strong {
  display: block;
  margin-top: 6px;
  color: var(--ink);
  font-size: 1.18rem;
  line-height: 1.15;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.data-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.data-table th,
.data-table td {
  padding: 11px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.data-table th {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.table-sort {
  display: inline-flex;
  align-items: center;
  border: 0;
  padding: 0;
  color: inherit;
  background: transparent;
  font: inherit;
  font-weight: 850;
  text-align: left;
  text-transform: uppercase;
}

.table-sort.active {
  color: var(--primary-strong);
}

.multi-select {
  min-height: 118px;
  padding-block: 7px;
}

.compact-table {
  min-width: 760px;
}

.empty-cell {
  color: var(--muted);
  text-align: center;
}

.station-cell {
  display: grid;
  gap: 3px;
  min-width: 210px;
}

.station-cell strong {
  font-size: 0.92rem;
}

.station-cell span {
  color: var(--muted);
  font-size: 0.8rem;
}

.score-badge {
  display: inline-flex;
  min-width: 42px;
  justify-content: center;
  border-radius: 999px;
  padding: 3px 9px;
  color: #ffffff;
  background: var(--primary);
  font-size: 0.78rem;
  font-weight: 800;
}

.score-badge.low {
  background: var(--muted);
}

.map-canvas {
  position: relative;
  min-height: 68vh;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #e8eeeb;
}

.map-tile-layer {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: #dce7e1;
}

.map-tile-layer img {
  position: absolute;
  max-width: none;
  user-select: none;
}

.svg-map {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 68vh;
}

.map-overlay {
  pointer-events: auto;
}

.map-label {
  fill: #8ca09a;
  font-size: 18px;
  font-weight: 750;
}

.map-point {
  cursor: pointer;
  filter: drop-shadow(0 2px 3px rgba(29, 44, 42, 0.25));
  pointer-events: auto;
}

.map-point:focus,
.map-star:focus {
  outline: none;
  stroke: var(--ink);
  stroke-width: 3;
}

.map-star {
  cursor: pointer;
  fill: #f5b82e;
  font-size: 28px;
  font-weight: 900;
  paint-order: stroke;
  stroke: #ffffff;
  stroke-width: 4px;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: auto;
}

.map-popup {
  position: absolute;
  z-index: 3;
  width: min(260px, calc(100% - 28px));
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  box-shadow: 0 10px 25px rgba(29, 44, 42, 0.16);
  color: var(--ink);
  font-size: 0.88rem;
  line-height: 1.45;
}

.map-legend {
  position: absolute;
  z-index: 2;
  right: 12px;
  bottom: 12px;
  display: flex;
  max-width: calc(100% - 24px);
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.94);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
  box-shadow: 0 8px 18px rgba(29, 44, 42, 0.1);
}

.legend-dot,
.legend-ring {
  display: inline-block;
  width: 11px;
  height: 11px;
  margin-right: 4px;
  border-radius: 50%;
  vertical-align: -1px;
}

.legend-dot.score-20 {
  background: #8ee6a2;
  border: 1px solid #5bbd70;
}

.legend-dot.score-19 {
  background: #111111;
}

.legend-ring {
  border: 2px solid var(--accent);
}

.map-fallback {
  display: grid;
  height: 68vh;
  place-items: center;
  color: var(--muted);
  font-weight: 700;
}

.leaflet-popup-content {
  margin: 12px;
  color: var(--ink);
  font-family: var(--font);
}

.star-marker {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 2px solid #ffffff;
  border-radius: 50%;
  background: var(--accent);
  color: #5b3a00;
  font-size: 18px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
}

.chart-box {
  position: relative;
  min-height: 410px;
}

.chart-box canvas,
.svg-chart {
  width: 100%;
  height: 410px;
}

.chart-svg {
  display: block;
  width: 100%;
  height: 100%;
}

.chart-grid {
  stroke: #dce4e1;
  stroke-width: 1;
}

.chart-axis-label,
.chart-axis-title {
  fill: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.chart-area {
  fill: rgba(15, 118, 110, 0.14);
}

.chart-line {
  fill: none;
  stroke: var(--primary);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.chart-point {
  fill: #ffffff;
  stroke: var(--primary);
  stroke-width: 2;
}

.chart-hotspot {
  cursor: crosshair;
  fill: transparent;
  stroke: transparent;
}

.chart-bar {
  fill: #3b82f6;
}

.chart-empty {
  display: grid;
  height: 100%;
  min-height: 240px;
  place-items: center;
  color: var(--muted);
  font-weight: 750;
}

.chart-note {
  margin: -6px 0 8px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 650;
}

.settings-panel {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  justify-content: flex-end;
  background: rgba(19, 31, 29, 0.28);
}

.settings-panel.open {
  display: flex;
}

.settings-card {
  width: min(520px, 100%);
  height: 100%;
  overflow-y: auto;
  padding: 18px;
  border-radius: 0;
}

.input-with-unit {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  align-items: center;
}

.input-with-unit input {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.input-with-unit span {
  display: grid;
  min-height: 42px;
  place-items: center;
  border: 1px solid var(--line);
  border-left: 0;
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--surface-strong);
  color: var(--muted);
  font-weight: 800;
}

.vehicle-form {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

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

.settings-section h3,
.vehicle-form h3 {
  margin: 0;
  font-size: 0.96rem;
}

.check-field {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-top: 10px;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 650;
}

.check-field input {
  width: 18px;
  min-height: 18px;
  height: 18px;
  accent-color: var(--primary);
}

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

.vehicle-list {
  display: grid;
  gap: 9px;
  margin-top: 16px;
}

.account-list {
  display: grid;
  gap: 9px;
  margin-top: 12px;
}

.account-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

.account-row strong,
.account-row span {
  display: block;
}

.account-row span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.82rem;
}

.account-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.vehicle-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

.vehicle-main {
  display: block;
  min-width: 0;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.vehicle-actions {
  display: flex;
  gap: 6px;
}

.vehicle-row strong,
.vehicle-row span,
.vehicle-main strong,
.vehicle-main span {
  display: block;
}

.vehicle-row span,
.vehicle-main span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.82rem;
}

.danger-button {
  color: var(--danger);
  border-color: rgba(207, 63, 63, 0.28);
}

.route-links {
  display: inline-flex;
  gap: 6px;
}

.mini-link {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0 9px;
  color: var(--primary-strong);
  background: #ffffff;
  font-size: 0.8rem;
  font-weight: 800;
  text-decoration: none;
}

.mini-link:hover {
  background: var(--primary-soft);
}

@media (max-width: 980px) {
  .decision-grid,
  .graphs-grid {
    grid-template-columns: 1fr;
  }

  .control-surface {
    order: 0;
  }

  .results-surface {
    order: 1;
  }
}

@media (max-width: 680px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .auth-grid,
  .account-row {
    grid-template-columns: 1fr;
  }

  .user-actions {
    width: 100%;
    align-items: stretch;
    flex-direction: column;
  }

  .user-chip {
    max-width: 100%;
  }

  .app-header .button {
    width: 100%;
  }

  .tabs {
    margin-inline: 10px;
  }

  .app-main {
    padding-inline: 10px;
  }

  .surface {
    padding: 12px;
  }

  .filter-row,
  .button-row {
    flex-direction: column;
    align-items: stretch;
  }

  .inline-field {
    width: 100%;
  }

  .metric-strip,
  .kpi-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .map-canvas {
    min-height: 62vh;
  }
}
