/* Perray's Momentum Lab — design system
   Identity: "instrument panel, not trading floor."
   A calm quantitative readout: measured slate ink, one restrained teal accent,
   monospace numerals so data aligns like a precision instrument. Deliberately
   avoids cream/terracotta/serif AI defaults. */

/* ---- Type ---- */
@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;600;700&family=Inter:wght@400;450;500;600&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  /* Palette — cool slate base, desaturated teal instrument accent */
  --ink:        #16202e;   /* deepest slate ink */
  --ink-2:      #223041;   /* raised slate */
  --ink-3:      #2f4155;   /* line/border on dark */
  --paper:      #eceef1;   /* cool paper (NOT cream) */
  --paper-2:    #f6f7f9;
  --paper-line: #d6dbe1;

  --accent:     #2f7d84;   /* measured teal-cyan */
  --accent-dim: #4a959b;
  --accent-soft:#e0edee;

  /* Zone semantics — quiet, not alarmist */
  --zone-explore: #2f7d84;   /* teal — top candidates */
  --zone-watch:   #9a7b3f;   /* muted amber — acceptable hold */
  --zone-cooling: #6b7885;   /* soft slate — weakening */
  --zone-explore-bg: #e2edee;
  --zone-watch-bg:   #f0e9da;
  --zone-cooling-bg: #e8ebef;

  --warn:  #a8562f;          /* overextension flag, muted clay */

  /* Light theme (default surfaces) */
  --bg:         var(--paper);
  --surface:    #ffffff;
  --surface-2:  var(--paper-2);
  --text:       var(--ink);
  --text-dim:   #5a6675;
  --text-faint: #8792a0;
  --border:     var(--paper-line);
  --border-strong: #c2c9d1;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(22,32,46,.04), 0 4px 16px rgba(22,32,46,.06);
  --shadow-lift: 0 2px 4px rgba(22,32,46,.06), 0 12px 32px rgba(22,32,46,.10);

  --font-display: 'Space Grotesk', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;

  --sidebar-w: 236px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:         var(--ink);
    --surface:    var(--ink-2);
    --surface-2:  #1b2839;
    --text:       #e6ebf1;
    --text-dim:   #9aa7b6;
    --text-faint: #6b7a8c;
    --border:     var(--ink-3);
    --border-strong: #3a4d63;
    --accent:     #4fa9b0;
    --accent-dim: #3d8990;
    --accent-soft:#1e3238;
    --zone-explore-bg: #163035;
    --zone-watch-bg:   #2e2818;
    --zone-cooling-bg: #212b37;
    --shadow: 0 1px 2px rgba(0,0,0,.2), 0 4px 16px rgba(0,0,0,.28);
    --shadow-lift: 0 2px 4px rgba(0,0,0,.3), 0 12px 32px rgba(0,0,0,.4);
  }
}

[data-theme="dark"] {
  --bg:         var(--ink);
  --surface:    var(--ink-2);
  --surface-2:  #1b2839;
  --text:       #e6ebf1;
  --text-dim:   #9aa7b6;
  --text-faint: #6b7a8c;
  --border:     var(--ink-3);
  --border-strong: #3a4d63;
  --accent:     #4fa9b0;
  --accent-dim: #3d8990;
  --accent-soft:#1e3238;
  --zone-explore-bg: #163035;
  --zone-watch-bg:   #2e2818;
  --zone-cooling-bg: #212b37;
  --shadow: 0 1px 2px rgba(0,0,0,.2), 0 4px 16px rgba(0,0,0,.28);
  --shadow-lift: 0 2px 4px rgba(0,0,0,.3), 0 12px 32px rgba(0,0,0,.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv05" 1, "ss01" 1;
}

/* ---- Layout shell ---- */
.app { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}

.brand {
  padding: 22px 20px 18px;
  border-bottom: 1px solid var(--border);
}
.brand-mark {
  font-family: var(--font-display);
  font-weight: 700; font-size: 15px; letter-spacing: -0.01em;
  display: flex; align-items: center; gap: 9px;
}
.brand-glyph {
  width: 22px; height: 22px; flex: none;
}
.brand-sub {
  font-family: var(--font-mono);
  font-size: 10px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-faint); margin-top: 5px; padding-left: 31px;
}

.nav { padding: 12px 12px; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.nav-label {
  font-family: var(--font-mono);
  font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--text-faint); padding: 14px 12px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  font-size: 13.5px; font-weight: 450; color: var(--text-dim);
  cursor: pointer; border: none; background: none; width: 100%; text-align: left;
  transition: background .12s, color .12s;
}
.nav-item svg { width: 17px; height: 17px; flex: none; opacity: .8; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.nav-item.active svg { opacity: 1; }

.sidebar-foot { padding: 14px 16px; border-top: 1px solid var(--border); }

/* Theme toggle */
.theme-row { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: var(--radius-sm); }
.theme-btn {
  flex: 1; border: none; background: none; cursor: pointer;
  padding: 6px; border-radius: 4px; color: var(--text-faint);
  display: flex; align-items: center; justify-content: center;
  transition: background .12s, color .12s;
}
.theme-btn svg { width: 15px; height: 15px; }
.theme-btn.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }

/* ---- Main ---- */
.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; align-items: center; gap: 20px;
  padding: 0 32px; height: 60px;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 10;
}
.topbar-title { font-family: var(--font-display); font-weight: 600; font-size: 17px; letter-spacing: -0.01em; }
.topbar-spacer { flex: 1; }

.status-chip {
  display: flex; align-items: center; gap: 8px;
  font-family: var(--font-mono); font-size: 11px;
  color: var(--text-dim);
  padding: 6px 11px; border: 1px solid var(--border); border-radius: 100px;
}
.status-chip .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.status-chip .label { color: var(--text-faint); }
.status-chip .val { color: var(--text); font-weight: 500; }

.runs-pill {
  font-family: var(--font-mono); font-size: 11px; font-weight: 500;
  padding: 6px 12px; border-radius: 100px;
  background: var(--accent-soft); color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
}

.content { padding: 28px 32px 48px; max-width: 1180px; width: 100%; }

.page { display: none; }
.page.active { display: block; animation: fade .25s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.page-head { margin-bottom: 24px; }
.page-eyebrow {
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.09em;
  text-transform: uppercase; color: var(--accent); margin-bottom: 7px;
}
.page-title { font-family: var(--font-display); font-weight: 600; font-size: 26px; letter-spacing: -0.02em; }
.page-desc { color: var(--text-dim); font-size: 14px; margin-top: 6px; max-width: 62ch; }

/* ---- Cards ---- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.card-pad { padding: 20px 22px; }
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 22px; border-bottom: 1px solid var(--border);
}
.card-head h3 { font-family: var(--font-display); font-size: 14px; font-weight: 600; letter-spacing: -0.01em; }
.card-head .hint { font-family: var(--font-mono); font-size: 11px; color: var(--text-faint); }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-metrics { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }

/* ---- Metric tile (instrument readout) ---- */
.metric {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 15px 17px;
  display: flex; flex-direction: column; gap: 6px;
}
.metric .k {
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--text-faint);
}
.metric .v {
  font-family: var(--font-mono); font-size: 22px; font-weight: 600;
  font-variant-numeric: tabular-nums; letter-spacing: -0.01em;
}
.metric .v.pos { color: var(--accent); }
.metric .v.neg { color: var(--warn); }
.metric .sub { font-family: var(--font-mono); font-size: 11px; color: var(--text-dim); }

/* ---- Table ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: 0.04em;
  text-transform: uppercase; color: var(--text-faint); font-weight: 500;
  text-align: right; padding: 11px 14px; border-bottom: 1px solid var(--border);
  white-space: nowrap; position: sticky; top: 0; background: var(--surface);
}
thead th:first-child, thead th:nth-child(2) { text-align: left; }
tbody td {
  padding: 11px 14px; border-bottom: 1px solid var(--border);
  text-align: right; font-variant-numeric: tabular-nums;
}
tbody td:first-child, tbody td:nth-child(2) { text-align: left; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
.sym { font-family: var(--font-mono); font-weight: 600; font-size: 12.5px; }
.num { font-family: var(--font-mono); font-size: 12.5px; }

/* Rank gauge — the signature element */
.rank-cell { display: flex; align-items: center; gap: 10px; }
.rank-n { font-family: var(--font-mono); font-weight: 600; width: 26px; }
.rank-gauge {
  width: 42px; height: 3px; border-radius: 2px;
  background: var(--border-strong); position: relative; overflow: hidden;
}
.rank-gauge i {
  position: absolute; left: 0; top: 0; bottom: 0; background: var(--accent);
  border-radius: 2px;
}

/* Grade bar inside cells */
.grade { display: inline-flex; align-items: center; gap: 8px; justify-content: flex-end; }
.grade .g-track { width: 40px; height: 4px; border-radius: 2px; background: var(--border-strong); overflow: hidden; }
.grade .g-fill { height: 100%; background: var(--accent-dim); border-radius: 2px; }
.grade .g-val { font-family: var(--font-mono); font-size: 12px; width: 30px; text-align: right; }

.zone-tag {
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 500;
  padding: 3px 9px; border-radius: 100px; white-space: nowrap;
}
.zone-explore { color: var(--zone-explore); background: var(--zone-explore-bg); }
.zone-watch   { color: var(--zone-watch);   background: var(--zone-watch-bg); }
.zone-cooling { color: var(--zone-cooling);  background: var(--zone-cooling-bg); }

.oe-flag {
  font-family: var(--font-mono); font-size: 10px; color: var(--warn);
  border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
  padding: 1px 6px; border-radius: 4px;
}

/* ---- Controls / sliders ---- */
.controls { display: flex; flex-direction: column; gap: 18px; }
.control label {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12.5px; font-weight: 500; color: var(--text-dim); margin-bottom: 9px;
}
.control label .cv {
  font-family: var(--font-mono); font-size: 12.5px; color: var(--text); font-weight: 600;
  background: var(--surface-2); padding: 2px 9px; border-radius: 5px;
}
.control .help {
  display: inline-flex; align-items: center; justify-content: center;
  width: 14px; height: 14px; border-radius: 50%; font-size: 9px;
  background: var(--border); color: var(--text-faint); margin-left: 6px; cursor: help;
  font-family: var(--font-mono);
}

input[type="range"] {
  -webkit-appearance: none; appearance: none; width: 100%; height: 4px;
  border-radius: 2px; background: var(--border-strong); outline: none;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; width: 16px; height: 16px;
  border-radius: 50%; background: var(--surface); border: 2px solid var(--accent);
  cursor: pointer; box-shadow: var(--shadow); transition: transform .1s;
}
input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.15); }
input[type="range"]::-moz-range-thumb {
  width: 16px; height: 16px; border-radius: 50%; background: var(--surface);
  border: 2px solid var(--accent); cursor: pointer;
}

select, input[type="number"] {
  font-family: var(--font-body); font-size: 13px; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 11px; width: 100%;
}
select:focus, input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }

.toggle-row { display: flex; align-items: center; justify-content: space-between; }
.toggle { position: relative; width: 38px; height: 22px; flex: none; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .track {
  position: absolute; inset: 0; background: var(--border-strong);
  border-radius: 100px; transition: background .15s; cursor: pointer;
}
.toggle .track::before {
  content: ''; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px;
  background: #fff; border-radius: 50%; transition: transform .15s; box-shadow: var(--shadow);
}
.toggle input:checked + .track { background: var(--accent); }
.toggle input:checked + .track::before { transform: translateX(16px); }

.accordion-head {
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer; padding: 14px 0 0; user-select: none;
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--text-faint);
}
.accordion-head svg { width: 14px; height: 14px; transition: transform .18s; }
.accordion.open .accordion-head svg { transform: rotate(180deg); }
.accordion-body { display: none; padding-top: 16px; }
.accordion.open .accordion-body { display: flex; flex-direction: column; gap: 18px; }

/* ---- Run button ---- */
.run-btn {
  width: 100%; font-family: var(--font-display); font-weight: 600; font-size: 14px;
  color: #fff; background: var(--accent); border: none; border-radius: var(--radius-sm);
  padding: 13px 18px; cursor: pointer; display: flex; align-items: center;
  justify-content: center; gap: 9px; transition: background .14s, transform .06s;
  box-shadow: var(--shadow);
}
.run-btn:hover { background: var(--accent-dim); }
.run-btn:active { transform: translateY(1px); }
.run-btn:disabled { background: var(--border-strong); color: var(--text-faint); cursor: not-allowed; }
.run-btn .count { font-family: var(--font-mono); font-weight: 500; opacity: .85; font-size: 12px; }
.run-btn svg { width: 16px; height: 16px; }

.btn-ghost {
  font-family: var(--font-body); font-size: 12.5px; font-weight: 500;
  color: var(--text-dim); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 13px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 7px; transition: background .12s;
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-ghost svg { width: 15px; height: 15px; }

/* ---- Equity chart ---- */
.chart-legend { display: flex; gap: 18px; margin-bottom: 14px; }
.legend-item { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text-dim); }
.legend-swatch { width: 14px; height: 3px; border-radius: 2px; }

/* ---- Empty / notice states ---- */
.empty {
  text-align: center; padding: 48px 24px; color: var(--text-dim);
}
.empty svg { width: 34px; height: 34px; color: var(--text-faint); margin-bottom: 14px; }
.empty h4 { font-family: var(--font-display); font-size: 15px; color: var(--text); margin-bottom: 6px; }
.empty p { font-size: 13px; max-width: 42ch; margin: 0 auto; }

.notice {
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
  background: var(--accent-soft); border-radius: var(--radius);
  padding: 14px 16px; font-size: 13px; color: var(--text); display: flex; gap: 11px;
}
.notice svg { width: 17px; height: 17px; color: var(--accent); flex: none; margin-top: 1px; }
.notice.warn {
  border-color: color-mix(in srgb, var(--warn) 30%, transparent);
  background: color-mix(in srgb, var(--warn) 8%, var(--surface));
}
.notice.warn svg { color: var(--warn); }

.disclaimer {
  font-size: 11.5px; color: var(--text-faint); line-height: 1.6;
  border-top: 1px solid var(--border); padding-top: 16px; margin-top: 28px;
}

/* Backtest layout */
.bt-layout { display: grid; grid-template-columns: 320px 1fr; gap: 20px; align-items: start; }
.bt-controls { position: sticky; top: 76px; }

/* Toast */
.toast-wrap { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 100; }
.toast {
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: var(--radius-sm);
  font-size: 13px; box-shadow: var(--shadow-lift); display: flex; align-items: center; gap: 10px;
  animation: toastIn .2s ease;
}
[data-theme="dark"] .toast { background: var(--surface); border: 1px solid var(--border); }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.spinner {
  width: 15px; height: 15px; border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Responsive */
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .bt-layout { grid-template-columns: 1fr; }
  .bt-controls { position: static; }
  .grid-2 { grid-template-columns: 1fr; }
  .menu-btn { display: inline-flex !important; }
}
.menu-btn { display: none; background: none; border: none; cursor: pointer; color: var(--text); }
.menu-btn svg { width: 22px; height: 22px; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- Account box (sidebar) ---- */
.acct { display: flex; align-items: center; gap: 10px; padding: 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2); }
.acct-avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: none;
  background: var(--accent); color: #fff; font-weight: 600; font-size: 13px;
  display: flex; align-items: center; justify-content: center; font-family: var(--font-display);
}
.acct-meta { flex: 1; min-width: 0; }
.acct-email { font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.acct-tier { font-family: var(--font-mono); font-size: 10px; color: var(--accent); text-transform: uppercase; letter-spacing: 0.05em; }
.acct-logout { background: none; border: none; cursor: pointer; color: var(--text-faint); padding: 4px; border-radius: 4px; transition: color .12s, background .12s; }
.acct-logout:hover { color: var(--warn); background: var(--surface); }
.acct-logout svg { width: 16px; height: 16px; }

/* ---- Auth modal ---- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(22,32,46,.5); backdrop-filter: blur(3px);
  display: none; align-items: center; justify-content: center; z-index: 200; padding: 20px;
}
.modal-backdrop.open { display: flex; animation: fade .18s ease; }
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lift); width: 100%; max-width: 380px; padding: 28px; position: relative;
}
.modal-close { position: absolute; top: 16px; right: 16px; background: none; border: none; cursor: pointer; color: var(--text-faint); padding: 4px; }
.modal-close svg { width: 18px; height: 18px; }
.modal-close:hover { color: var(--text); }
.modal-brand { display: flex; align-items: center; gap: 10px; font-family: var(--font-display); font-weight: 700; font-size: 15px; margin-bottom: 20px; }

.auth-tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 3px; border-radius: var(--radius-sm); margin-bottom: 20px; }
.auth-tab {
  flex: 1; border: none; background: none; cursor: pointer; padding: 8px; border-radius: 5px;
  font-family: var(--font-body); font-size: 13px; font-weight: 500; color: var(--text-dim); transition: background .12s, color .12s;
}
.auth-tab.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }
.auth-fields { display: flex; flex-direction: column; gap: 14px; }
.auth-label { display: flex; flex-direction: column; gap: 6px; font-size: 12.5px; font-weight: 500; color: var(--text-dim); }
.auth-label input { font-family: var(--font-body); }
.auth-error { color: var(--warn); font-size: 12.5px; min-height: 1px; }
.auth-note { font-size: 11.5px; color: var(--text-faint); text-align: center; margin-top: 4px; }

/* ---- Saved strategies (self-hosted) ---- */
.saved-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); margin-bottom: 8px;
}
