:root {
  color-scheme: light;
  --bg: #f4f1e9;
  --panel: #fffdf8;
  --panel-strong: #f9f6ee;
  --ink: #17201f;
  --muted: #67716f;
  --line: #d9d2c4;
  --line-strong: #b9ad98;
  --teal: #0f766e;
  --teal-dark: #0b4f4a;
  --coral: #cc5538;
  --amber: #b7791f;
  --green: #2f7d54;
  --red: #ad2f2f;
  --road: #dcc9a4;
  --road-edge: #f1eadc;
  --shadow: 0 18px 45px rgba(24, 32, 31, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(120deg, rgba(15, 118, 110, 0.08), transparent 36%),
    linear-gradient(255deg, rgba(204, 85, 56, 0.07), transparent 34%),
    var(--bg);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.icon-sprite {
  display: none;
}

.app-shell {
  min-height: 100vh;
  padding: 20px;
}

.topbar {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: space-between;
  margin: 0 auto 16px;
  max-width: 1500px;
}

.brand {
  align-items: center;
  display: flex;
  gap: 12px;
}

.brand-mark {
  align-items: center;
  background: var(--ink);
  border-radius: 8px;
  color: #fffdf8;
  display: grid;
  font-size: 17px;
  font-weight: 800;
  height: 48px;
  letter-spacing: 0;
  place-items: center;
  width: 48px;
}

.brand h1,
.brand p,
.panel-heading h2,
.panel-heading p,
.info-heading h3 {
  margin: 0;
}

.brand h1 {
  font-size: 23px;
  line-height: 1.1;
}

.brand p {
  color: var(--muted);
  margin-top: 3px;
}

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

.system-status {
  background: rgba(47, 125, 84, 0.12);
  border: 1px solid rgba(47, 125, 84, 0.25);
  border-radius: 8px;
  color: #24583d;
  font-size: 14px;
  padding: 10px 12px;
  white-space: nowrap;
}

.workspace {
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(270px, 340px) minmax(420px, 1fr) minmax(300px, 380px);
  margin: 0 auto;
  max-width: 1500px;
}

body.login-view .workspace,
body.login-view .topbar-actions {
  display: none !important;
}

body.app-view .login-screen {
  display: none !important;
}

.login-screen {
  display: grid;
  margin: 42px auto 0;
  max-width: 760px;
  min-height: calc(100vh - 150px);
  place-items: center;
}

.login-card {
  background: #17312f;
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: #fffdf8;
  display: grid;
  gap: 18px;
  padding: 22px;
  width: min(100%, 720px);
}

.login-card strong {
  display: block;
  font-size: 24px;
  line-height: 1.2;
}

.login-card span {
  color: rgba(255, 253, 248, 0.78);
  display: block;
  font-size: 14px;
  margin-top: 6px;
}

.quick-profile {
  align-items: end;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(240px, 1fr) 100px auto auto;
}

.quick-profile label {
  color: rgba(255, 253, 248, 0.82);
  font-size: 12px;
}

.quick-profile input {
  background: rgba(255, 253, 248, 0.95);
  border-color: transparent;
  margin-top: 4px;
}

.login-code-field input {
  text-align: center;
}

.logout-button {
  color: rgba(255, 253, 248, 0.82);
  min-height: 40px;
}

.panel {
  background: var(--panel);
  border: 1px solid rgba(185, 173, 152, 0.55);
  border-radius: 8px;
  box-shadow: var(--shadow);
  min-width: 0;
  padding: 16px;
}

.panel-heading {
  align-items: center;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 16px;
}

.panel-heading h2 {
  font-size: 19px;
  line-height: 1.2;
}

.eyebrow {
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.panel-icon {
  color: var(--teal);
  height: 24px;
  width: 24px;
}

.form-stack {
  display: grid;
  gap: 14px;
}

label {
  color: var(--muted);
  display: grid;
  font-size: 13px;
  gap: 6px;
}

input {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  min-height: 40px;
  outline: none;
  padding: 9px 10px;
  width: 100%;
}

input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

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

.section-label {
  color: var(--ink);
  font-size: 13px;
  font-weight: 800;
  margin-bottom: -6px;
}

.segmented {
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  padding: 3px;
}

.segment {
  background: transparent;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  min-height: 36px;
}

.segment.active {
  background: var(--ink);
  color: #fffdf8;
  font-weight: 750;
}

.route-manager {
  display: grid;
  gap: 10px;
}

.route-tabs {
  display: grid;
  gap: 7px;
}

.route-tab,
.route-option {
  background: #f2ece1;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  display: grid;
  gap: 3px;
  min-height: 48px;
  padding: 9px 10px;
  text-align: left;
  width: 100%;
}

.route-tab.active,
.route-option.active {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
}

.route-tab span,
.route-option strong {
  font-size: 14px;
  font-weight: 850;
}

.route-tab small,
.route-option small,
.route-option span {
  color: var(--muted);
  font-size: 12px;
}

.days {
  display: grid;
  gap: 7px;
  grid-template-columns: repeat(4, 1fr);
}

.days label {
  align-items: center;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  display: flex;
  font-size: 13px;
  gap: 6px;
  justify-content: center;
  min-height: 34px;
}

.days input {
  height: 15px;
  min-height: 15px;
  width: 15px;
}

.range-row {
  align-items: center;
  display: grid;
  gap: 9px;
  grid-template-columns: 1fr 1.3fr 52px;
}

.range-row label {
  color: var(--ink);
  font-weight: 750;
}

input[type="range"] {
  accent-color: var(--teal);
  border: 0;
  padding: 0;
}

output {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.channel-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.switch {
  align-items: center;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  display: flex;
  font-size: 14px;
  gap: 9px;
  min-height: 40px;
  padding: 8px 10px;
}

.switch input {
  display: none;
}

.switch span {
  background: var(--line-strong);
  border-radius: 99px;
  display: inline-block;
  height: 20px;
  position: relative;
  transition: background 160ms ease;
  width: 36px;
}

.switch span::after {
  background: #fff;
  border-radius: 50%;
  content: "";
  height: 16px;
  left: 2px;
  position: absolute;
  top: 2px;
  transition: transform 160ms ease;
  width: 16px;
}

.switch input:checked + span {
  background: var(--teal);
}

.switch input:checked + span::after {
  transform: translateX(16px);
}

.button,
.icon-button,
.text-button {
  align-items: center;
  border: 0;
  border-radius: 7px;
  display: inline-flex;
  font-weight: 750;
  gap: 7px;
  justify-content: center;
  min-height: 40px;
  padding: 9px 12px;
}

.button svg,
.icon-button svg,
.panel-icon {
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.button svg {
  height: 18px;
  width: 18px;
}

.button.primary {
  background: var(--teal);
  color: #fff;
}

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

.button.secondary {
  background: #ece7dc;
  color: var(--ink);
}

.button.secondary:hover {
  background: #e0d8c9;
}

.button.full {
  width: 100%;
}

.icon-button {
  background: #f1e9de;
  color: var(--ink);
  flex: 0 0 auto;
  padding: 9px;
  width: 40px;
}

.icon-button svg {
  height: 18px;
  width: 18px;
}

.text-button {
  background: transparent;
  color: var(--teal-dark);
  min-height: 30px;
  padding: 4px 0;
}

.text-button.danger {
  color: var(--red);
  justify-self: start;
}

.text-button:disabled {
  color: var(--muted);
  cursor: not-allowed;
  opacity: 0.6;
}

.map-panel {
  display: grid;
  grid-template-rows: auto minmax(480px, 1fr);
  min-height: 650px;
}

.map-heading {
  align-items: start;
}

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

.map-frame {
  background: #efe9dd;
  border: 1px solid var(--line);
  border-radius: 8px;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

#routeMap {
  background: #e8e1d4;
  cursor: crosshair;
  height: 100%;
  min-height: 500px;
  overflow: hidden;
  position: relative;
  touch-action: none;
  user-select: none;
  width: 100%;
}

#routeMap.is-dragging {
  cursor: grabbing;
}

#routeMap:focus {
  outline: 3px solid rgba(15, 118, 110, 0.25);
  outline-offset: -3px;
}

.map-tile-layer,
.map-overlay,
.map-controls,
.map-attribution {
  position: absolute;
}

.map-tile-layer {
  inset: 0;
}

.map-tile {
  height: 256px;
  position: absolute;
  width: 256px;
}

.map-overlay {
  inset: 0;
  pointer-events: none;
}

.map-overlay .route-path {
  fill: none;
  stroke: var(--teal);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 7;
}

.map-overlay .route-halo {
  fill: none;
  stroke: rgba(23, 32, 31, 0.22);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 12;
}

.map-overlay .route-point-svg {
  fill: #fffdf8;
  stroke: var(--teal-dark);
  stroke-width: 4;
}

.map-overlay .route-number {
  fill: var(--teal-dark);
  font-size: 12px;
  font-weight: 900;
  text-anchor: middle;
}

.map-overlay .event-point {
  fill: #fffdf8;
  stroke: var(--amber);
  stroke-width: 4;
}

.map-overlay .event-point.high {
  stroke: var(--red);
}

.map-overlay .event-point.low {
  stroke: var(--green);
}

.map-overlay .event-label {
  fill: var(--ink);
  font-size: 18px;
  font-weight: 900;
  text-anchor: middle;
}

.map-controls {
  align-items: start;
  display: flex;
  gap: 8px;
  left: 12px;
  top: 12px;
  z-index: 2;
}

.zoom-controls {
  display: grid;
  gap: 5px;
}

.pan-controls {
  display: grid;
  gap: 4px;
  grid-template-columns: repeat(3, 30px);
}

.pan-controls [data-pan="north"] {
  grid-column: 2;
  grid-row: 1;
}

.pan-controls [data-pan="west"] {
  grid-column: 1;
  grid-row: 2;
}

.pan-controls [data-pan="east"] {
  grid-column: 3;
  grid-row: 2;
}

.pan-controls [data-pan="south"] {
  grid-column: 2;
  grid-row: 3;
}

.map-controls button {
  align-items: center;
  background: #fffdf8;
  border: 1px solid rgba(185, 173, 152, 0.75);
  border-radius: 7px;
  box-shadow: 0 5px 14px rgba(23, 32, 31, 0.15);
  color: var(--ink);
  display: flex;
  font-size: 18px;
  font-weight: 850;
  height: 32px;
  justify-content: center;
  padding: 0;
  width: 32px;
}

.map-attribution {
  background: rgba(255, 253, 248, 0.9);
  bottom: 0;
  color: var(--muted);
  font-size: 11px;
  padding: 3px 6px;
  right: 0;
  z-index: 2;
}

.map-attribution a {
  color: var(--teal-dark);
}

.route-point-marker {
  align-items: center;
  background: #fffdf8;
  border: 3px solid var(--teal-dark);
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(23, 32, 31, 0.25);
  color: var(--teal-dark);
  display: flex;
  font-size: 12px;
  font-weight: 900;
  height: 25px;
  justify-content: center;
  width: 25px;
}

.traffic-event-marker {
  align-items: center;
  background: #fffdf8;
  border: 4px solid var(--amber);
  border-radius: 50%;
  box-shadow: 0 3px 12px rgba(23, 32, 31, 0.25);
  color: var(--ink);
  display: flex;
  font-size: 16px;
  font-weight: 900;
  height: 30px;
  justify-content: center;
  width: 30px;
}

.traffic-event-marker.high {
  border-color: var(--red);
}

.traffic-event-marker.low {
  border-color: var(--green);
}

.map-help {
  background: rgba(255, 253, 248, 0.92);
  border: 1px solid rgba(185, 173, 152, 0.58);
  border-radius: 7px;
  bottom: 12px;
  color: var(--muted);
  font-size: 13px;
  left: 12px;
  max-width: min(540px, calc(100% - 24px));
  padding: 9px 10px;
  position: absolute;
}

.monitor-panel {
  display: grid;
  gap: 14px;
  grid-auto-rows: max-content;
}

.status-tile {
  background: #17312f;
  border-radius: 8px;
  color: #fffdf8;
  display: grid;
  gap: 5px;
  padding: 14px;
}

.status-tile span {
  color: rgba(255, 253, 248, 0.7);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.status-tile strong {
  font-size: 18px;
  line-height: 1.25;
}

.info-block {
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.info-heading {
  align-items: center;
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
}

.info-heading h3 {
  font-size: 15px;
}

.info-heading span {
  background: var(--panel-strong);
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  min-width: 26px;
  padding: 3px 8px;
  text-align: center;
}

.chips,
.route-options,
.event-list,
.inbox {
  display: grid;
  gap: 8px;
}

.chip {
  align-items: center;
  background: #f2ece1;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--ink);
  display: inline-flex;
  font-size: 13px;
  font-weight: 700;
  min-height: 30px;
  padding: 6px 10px;
  width: fit-content;
}

.empty {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.event-item,
.message-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 5px;
  padding: 10px;
}

.event-item {
  background: #fffaf0;
}

.event-item.high {
  border-left: 5px solid var(--red);
}

.event-item.medium {
  border-left: 5px solid var(--amber);
}

.event-item.low {
  border-left: 5px solid var(--green);
}

.event-title,
.message-title {
  align-items: center;
  display: flex;
  gap: 7px;
  justify-content: space-between;
}

.event-title strong,
.message-title strong {
  font-size: 14px;
}

.badge {
  border-radius: 999px;
  color: #fff;
  font-size: 11px;
  font-weight: 850;
  padding: 3px 7px;
  white-space: nowrap;
}

.badge.high {
  background: var(--red);
}

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

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

.event-meta,
.message-meta {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.message-item {
  background: #f7f3ea;
}

.message-item svg {
  color: var(--teal);
  fill: none;
  height: 16px;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
  width: 16px;
}

.toast {
  background: var(--ink);
  border-radius: 8px;
  bottom: 22px;
  color: #fffdf8;
  left: 50%;
  max-width: min(420px, calc(100% - 32px));
  opacity: 0;
  padding: 11px 14px;
  pointer-events: none;
  position: fixed;
  transform: translate(-50%, 16px);
  transition: opacity 180ms ease, transform 180ms ease;
  z-index: 10;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: minmax(280px, 360px) 1fr;
  }

  .monitor-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 820px) {
  .app-shell {
    padding: 12px;
  }

  .topbar,
  .login-card {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions,
  .quick-profile {
    align-items: stretch;
    grid-template-columns: 1fr;
  }

  .topbar-actions {
    display: grid;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .field-grid,
  .time-grid,
  .range-row {
    grid-template-columns: 1fr;
  }

  output {
    text-align: left;
  }

  .days {
    grid-template-columns: repeat(3, 1fr);
  }

  .map-panel {
    min-height: 560px;
  }

  #routeMap {
    min-height: 450px;
  }

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

  .map-actions {
    justify-content: stretch;
  }

  .map-actions .button {
    flex: 1 1 auto;
  }
}
