:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --panel-raised: #fbfcfd;
  --ink: #18202a;
  --muted: #657181;
  --line: #d9e0ea;
  --line-strong: #b9c3d0;
  --blue: #2868c7;
  --red: #c44031;
  --green: #20845e;
  --amber: #b97900;
  --violet: #7353b8;
  --button-ink: #ffffff;
  --badge-bg: #eef2f6;
  --spark-bg: #fbfcfd;
  --spark-gradient: rgba(40, 104, 199, 0.07);
  --chart-grid: #d9e0ea;
  --treasury-fill: rgba(40, 104, 199, 0.13);
  --inflation-fill: rgba(196, 64, 49, 0.12);
  --dollar-fill: rgba(32, 132, 94, 0.12);
  --shadow: 0 14px 35px rgba(24, 32, 42, 0.08);
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

[data-theme="dark"] {
  --bg: #111827;
  --panel: #182231;
  --panel-raised: #202c3d;
  --ink: #f4f7fb;
  --muted: #a4b2c5;
  --line: #2d3a4c;
  --line-strong: #506176;
  --blue: #67a6ff;
  --red: #ff776b;
  --green: #42d392;
  --amber: #f2b84b;
  --violet: #b59bff;
  --button-ink: #08111f;
  --badge-bg: #263447;
  --spark-bg: #121b29;
  --spark-gradient: rgba(103, 166, 255, 0.12);
  --chart-grid: #334255;
  --treasury-fill: rgba(103, 166, 255, 0.16);
  --inflation-fill: rgba(255, 119, 107, 0.15);
  --dollar-fill: rgba(66, 211, 146, 0.15);
  --shadow: 0 18px 38px rgba(0, 0, 0, 0.24);
  color-scheme: dark;
}

[data-theme="contrast"] {
  --bg: #000000;
  --panel: #050505;
  --panel-raised: #101010;
  --ink: #ffffff;
  --muted: #d0d0d0;
  --line: #707070;
  --line-strong: #ffffff;
  --blue: #00a2ff;
  --red: #ff4f58;
  --green: #00f5a0;
  --amber: #ffd400;
  --violet: #d78cff;
  --button-ink: #000000;
  --badge-bg: #1a1a1a;
  --spark-bg: #080808;
  --spark-gradient: rgba(0, 162, 255, 0.16);
  --chart-grid: #555555;
  --treasury-fill: rgba(0, 162, 255, 0.17);
  --inflation-fill: rgba(255, 79, 88, 0.17);
  --dollar-fill: rgba(0, 245, 160, 0.15);
  --shadow: none;
  color-scheme: dark;
}

[data-theme="solarized"] {
  --bg: #fdf6e3;
  --panel: #fffaf0;
  --panel-raised: #f7efd6;
  --ink: #253942;
  --muted: #657b83;
  --line: #ded1a4;
  --line-strong: #b8a86d;
  --blue: #268bd2;
  --red: #dc322f;
  --green: #2aa198;
  --amber: #b58900;
  --violet: #6c71c4;
  --button-ink: #ffffff;
  --badge-bg: #eee8d5;
  --spark-bg: #fff8e8;
  --spark-gradient: rgba(38, 139, 210, 0.11);
  --chart-grid: #d8ca9b;
  --treasury-fill: rgba(38, 139, 210, 0.14);
  --inflation-fill: rgba(220, 50, 47, 0.11);
  --dollar-fill: rgba(42, 161, 152, 0.12);
  --shadow: 0 12px 28px rgba(88, 75, 38, 0.12);
  color-scheme: light;
}

[data-theme="terminal"] {
  --bg: #07130d;
  --panel: #0b1d14;
  --panel-raised: #10291b;
  --ink: #d8f7df;
  --muted: #86a891;
  --line: #1e4630;
  --line-strong: #3d7c56;
  --blue: #6bb6ff;
  --red: #ff6d5f;
  --green: #2ee66b;
  --amber: #d9b650;
  --violet: #bd8cff;
  --button-ink: #06120c;
  --badge-bg: #12311f;
  --spark-bg: #08160f;
  --spark-gradient: rgba(46, 230, 107, 0.1);
  --chart-grid: #24513a;
  --treasury-fill: rgba(107, 182, 255, 0.12);
  --inflation-fill: rgba(255, 109, 95, 0.12);
  --dollar-fill: rgba(46, 230, 107, 0.12);
  --shadow: 0 14px 35px rgba(0, 0, 0, 0.3);
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  width: min(1360px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 34px;
}

.topbar,
.status-strip,
.signal-grid,
.workspace-grid,
.history-panel,
.methodology-panel,
footer {
  margin-bottom: 16px;
}

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

.topbar h1,
.signal-card h2,
.panel h2,
.method-block h3,
.method-rules h3,
.method-sources h3 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 34px;
  line-height: 1.05;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.topbar-actions,
.history-actions,
.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.theme-picker {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 0 10px 0 12px;
}

.theme-picker span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}

.theme-picker select {
  min-height: 32px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font-weight: 800;
  outline: 0;
}

.button,
.icon-button {
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 14px;
  font-weight: 750;
  transition:
    border-color 0.18s ease,
    transform 0.18s ease,
    background 0.18s ease;
}

.button:hover,
.icon-button:hover,
.text-link:hover {
  border-color: var(--ink);
  transform: translateY(-1px);
}

.button.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: var(--button-ink);
}

.danger-button {
  color: var(--red);
}

.text-link {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--blue);
  padding: 0 12px;
  font-size: 13px;
  font-weight: 850;
  text-decoration: none;
  transition:
    border-color 0.18s ease,
    transform 0.18s ease;
}

.icon-button {
  width: 40px;
  padding: 0;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
}

.status-strip > div {
  min-height: 76px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  background: var(--panel);
  padding: 14px 16px;
}

.label,
.metric-list dt,
.controls-grid span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.status-strip strong {
  font-size: 16px;
}

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

.signal-card,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.signal-card {
  min-height: 390px;
  display: flex;
  flex-direction: column;
  padding: 18px;
  border-top: 5px solid var(--line-strong);
}

.signal-card.active {
  border-top-color: var(--red);
}

.signal-card.watch {
  border-top-color: var(--amber);
}

.signal-card.ok {
  border-top-color: var(--green);
}

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

.signal-card h2,
.panel h2 {
  font-size: 20px;
  line-height: 1.15;
}

.badge,
.small-badge {
  min-width: 74px;
  display: inline-flex;
  justify-content: center;
  border-radius: 999px;
  padding: 6px 10px;
  background: var(--badge-bg);
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.badge.active,
.small-badge.active {
  background: rgba(196, 64, 49, 0.1);
  color: var(--red);
}

.badge.watch,
.small-badge.watch {
  background: rgba(185, 121, 0, 0.13);
  color: var(--amber);
}

.badge.ok,
.small-badge.ok {
  background: rgba(32, 132, 94, 0.12);
  color: var(--green);
}

.metric-main {
  min-height: 74px;
  margin: 18px 0 14px;
  color: var(--ink);
  font-size: 30px;
  font-weight: 850;
  line-height: 1.08;
}

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

.metric-list div {
  min-height: 68px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.metric-list dt {
  margin-bottom: 8px;
}

.metric-list dd {
  margin: 0;
  font-size: 16px;
  font-weight: 850;
  white-space: nowrap;
}

.sparkline {
  width: 100%;
  height: 118px;
  min-height: 118px;
  margin-top: auto;
  border-radius: 8px;
  background:
    linear-gradient(180deg, var(--spark-gradient), transparent),
    var(--spark-bg);
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(320px, 0.9fr);
  gap: 16px;
}

.panel {
  padding: 18px;
}

.controls-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 18px;
}

.controls-grid label {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.controls-grid input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel-raised);
  color: var(--ink);
  padding: 0 10px;
  font-weight: 800;
}

.controls-grid input:focus {
  outline: 3px solid rgba(40, 104, 199, 0.2);
  border-color: var(--blue);
}

.toggle-row {
  justify-content: space-between;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-weight: 750;
}

.switch input {
  width: 18px;
  height: 18px;
  accent-color: var(--blue);
}

.narrative {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.narrative p {
  margin: 0;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  line-height: 1.45;
}

.narrative p:last-child {
  border-bottom: 0;
}

.methodology-panel {
  box-shadow: none;
}

.history-panel {
  contain: paint;
  overflow: hidden;
}

.methodology-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 18px;
}

.method-block {
  min-width: 0;
  min-height: 190px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-raised);
  padding: 16px;
  overflow-wrap: anywhere;
}

.method-block h3,
.method-rules h3,
.method-sources h3 {
  font-size: 16px;
  line-height: 1.2;
}

.method-block p,
.source-list,
.formula-list,
.method-rule-list {
  color: var(--ink);
  font-size: 14px;
  line-height: 1.48;
}

.method-block p {
  margin: 12px 0 0;
}

.formula-list,
.source-list {
  display: grid;
  gap: 9px;
  margin: 12px 0 0;
  padding-left: 20px;
}

code {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  padding: 2px 5px;
  font-family:
    "SFMono-Regular", Consolas, "Liberation Mono", Menlo, ui-monospace,
    monospace;
  font-size: 0.92em;
}

.method-rules,
.method-sources {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.method-rule-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  margin: 12px 0 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
}

.method-rule-list div {
  min-height: 112px;
  background: var(--panel-raised);
  padding: 14px;
}

.method-rule-list dt {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.method-rule-list dd {
  margin: 0;
}

.source-list a {
  color: var(--blue);
  font-weight: 850;
  text-decoration: none;
}

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

.table-wrap {
  width: 100%;
  max-width: 100%;
  contain: inline-size;
  overflow-x: auto;
  margin-top: 16px;
}

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

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

th {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

td {
  font-weight: 650;
}

.file-button {
  position: relative;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  pointer-events: none;
}

.positive {
  color: var(--green);
}

.negative {
  color: var(--red);
}

.amber {
  color: var(--amber);
}

footer {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 13px;
}

footer a {
  color: var(--blue);
  font-weight: 800;
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

@media (max-width: 1040px) {
  .signal-grid,
  .workspace-grid,
  .methodology-grid,
  .method-rule-list {
    grid-template-columns: 1fr;
  }

  .signal-card {
    min-height: auto;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 20px, 1360px);
    padding-top: 16px;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions,
  .history-actions {
    width: 100%;
  }

  .theme-picker {
    width: 100%;
    justify-content: space-between;
  }

  .button {
    flex: 1 1 auto;
  }

  .status-strip {
    grid-template-columns: 1fr;
  }

  .metric-list,
  .controls-grid {
    grid-template-columns: 1fr;
  }

  .metric-main {
    min-height: unset;
    font-size: 25px;
  }
}
