:root {
  color-scheme: light;
  --ink: #1f2522;
  --muted: #66706a;
  --panel: rgba(255, 252, 246, 0.88);
  --panel-strong: rgba(255, 252, 246, 0.96);
  --line: rgba(31, 37, 34, 0.14);
  --teal: #0f8f78;
  --copper: #c85f2a;
  --gold: #d4a429;
  --green: #5b8e44;
  --shadow: 0 18px 48px rgba(42, 37, 28, 0.18);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  overflow: hidden;
  background: #e9e1d4;
  color: var(--ink);
}

button,
input {
  font: inherit;
}

.dashboard-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  min-height: 640px;
  overflow: hidden;
}

#routeScene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.topbar,
.metrics-panel,
.details-panel,
.scene-controls {
  position: absolute;
  z-index: 4;
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.topbar {
  top: 20px;
  left: 24px;
  right: 24px;
  min-height: 76px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px 18px;
  background: var(--panel);
  border-radius: 8px;
}

.topbar-actions {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--copper);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.2rem, 2.1vw, 2rem);
  line-height: 1.05;
  font-weight: 800;
}

.scenario-switch {
  display: inline-grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(92px, 1fr);
  min-width: 200px;
  min-height: 38px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
}

.unit-switch {
  display: inline-grid;
  grid-template-columns: repeat(2, minmax(74px, 1fr));
  min-width: 152px;
  min-height: 38px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.58);
}

.scenario-switch:empty {
  display: none;
}

.scenario-option,
.unit-option {
  min-width: 0;
  height: 38px;
  padding: 0 12px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.scenario-option:last-child,
.unit-option:last-child {
  border-right: 0;
}

.scenario-option.is-active,
.unit-option.is-active {
  color: var(--ink);
  background: rgba(15, 143, 120, 0.13);
}

.metrics-panel {
  left: 24px;
  bottom: 24px;
  width: min(900px, calc(100vw - 390px));
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  background: var(--panel-strong);
  border-radius: 8px;
  overflow: hidden;
}

.metric {
  min-width: 0;
  min-height: 116px;
  padding: 16px;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 8px;
}

.metric:last-child {
  border-right: 0;
}

.metric--primary {
  background: linear-gradient(180deg, rgba(15, 143, 120, 0.13), rgba(255, 255, 255, 0));
}

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

.metric strong {
  font-size: clamp(1.35rem, 2.2vw, 2.2rem);
  line-height: 1;
}

.metric span:last-child {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.25;
}

.details-panel {
  right: 24px;
  top: 150px;
  width: 330px;
  max-height: calc(100vh - 252px);
  display: flex;
  flex-direction: column;
  background: var(--panel-strong);
  border-radius: 8px;
  overflow: hidden;
}

.tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
}

.tab {
  flex: 1 1 0;
  height: 44px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 800;
}

.tab:last-child {
  border-right: 0;
}

.tab.is-active {
  color: var(--ink);
  background: rgba(15, 143, 120, 0.11);
}

.tab-panel {
  display: none;
  flex: 1 1 auto;
  min-height: 250px;
  overflow: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}

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

.facts {
  display: grid;
  gap: 10px;
  margin: 0;
}

.facts div,
.range-item,
.driver-list li {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.48);
}

.facts dt,
.range-title,
.driver-name {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.facts dd {
  margin: 4px 0 0;
  font-weight: 800;
}

.range-list {
  display: grid;
  gap: 12px;
}

.range-item {
  display: grid;
  gap: 8px;
}

.range-line {
  position: relative;
  height: 12px;
  border-radius: 999px;
  background: rgba(31, 37, 34, 0.1);
  overflow: hidden;
}

.range-line span {
  position: absolute;
  top: 0;
  bottom: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--teal), var(--gold));
}

.range-value {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 0.82rem;
}

.driver-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.driver-list li {
  display: grid;
  gap: 6px;
}

.driver-explain {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.25;
}

.driver-score {
  justify-self: start;
  min-width: 52px;
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 10px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 800;
  line-height: 1;
}

.driver-score--positive {
  border-color: rgba(15, 143, 120, 0.28);
  background: rgba(15, 143, 120, 0.14);
  color: #0b6f5e;
}

.driver-score--negative {
  border-color: rgba(200, 95, 42, 0.3);
  background: rgba(200, 95, 42, 0.14);
  color: #a6471f;
}

.driver-score--neutral {
  border-color: rgba(102, 112, 106, 0.26);
  background: rgba(102, 112, 106, 0.12);
  color: var(--muted);
}

.node-details {
  display: grid;
  gap: 10px;
}

.node-kicker {
  margin: 0;
  color: var(--copper);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.node-details h2 {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.15;
}

.node-details p {
  margin: 0;
}

#modelNodeDescription {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
}

.node-facts {
  display: grid;
  gap: 8px;
  margin: 0;
}

.node-facts div {
  display: grid;
  gap: 3px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.48);
}

.node-facts dt {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.node-facts dd {
  margin: 0;
  font-size: 0.86rem;
  line-height: 1.3;
  font-weight: 800;
}

.scene-controls {
  right: 24px;
  bottom: 24px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 54px;
  max-width: calc(100vw - 48px);
  padding: 8px;
  background: var(--panel);
  border-radius: 8px;
}

.view-toggle {
  display: grid;
  grid-template-columns: repeat(2, minmax(74px, 1fr));
  min-width: 154px;
  min-height: 38px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.66);
}

.mode-option {
  min-width: 0;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 10px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 800;
}

.mode-option:last-child {
  border-right: 0;
}

.mode-option.is-active {
  color: var(--ink);
  background: rgba(15, 143, 120, 0.13);
}

.mode-option svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
}

.icon-button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.76);
  color: var(--ink);
  cursor: pointer;
}

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

.scale-control {
  display: grid;
  grid-template-columns: auto 92px;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.scale-control input {
  accent-color: var(--teal);
}

.scale-control.is-disabled {
  opacity: 0.42;
}

.scale-control.is-disabled input {
  pointer-events: none;
}

body[data-dashboard-state="error"] .topbar {
  border-color: rgba(200, 95, 42, 0.45);
}

@media (max-width: 980px) {
  .dashboard-shell {
    min-height: 0;
  }

  .topbar {
    top: 12px;
    left: 12px;
    right: 12px;
    min-height: 68px;
  }

  .scenario-switch {
    min-width: 150px;
    grid-auto-columns: minmax(72px, 1fr);
  }

  .unit-switch {
    min-width: 136px;
    grid-template-columns: repeat(2, minmax(66px, 1fr));
  }

  .scenario-option,
  .unit-option {
    padding: 0 8px;
    font-size: 0.78rem;
  }

  .details-panel {
    top: auto;
    right: 12px;
    left: 12px;
    bottom: 162px;
    width: auto;
    max-height: 240px;
  }

  .metrics-panel {
    left: 12px;
    right: 12px;
    bottom: 12px;
    width: auto;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric {
    min-height: 74px;
    padding: 11px;
    border-bottom: 1px solid var(--line);
  }

  .metric:nth-child(2n) {
    border-right: 0;
  }

  .metric:nth-last-child(-n + 2) {
    border-bottom: 0;
  }

  .scene-controls {
    right: 12px;
    bottom: 316px;
  }
}

@media (max-width: 560px) {
  .dashboard-shell {
    display: grid;
    grid-template-rows: auto auto minmax(210px, 1fr) minmax(0, auto) auto;
    gap: 10px;
    padding: 6px;
  }

  #routeScene,
  .topbar,
  .metrics-panel,
  .details-panel,
  .scene-controls {
    position: relative;
    inset: auto;
    min-width: 0;
    width: auto;
  }

  #routeScene {
    grid-row: 3;
    width: 100%;
    max-width: 100%;
    height: 100%;
    min-height: 0;
    border-radius: 8px;
  }

  .topbar {
    grid-row: 1;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-items: start;
    gap: 9px;
    padding: 10px;
    min-height: 0;
  }

  .topbar > div {
    min-width: 0;
  }

  .topbar-actions {
    width: 100%;
    display: grid;
    grid-template-columns: minmax(126px, 0.45fr) minmax(0, 1fr);
    align-items: center;
    gap: 8px;
  }

  .eyebrow {
    font-size: 0.68rem;
  }

  h1 {
    font-size: 1.08rem;
    line-height: 1.08;
  }

  .scenario-switch {
    width: 100%;
    min-width: 0;
    grid-auto-columns: minmax(70px, 1fr);
    overflow-x: auto;
    scrollbar-width: none;
  }

  .unit-switch {
    width: auto;
    min-width: 0;
  }

  .scenario-switch::-webkit-scrollbar {
    display: none;
  }

  .details-panel {
    grid-row: 4;
    height: min(260px, 34dvh);
    max-height: min(260px, 34dvh);
    min-height: 0;
  }

  .tab {
    height: 40px;
  }

  .tab-panel {
    min-height: 0;
    padding: 12px;
    overscroll-behavior: contain;
  }

  .metrics-panel {
    grid-row: 5;
    grid-template-columns: repeat(4, minmax(128px, 1fr));
    overflow-x: auto;
    scrollbar-width: none;
  }

  .metrics-panel::-webkit-scrollbar {
    display: none;
  }

  .metric {
    min-height: 96px;
    border-right: 1px solid var(--line);
    border-bottom: 0;
  }

  .metric:nth-child(2n) {
    border-right: 1px solid var(--line);
  }

  .metric:nth-last-child(-n + 2) {
    border-bottom: 0;
  }

  .metric:last-child {
    border-right: 0;
    border-bottom: 0;
  }

  .metric strong {
    font-size: 1.25rem;
  }

  .metric span:last-child {
    font-size: 0.78rem;
  }

  .scene-controls {
    grid-row: 2;
    justify-self: end;
    align-self: start;
    min-height: 48px;
    padding: 6px;
    max-width: 100%;
  }

  .view-toggle {
    min-width: 132px;
    grid-template-columns: repeat(2, minmax(64px, 1fr));
  }

  .mode-option {
    height: 36px;
    padding: 0 8px;
    font-size: 0.74rem;
  }

  .icon-button {
    width: 36px;
    height: 36px;
  }

  .scale-control {
    grid-template-columns: 1fr;
    gap: 2px;
  }
}

@media (max-width: 560px) and (max-height: 700px) {
  .dashboard-shell {
    grid-template-rows: auto auto minmax(160px, 1fr) minmax(0, auto) auto;
    gap: 8px;
    padding: 6px;
  }

  .topbar {
    gap: 7px;
    padding: 8px;
  }

  h1 {
    font-size: 1rem;
  }

  .scenario-switch,
  .scenario-option,
  .unit-switch,
  .unit-option {
    min-height: 34px;
    height: 34px;
  }

  .details-panel {
    height: min(190px, 30dvh);
    max-height: min(190px, 30dvh);
  }

  .tab {
    height: 36px;
  }

  .tab-panel {
    padding: 10px;
  }

  .facts {
    gap: 8px;
  }

  .facts div,
  .range-item,
  .driver-list li {
    padding: 10px;
  }

  .metric {
    min-height: 88px;
  }
}
