:root {
  --bg: #f3f5f2;
  --surface: #ffffff;
  --surface-2: #eef3f5;
  --ink: #182022;
  --muted: #5d6b70;
  --line: #d8e0de;
  --strong-line: #aebcba;
  --teal: #16736d;
  --green: #4c8f3f;
  --blue: #315f9f;
  --amber: #a76512;
  --red: #b34438;
  --steel: #53606d;
  --lav: #6f5d8d;
  --shadow: 0 10px 30px rgba(24, 32, 34, 0.08);
  --radius: 8px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

.app-header {
  min-height: 84px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 24px;
  border-bottom: 1px solid var(--line);
  background: #fafbf9;
  position: sticky;
  top: 0;
  z-index: 10;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.05;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 15px;
  line-height: 1.2;
}

h3 {
  margin-bottom: 8px;
  font-size: 14px;
}

p {
  color: var(--muted);
  line-height: 1.45;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 320px) minmax(0, 1fr);
  gap: 18px;
  padding: 18px;
}

.control-rail,
.workspace {
  min-width: 0;
}

.control-rail {
  display: grid;
  gap: 14px;
  align-self: start;
  position: sticky;
  top: 104px;
  max-height: calc(100vh - 122px);
  overflow: auto;
  padding-right: 2px;
}

.workspace {
  display: grid;
  gap: 14px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}

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

.panel-title p {
  margin: 6px 0 0;
  font-size: 13px;
}

.panel-title span {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.header-actions,
.graph-tools {
  display: flex;
  align-items: center;
  gap: 8px;
}

.button {
  min-height: 36px;
  border: 1px solid var(--strong-line);
  border-radius: 7px;
  background: #f8faf8;
  color: var(--ink);
  cursor: pointer;
  padding: 8px 12px;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.button:hover {
  background: #eef5f3;
  border-color: var(--teal);
}

.button:active {
  transform: translateY(1px);
}

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

.button.primary:hover {
  background: #105f5a;
}

.button.small {
  min-height: 30px;
  padding: 5px 9px;
  font-size: 12px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 12px;
}

.segmented button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--ink);
  cursor: pointer;
  padding: 6px 8px;
  font-size: 12px;
}

.segmented button.active {
  border-color: var(--teal);
  background: #dcefeb;
  color: #0d5e59;
  font-weight: 700;
}

.slider-stack {
  display: grid;
  gap: 12px;
}

.slider-row {
  display: grid;
  gap: 6px;
}

.slider-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 13px;
}

.slider-label strong {
  min-width: 58px;
  text-align: right;
  color: var(--teal);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--teal);
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  font-size: 13px;
}

.field input {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 7px 9px;
  color: var(--ink);
}

.check-grid {
  display: grid;
  gap: 7px;
  margin-bottom: 12px;
}

.check-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  font-size: 13px;
}

.check-grid input {
  accent-color: var(--teal);
}

.watchlist {
  border-top: 1px solid var(--line);
  padding-top: 12px;
  min-height: 36px;
}

.watchlist-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 700;
}

.watch-tickers {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #f7faf9;
  color: var(--ink);
  min-height: 24px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.pill.hot {
  background: #eef8e9;
  border-color: #b6d9a7;
  color: #2d6426;
}

.pill.warn {
  background: #fff4df;
  border-color: #e4c27e;
  color: #83500b;
}

.pill.risk {
  background: #fae8e5;
  border-color: #e2aaa4;
  color: #93372d;
}

.stat-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
}

.stat {
  min-width: 0;
  min-height: 86px;
  padding: 13px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stat span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
}

.stat strong {
  display: block;
  color: var(--ink);
  font-size: clamp(18px, 2.2vw, 26px);
  line-height: 1.1;
}

.stat small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}

.graph-panel {
  min-height: 500px;
}

.graph-wrap {
  position: relative;
  width: 100%;
  height: clamp(430px, 52vw, 620px);
  border: 1px solid var(--line);
  border-radius: 7px;
  background:
    linear-gradient(90deg, rgba(22, 115, 109, 0.05), transparent 28%),
    linear-gradient(180deg, #fbfcfb, #eef3f5);
  overflow: hidden;
}

#supplyGraph {
  width: 100%;
  height: 100%;
  display: block;
}

.edge {
  fill: none;
  stroke: rgba(83, 96, 109, 0.42);
  stroke-linecap: round;
}

.edge.highlight {
  stroke: var(--red);
  stroke-opacity: 0.82;
}

.node {
  cursor: pointer;
}

.node circle,
.node rect {
  transition: stroke-width 120ms ease, filter 120ms ease, opacity 120ms ease;
}

.node text {
  font-size: 12px;
  paint-order: stroke;
  stroke: rgba(255, 255, 255, 0.9);
  stroke-width: 4px;
  stroke-linejoin: round;
  fill: var(--ink);
  pointer-events: none;
}

.node.selected circle,
.node.selected rect {
  stroke: #101517;
  stroke-width: 3px;
  filter: drop-shadow(0 5px 8px rgba(24, 32, 34, 0.24));
}

.node.dim,
.edge.dim {
  opacity: 0.22;
}

.layer-label {
  fill: #69777c;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.tooltip {
  position: absolute;
  max-width: 260px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow);
  color: var(--ink);
  font-size: 12px;
  pointer-events: none;
  z-index: 5;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.28fr) minmax(0, 1fr);
  gap: 14px;
}

.table-panel,
.detail-panel,
.sim-panel {
  min-height: 340px;
}

.table-wrap {
  overflow: auto;
  max-height: 480px;
  border: 1px solid var(--line);
  border-radius: 7px;
}

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

th,
td {
  padding: 10px 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 12px;
}

td small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  line-height: 1.35;
}

th {
  position: sticky;
  top: 0;
  background: #eef3f5;
  color: #3d4a4e;
  z-index: 2;
  cursor: pointer;
}

tbody tr {
  cursor: pointer;
}

tbody tr:hover {
  background: #f7fbfa;
}

.ticker-cell strong {
  display: block;
  font-size: 13px;
}

.ticker-cell small,
.setup-cell small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  line-height: 1.35;
}

.bar {
  width: 96px;
  height: 8px;
  margin-top: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5ebea;
}

.bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--teal);
}

.bar.red span {
  background: var(--red);
}

.bar.amber span {
  background: var(--amber);
}

.watch-btn {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  cursor: pointer;
  min-width: 34px;
  min-height: 28px;
  font-weight: 700;
}

.watch-btn.active {
  border-color: #c69a39;
  background: #fff5db;
  color: #8a5a00;
}

#detailPane {
  display: grid;
  gap: 12px;
}

.detail-block {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfb;
}

.detail-block p {
  margin-bottom: 0;
  font-size: 13px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.metric {
  padding: 9px;
  border-radius: 7px;
  background: var(--surface-2);
  min-width: 0;
}

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

.metric strong {
  display: block;
  margin-top: 4px;
  font-size: 16px;
}

.exposure-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.sim-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.sim-metric {
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px;
  background: #fbfcfb;
}

.sim-metric span {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.sim-metric strong {
  display: block;
  margin-top: 5px;
  font-size: 16px;
}

#simHistogram {
  width: 100%;
  height: 220px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfcfb;
}

.source-panel p {
  margin-bottom: 10px;
  font-size: 13px;
}

.source-links {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.source-links a {
  color: var(--teal);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}

.source-links a:hover {
  text-decoration: underline;
}

@media (max-width: 1180px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .control-rail {
    position: static;
    max-height: none;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 880px) {
  .app-header {
    position: static;
    flex-direction: column;
    align-items: flex-start;
  }

  .header-actions,
  .graph-tools {
    width: 100%;
    flex-wrap: wrap;
  }

  .button {
    flex: 1;
  }

  .control-rail,
  .dashboard-grid,
  .stat-strip {
    grid-template-columns: 1fr;
  }

  .graph-wrap {
    height: 560px;
  }

  .sim-summary,
  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

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

  .segmented,
  .sim-summary,
  .metric-grid {
    grid-template-columns: 1fr;
  }
}
