:root {
  --bg: #07111b;
  --panel: #0b1722;
  --panel2: #0e1c29;
  --line: #21384c;
  --line2: #35516b;
  --text: #eaf1f8;
  --muted: #8fa4ba;
  --dim: #667d93;
  --ndx: #5b9bea;
  --xau: #d8b152;
  --ok: #69c59a;
  --warn: #d1a151;
  --danger: #d27378;
  --font: "Segoe UI Variable Text", "Segoe UI", Inter, system-ui, sans-serif;
  --mono: "Cascadia Mono", Consolas, monospace;
  --type-compact: 10px;
  --type-label: 10.5px;
  --type-data: 11px;
  --type-body: 11.5px;
  --type-heading: 12px;
  --type-emphasis: 13px;
  --radius-panel: 3px;
  --radius-control: 3px;
  --radius-inner: 2px;
}

html[data-theme="light"] {
  --bg: #eef3f8;
  --panel: #ffffff;
  --panel2: #f5f8fb;
  --line: #ced9e5;
  --line2: #aebfd0;
  --text: #102238;
  --muted: #536a82;
  --dim: #71849a;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); font: 400 14px/1.45 var(--font); }
button { font: inherit; }

/* View switching is functional state; shell geometry lives in institutional-shell.css. */
.view { display: none; padding: 21px 0 0; }
.view.active { display: block; }

/* Functional module bars */
.module-bar {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
}
.module-label { font: 800 var(--type-label) var(--mono); letter-spacing: 0.13em; }

/* Asset desks */
.asset-head {
  min-height: 72px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 7px 0 15px;
  border-bottom: 1px solid var(--line);
}
.desk-label { font: 800 var(--type-label) var(--mono); letter-spacing: 0.11em; color: var(--dim); }
h1 { margin: 6px 0 0; font-size: clamp(32px, 2.5vw, 42px); letter-spacing: -0.035em; line-height: 1; }
.ndx { color: var(--ndx); }
.xau { color: var(--xau); }

/* Metrics */
.metric-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  overflow: hidden;
  background: var(--panel);
  margin-bottom: 14px;
}
.metric { min-height: 88px; padding: 13px 15px; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric span,
.metric small { display: block; }
.metric span { color: var(--dim); font: 700 var(--type-label) var(--mono); letter-spacing: 0.07em; }
.metric strong { display: block; margin-top: 7px; font-size: 16px; letter-spacing: -0.01em; }
.metric small { margin-top: 5px; color: var(--muted); font-size: var(--type-body); line-height: 1.45; }
.home-metrics .metric { min-height: 88px; }

/* Grid */
.grid { display: grid; gap: 10px; }
.cols-12,
.work-grid { grid-template-columns: repeat(12, minmax(0, 1fr)); }
.span-12 { grid-column: span 12; }
.span-8 { grid-column: span 8; }
.span-7 { grid-column: span 7; }
.span-6 { grid-column: span 6; }
.span-5 { grid-column: span 5; }
.span-4 { grid-column: span 4; }
.home-grid {
  min-height: calc(100vh - 248px);
  grid-template-rows: minmax(255px, 1.05fr) minmax(220px, .95fr);
  align-items: stretch;
}
.home-grid > .panel { min-height: 0; display: flex; flex-direction: column; }
.home-grid > .panel > .rows,
.home-grid > .panel > .empty-state { flex: 1; min-height: 0; }

/* Panels */
.panel,
.work-card {
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  background: var(--panel);
  overflow: hidden;
}
.surface-primary {
  border-color: var(--line2);
  box-shadow: inset 0 2px 0 var(--line2);
}
#nasdaq .surface-primary { box-shadow: inset 0 2px 0 color-mix(in srgb, var(--ndx) 72%, var(--line2)); }
#gold .surface-primary { box-shadow: inset 0 2px 0 color-mix(in srgb, var(--xau) 72%, var(--line2)); }
.surface-secondary { background: color-mix(in srgb, var(--panel) 88%, var(--bg)); }
.surface-support {
  border-right: 0;
  border-bottom: 0;
  border-left: 0;
  border-radius: 0;
  background: transparent;
}
.surface-primary > .panel-head {
  border-bottom-color: var(--line2);
  background: color-mix(in srgb, var(--panel2) 46%, transparent);
}
.surface-support > .panel-head { padding-inline: 0; }
.surface-support > .rows > .row { padding-inline: 0; }
.surface-support > .empty-state { min-height: 126px; }
.panel-head {
  min-height: 44px;
  padding: 10px 13px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.panel-head span { color: var(--dim); font: 800 var(--type-label) var(--mono); letter-spacing: 0.08em; }
.panel-head strong { font: 750 var(--type-data) var(--mono); }
.home-primary { min-height: 218px; }

.rows { display: grid; }
.row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  padding: 12px 13px;
  border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }
.row b { font-size: var(--type-heading); font-weight: 700; }
.row span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: var(--type-body);
  line-height: 1.45;
  word-break: normal;
  overflow-wrap: break-word;
}
.row strong { font: 700 var(--type-data) var(--mono); text-align: right; }
.empty-state { min-height: 148px; display: grid; place-items: center; color: var(--dim); font: 700 var(--type-data) var(--mono); }

/* Asset context */
.proxy-line {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 8px 11px;
  margin: 10px 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  background: var(--panel2);
  font-size: var(--type-body);
}
.proxy-line span { font: 800 var(--type-label) var(--mono); }
.proxy-line small { color: var(--muted); font-size: var(--type-label); }
.proxy-line strong { margin-left: auto; }

.chart {
  height: 480px;
  position: relative;
  overflow: hidden;
  background: linear-gradient(180deg, var(--panel), var(--panel2));
  cursor: crosshair;
  touch-action: pan-y;
}
.chart::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(to bottom, transparent 0, transparent 76px, var(--line) 77px),
    repeating-linear-gradient(to right, transparent 0, transparent 148px, var(--line) 149px);
  opacity: 0.28;
}
.chart-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--dim); font: 700 var(--type-data) var(--mono); }
.chart-crosshair { display: none; position: absolute; inset: 0; pointer-events: none; }
.chart-crosshair::before,
.chart-crosshair::after { content: ""; position: absolute; background: var(--line2); }
.chart-crosshair::before { width: 1px; height: 100%; left: var(--x); }
.chart-crosshair::after { height: 1px; width: 100%; top: var(--y); }
.chart-tooltip {
  display: none;
  position: absolute;
  z-index: 3;
  padding: 7px 8px;
  border: 1px solid var(--line2);
  border-radius: var(--radius-inner);
  background: var(--panel);
  font: 700 var(--type-data) var(--mono);
  pointer-events: none;
}

.context-layers { margin-top: 0; }
.layer-strip { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.layer { padding: 12px; border-right: 1px solid var(--line); min-height: 76px; cursor: pointer; }
.layer:last-child { border-right: 0; }
.layer:hover { background: var(--panel2); }
.layer b,
.layer span { display: block; }
.layer b { font-size: var(--type-body); }
.layer span {
  margin-top: 6px;
  color: var(--dim);
  font-size: var(--type-label);
  line-height: 1.45;
  word-break: normal;
  overflow-wrap: break-word;
}

/* Controls */
.horizon-control,
.segmented {
  display: flex;
  align-items: center;
  flex: 0 0 auto;
  min-height: 38px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--panel2);
  gap: 3px;
}
.horizon-control button,
.segmented button {
  flex: 0 0 40px;
  width: 40px;
  min-width: 40px;
  height: 31px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-inner);
  background: transparent;
  color: var(--muted);
  font: 700 var(--type-compact) var(--mono);
  line-height: 31px;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  cursor: pointer;
}
.horizon-control button.active,
.segmented button.active { background: var(--panel); color: var(--text); box-shadow: inset 0 0 0 1px var(--line2); }
.focus-controls { display: flex; gap: 8px; }

/* Intelligence */
.mode-nav { position: relative; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 5px; margin: 0 0 10px; }
.mode-nav button {
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  background: var(--panel);
  color: var(--muted);
  padding: 9px 10px;
  text-align: left;
  cursor: pointer;
  font: 700 var(--type-label) var(--mono);
}
.mode-nav button.active { border-color: var(--line2); color: var(--text); background: var(--panel2); }
.work-grid { display: grid; gap: 10px; }
.work-body { padding: 11px; }
.work-list { display: grid; gap: 6px; }
.work-item { padding: 9px 10px; border: 1px solid var(--line); border-radius: var(--radius-panel); background: var(--panel2); }
.work-item b { display: block; font-size: var(--type-heading); }
.work-item span { display: block; margin-top: 5px; color: var(--muted); font-size: var(--type-body); line-height: 1.5; }

/* System */
.chain { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 11px; }
.chain span { padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; font: 700 var(--type-label) var(--mono); }
.chain i { color: var(--dim); font-style: normal; }
.table { display: grid; }
.table-row { display: grid; grid-template-columns: 1.1fr 0.8fr 1.5fr; gap: 10px; padding: 9px 11px; border-bottom: 1px solid var(--line); font-size: var(--type-body); }
.table-row:last-child { border-bottom: 0; }
.table-row span { color: var(--muted); }
.system-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  margin-bottom: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius-panel);
  overflow: hidden;
  background: var(--panel);
}
.system-card {
  padding: 11px;
  border: 0;
  border-right: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
}
.system-card:last-child { border-right: 0; }
.setting { padding: 14px; border: 1px solid var(--line); border-radius: var(--radius-panel); background: var(--panel); }
.system-card span,
.setting > span { display: block; color: var(--dim); font: 800 var(--type-label) var(--mono); letter-spacing: 0.07em; }
.system-card strong,
.setting > strong { display: block; margin-top: 8px; font-size: 13px; }
.system-card small { display: block; margin-top: 6px; color: var(--muted); font-size: var(--type-body); }

/* Settings */
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; max-width: 820px; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.setting .segmented { flex: 0 0 auto; }

.state-ok { color: var(--ok); }
.state-warn { color: var(--warn); }
.state-danger { color: var(--danger); }

@media (max-width: 1080px) {
  .metric-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .metric:nth-child(3) { border-right: 0; }
  .layer-strip {
    display: flex;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-width: thin;
  }
  .layer { flex: 0 0 150px; border-right: 1px solid var(--line); }
}

@media (max-width: 900px) {
  .span-8,
  .span-7,
  .span-6,
  .span-5,
  .span-4 { grid-column: span 12; }
  .home-grid { min-height: 0; grid-template-rows: none; }
  .chart { height: 420px; }
}

@media (max-width: 820px) {
  .view { padding-top: 11px; }
  .asset-head { min-height: 56px; padding: 5px 0 12px; flex-direction: row; align-items: center; }
  h1 { font-size: 27px; }
  .metric-strip { display: flex; overflow-x: auto; overscroll-behavior-inline: contain; }
  .metric { flex: 0 0 158px; border-right: 1px solid var(--line); }
  .intelligence-bar { align-items: flex-start; flex-direction: column; }
  .focus-controls { width: 100%; max-width: 100%; overflow-x: auto; }
  .mode-nav { display: flex; overflow-x: auto; }
  .mode-nav button { flex: 0 0 150px; }
  .system-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .system-card:nth-child(2) { border-right: 0; }
  .system-card:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .chart { height: 400px; }
}

@media (max-width: 620px) {
  .metric strong { font-size: 15px; }
  .chart { height: 360px; }
}

@media (max-width: 560px) {
  .system-strip,
  .settings-grid { grid-template-columns: 1fr; }
  h1 { font-size: 25px; }
  .chart { height: 350px; }
  .system-card,
  .system-card:nth-child(2) { border-right: 0; border-bottom: 1px solid var(--line); }
  .system-card:last-child { border-bottom: 0; }
}
