:root {
  color-scheme: dark;
  --bg: #0c1117;
  --panel: #121a23;
  --panel-2: #17222d;
  --border: #263646;
  --text: #eff6fb;
  --muted: #96a8b7;
  --demand: #f2b84b;
  --supply: #48c6b8;
  --tight: #ee6d62;
  --cool: #7aa7ff;
  --grid: rgba(150, 168, 183, 0.2);
  --shadow: 0 22px 70px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(33, 50, 62, 0.72), rgba(12, 17, 23, 0) 340px),
    var(--bg);
}

button,
select {
  font: inherit;
}

.topbar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 24px clamp(16px, 4vw, 42px) 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

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

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.45rem, 3vw, 2.25rem);
  line-height: 1.05;
}

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

.controls {
  display: flex;
  align-items: end;
  gap: 10px;
}

.controls label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
}

select,
button {
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  background: #18232d;
}

select {
  min-width: 126px;
  padding: 0 34px 0 10px;
}

button {
  padding: 0 14px;
  cursor: pointer;
}

button:hover {
  border-color: #49687d;
  background: #20303c;
}

.dashboard {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(300px, 0.75fr);
  grid-template-areas:
    "map snapshot"
    "graph timeline"
    "evidence evidence";
  gap: 16px;
  padding: 18px clamp(16px, 4vw, 42px) 38px;
}

.surface {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.025), rgba(255, 255, 255, 0)), var(--panel);
  box-shadow: var(--shadow);
}

.map-panel {
  grid-area: map;
  padding: 18px;
}

.snapshot {
  grid-area: snapshot;
  padding: 18px;
}

.graph-panel {
  grid-area: graph;
  padding: 18px;
}

.timeline-panel {
  grid-area: timeline;
  padding: 18px;
}

.evidence-panel {
  grid-area: evidence;
  padding: 18px;
}

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

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px 14px;
  color: var(--muted);
  font-size: 0.82rem;
}

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

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

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

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

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

.pressure-map,
.timeline {
  display: block;
  width: 100%;
  height: auto;
}

.map-ocean {
  fill: #0b141c;
  stroke: #2d4051;
  stroke-width: 1.2;
}

.map-grid {
  fill: none;
  stroke: var(--grid);
  stroke-width: 0.7;
}

.map-land {
  fill: rgba(72, 198, 184, 0.08);
  stroke: rgba(122, 167, 255, 0.22);
}

.flow-arc {
  fill: none;
  stroke-linecap: round;
  stroke-width: 2.2;
  opacity: 0.62;
}

.flow-arc.exports {
  stroke: var(--supply);
}

.flow-arc.imports {
  stroke: var(--demand);
}

.hotspot-point {
  cursor: pointer;
}

.hotspot-core {
  stroke: rgba(255, 255, 255, 0.8);
  stroke-width: 1.4;
}

.hotspot-ring {
  fill: none;
  stroke-width: 1.5;
  opacity: 0.38;
}

.map-label {
  fill: var(--text);
  font-size: 11px;
  font-weight: 700;
  paint-order: stroke;
  stroke: #071018;
  stroke-width: 3px;
}

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

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

.metric span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
}

.metric strong {
  display: block;
  margin-top: 10px;
  font-size: 1.7rem;
  line-height: 1;
}

.hotspots {
  display: grid;
  gap: 9px;
}

.hotspot {
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.025);
}

.rank {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  color: #10151b;
  background: var(--tight);
  font-weight: 800;
}

.hotspot-title {
  overflow: hidden;
  margin: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 800;
}

.hotspot-subtitle {
  overflow: hidden;
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.score {
  font-variant-numeric: tabular-nums;
  font-weight: 850;
  color: var(--tight);
}

.graph-links {
  display: grid;
  gap: 8px;
  max-height: 320px;
  overflow: auto;
  padding-right: 4px;
}

.graph-link {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.025);
}

.node-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.relation {
  padding: 4px 8px;
  border: 1px solid rgba(242, 184, 75, 0.35);
  border-radius: 999px;
  color: #ffe0a0;
  background: rgba(242, 184, 75, 0.09);
  font-size: 0.74rem;
  font-weight: 800;
  text-transform: uppercase;
}

.axis,
.tick {
  stroke: rgba(150, 168, 183, 0.32);
  stroke-width: 1;
}

.line-demand,
.line-supply,
.line-imbalance {
  fill: none;
  stroke-linejoin: round;
  stroke-linecap: round;
  stroke-width: 3;
}

.line-demand {
  stroke: var(--demand);
}

.line-supply {
  stroke: var(--supply);
}

.line-imbalance {
  stroke: var(--tight);
}

.timeline-label {
  fill: var(--muted);
  font-size: 12px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
}

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

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 0.9rem;
}

th {
  color: var(--muted);
  background: #17222d;
  font-size: 0.75rem;
  text-transform: uppercase;
}

td {
  color: #dbe7ef;
}

tbody tr:hover {
  background: rgba(255, 255, 255, 0.025);
}

@media (max-width: 1050px) {
  .dashboard {
    grid-template-columns: 1fr;
    grid-template-areas:
      "map"
      "snapshot"
      "timeline"
      "graph"
      "evidence";
  }
}

@media (max-width: 680px) {
  .topbar,
  .panel-heading {
    align-items: stretch;
    flex-direction: column;
  }

  .controls {
    align-items: stretch;
  }

  .controls label,
  .controls button {
    flex: 1;
  }

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

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

  .score {
    grid-column: 2;
  }

  .graph-link {
    grid-template-columns: 1fr;
  }
}
