/* ===========================================================================
   Go / No-Go Dashboard -- Styles
   =========================================================================== */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
a, button, input, select, [onclick] {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;             /* eliminates 300ms tap delay */
}

/* -- DARK THEME (default) -- AttaGo Brand Palette ----------------------- */
[data-theme="dark"] {
  --bg: #0A0A0A;
  --bg-card: #161616;
  --bg-hover: #1E1E1E;
  --bg-elev: #1E1E1E;
  --bg-input: #0A0A0A;
  --bdr: #272727;
  --bdr-a: #2E2E2E;
  --t1: #FFFFFF;
  --t2: #AAAAAA;
  --t3: #888888;
  --t4: #555555;
  --go: #34D399;
  --go-bg: rgba(52,211,153,.08);
  --go-bdr: rgba(52,211,153,.25);
  --starter: #FFA94D;
  --starter-bg: rgba(255,169,77,.08);
  --starter-bdr: rgba(255,169,77,.25);
  --nogo: #FF6B6B;
  --nogo-bg: rgba(255,107,107,.08);
  --nogo-bdr: rgba(255,107,107,.25);
  --long: #34D399;
  --short: #FF6B6B;
  --neutral: #9ca3af;
  --accent: #10B981;
  --accent-dim: rgba(16,185,129,.14);
  --sq-low: #34D399;
  --sq-med: #FFA94D;
  --sq-hi: #FF6B6B;
  --card-text: #FFFFFF;
  --label-text: #AAAAAA;
  --shd: 0 2px 12px rgba(0,0,0,.5);
}

/* -- LIGHT THEME -- AttaGo Brand (adapted) ------------------------------ */
[data-theme="light"] {
  --bg: #F2F2F2;
  --bg-card: #FFFFFF;
  --bg-hover: #E8E8E8;
  --bg-elev: #F5F5F5;
  --bg-input: #E4E4E4;
  --bdr: #D0D0D0;
  --bdr-a: #B8B8B8;
  --t1: #111111;
  --t2: #3C3C3C;
  --t3: #5A5A5A;
  --t4: #8B8B8B;
  --go: #059669;
  --go-bg: rgba(5,150,105,.06);
  --go-bdr: rgba(5,150,105,.25);
  --starter: #D98A20;
  --starter-bg: rgba(217,138,32,.06);
  --starter-bdr: rgba(217,138,32,.25);
  --nogo: #E05555;
  --nogo-bg: rgba(224,85,85,.06);
  --nogo-bdr: rgba(224,85,85,.25);
  --long: #059669;
  --short: #E05555;
  --neutral: #6b7280;
  --accent: #059669;
  --accent-dim: rgba(5,150,105,.1);
  --sq-low: #059669;
  --sq-med: #D98A20;
  --sq-hi: #E05555;
  --card-text: #1a1a1a;
  --label-text: #3c3c3c;
  --shd: 0 2px 12px rgba(0,0,0,.08);
}

/* -- BASE --------------------------------------------------------------- */
:root {
  --sans: 'Inter', system-ui, sans-serif;
  --mono: 'JetBrains Mono', monospace;
  --r-sm: 6px;
  --r: 10px;
  --r-lg: 14px;
}

/* -- Logo theme swap ---------------------------------------------------- */
.brand-logo-light { display: none !important; }
.brand-logo-dark  { display: inline !important; }
[data-theme="light"] .brand-logo-light { display: inline !important; }
[data-theme="light"] .brand-logo-dark  { display: none !important; }

/* -- Tutorial hint speech bubble ----------------------------------------- */
.tutorial-hint {
  display: none;
  position: fixed;
  z-index: 900;
  padding: 0.5rem 1rem;
  border-radius: 20px;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 0.75rem;
  font-weight: 500;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.4s ease;
  white-space: nowrap;
}
.tutorial-hint.visible {
  display: block;
  opacity: 1;
}
.tutorial-hint.fade-out {
  opacity: 0;
}
/* Opposite theme colors for contrast */
[data-theme="dark"] .tutorial-hint {
  background: #F0F0F0;
  color: #222;
  box-shadow: 0 3px 12px rgba(0,0,0,0.35);
}
[data-theme="light"] .tutorial-hint {
  background: #1E1E1E;
  color: #F0F0F0;
  box-shadow: 0 3px 12px rgba(0,0,0,0.2);
}
/* Speech bubble tail pointing up-right */
.tutorial-hint::after {
  content: "";
  position: absolute;
  top: -8px;
  right: 20px;
  width: 16px;
  height: 16px;
  border-radius: 0 0 0 4px;
  transform: rotate(45deg) skew(-8deg, -8deg);
}
[data-theme="dark"] .tutorial-hint::after {
  background: #F0F0F0;
}
[data-theme="light"] .tutorial-hint::after {
  background: #1E1E1E;
}

html { font-size: 15px; }

body {
  background: var(--bg);
  color: var(--t1);
  font-family: var(--sans);
  min-height: 100vh;
  transition: background .25s, color .25s;
  /* Safe area for notched devices (iPhone X+) */
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

.app {
  max-width: 1440px;
  margin: 0 auto;
  padding: 0.75rem 1rem 2rem;
}

/* -- HEADER ------------------------------------------------------------- */
.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}

.header-brand .brand-logo {
  height: 34px;
  width: auto;
}

/* Global risk tolerance in header */
.header-risk-tol {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-left: 0.5rem;
  padding-left: 0.75rem;
  border-left: 1px solid var(--bdr);
}
.header-risk-label {
  font-size: 0.72rem;
  font-family: var(--mono);
  font-weight: 500;
  color: var(--t3);
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* -- BUTTONS & CONTROLS ------------------------------------------------- */
.btn {
  background: var(--bg-elev);
  color: var(--t2);
  border: 1px solid var(--bdr);
  border-radius: var(--r-sm);
  padding: 0.35rem 0.65rem;
  font-size: 0.75rem;
  font-family: var(--mono);
  cursor: pointer;
  transition: all .15s;
}
.btn:hover {
  border-color: var(--bdr-a);
  color: var(--t1);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--t3);
  display: inline-block;
  margin-right: 4px;
}
.status-dot.live {
  background: var(--go);
  box-shadow: 0 0 6px var(--go);
}
.status-dot.error { background: var(--nogo); }

/* Toggle switch */
.toggle-track {
  width: 32px;
  height: 18px;
  border-radius: 9px;
  background: var(--bg-input);
  border: 1px solid var(--bdr);
  cursor: pointer;
  position: relative;
  transition: background .2s;
}
.toggle-track.on {
  background: rgba(52,211,153,.25);
  border-color: var(--go);
}
.toggle-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--t3);
  position: absolute;
  top: 1px;
  left: 1px;
  transition: all .2s;
}
.toggle-track.on .toggle-thumb {
  left: 15px;
  background: var(--go);
}

/* Theme toggle button */
.theme-btn {
  background: var(--bg-elev);
  border: 1px solid var(--bdr);
  border-radius: var(--r-sm);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  transition: all .15s;
}
.theme-btn:hover { border-color: var(--bdr-a); }

/* -- ERROR BANNER ------------------------------------------------------- */
.error-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  background: var(--nogo);
  color: #fff;
  text-align: center;
  padding: 0.5rem;
  padding-top: calc(0.5rem + env(safe-area-inset-top));
  font-size: 0.8rem;
  font-weight: 600;
  z-index: 100;
  transform: translateY(-100%);
  transition: transform .3s;
}
.error-banner.show { transform: translateY(0); }

/* -- REGIME BAR --------------------------------------------------------- */
.regime-bar {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
  padding: 0.45rem 0.7rem;
  background: var(--bg-card);
  border: 1px solid var(--bdr);
  border-radius: var(--r);
}

.regime-badge {
  font-size: 0.78rem;
  font-family: var(--mono);
  color: var(--t2);
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.regime-badge .label {
  color: var(--t3);
  text-transform: uppercase;
  font-size: 0.65rem;
  letter-spacing: 0.05em;
}

/* -- ASSET SELECTOR -- max 3 rows ---------------------------------------- */
.asset-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 3px;
  margin-bottom: 0.5rem;
  padding: 0.35rem;
  background: var(--bg-card);
  border: 1px solid var(--bdr);
  border-radius: var(--r);
  max-height: calc(3 * 2.2rem + 0.7rem + 6px);
  overflow: hidden;
}

.asset-chip {
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.32rem 0.5rem;
  background: var(--bg-input);
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: 0.72rem;
  font-family: var(--mono);
  color: var(--t2);
  transition: all .15s;
  display: flex;
  align-items: center;
  gap: 4px;
  justify-content: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  height: 2.2rem;
}
.asset-chip:hover { border-color: var(--bdr-a); color: var(--t1); }
.asset-chip.selected {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--t1);
}

.asset-chip .price-tag { color: var(--t3); font-size: 0.65rem; }
.asset-chip .change-tag { font-size: 0.65rem; font-weight: 600; }
.asset-chip .change-tag.up { color: var(--go); }
.asset-chip .change-tag.down { color: var(--nogo); }

/* Dual status dots (spot + perps) */
.chip-dots { display: flex; gap: 2px; align-items: center; }
.chip-dot { width: 6px; height: 6px; border-radius: 50%; }

/* -- SUMMARY BAR -------------------------------------------------------- */
/* -- RISK CONTROLS ------------------------------------------------------ */
.risk-controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
  padding: 0.45rem 0.7rem;
  background: var(--bg-card);
  border: 1px solid var(--bdr);
  border-radius: var(--r);
}

.risk-control {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  color: var(--t2);
}
.risk-control label { color: var(--label-text); font-weight: 500; }
.risk-control select {
  background: var(--bg-input);
  border: 1px solid var(--bdr);
  border-radius: var(--r-sm);
  color: var(--t1);
  padding: 0.28rem 0.45rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  width: 80px;
  cursor: pointer;
}

/* Risk tolerance button group (used by header Risk: LOW/MED/HIGH) */
.risk-tol-group {
  display: inline-flex;
  gap: 0;
  border: 1px solid var(--bdr);
  border-radius: var(--r-sm);
  overflow: hidden;
}
.risk-tol-btn {
  padding: 0.22rem 0.55rem;
  font-size: 0.68rem;
  font-family: var(--mono);
  font-weight: 600;
  background: var(--bg-input);
  color: var(--t3);
  cursor: pointer;
  border: none;
  border-right: 1px solid var(--bdr);
  transition: all .15s;
}
.risk-tol-btn:last-child { border-right: none; }
.risk-tol-btn:hover { color: var(--t1); background: var(--bg-hover); }
.risk-tol-btn.active {
  color: var(--t1);
  background: var(--accent-dim);
  box-shadow: inset 0 0 0 1px var(--accent);
}

/* -- MAIN GRID ---------------------------------------------------------- */
.main-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.loading-overlay {
  grid-column: 1 / -1;
  text-align: center;
  padding: 3rem;
  color: var(--t3);
  font-size: 0.95rem;
}

/* -- DECISION CARD ------------------------------------------------------ */
.decision-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--bdr);
  border-radius: var(--r-lg);
  padding: 1rem 1.1rem;
}
.decision-card.go     { border-color: var(--go-bdr);      background: var(--go-bg); }
.decision-card.starter{ border-color: var(--starter-bdr);  background: var(--starter-bg); }
.decision-card.nogo   { border-color: var(--nogo-bdr);     background: var(--nogo-bg); }

.card-sparkline {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
  border-radius: var(--r-lg);
}
.card-sparkline svg { width: 100%; height: 100%; }
.card-content { position: relative; z-index: 1; }

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 0.5rem;
}

.card-header-left {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}

.token-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
}

.token-icon-fallback {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-input);
  border: 1px solid var(--bdr);
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--t3);
  font-family: var(--mono);
}

.card-header-text {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.card-type-link {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--t1);
  text-decoration: underline;
  text-decoration-color: var(--t4);
  text-underline-offset: 2px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  transition: color .15s;
}
.card-type-link:hover { color: var(--accent); text-decoration-color: var(--accent); }

.card-type-sep {
  font-size: 0.78rem;
  color: var(--t4);
  margin: 0 0.2rem;
}

.card-type {
  font-size: 0.78rem;
  color: var(--t3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.token-links {
  display: flex;
  gap: 0.5rem;
  line-height: 1;
}

.token-link {
  font-size: 0.62rem;
  color: var(--t4);
  text-decoration: none;
  transition: color .15s;
  font-weight: 500;
}
.token-link:hover { color: var(--accent); text-decoration: underline; }

.card-confidence {
  font-size: 0.75rem;
  color: var(--t3);
  font-family: var(--mono);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.decision-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
  flex-wrap: wrap;
}

.decision-badge {
  font-family: var(--sans);
  font-weight: 800;
  font-size: 1.7rem;
  letter-spacing: -0.04em;
}
.decision-badge.go      { color: var(--go); }
.decision-badge.starter { color: var(--starter); }
.decision-badge.nogo    { color: var(--nogo); }

.bias-badge {
  padding: 0.18rem 0.5rem;
  border-radius: 100px;
  font-size: 0.72rem;
  font-weight: 600;
  border: 1px solid;
}
.bias-badge.long    { color: var(--long);    border-color: rgba(52,211,153,.3); }
.bias-badge.short   { color: var(--short);   border-color: rgba(255,107,107,.3); }
.bias-badge.neutral { color: var(--neutral); border-color: rgba(107,114,128,.3); }
.bias-badge.pumping { color: var(--nogo);    border-color: rgba(255,107,107,.3); }
.bias-badge.dumping { color: var(--go);      border-color: rgba(52,211,153,.3); }
.bias-badge.chop    { color: var(--starter); border-color: rgba(255,169,77,.3); }

.leverage-caution {
  font-size: 0.72rem;
  color: var(--t3);
  font-family: var(--mono);
}

/* -- SCORE GRID --------------------------------------------------------- */
.score-grid {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 0.5rem;
}
.score-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.25rem 0;
  font-size: 0.8rem;
}
.score-label { color: var(--label-text); flex: 1; }
.score-value {
  color: var(--card-text);
  font-family: var(--mono);
  text-align: right;
  margin-right: 0.4rem;
}
.score-value.unavailable { color: var(--t4); font-style: italic; }

.score-pip { display: flex; gap: 2px; }
.pip {
  width: 9px;
  height: 9px;
  border-radius: 2px;
  background: var(--bg-input);
  border: 1px solid var(--bdr);
}
.pip.pos { background: var(--go);   border-color: var(--go); }
.pip.neg { background: var(--nogo); border-color: var(--nogo); }

/* -- DRIVERS & INVALIDATIONS -------------------------------------------- */
.drivers { margin-bottom: 0.4rem; }
.drivers-title {
  font-size: 0.68rem;
  text-transform: uppercase;
  color: var(--t3);
  letter-spacing: 0.06em;
  margin-bottom: 0.25rem;
  font-weight: 600;
}
.driver-item {
  font-size: 0.78rem;
  color: var(--label-text);
  font-family: var(--mono);
  padding: 0.12rem 0;
}
.driver-item::before { content: "\2013  "; color: var(--t4); }

.invalidations {
  border-top: 1px solid var(--bdr);
  padding-top: 0.4rem;
  margin-top: 0.3rem;
}
.invalidation-item {
  font-size: 0.78rem;
  color: var(--starter);
  font-family: var(--mono);
  padding: 0.12rem 0;
}
.invalidation-item::before { content: "! "; }

/* -- SQUEEZE DOT -------------------------------------------------------- */
.squeeze-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}
.squeeze-dot.low    { background: var(--sq-low); }
.squeeze-dot.medium { background: var(--sq-med); }
.squeeze-dot.high   { background: var(--sq-hi); }

/* -- BOTTOM PANELS ------------------------------------------------------ */
.bottom-panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.panel {
  background: var(--bg-card);
  border: 1px solid var(--bdr);
  border-radius: var(--r-lg);
  padding: 0.8rem 1rem;
}

.panel-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--t3);
  font-weight: 600;
  margin-bottom: 0.5rem;
}

/* Squeeze panel */
.squeeze-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.18rem 0;
  font-size: 0.82rem;
  font-family: var(--mono);
}
.squeeze-sym { color: var(--label-text); width: 44px; }

/* Relative strength */
.relstr-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.18rem 0;
  font-size: 0.78rem;
  font-family: var(--mono);
}
.relstr-sym { color: var(--label-text); width: 44px; }
.relstr-bar {
  flex: 1;
  height: 10px;
  background: var(--bg-input);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
}
.relstr-fill {
  height: 100%;
  border-radius: 3px;
  position: absolute;
  top: 0;
}
.relstr-fill.pos { background: var(--go);   right: 50%; }
.relstr-fill.neg { background: var(--nogo); left: 50%; }
.relstr-val { width: 54px; text-align: right; font-size: 0.75rem; }

/* -- HEATMAP ------------------------------------------------------------ */
.heatmap-section { margin-bottom: 0.75rem; }
.heatmap-grid { display: grid; gap: 3px; }
.heatmap-cell {
  padding: 0.4rem 0.2rem;
  border-radius: var(--r-sm);
  text-align: center;
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform .1s, opacity .1s;
  min-width: 0;
}
.heatmap-cell:hover { transform: scale(1.05); opacity: 0.9; }
.hm-sym { font-weight: 700; font-size: 0.78rem; }
.hm-change { font-size: 0.65rem; opacity: 0.85; }

/* -- DEBUG DRAWER ------------------------------------------------------- */
.debug-drawer {
  margin-bottom: 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--bdr);
  border-radius: var(--r-lg);
  overflow: hidden;
}
.debug-header {
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.debug-title { font-size: 0.75rem; font-weight: 600; color: var(--t2); }
.debug-body { padding: 0 0.75rem 0.75rem; }
.debug-json {
  background: var(--bg-input);
  border-radius: var(--r-sm);
  padding: 0.5rem;
  font-family: var(--mono);
  font-size: 0.65rem;
  color: var(--t3);
  max-height: 300px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-all;
}
.debug-actions { display: flex; gap: 0.5rem; margin-top: 0.5rem; }

/* -- ATTRIBUTION BAR ---------------------------------------------------- */
.attribution-bar {
  padding: 0.35rem 0.75rem;
  font-size: 0.65rem;
  color: var(--t4);
  text-align: center;
  border-top: 1px solid var(--card-border);
  line-height: 1.5;
}
.attr-label { font-weight: 600; color: var(--t3); }
.attr-source { color: var(--t3); }
.attr-license {
  display: inline-block;
  padding: 0.05rem 0.35rem;
  border-radius: 3px;
  background: var(--bg2);
  color: var(--t4);
  font-weight: 600;
  font-size: 0.6rem;
  margin-left: 0.3rem;
  vertical-align: middle;
}
.attr-license.commercial { background: var(--accent); color: #fff; }

/* -- PROVIDER HEALTH (debug drawer) ------------------------------------- */
.debug-provider-health {
  margin-bottom: 0.75rem;
  padding: 0.5rem;
  background: var(--bg2);
  border-radius: 6px;
  font-size: 0.7rem;
}
.ph-header {
  font-weight: 700;
  font-size: 0.75rem;
  color: var(--t2);
  margin-bottom: 0.35rem;
}
.ph-tier {
  display: inline-block;
  padding: 0.05rem 0.4rem;
  border-radius: 3px;
  background: var(--accent);
  color: #fff;
  font-size: 0.6rem;
  margin-left: 0.3rem;
  vertical-align: middle;
}
.ph-grid { display: flex; flex-direction: column; gap: 0.15rem; }
.ph-row { color: var(--t3); }
.ph-name { font-weight: 600; color: var(--t2); }
.ph-active { margin-bottom: 0.3rem; color: var(--t3); font-size: 0.68rem; }
.ph-active code { background: var(--bg1); padding: 0.1rem 0.3rem; border-radius: 3px; font-size: 0.65rem; }
.ph-sources { margin-top: 0.35rem; color: var(--t4); font-size: 0.65rem; }

/* -- TOAST -------------------------------------------------------------- */
.copy-toast {
  position: fixed;
  bottom: calc(1rem + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(60px);
  background: var(--accent);
  color: #fff;
  padding: 0.4rem 1rem;
  border-radius: 100px;
  font-size: 0.8rem;
  font-weight: 600;
  transition: transform .3s;
  z-index: 200;
  pointer-events: none;
}
.copy-toast.show { transform: translateX(-50%) translateY(0); }

/* -- MISC --------------------------------------------------------------- */
.no-deriv {
  font-size: 0.75rem;
  color: var(--t4);
  font-style: italic;
  text-align: center;
  padding: 1rem;
}

/* -- DISCLAIMER MODAL --------------------------------------------------- */
.disclaimer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(0,0,0,.15);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  justify-content: center;
  align-items: center;
  padding: 1rem;
}
.disclaimer-backdrop.show {
  display: flex;
}
.disclaimer-modal {
  background: var(--bg-card);
  border: 1px solid var(--bdr);
  border-radius: var(--r-lg);
  max-width: 560px;
  width: 100%;
  padding: 2rem 2rem 1.5rem;
  box-shadow: 0 12px 48px rgba(0,0,0,.5);
  animation: modalSlide .25s ease-out;
  max-height: 90vh;
  overflow-y: auto;
}
@keyframes modalSlide {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
.disclaimer-icon {
  font-size: 2.5rem;
  text-align: center;
  margin-bottom: 0.5rem;
  filter: saturate(1.5);
}
.disclaimer-title {
  font-family: var(--sans);
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--t1);
  text-align: center;
  margin: 0 0 1rem;
}
.disclaimer-body {
  font-family: var(--sans);
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--t2);
}
.disclaimer-body p {
  margin: 0 0 0.6rem;
}
.disclaimer-body strong {
  color: var(--t1);
}
.disclaimer-checks {
  margin: 1.2rem 0 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.disclaimer-check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-family: var(--sans);
  font-size: 0.82rem;
  color: var(--t2);
  cursor: pointer;
}
.disclaimer-check input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}
.disclaimer-btn {
  display: block;
  width: 100%;
  padding: 0.7rem;
  border: none;
  border-radius: var(--r-sm);
  background: var(--accent);
  color: #fff;
  font-family: var(--sans);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, filter .15s;
}
.disclaimer-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  filter: grayscale(0.5);
}
.disclaimer-btn:not(:disabled):hover {
  filter: brightness(1.15);
}

/* -- COOKIE CONSENT BANNER ---------------------------------------------- */
.cookie-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 9998;
  background: var(--bg-card);
  border-top: 2px solid var(--accent);
  padding: 1.5rem 2rem;
  padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 40px rgba(0,0,0,.5);
  animation: cookieSlide .3s ease-out;
}
@keyframes cookieSlide {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}
.cookie-inner {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 1.2rem;
}
.cookie-icon {
  font-size: 2rem;
  flex-shrink: 0;
}
.cookie-text {
  flex: 1;
  font-family: var(--sans);
  font-size: 0.85rem;
  line-height: 1.6;
  color: var(--t2);
}
.cookie-text strong {
  color: var(--t1);
  font-size: 0.95rem;
}
.cookie-detail {
  margin-top: 0.5rem;
  font-size: 0.78rem;
  color: var(--t3);
}
.cookie-detail b {
  color: var(--t2);
}
.cookie-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex-shrink: 0;
  min-width: 160px;
}
.cookie-btn {
  padding: 0.55rem 1.2rem;
  border: 1px solid var(--bdr);
  border-radius: var(--r-sm);
  font-family: var(--sans);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
  text-align: center;
}
.cookie-btn.accept {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.cookie-btn.accept:hover { filter: brightness(1.15); }
.cookie-btn.decline {
  background: transparent;
  color: var(--t2);
}
.cookie-btn.decline:hover {
  background: var(--bg-elev);
  color: var(--t1);
}
@media (max-width: 600px) {
  .cookie-banner { padding: 1rem; }
  .cookie-inner { flex-direction: column; text-align: center; }
  .cookie-actions { width: 100%; flex-direction: row; justify-content: center; }
  .cookie-icon { display: none; }
}

/* -- CHART MODAL -------------------------------------------------------- */
.chart-modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  z-index: 2000;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
[data-theme="light"] .chart-modal-backdrop {
  background: rgba(0, 0, 0, 0.45);
}
.chart-modal-backdrop.open {
  display: flex;
}

.chart-modal {
  background: var(--bg-card);
  border: 1px solid var(--bdr);
  border-radius: var(--r-lg);
  width: 100%;
  max-width: 960px;
  height: 90vh;
  max-height: 900px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

.chart-modal-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--bdr);
  flex-shrink: 0;
}

.chart-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--t1);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.chart-legend {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  flex: 1;
  font-size: 0.68rem;
  font-family: var(--mono);
  color: var(--t3);
}

.chart-legend-item {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.chart-legend-swatch {
  width: 10px;
  height: 3px;
  border-radius: 1px;
  flex-shrink: 0;
}

.chart-close-btn {
  background: none;
  border: 1px solid var(--bdr);
  border-radius: var(--r-sm);
  color: var(--t2);
  font-size: 1.2rem;
  width: 32px;
  height: 32px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all .15s;
  flex-shrink: 0;
  margin-left: auto;
}
.chart-close-btn:hover { color: var(--t1); border-color: var(--t3); }

.chart-body {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
}

.chart-pane {
  position: relative;
  width: 100%;
}
.chart-pane-label {
  position: absolute;
  top: 6px;
  left: 10px;
  z-index: 10;
  font-size: 0.68rem;
  font-weight: 600;
  font-family: var(--mono);
  color: var(--t3);
  background: var(--bg-card);
  opacity: 0.85;
  padding: 1px 6px;
  border-radius: 3px;
  pointer-events: none;
}
.chart-pane-separator {
  height: 1px;
  background: var(--bdr);
  flex-shrink: 0;
}

/* Open Plot button — prominent, brand green */
.open-plot-btn {
  font-size: 0.72rem;
  font-family: var(--mono);
  font-weight: 600;
  color: var(--go);
  background: rgba(52,211,153,.08);
  border: 1px solid rgba(52,211,153,.3);
  border-radius: var(--r-sm);
  padding: 0.25rem 0.6rem;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
  letter-spacing: 0.02em;
}
.open-plot-btn:hover { background: rgba(52,211,153,.15); border-color: var(--go); }

/* -- RESPONSIVE --------------------------------------------------------- */

/* === TABLET (max 900px) ================================================ */
@media (max-width: 900px) {
  .main-grid, .bottom-panels { grid-template-columns: 1fr; }

  /* Header: stack brand row + controls row */
  .header {
    flex-direction: column;
    align-items: stretch;
    gap: 0.4rem;
  }
  .header-brand {
    justify-content: space-between;
  }
  .header-controls {
    justify-content: flex-end;
  }

  /* Regime bar: 2x2 grid instead of 4-across */
  .regime-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.35rem 0.75rem;
  }

  /* Risk controls: wrap more aggressively */
  .risk-controls {
    gap: 0.5rem 0.75rem;
  }
}

/* === PHONE (max 600px) ================================================= */
@media (max-width: 600px) {
  html { font-size: 13.5px; }
  .app { padding: 0.5rem; }

  /* Header: compact */
  .header-brand {
    font-size: 1rem;
    flex-wrap: wrap;
    gap: 0.35rem;
  }
  .header-brand .brand-logo {
    height: 28px;
  }
  .header-risk-tol {
    margin-left: 0;
    padding-left: 0;
    border-left: none;
  }
  .header-controls {
    gap: 0.35rem;
    flex-wrap: wrap;
  }
  .header-controls .btn {
    padding: 0.25rem 0.4rem;
    font-size: 0.7rem;
  }
  .theme-btn {
    width: 28px;
    height: 28px;
    font-size: 0.85rem;
  }

  /* Regime bar */
  .regime-bar {
    padding: 0.35rem 0.5rem;
    gap: 0.25rem 0.5rem;
  }
  .regime-badge { font-size: 0.72rem; }
  .regime-badge .label { font-size: 0.58rem; }

  /* Asset chips */
  .asset-selector {
    gap: 2px;
    padding: 0.25rem;
    max-height: none; /* Allow full expansion on mobile for scrollability */
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
  }
  .asset-chip {
    padding: 0.2rem 0.35rem;
    font-size: 0.65rem;
    height: 1.9rem;
    gap: 3px;
  }
  .asset-chip .price-tag { font-size: 0.58rem; }
  .asset-chip .change-tag { font-size: 0.58rem; }
  .chip-dot { width: 5px; height: 5px; }

  /* Risk controls: stack vertically */
  .risk-controls {
    flex-direction: column;
    align-items: stretch;
    gap: 0.4rem;
    padding: 0.4rem 0.6rem;
  }
  .risk-control {
    width: 100%;
    justify-content: space-between;
  }
  .risk-control select { width: auto; flex: 1; max-width: 120px; }

  /* Chart modal: full screen on phone */
  .chart-modal-backdrop { padding: 0.5rem; }
  .chart-modal { max-height: 95vh; }
  .chart-modal-header { padding: 0.5rem 0.75rem; gap: 0.4rem; flex-wrap: wrap; }
  .chart-title { font-size: 0.75rem; }
  .chart-legend { font-size: 0.6rem; gap: 0.4rem; }

  /* iOS auto-zoom fix: inputs below 16px trigger Safari zoom-on-focus */
  input, select, textarea {
    font-size: 16px !important;
  }

  /* Decision cards */
  .decision-card {
    padding: 0.75rem 0.8rem;
  }
  .card-header {
    flex-direction: column;
    gap: 0.2rem;
    margin-bottom: 0.35rem;
  }
  .card-header-left { gap: 0.4rem; }
  .token-icon { width: 26px; height: 26px; }
  .card-type-link { font-size: 0.75rem; }
  .card-type { font-size: 0.72rem; }
  .card-confidence { font-size: 0.68rem; }
  .decision-badge { font-size: 1.35rem; }
  .bias-badge { font-size: 0.65rem; padding: 0.14rem 0.4rem; }
  .leverage-caution { font-size: 0.65rem; }

  /* Score grid: tighter layout */
  .score-row {
    font-size: 0.72rem;
    padding: 0.18rem 0;
    gap: 0.25rem;
  }
  .score-label { font-size: 0.68rem; min-width: 0; }
  .score-value { font-size: 0.68rem; margin-right: 0.25rem; }
  .pip { width: 7px; height: 7px; }

  /* Drivers & invalidations */
  .driver-item { font-size: 0.7rem; }
  .invalidation-item { font-size: 0.7rem; }
  .drivers-title { font-size: 0.62rem; }

  /* Bottom panels */
  .panel {
    padding: 0.6rem 0.75rem;
  }
  .panel-title { font-size: 0.7rem; }
  .squeeze-row { font-size: 0.75rem; gap: 0.35rem; }
  .squeeze-sym { width: 38px; }
  .relstr-row { font-size: 0.72rem; gap: 0.3rem; }
  .relstr-sym { width: 38px; }
  .relstr-val { width: 48px; font-size: 0.68rem; }

  /* Heatmap: force fewer columns on mobile */
  .heatmap-grid {
    grid-template-columns: repeat(4, 1fr) !important;
  }
  .heatmap-cell {
    padding: 0.3rem 0.15rem;
    font-size: 0.65rem;
  }
  .hm-sym { font-size: 0.7rem; }
  .hm-change { font-size: 0.58rem; }

  /* Debug drawer */
  .debug-json {
    font-size: 0.58rem;
    max-height: 200px;
  }

  /* Tutorial tooltip: constrain to viewport */
  .tutorial-tooltip {
    max-width: calc(100vw - 2rem);
    min-width: 200px;
  }
  .tutorial-tooltip-body {
    font-size: 0.72rem;
    max-height: 280px;
  }
  .tutorial-tooltip-body code {
    font-size: 0.65rem;
  }
  .tutorial-badge {
    width: 12px;
    height: 12px;
    font-size: 8px;
  }

  /* Disclaimer modal */
  .disclaimer-modal {
    padding: 1.2rem 1rem 1rem;
  }
  .disclaimer-icon { font-size: 2rem; }
  .disclaimer-title { font-size: 1.1rem; }
  .disclaimer-body { font-size: 0.78rem; }
}

/* === SMALL PHONE (max 480px) =========================================== */
@media (max-width: 480px) {
  html { font-size: 12.5px; }

  .header-brand {
    font-size: 0.9rem;
  }
  .header-brand .brand-logo {
    height: 24px;
  }
  .header-risk-tol {
    width: 100%;
    justify-content: flex-start;
    margin-top: 0.15rem;
  }

  /* Regime bar: single column */
  .regime-bar {
    grid-template-columns: 1fr;
    gap: 0.2rem;
  }

  /* Asset chips: smaller still, allow horizontal scroll */
  .asset-selector {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 3px;
    padding-bottom: 0.4rem;
    scroll-snap-type: x mandatory;
    max-height: none;
  }
  .asset-chip {
    flex: 0 0 auto;
    min-width: 60px;
    scroll-snap-align: start;
  }

  /* Decision badge even smaller */
  .decision-badge { font-size: 1.15rem; }
  .decision-row { gap: 0.3rem; }

  /* Score grid: abbreviate */
  .score-row { font-size: 0.65rem; }
  .score-label { font-size: 0.62rem; }
  .score-value { font-size: 0.62rem; }
  .pip { width: 6px; height: 6px; }

  /* Heatmap: 3 columns */
  .heatmap-grid {
    grid-template-columns: repeat(3, 1fr) !important;
  }

  /* Risk controls labels */
  .risk-control label { font-size: 0.68rem; }
  .risk-tol-btn { padding: 0.18rem 0.4rem; font-size: 0.62rem; }

  /* Cookie banner: full stack */
  .cookie-banner { padding: 0.75rem; }
  .cookie-inner {
    flex-direction: column;
    text-align: center;
    gap: 0.8rem;
  }
  .cookie-actions {
    width: 100%;
    flex-direction: column;
    gap: 0.35rem;
  }
  .cookie-icon { display: none; }
  .cookie-text { font-size: 0.78rem; }
  .cookie-detail { font-size: 0.72rem; }
}

/* === TOUCH HELPERS ====================================================== */
@media (hover: none) {
  /* Larger tap targets on touch devices */
  .asset-chip { min-height: 2rem; }
  .btn { min-height: 32px; min-width: 32px; }
  .risk-tol-btn { min-height: 28px; }
  .heatmap-cell { min-height: 40px; }
  .toggle-track { min-width: 30px; min-height: 16px; }
  .tutorial-badge { width: 18px; height: 18px; font-size: 10px; }
  .cookie-btn { min-height: 40px; }

  /* Remove hover-only effects */
  .heatmap-cell:hover { transform: none; opacity: 1; }
  .asset-chip:hover { border-color: transparent; }
}

/* === LANDSCAPE PHONE =================================================== */
@media (max-height: 500px) and (orientation: landscape) {
  .disclaimer-modal {
    max-height: 85vh;
    padding: 0.8rem 1rem;
  }
  .disclaimer-icon { font-size: 1.5rem; margin-bottom: 0.2rem; }
  .disclaimer-title { font-size: 1rem; margin-bottom: 0.5rem; }
  .disclaimer-body { font-size: 0.75rem; line-height: 1.4; }
  .disclaimer-body p { margin-bottom: 0.3rem; }
}
