:root {
  color-scheme: light;
  --bg: #eef2f0;
  --panel: #ffffff;
  --ink: #172027;
  --muted: #637078;
  --line: #d7dfdb;
  --accent: #1267d6;
  --accent-deep: #0b4f9f;
  --green: #0d835c;
  --green-soft: #eaf7f0;
  --amber: #b76e00;
  --red: #d94b3d;
  --shadow: 0 14px 34px rgba(33, 44, 49, 0.12);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
summary:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(18, 103, 214, 0.22);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-areas:
    "planner"
    "map"
    "insights";
  min-height: 100dvh;
}

.planner-panel,
.insights-panel {
  background: linear-gradient(180deg, #ffffff 0%, #f6f8f7 100%);
}

.planner-panel {
  grid-area: planner;
  position: relative;
  z-index: 10;
  display: grid;
  gap: 16px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.insights-panel {
  grid-area: insights;
  display: grid;
  gap: 14px;
  padding: 16px 16px 24px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--green);
  font-size: 0.73rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  max-width: 13ch;
  font-size: 1.72rem;
  line-height: 1.05;
  font-weight: 850;
}

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

.route-form {
  display: grid;
  gap: 13px;
}

.route-card {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.route-card::after {
  content: "";
  position: absolute;
  left: 24px;
  top: 55px;
  bottom: 55px;
  width: 2px;
  border-radius: 999px;
  background: #c8d2ce;
}

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.field span {
  color: #334047;
  font-size: 0.8rem;
  font-weight: 760;
}

.route-field {
  position: relative;
  padding-left: 22px;
}

.route-field::before {
  content: "";
  position: absolute;
  z-index: 1;
  left: 8px;
  top: 34px;
  width: 10px;
  height: 10px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 1px rgba(15, 28, 35, 0.15);
}

.route-field:last-child::before {
  background: var(--red);
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid #c6d0cb;
  border-radius: 7px;
  padding: 10px 12px;
  background: #fbfcfb;
  color: var(--ink);
  outline: none;
}

select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, #536069 50%),
    linear-gradient(135deg, #536069 50%, transparent 50%);
  background-position:
    calc(100% - 18px) 19px,
    calc(100% - 13px) 19px;
  background-repeat: no-repeat;
  background-size:
    5px 5px,
    5px 5px;
  padding-right: 34px;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(18, 103, 214, 0.14);
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 1px solid #c6d0cb;
  border-radius: 7px;
  background: #f8faf9;
  color: #27323a;
}

.route-swap {
  grid-column: 2;
  grid-row: 1 / 3;
  align-self: center;
}

.icon-button:hover {
  border-color: var(--accent);
  color: var(--accent-deep);
}

.icon-button svg,
.primary-button svg,
.secondary-button svg {
  width: 18px;
  height: 18px;
  stroke-width: 2.25;
}

.trip-controls {
  display: grid;
  gap: 11px;
}

.mode-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  border: 1px solid #c6d0cb;
  border-radius: 8px;
  background: #e9eeec;
}

.mode-control label {
  position: relative;
  min-width: 0;
}

.mode-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.mode-control span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border-radius: 6px;
  color: #49565e;
  font-size: 0.88rem;
  font-weight: 820;
}

.mode-control input:checked + span {
  background: #ffffff;
  color: var(--ink);
  box-shadow: 0 4px 12px rgba(34, 39, 42, 0.08);
}

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

.return-controls {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.72);
}

.compact-heading h2 {
  font-size: 0.9rem;
}

.compact-heading span {
  font-size: 0.73rem;
}

.quick-picker {
  display: grid;
  gap: 8px;
  padding: 8px;
  border: 1px solid rgba(79, 111, 105, 0.18);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(240, 165, 52, 0.1), rgba(55, 132, 116, 0.08)),
    #f8fbfa;
}

.quick-picker-group {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 36px;
  border: 1px solid rgba(79, 111, 105, 0.26);
  border-radius: 7px;
  padding: 7px 11px;
  background: rgba(255, 255, 255, 0.82);
  color: #3e4a4d;
  box-shadow: 0 1px 2px rgba(20, 37, 44, 0.05);
  font-size: 0.79rem;
  font-weight: 840;
  transition:
    border-color 0.16s ease,
    background 0.16s ease,
    box-shadow 0.16s ease,
    color 0.16s ease,
    transform 0.16s ease;
}

.chip-button:hover {
  border-color: rgba(55, 132, 116, 0.56);
  background: #ffffff;
  color: var(--accent-deep);
  box-shadow: 0 5px 14px rgba(20, 37, 44, 0.1);
  transform: translateY(-1px);
}

.date-chip,
.return-chip {
  border-color: rgba(21, 50, 56, 0.28);
  background: #153238;
  color: #ffffff;
}

.date-chip:hover,
.return-chip:hover {
  border-color: #153238;
  background: #1d484f;
  color: #ffffff;
}

.time-chip {
  min-width: 58px;
}

.time-step {
  min-width: 66px;
  background: #fff7e7;
  color: #6a3c00;
}

.time-step:hover {
  border-color: rgba(240, 165, 52, 0.72);
  color: #6a3c00;
}

.chip-button svg {
  width: 14px;
  height: 14px;
}

.address-confirmation {
  min-height: 16px;
  color: var(--green);
  font-size: 0.74rem;
  font-weight: 760;
  line-height: 1.3;
}

.address-suggestions {
  display: grid;
  gap: 6px;
}

.suggestion-option {
  display: grid;
  gap: 2px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  background: #ffffff;
  color: var(--ink);
  text-align: left;
}

.suggestion-option:hover {
  border-color: var(--accent);
  background: #f3f8ff;
}

.suggestion-option strong {
  font-size: 0.82rem;
  line-height: 1.2;
}

.suggestion-option small,
.suggestion-muted {
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.35;
}

.form-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  border: 0;
  border-radius: 7px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 850;
  box-shadow: 0 10px 20px rgba(18, 103, 214, 0.18);
}

.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  border: 1px solid #c6d0cb;
  border-radius: 7px;
  padding: 0 12px;
  background: #ffffff;
  color: #27323a;
  font-weight: 850;
}

.secondary-button:hover {
  border-color: var(--accent);
  color: var(--accent-deep);
}

.reset-button {
  color: #5d5550;
}

.reset-button:hover {
  border-color: #b98565;
  color: #8b4a28;
}

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

.primary-button:disabled {
  cursor: progress;
  background: #8a969d;
  box-shadow: none;
}

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

.metric-card {
  min-height: 78px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.metric-card span,
.recommendation span,
.section-heading span {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 760;
}

.metric-card strong {
  display: block;
  margin-top: 8px;
  overflow-wrap: anywhere;
  font-size: 1.36rem;
  line-height: 1;
}

.metric-card.highlight {
  border-color: rgba(13, 131, 92, 0.28);
  background: var(--green-soft);
}

.metric-card.highlight strong {
  color: var(--green);
}

.recommendation {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 13px;
  border: 1px solid rgba(13, 131, 92, 0.24);
  border-radius: 8px;
  background: #f4fbf7;
}

.recommendation-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: #dff2e8;
  color: var(--green);
}

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

.recommendation strong {
  display: block;
  margin-top: 4px;
  font-size: 1.03rem;
  line-height: 1.2;
}

.recommendation p {
  margin-top: 5px;
  color: #47535a;
  font-size: 0.9rem;
  line-height: 1.45;
}

.results-section {
  display: grid;
  gap: 10px;
}

.route-options-section {
  animation: fade-up 0.24s ease both;
}

.route-options {
  display: grid;
  gap: 9px;
}

.route-option-group-title {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 850;
  text-transform: uppercase;
}

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

.route-option {
  position: relative;
  display: grid;
  gap: 5px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: var(--panel);
  color: var(--ink);
  text-align: left;
  transition:
    border-color 0.16s ease,
    transform 0.16s ease,
    box-shadow 0.16s ease;
}

.route-option:hover,
.route-option.selected {
  border-color: rgba(18, 103, 214, 0.45);
  box-shadow: 0 8px 18px rgba(31, 42, 47, 0.08);
  transform: translateY(-1px);
}

.route-option.selected {
  background: #f2f7ff;
}

.route-option-name {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 850;
}

.route-option strong {
  font-size: 1.15rem;
}

.route-option small {
  color: var(--muted);
  font-size: 0.78rem;
}

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

.trip-breakdown article {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  background: var(--panel);
}

.trip-breakdown span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 850;
}

.trip-breakdown strong {
  font-size: 1.1rem;
}

.trip-breakdown small {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.section-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
}

.section-heading span {
  max-width: 190px;
  text-align: right;
}

.table-shell {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

table {
  width: 100%;
  min-width: 420px;
  border-collapse: collapse;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid #e5eae7;
  text-align: left;
  font-size: 0.86rem;
}

th {
  background: #f5f8f6;
  color: #566168;
  font-size: 0.73rem;
  font-weight: 850;
  text-transform: uppercase;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr.best-row {
  background: #eef8f2;
}

tbody tr.current-row {
  box-shadow: inset 3px 0 0 var(--accent);
}

.money {
  font-weight: 850;
}

.empty-row,
.empty-state {
  color: var(--muted);
  text-align: center;
}

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

.gantry-item {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.tooltip-card::after {
  content: attr(data-tooltip);
  position: absolute;
  z-index: 30;
  right: 10px;
  bottom: calc(100% + 8px);
  display: none;
  width: min(280px, calc(100vw - 40px));
  border: 1px solid rgba(23, 32, 39, 0.14);
  border-radius: 8px;
  padding: 9px 10px;
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 12px 30px rgba(25, 35, 42, 0.16);
  color: #27323a;
  font-size: 0.78rem;
  font-weight: 720;
  line-height: 1.35;
  text-align: left;
}

.tooltip-card:hover::after,
.tooltip-card:focus-visible::after,
.tooltip-card.show-tooltip::after {
  display: block;
}

.gantry-item strong {
  display: block;
  font-size: 0.94rem;
  line-height: 1.25;
}

.gantry-item small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.gantry-price {
  min-width: 64px;
  border-radius: 999px;
  padding: 5px 8px;
  background: #f0f4f3;
  color: #263139;
  font-size: 0.8rem;
  font-weight: 850;
  text-align: center;
}

.gantry-price.charge {
  background: #fff1eb;
  color: #b33d30;
}

.source-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
}

.source-section summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px;
  list-style: none;
  cursor: pointer;
}

.source-section summary::-webkit-details-marker {
  display: none;
}

.source-section summary strong {
  display: block;
  font-size: 0.95rem;
}

.source-section summary small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.35;
}

.source-section summary svg {
  flex: 0 0 auto;
  width: 18px;
  height: 18px;
  color: #516068;
  transition: transform 0.18s ease;
}

.source-section[open] summary svg {
  transform: rotate(180deg);
}

.source-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 13px 12px;
}

.source-list a {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border: 1px solid #c6d0cb;
  border-radius: 999px;
  padding: 6px 10px;
  color: var(--accent-deep);
  background: #f3f7fb;
  font-size: 0.78rem;
  font-weight: 820;
  text-decoration: none;
}

.source-list a:hover {
  border-color: var(--accent);
  background: #eaf2ff;
}

.source-copy {
  padding: 0 13px 13px;
  color: #536069;
  font-size: 0.84rem;
  line-height: 1.45;
}

.map-panel {
  grid-area: map;
  position: relative;
  min-height: 54dvh;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
  background: #dfe7e2;
}

.map-controls {
  position: absolute;
  z-index: 560;
  top: 96px;
  right: 10px;
  left: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  width: fit-content;
  max-width: calc(100% - 20px);
  border: 1px solid rgba(25, 28, 31, 0.12);
  border-radius: 8px;
  padding: 8px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 10px 25px rgba(20, 30, 32, 0.12);
}

.map-controls label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #334047;
  font-size: 0.76rem;
  font-weight: 850;
}

.map-controls select {
  min-height: 34px;
  width: 152px;
  padding-top: 6px;
  padding-bottom: 6px;
  font-size: 0.78rem;
}

.map-controls .icon-button {
  width: 34px;
  height: 34px;
}

.toggle-row input {
  width: 16px;
  min-height: 16px;
}

#map {
  width: 100%;
  height: 54dvh;
  min-height: 360px;
}

/* Critical Leaflet layout rules are kept locally so the map still works if CDN CSS is delayed. */
.leaflet-container {
  overflow: hidden;
  outline-offset: 1px;
}

.leaflet-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
  position: absolute;
  top: 0;
  left: 0;
}

.leaflet-tile {
  width: 256px;
  height: 256px;
  user-select: none;
}

.leaflet-zoom-animated {
  transform-origin: 0 0;
}

.leaflet-tile-pane {
  z-index: 200;
}

.leaflet-overlay-pane {
  z-index: 400;
}

.leaflet-shadow-pane {
  z-index: 500;
}

.leaflet-marker-pane {
  z-index: 600;
}

.leaflet-tooltip-pane {
  z-index: 650;
}

.leaflet-popup-pane {
  z-index: 700;
}

.leaflet-control {
  position: relative;
  z-index: 800;
  pointer-events: auto;
}

.leaflet-top,
.leaflet-bottom {
  position: absolute;
  z-index: 1000;
  pointer-events: none;
}

.leaflet-top {
  top: 0;
}

.leaflet-right {
  right: 0;
}

.leaflet-bottom {
  bottom: 0;
}

.leaflet-left {
  left: 0;
}

.leaflet-control {
  float: left;
  clear: both;
}

.leaflet-right .leaflet-control {
  float: right;
}

.leaflet-top .leaflet-control {
  margin-top: 10px;
}

.leaflet-bottom .leaflet-control {
  margin-bottom: 10px;
}

.leaflet-left .leaflet-control {
  margin-left: 10px;
}

.leaflet-right .leaflet-control {
  margin-right: 10px;
}

.leaflet-bar {
  border-radius: 4px;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.28);
}

.leaflet-bar a {
  display: block;
  width: 30px;
  height: 30px;
  border-bottom: 1px solid #d5d5d5;
  background: #ffffff;
  color: #172027;
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 30px;
  text-align: center;
  text-decoration: none;
}

.leaflet-bar a:first-child {
  border-top-left-radius: 4px;
  border-top-right-radius: 4px;
}

.leaflet-bar a:last-child {
  border-bottom: 0;
  border-bottom-right-radius: 4px;
  border-bottom-left-radius: 4px;
}

.leaflet-control-attribution {
  padding: 2px 5px;
  background: rgba(255, 255, 255, 0.82);
  color: #39454d;
  font-size: 0.68rem;
}

.map-legend,
.status-bar {
  position: absolute;
  z-index: 500;
  left: 10px;
  right: 10px;
  border: 1px solid rgba(25, 28, 31, 0.12);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: 0 10px 25px rgba(20, 30, 32, 0.12);
}

.map-legend {
  bottom: 40px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, auto));
  gap: 8px 12px;
  align-items: center;
  width: fit-content;
  max-width: calc(100% - 20px);
  padding: 9px 11px;
  color: #48545b;
  font-size: 0.76rem;
  font-weight: 820;
}

.map-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.legend-line {
  display: inline-block;
  width: 24px;
  height: 4px;
  border-radius: 99px;
}

.legend-line.route {
  background: var(--accent);
}

.legend-line.return-route {
  background: var(--green);
}

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

.legend-dot.priced {
  background: var(--amber);
}

.legend-dot.matched {
  background: var(--red);
}

.legend-dot.all {
  background: #6f7a80;
}

.status-bar {
  top: 10px;
  left: 52px;
  max-width: calc(100% - 20px);
  padding: 10px 12px;
  color: #334047;
  font-size: 0.84rem;
  font-weight: 760;
  line-height: 1.35;
}

.leaflet-popup-content {
  margin: 0;
  color: #253039;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.9rem;
  line-height: 1.45;
}

.leaflet-interactive.erp-map-target {
  cursor: help;
  pointer-events: auto;
}

.leaflet-pane > svg path.leaflet-interactive {
  pointer-events: auto;
}

.leaflet-tooltip.map-info-tooltip {
  max-width: min(320px, calc(100vw - 48px));
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: #ffffff;
  background-color: #ffffff;
  box-shadow: 0 18px 44px rgba(20, 37, 44, 0.28);
  color: #253039;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 0.94rem;
  font-weight: 720;
  line-height: 1.45;
  opacity: 1 !important;
  white-space: normal;
}

.leaflet-tooltip.map-info-tooltip::before {
  display: none;
}

.map-info-popup .leaflet-popup-content-wrapper {
  overflow: hidden;
  border: 1px solid rgba(21, 50, 56, 0.14);
  border-radius: 10px;
  box-shadow: 0 20px 48px rgba(20, 37, 44, 0.26);
}

.map-info-popup .leaflet-popup-content {
  width: min(316px, calc(100vw - 72px)) !important;
}

.map-info-popup .leaflet-popup-close-button {
  top: 7px;
  right: 7px;
  width: 26px;
  height: 26px;
  border-radius: 999px;
  color: #ffffff;
  font-size: 1.1rem;
  line-height: 26px;
}

.map-info-popup .leaflet-popup-close-button:hover {
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
}

.erp-rate-card {
  overflow: hidden;
  background: #ffffff;
  color: #111b20;
  font-family: Arial, Helvetica, sans-serif;
}

.erp-rate-card h3 {
  margin: 0;
  padding: 12px 40px 12px 13px;
  background: #153238;
  color: #ffffff;
  font-size: 1.02rem;
  font-weight: 800;
  line-height: 1.28;
}

.erp-rate-controls {
  display: grid;
  gap: 6px;
  padding: 10px 10px 0;
}

.erp-rate-select {
  position: relative;
  min-height: 22px;
  padding: 5px 26px 5px 8px;
  border: 1px solid #a7b7b5;
  border-radius: 6px;
  background: #f7fbfa;
  color: #111b20;
  font-size: 0.82rem;
  line-height: 1.25;
}

.erp-rate-select::after {
  content: "";
  position: absolute;
  top: 50%;
  right: 8px;
  width: 0;
  height: 0;
  border-right: 4px solid transparent;
  border-left: 4px solid transparent;
  border-top: 5px solid #20282c;
  transform: translateY(-35%);
}

.erp-rate-table-wrap {
  max-height: min(360px, 56vh);
  margin: 10px;
  border: 1px solid #8fb0af;
  border-radius: 7px;
  overflow: auto;
}

.erp-rate-table {
  width: 100%;
  border-collapse: collapse;
  color: #111b20;
  font-size: 0.86rem;
  line-height: 1.2;
}

.erp-rate-table td {
  padding: 5px 7px;
  border-bottom: 1px solid #9bbdbc;
  background: #e0f8f7;
}

.erp-rate-table tr:nth-child(even) td {
  background: #edfdfc;
}

.erp-rate-table tr:last-child td {
  border-bottom: 0;
}

.erp-rate-table td:last-child {
  width: 84px;
  text-align: left;
  white-space: nowrap;
}

.erp-rate-note {
  margin: 0;
  padding: 0 10px 10px;
  color: #405057;
  font-size: 0.76rem;
  line-height: 1.3;
}

.erp-hover-card {
  width: min(300px, calc(100vw - 56px));
  padding: 12px;
  border: 1px solid rgba(21, 50, 56, 0.18);
  border-left: 5px solid #f0a534;
  border-radius: 8px;
  background: #ffffff;
  color: #16272d;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.erp-hover-kicker {
  display: block;
  margin-bottom: 4px;
  color: #6a3c00;
  font-size: 0.7rem;
  font-weight: 850;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.erp-hover-card h3 {
  margin: 0 0 8px;
  font-size: 0.96rem;
  font-weight: 850;
  line-height: 1.25;
}

.erp-hover-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-bottom: 9px;
}

.erp-hover-meta span {
  padding: 3px 6px;
  border-radius: 999px;
  background: #eef5f3;
  color: #405057;
  font-size: 0.72rem;
  font-weight: 760;
}

.erp-hover-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.erp-hover-stats div {
  padding: 8px;
  border: 1px solid #d4e2df;
  border-radius: 7px;
  background: #f8fbfa;
}

.erp-hover-stats span,
.erp-hover-card p span {
  display: block;
  color: #69787d;
  font-size: 0.72rem;
  font-weight: 760;
}

.erp-hover-stats strong {
  display: block;
  margin-top: 2px;
  color: #111b20;
  font-size: 1.05rem;
  font-weight: 900;
}

.erp-hover-card p {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin: 9px 0 0;
  padding-top: 8px;
  border-top: 1px solid #e4eeeb;
}

.erp-hover-card p strong {
  color: #111b20;
  font-size: 0.82rem;
  font-weight: 850;
  text-align: right;
}

@media (max-width: 760px) {
  .map-info-popup .leaflet-popup-content {
    width: min(284px, calc(100vw - 88px)) !important;
  }

  .erp-rate-card h3 {
    padding: 11px 38px 11px 12px;
    font-size: 0.94rem;
  }

  .erp-rate-select {
    font-size: 0.76rem;
  }

  .erp-rate-table-wrap {
    max-height: min(300px, 42vh);
  }

  .erp-rate-table {
    font-size: 0.8rem;
  }

  .erp-rate-table td:last-child {
    width: 72px;
  }

  .erp-hover-card {
    width: min(276px, calc(100vw - 70px));
  }

  .primary-button {
    position: sticky;
    bottom: 12px;
    z-index: 20;
  }

  .form-actions {
    grid-template-columns: 1fr;
  }

  .secondary-button {
    min-height: 42px;
  }
}

@media (max-width: 640px) {
  .topbar,
  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .section-heading span {
    max-width: none;
    text-align: left;
  }

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

  .quick-picker {
    gap: 7px;
  }

  .quick-picker-group {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .time-shortcuts {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .chip-button {
    min-width: 0;
    padding-right: 8px;
    padding-left: 8px;
  }

  .form-actions {
    margin-top: -2px;
  }

  .trip-breakdown {
    grid-template-columns: 1fr;
  }

  .table-shell {
    overflow: visible;
    border: 0;
    background: transparent;
  }

  table,
  tbody,
  tr,
  td {
    display: block;
    width: 100%;
  }

  table {
    min-width: 0;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 8px;
  }

  tbody tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
  }

  tbody tr.best-row {
    border-color: rgba(13, 131, 92, 0.32);
    background: var(--green-soft);
  }

  tbody tr.current-row {
    box-shadow: inset 3px 0 0 var(--accent);
  }

  td {
    padding: 0;
    border-bottom: 0;
    color: #263139;
    font-size: 0.9rem;
  }

  td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 3px;
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
  }

  td.money {
    font-size: 1.05rem;
  }

  .empty-row {
    grid-column: 1 / -1;
    padding: 8px;
  }

  .empty-row::before {
    content: "";
  }
}

@media (min-width: 760px) {
  .planner-panel,
  .insights-panel {
    padding-right: 22px;
    padding-left: 22px;
  }

  .map-legend {
    left: 16px;
    right: auto;
    bottom: 16px;
    grid-template-columns: repeat(5, auto);
    max-width: calc(100% - 32px);
    font-size: 0.78rem;
  }

  .status-bar {
    top: 16px;
    left: 58px;
    right: auto;
    max-width: 560px;
    font-size: 0.86rem;
  }

  .map-controls {
    top: 16px;
    right: 16px;
    left: auto;
    max-width: calc(100% - 650px);
  }

  .route-option-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (min-width: 980px) {
  .app-shell {
    grid-template-columns: minmax(390px, 480px) minmax(0, 1fr);
    grid-template-areas:
      "planner map"
      "insights map";
    align-items: start;
  }

  .planner-panel {
    padding: 24px 24px 12px;
    border-right: 1px solid var(--line);
    border-bottom: 0;
  }

  .insights-panel {
    padding: 2px 24px 24px;
    border-right: 1px solid var(--line);
  }

  h1 {
    font-size: 1.95rem;
  }

  .map-panel {
    position: sticky;
    top: 0;
    min-height: 100dvh;
    border-bottom: 0;
  }

  #map {
    height: 100dvh;
    min-height: 620px;
  }
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.metric-card,
.recommendation,
.gantry-item,
.route-option,
.trip-breakdown article {
  animation: fade-up 0.22s ease both;
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.001ms !important;
  }
}

@media (min-width: 1240px) {
  .app-shell {
    grid-template-columns: minmax(420px, 500px) minmax(0, 1fr);
  }
}
