:root {
  --ink: #15202b;
  --muted: #657383;
  --subtle: #eef2f5;
  --line: #dbe3ea;
  --panel: rgba(255, 255, 255, 0.94);
  --panel-solid: #ffffff;
  --cyan: #00a99d;
  --cyan-soft: #dff7f3;
  --amber: #f2a529;
  --rose: #d94f70;
  --blue: #3267a8;
  --slate: #405266;
  --shadow: 0 16px 40px rgba(31, 46, 62, 0.14);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background: #edf2f4;
}

button,
select,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(320px, 1fr);
  width: 100vw;
  height: 100vh;
}

.map-stage {
  position: relative;
  min-width: 0;
  overflow: hidden;
  background: #dfe8ec;
}

.map-root,
.map-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.map-canvas {
  z-index: 4;
  pointer-events: none;
}

.brand-bar {
  position: absolute;
  z-index: 8;
  top: 10px;
  left: 18px;
  right: 18px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  pointer-events: none;
}

.brand-bar > * {
  pointer-events: auto;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(22px, 2.1vw, 34px);
  line-height: 1.08;
  letter-spacing: 0;
}

h2 {
  margin: 0;
  font-size: 19px;
  line-height: 1.18;
  letter-spacing: 0;
}

.driver-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid rgba(219, 227, 234, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow);
}

.driver-picker label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.driver-picker select {
  max-width: 180px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-weight: 800;
  outline: 0;
}

.layer-switches {
  display: none;
}

.layer-switches label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 28px;
  padding: 6px 9px;
  border: 1px solid rgba(219, 227, 234, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--slate);
  font-size: 12px;
  font-weight: 700;
  box-shadow: 0 6px 18px rgba(31, 46, 62, 0.08);
}

.layer-switches input {
  width: 13px;
  height: 13px;
  accent-color: var(--cyan);
}

.map-legend {
  position: absolute;
  z-index: 11;
  right: 18px;
  bottom: 86px;
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  max-width: min(560px, calc(100% - 36px));
  padding: 8px 10px;
  border: 1px solid rgba(219, 227, 234, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 6px 18px rgba(31, 46, 62, 0.08);
}

.map-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--slate);
  font-size: 11px;
  font-weight: 800;
}

.legend-dot {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.95);
}

.legend-dot.ghost {
  background: rgba(63, 82, 101, 0.34);
}

.legend-dot.search {
  background: var(--cyan);
}

.legend-dot.memory {
  background: rgba(247, 203, 84, 0.82);
}

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

.legend-endpoints {
  position: relative;
  display: inline-block;
  width: 22px;
  height: 12px;
}

.legend-endpoints::before,
.legend-endpoints::after {
  position: absolute;
  top: 1px;
  width: 9px;
  height: 9px;
  border: 2px solid;
  background: #fff;
  content: "";
}

.legend-endpoints::before {
  left: 0;
  border-color: var(--amber);
  border-radius: 50%;
}

.legend-endpoints::after {
  right: 0;
  border-color: var(--cyan);
  border-radius: 3px;
}

.legend-ring {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid rgba(217, 79, 112, 0.65);
  border-radius: 50%;
  background: rgba(217, 79, 112, 0.08);
}

.legend-line {
  display: inline-block;
  width: 20px;
  height: 0;
  border-top: 3px solid var(--cyan);
  border-radius: 999px;
}

.playback-bar {
  position: absolute;
  z-index: 12;
  right: 18px;
  bottom: 18px;
  left: 18px;
  display: grid;
  grid-template-columns: 36px 36px 36px minmax(150px, 230px) minmax(180px, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid rgba(219, 227, 234, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.icon-button svg {
  width: 18px;
  height: 18px;
  pointer-events: none;
  stroke-width: 2.2;
}

.time-readout {
  min-width: 0;
}

.time-readout strong {
  display: block;
  font-size: 15px;
  line-height: 1.1;
}

.time-readout span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#time-slider {
  width: 100%;
  accent-color: var(--cyan);
}

.speed-control {
  display: flex;
  gap: 5px;
}

.speed-button {
  min-width: 42px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--slate);
  font-size: 12px;
  font-weight: 800;
}

.speed-button.is-active {
  border-color: var(--cyan);
  background: var(--cyan-soft);
  color: #04766d;
}

.map-tooltip {
  position: absolute;
  z-index: 9;
  max-width: 270px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--shadow);
  cursor: pointer;
  pointer-events: auto;
}

.map-tooltip strong {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
}

.map-tooltip span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.insight-panel {
  z-index: 10;
  display: grid;
  grid-template-rows: minmax(380px, 0.96fr) minmax(320px, 1fr);
  min-width: 0;
  height: 100vh;
  border-left: 1px solid var(--line);
  background: #f7f9fb;
}

.panel-section {
  min-height: 0;
  padding: 18px;
  overflow: hidden;
}

.decision-section {
  border-bottom: 1px solid var(--line);
}

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

.status-pill {
  flex: 0 0 auto;
  padding: 5px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.action-card {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-solid);
}

.action-main {
  display: flex;
  gap: 10px;
  align-items: center;
  min-width: 0;
}

.action-icon {
  display: grid;
  flex: 0 0 auto;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--cyan-soft);
  color: var(--cyan);
}

.action-icon svg {
  width: 20px;
  height: 20px;
}

.action-name {
  margin: 0 0 3px;
  font-size: 18px;
  font-weight: 850;
  line-height: 1.12;
}

.muted-text {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.reason-text {
  min-height: 34px;
  margin: 10px 0 0;
  color: var(--slate);
  font-size: 13px;
  line-height: 1.35;
}

.score-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

.score-grid > div {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.score-grid span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.score-grid strong {
  display: block;
  font-size: clamp(16px, 1.35vw, 22px);
  line-height: 1.05;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.net-cell strong {
  color: #04766d;
}

.waterfall {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.waterfall-row {
  display: grid;
  grid-template-columns: 64px minmax(30px, 1fr) 58px;
  align-items: center;
  gap: 8px;
  min-width: 0;
  font-size: 12px;
}

.waterfall-row > span {
  color: var(--muted);
  font-weight: 800;
}

.waterfall-row div {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #edf2f5;
}

.waterfall-row div span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  transition: width 160ms ease;
}

.waterfall-row.positive div span {
  background: var(--cyan);
}

.waterfall-row.negative div span {
  background: var(--amber);
}

.waterfall-row.penalty div span {
  background: var(--rose);
}

.waterfall-row strong {
  text-align: right;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}

.tab-button {
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--slate);
  font-size: 12px;
  font-weight: 850;
}

.tab-button.is-active {
  border-color: var(--cyan);
  background: var(--cyan-soft);
  color: #04766d;
}

.tab-pane {
  display: none;
  height: calc(100% - 46px);
  min-height: 0;
  overflow: auto;
}

.tab-pane.is-active {
  display: block;
}

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

.cargo-item,
.preference-item,
.event-item {
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.cargo-item.is-selected {
  border-color: rgba(242, 165, 41, 0.75);
  background: #fff8e9;
}

.cargo-group {
  display: grid;
  gap: 7px;
  padding: 9px;
  border: 1px solid rgba(219, 227, 234, 0.9);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
}

.cargo-group-title {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--slate);
  font-size: 12px;
  font-weight: 850;
}

.cargo-group-title em {
  flex: 0 0 auto;
  color: var(--cyan);
  font-style: normal;
}

.item-title {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 850;
}

.item-title span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-title em {
  flex: 0 0 auto;
  color: var(--cyan);
  font-style: normal;
  font-size: 12px;
}

.item-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px 8px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
}

.item-meta span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-meta .location-path {
  grid-column: 1 / -1;
  white-space: normal;
}

.preference-summary .item-meta {
  grid-template-columns: 1fr;
}

.event-item {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 8px;
  align-items: start;
}

.event-time {
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.event-copy strong {
  display: block;
  margin-bottom: 3px;
  font-size: 12px;
}

.event-copy span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}

.empty-state {
  padding: 18px 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

@media (max-width: 1080px) {
  .app-shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: 62vh 38vh;
    height: 100vh;
  }

  .insight-panel {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: minmax(0, 1fr);
    height: 38vh;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .decision-section {
    border-right: 1px solid var(--line);
    border-bottom: 0;
  }

  .panel-section {
    padding: 12px;
  }
}

@media (max-width: 760px) {
  html,
  body {
    overflow: auto;
    overflow-x: hidden;
  }

  .app-shell {
    display: block;
    width: 100%;
    height: auto;
    min-height: 100vh;
    overflow-x: hidden;
  }

  .map-stage {
    height: 64vh;
    min-height: 520px;
  }

  .insight-panel {
    display: block;
    width: 100%;
    height: auto;
    overflow-x: hidden;
  }

  .panel-section {
    min-height: 420px;
  }

  .playback-bar {
    right: 12px;
    left: 12px;
    grid-template-columns: 36px 36px 36px minmax(120px, 1fr);
    grid-auto-rows: auto;
  }

  #time-slider,
  .speed-control {
    grid-column: 1 / -1;
  }

  .brand-bar {
    left: 12px;
    right: 12px;
    flex-direction: column;
  }

  .layer-switches {
    display: none;
  }

  .map-legend {
    right: 12px;
    bottom: 142px;
    max-width: calc(100% - 24px);
  }
}
