:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #eef2ea;
  --ink: #17201a;
  --muted: #687166;
  --line: #dce2d8;
  --accent: #0f7b62;
  --accent-2: #d97732;
  --danger: #b23b3b;
  --positive: #16734f;
  --shadow: 0 18px 42px rgba(28, 38, 27, 0.08);
  --radius: 8px;
  color-scheme: light;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  gap: 28px;
  height: 100vh;
  padding: 24px 18px;
  background: #111812;
  color: #eef5ec;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  color: inherit;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: #e7f0df;
  color: #101a12;
  font-weight: 800;
}

.brand strong,
.brand small {
  display: block;
  line-height: 1.05;
}

.brand small {
  color: #9eaa9b;
  font-size: 12px;
}

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

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: #c7d2c4;
  text-align: left;
  font-size: 14px;
}

.nav-item:hover,
.nav-item.active {
  border-color: rgba(238, 245, 236, 0.12);
  background: rgba(238, 245, 236, 0.08);
  color: #ffffff;
}

.icon {
  width: 22px;
  color: #94b7a4;
  text-align: center;
  font-size: 18px;
}

.sidebar-card {
  display: flex;
  gap: 10px;
  margin-top: auto;
  padding: 14px;
  border: 1px solid rgba(238, 245, 236, 0.12);
  border-radius: var(--radius);
  background: rgba(238, 245, 236, 0.07);
}

.sidebar-card strong {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
}

.sidebar-card p {
  margin: 0;
  color: #aab7a6;
  font-size: 12px;
  line-height: 1.45;
}

.state-dot {
  width: 9px;
  height: 9px;
  margin-top: 4px;
  border-radius: 50%;
  background: #58d68d;
  box-shadow: 0 0 0 5px rgba(88, 214, 141, 0.12);
}

.workspace {
  display: grid;
  gap: 18px;
  padding: 24px;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.1;
  letter-spacing: 0;
}

h2 {
  font-size: 16px;
  line-height: 1.2;
}

.topbar p,
.panel-heading p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.mode-switch,
.segmented {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.mode-switch button,
.segmented button {
  min-height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.mode-switch .selected,
.segmented .active {
  background: #17201a;
  color: #ffffff;
}

.mode-switch .locked {
  color: #8a9287;
  cursor: not-allowed;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}

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

.metric {
  min-height: 108px;
  padding: 16px;
}

.metric span,
.metric em,
th,
td,
label {
  font-size: 12px;
}

.metric span {
  color: var(--muted);
  font-weight: 700;
}

.metric strong {
  display: block;
  margin: 10px 0 6px;
  font-size: 25px;
  line-height: 1;
}

.metric em {
  color: var(--muted);
  font-style: normal;
  font-weight: 700;
}

.positive {
  color: var(--positive) !important;
}

.negative {
  color: var(--danger) !important;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(280px, 0.72fr);
  gap: 18px;
}

.lower {
  grid-template-columns: minmax(0, 1.45fr) minmax(280px, 0.8fr);
}

.panel {
  padding: 18px;
}

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

.panel-heading.compact {
  align-items: center;
}

.chart-panel {
  min-height: 360px;
}

.equity-chart {
  display: block;
  width: 100%;
  height: 260px;
}

.axis {
  stroke: #d8dfd4;
  stroke-width: 1;
}

.chart-fill {
  fill: rgba(15, 123, 98, 0.1);
}

.chart-line {
  fill: none;
  stroke: var(--accent);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 4;
}

.chart-dot {
  fill: var(--surface);
  stroke: var(--accent);
  stroke-width: 3;
}

.signal-panel {
  display: grid;
  align-content: start;
  gap: 16px;
}

#regimeTag {
  padding: 5px 8px;
  border-radius: 6px;
  background: #e6f2ed;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
}

.gauge {
  position: relative;
  display: grid;
  place-items: center;
  width: min(190px, 100%);
  aspect-ratio: 1;
  margin: 0 auto;
  border-radius: 50%;
  background:
    radial-gradient(circle at center, #fff 0 56%, transparent 57%),
    conic-gradient(var(--accent) calc(var(--value, 68) * 1%), #e4e9df 0);
}

.gauge strong {
  font-size: 38px;
  line-height: 1;
}

.gauge small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.gauge span {
  position: absolute;
  inset: 14px;
  border-radius: 50%;
  background: var(--surface);
}

.gauge strong,
.gauge small {
  position: relative;
}

.signal-list {
  display: grid;
  gap: 10px;
  margin: 0;
}

.signal-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

dt,
dd {
  margin: 0;
  font-size: 13px;
}

dt {
  color: var(--muted);
  font-weight: 700;
}

dd {
  font-weight: 800;
}

.primary-btn,
.secondary-btn,
.ghost-btn {
  min-height: 38px;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 800;
}

.primary-btn,
.secondary-btn {
  border: 0;
  padding: 0 14px;
  background: var(--accent);
  color: white;
}

.secondary-btn {
  width: 100%;
  margin-top: 10px;
  background: #17201a;
}

.ghost-btn {
  border: 1px solid var(--line);
  padding: 0 12px;
  background: var(--surface);
  color: var(--ink);
}

.decision-stack {
  display: grid;
  gap: 10px;
}

.decision-row {
  display: grid;
  grid-template-columns: 76px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fbfcfa;
}

.decision-row strong {
  font-size: 14px;
}

.decision-row p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.action {
  display: inline-grid;
  place-items: center;
  min-height: 28px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 900;
}

.action.buy {
  background: #e6f2ed;
  color: var(--positive);
}

.action.sell {
  background: #fae9e7;
  color: var(--danger);
}

.action.hold {
  background: #f4eee4;
  color: #9b5b1f;
}

.confidence {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.risk-panel {
  display: grid;
  align-content: start;
  gap: 16px;
}

.risk-panel label {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  color: var(--muted);
  font-weight: 800;
}

.risk-panel input {
  grid-column: 1 / -1;
  accent-color: var(--accent);
}

.audit-panel {
  overflow: hidden;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  color: var(--muted);
  text-align: left;
  text-transform: uppercase;
}

th,
td {
  padding: 12px 10px;
  border-top: 1px solid var(--line);
  white-space: nowrap;
}

td {
  color: #293329;
  font-size: 13px;
}

.status {
  display: inline-flex;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 11px;
  font-weight: 900;
}

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

  .sidebar {
    position: static;
    height: auto;
  }

  .nav-list,
  .metrics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .sidebar-card {
    margin-top: 0;
  }

  .content-grid,
  .lower {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .sidebar {
    gap: 14px;
    padding: 16px;
  }

  .sidebar-card {
    display: none;
  }

  .nav-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .nav-item {
    min-height: 38px;
    font-size: 13px;
  }

  .workspace {
    padding: 16px;
  }

  .topbar,
  .panel-heading,
  .decision-row {
    align-items: stretch;
    flex-direction: column;
    grid-template-columns: 1fr;
  }

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

  h1 {
    font-size: 23px;
  }

  .metric strong {
    font-size: 22px;
  }
}

/* Strategy Backtest panel */
.backtest-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.backtest-controls select {
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.backtest-result .empty,
.decision-stack .empty {
  color: var(--muted);
  margin: 8px 0;
}

.bt-metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 4px 0 14px;
}

.bt-metrics div {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.bt-metrics span {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.bt-metrics strong {
  display: block;
  margin-top: 6px;
  font-size: 18px;
  line-height: 1;
}

.sparkline {
  width: 100%;
  height: 64px;
  display: block;
}

.backtest-result .disclaimer {
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
}

@media (max-width: 760px) {
  .bt-metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .backtest-controls {
    flex-wrap: wrap;
  }
}

/* Strategy comparison */
.strategy-description {
  color: var(--muted);
  font-size: 13px;
  margin: -2px 0 12px;
}

.compare-result {
  margin-top: 16px;
}

.compare-title {
  font-size: 14px;
  margin: 0 0 10px;
}

.compare-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.compare-table th,
.compare-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

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

.compare-table tr.best {
  background: var(--surface-2);
}

.best-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Broker adapters panel */
.broker-mode {
  font-weight: 700;
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--accent);
}

.broker-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 4px 0 12px;
}

.broker-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.broker-row small {
  display: block;
  color: var(--muted);
  margin-top: 2px;
}

.broker-status {
  font-size: 12px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.broker-status.ok {
  background: rgba(22, 115, 79, 0.12);
  color: var(--positive);
}

.broker-status.locked {
  background: rgba(178, 59, 59, 0.12);
  color: var(--danger);
}

.broker-status.muted {
  background: var(--surface-2);
  color: var(--muted);
}

/* ---- UI polish pass ---- */
html {
  scroll-behavior: smooth;
}

/* Offset scroll targets so smooth-scrolled panels aren't flush to the edge. */
.metrics-grid,
.panel,
.content-grid {
  scroll-margin-top: 18px;
}

/* Consistent, subtle interaction feedback. */
button {
  transition: background-color 0.15s ease, border-color 0.15s ease,
    color 0.15s ease, transform 0.05s ease, box-shadow 0.15s ease;
}

.primary-btn:hover:not(:disabled),
.secondary-btn:hover:not(:disabled) {
  filter: brightness(1.05);
}

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

button:disabled {
  opacity: 0.6;
  cursor: progress;
}

.nav-item {
  cursor: pointer;
}

/* Gentle lift on interactive cards. */
.panel {
  transition: box-shadow 0.18s ease, transform 0.18s ease;
}

/* Accessible keyboard focus rings. */
a:focus-visible,
button:focus-visible,
select:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Respect reduced-motion preferences. */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}

/* Topbar data-source indicator */
.topbar-status {
  display: flex;
  align-items: center;
  gap: 12px;
}

.data-source {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  white-space: nowrap;
}

@media (max-width: 720px) {
  .data-source {
    display: none;
  }
}

/* Per-symbol trade chips (portfolio backtest) */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 0 12px;
}

.chip {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
}
