:root {
  --bg: #0f1117;
  --bg2: #161b27;
  --bg3: #1e2535;
  --border: #2a3045;
  --text: #e2e8f0;
  --text2: #8892a4;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --green: #22c55e;
  --green-bg: rgba(34,197,94,0.12);
  --red: #ef4444;
  --red-bg: rgba(239,68,68,0.12);
  --yellow: #f59e0b;
  --yellow-bg: rgba(245,158,11,0.12);
  --radius: 10px;
  --shadow: 0 4px 24px rgba(0,0,0,0.35);
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  height: 100vh;
  overflow: hidden;
}

#app {
  display: flex;
  height: 100vh;
}

/* ---- SIDEBAR ---- */
.sidebar {
  width: 220px;
  min-width: 220px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 0 0 16px;
  overflow-y: auto;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px 16px;
  border-bottom: 1px solid var(--border);
}
.logo-icon { font-size: 22px; }
.logo-text { font-size: 16px; font-weight: 700; color: var(--text); }

.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; }
.nav-btn {
  display: flex; align-items: center; gap: 10px;
  background: none; border: none; color: var(--text2);
  padding: 9px 10px; border-radius: 8px; cursor: pointer;
  font-size: 13.5px; text-align: left; width: 100%;
  transition: all .15s;
}
.nav-btn svg { width: 18px; height: 18px; fill: currentColor; flex-shrink: 0; }
.nav-btn:hover { background: var(--bg3); color: var(--text); }
.nav-btn.active { background: rgba(59,130,246,0.18); color: var(--accent); }

.sidebar-section-title {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .08em; color: var(--text2); padding: 12px 18px 6px;
}

#sidebar-tickers { padding: 0 10px; display: flex; flex-direction: column; gap: 2px; }

.sidebar-ticker {
  display: flex; justify-content: space-between; align-items: center;
  padding: 7px 8px; border-radius: 7px; cursor: pointer;
  transition: background .12s;
}
.sidebar-ticker:hover { background: var(--bg3); }
.sidebar-ticker .sym { font-weight: 600; font-size: 13px; }
.sidebar-ticker .chg { font-size: 12px; font-weight: 500; }

/* ---- MAIN ---- */
.main {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px; border-bottom: 1px solid var(--border);
  background: var(--bg2); gap: 16px; flex-shrink: 0;
}

.search-wrap { display: flex; gap: 8px; flex: 1; max-width: 500px; }
.search-wrap input {
  flex: 1; background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); padding: 8px 14px; border-radius: 8px;
  font-size: 14px; outline: none;
  transition: border-color .15s;
}
.search-wrap input:focus { border-color: var(--accent); }
.search-wrap button, .screener-btn, #watchlist-add-btn {
  background: var(--accent); color: #fff; border: none;
  padding: 8px 18px; border-radius: 8px; cursor: pointer;
  font-size: 14px; font-weight: 600; transition: background .15s;
}
.search-wrap button:hover, .screener-btn:hover, #watchlist-add-btn:hover {
  background: var(--accent-hover);
}

.topbar-right { display: flex; align-items: center; gap: 16px; }
.market-status { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 20px; }
.market-open { background: var(--green-bg); color: var(--green); }
.market-closed { background: var(--red-bg); color: var(--red); }
.current-time { color: var(--text2); font-size: 13px; }

/* ---- PAGES ---- */
.page { display: none; flex: 1; overflow-y: auto; padding: 24px; }
.page.active { display: block; }
.page-title { font-size: 20px; font-weight: 700; margin-bottom: 20px; }

/* ---- INDICES ---- */
.indices-row {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 24px;
}
.index-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.index-card .idx-name { font-size: 12px; color: var(--text2); margin-bottom: 4px; }
.index-card .idx-price { font-size: 18px; font-weight: 700; margin-bottom: 2px; }
.index-card .idx-chg { font-size: 13px; font-weight: 500; }
.skeleton { min-height: 80px; animation: pulse 1.5s infinite; }
@keyframes pulse {
  0%,100% { opacity: .5; }
  50% { opacity: .25; }
}

/* ---- FEATURED SIGNAL ---- */
.featured-signal {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin-bottom: 24px;
}
.featured-inner {
  display: grid; grid-template-columns: 1fr auto; gap: 20px; align-items: center;
}
.featured-ticker { font-size: 28px; font-weight: 800; }
.featured-price { font-size: 22px; font-weight: 600; margin-top: 2px; }
.featured-desc { color: var(--text2); font-size: 13px; margin-top: 6px; }

.signal-badge {
  font-size: 18px; font-weight: 800; padding: 14px 24px;
  border-radius: 10px; text-align: center; min-width: 140px;
}
.strong-buy { background: rgba(34,197,94,0.2); color: #4ade80; border: 1.5px solid rgba(34,197,94,0.4); }
.buy { background: rgba(34,197,94,0.12); color: #86efac; border: 1.5px solid rgba(34,197,94,0.25); }
.sell { background: rgba(239,68,68,0.12); color: #fca5a5; border: 1.5px solid rgba(239,68,68,0.25); }
.strong-sell { background: rgba(239,68,68,0.2); color: #f87171; border: 1.5px solid rgba(239,68,68,0.4); }
.neutral { background: rgba(245,158,11,0.12); color: #fcd34d; border: 1.5px solid rgba(245,158,11,0.25); }

/* ---- TWO COL ---- */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

.section-title {
  font-size: 14px; font-weight: 700; color: var(--text2);
  text-transform: uppercase; letter-spacing: .06em; margin-bottom: 12px;
}

.movers-list {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
}
.mover-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 11px 16px; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background .12s;
}
.mover-row:last-child { border-bottom: none; }
.mover-row:hover { background: var(--bg3); }
.mover-sym { font-weight: 700; font-size: 14px; }
.mover-name { font-size: 12px; color: var(--text2); }
.mover-price { font-size: 14px; font-weight: 600; }
.mover-chg { font-size: 13px; font-weight: 600; padding: 2px 8px; border-radius: 5px; }
.up { color: var(--green); background: var(--green-bg); }
.down { color: var(--red); background: var(--red-bg); }

/* ---- ANALYSIS ---- */
.quote-bar {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 20px; margin-bottom: 16px;
}
.q-ticker { font-size: 22px; font-weight: 800; }
.q-price { font-size: 22px; font-weight: 700; }
.q-change { font-size: 15px; font-weight: 600; padding: 2px 10px; border-radius: 6px; }
.q-meta { color: var(--text2); font-size: 13px; }

.period-row {
  display: flex; align-items: center; gap: 6px; margin-bottom: 12px; flex-wrap: wrap;
}
.period-btn {
  background: var(--bg3); border: 1px solid var(--border); color: var(--text2);
  padding: 5px 14px; border-radius: 6px; cursor: pointer; font-size: 13px;
  transition: all .12s;
}
.period-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.period-btn:hover:not(.active) { border-color: var(--accent); color: var(--text); }

.overlay-toggles {
  margin-left: auto; display: flex; gap: 12px; align-items: center;
  color: var(--text2); font-size: 13px;
}
.overlay-toggles label { display: flex; align-items: center; gap: 5px; cursor: pointer; }
.overlay-toggles input[type=checkbox] { accent-color: var(--accent); }

.chart-wrap {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px; margin-bottom: 8px;
  height: 320px; position: relative;
}

/* ---- SIGNAL PANEL ---- */
.signal-summary {
  display: flex; gap: 12px; align-items: center; margin-bottom: 16px; flex-wrap: wrap;
}
.signal-overall {
  font-size: 20px; font-weight: 800; padding: 12px 22px; border-radius: 10px;
}
.signal-counts { display: flex; gap: 8px; }
.sig-count {
  display: flex; flex-direction: column; align-items: center;
  padding: 8px 16px; border-radius: 8px; font-size: 12px; font-weight: 600;
}
.sig-count .num { font-size: 20px; font-weight: 800; }
.sig-count.buy { background: var(--green-bg); color: var(--green); }
.sig-count.sell { background: var(--red-bg); color: var(--red); }
.sig-count.neutral { background: var(--yellow-bg); color: var(--yellow); }

.score-bar-wrap { flex: 1; min-width: 200px; }
.score-bar-label {
  display: flex; justify-content: space-between;
  font-size: 12px; color: var(--text2); margin-bottom: 4px;
}
.score-bar-track {
  height: 8px; background: var(--bg3); border-radius: 4px; overflow: hidden;
}
.score-bar-fill {
  height: 100%; border-radius: 4px; transition: width .5s;
}

.signals-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 10px;
}
.signal-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
  display: flex; align-items: center; gap: 12px;
}
.signal-icon {
  width: 36px; height: 36px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 800; flex-shrink: 0;
}
.signal-icon.BUY { background: var(--green-bg); color: var(--green); }
.signal-icon.SELL { background: var(--red-bg); color: var(--red); }
.signal-icon.NEUTRAL { background: var(--yellow-bg); color: var(--yellow); }
.signal-info .sig-name { font-weight: 700; font-size: 13px; margin-bottom: 2px; }
.signal-info .sig-desc { color: var(--text2); font-size: 12px; line-height: 1.4; }
.signal-badge-sm {
  margin-left: auto; padding: 3px 10px; border-radius: 5px;
  font-size: 11px; font-weight: 700; flex-shrink: 0;
}
.signal-badge-sm.BUY { background: var(--green-bg); color: var(--green); }
.signal-badge-sm.SELL { background: var(--red-bg); color: var(--red); }
.signal-badge-sm.NEUTRAL { background: var(--yellow-bg); color: var(--yellow); }

/* ---- NEWS ---- */
.news-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.news-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.news-card a { color: var(--text); text-decoration: none; font-weight: 600; font-size: 14px; }
.news-card a:hover { color: var(--accent); }
.news-meta { color: var(--text2); font-size: 12px; margin-top: 4px; }
.news-summary { color: var(--text2); font-size: 13px; margin-top: 6px; line-height: 1.5; }

/* ---- SCREENER ---- */
.screener-controls {
  display: flex; gap: 10px; margin-bottom: 20px;
}
.screener-controls input {
  flex: 1; background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); padding: 8px 14px; border-radius: 8px;
  font-size: 14px; outline: none;
}
.screener-controls input:focus { border-color: var(--accent); }
.screener-btn { padding: 8px 20px; }

.screener-table {
  width: 100%; border-collapse: collapse;
  background: var(--bg2); border-radius: var(--radius); overflow: hidden;
  border: 1px solid var(--border);
}
.screener-table th {
  background: var(--bg3); padding: 11px 14px; text-align: left;
  font-size: 12px; font-weight: 700; color: var(--text2);
  text-transform: uppercase; letter-spacing: .05em;
}
.screener-table td {
  padding: 11px 14px; border-top: 1px solid var(--border);
  font-size: 13px;
}
.screener-table tr:hover td { background: var(--bg3); cursor: pointer; }
.screener-table .sym-cell { font-weight: 700; font-size: 14px; }

/* ---- WATCHLIST ---- */
.watchlist-add {
  display: flex; gap: 10px; margin-bottom: 20px;
}
.watchlist-add input {
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); padding: 8px 14px; border-radius: 8px;
  font-size: 14px; outline: none; width: 220px;
}
.watchlist-add input:focus { border-color: var(--accent); }
.watchlist-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 12px;
}
.watchlist-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; cursor: pointer;
  transition: border-color .15s; position: relative;
}
.watchlist-card:hover { border-color: var(--accent); }
.wl-ticker { font-size: 18px; font-weight: 800; margin-bottom: 4px; }
.wl-price { font-size: 16px; font-weight: 600; }
.wl-change { font-size: 13px; margin-top: 2px; }
.wl-signal { font-size: 11px; font-weight: 700; margin-top: 8px; padding: 3px 8px; border-radius: 5px; display: inline-block; }
.wl-remove {
  position: absolute; top: 8px; right: 10px;
  background: none; border: none; color: var(--text2);
  cursor: pointer; font-size: 16px; line-height: 1;
  transition: color .12s;
}
.wl-remove:hover { color: var(--red); }

/* ---- BACKTEST ---- */
.backtest-run-btn {
  background: var(--accent); color: #fff; border: none;
  padding: 10px 22px; border-radius: 8px; cursor: pointer;
  font-size: 14px; font-weight: 600; transition: background .15s;
}
.backtest-run-btn:hover { background: var(--accent-hover); }

.bt-stats {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px; margin-bottom: 16px;
}
.bt-stat {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 12px 14px;
}
.bt-stat .bt-label { font-size: 11px; color: var(--text2); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px; }
.bt-stat .bt-value { font-size: 19px; font-weight: 800; }
.bt-verdict {
  padding: 14px 18px; border-radius: var(--radius); margin-bottom: 16px;
  font-size: 14px; font-weight: 600; line-height: 1.5;
}
.bt-verdict.good { background: var(--green-bg); color: var(--green); border: 1px solid rgba(34,197,94,0.3); }
.bt-verdict.bad { background: var(--red-bg); color: var(--red); border: 1px solid rgba(239,68,68,0.3); }

.bt-trades-table { width: 100%; border-collapse: collapse; background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-top: 12px; }
.bt-trades-table th { background: var(--bg3); padding: 8px 12px; text-align: left; font-size: 11px; color: var(--text2); text-transform: uppercase; }
.bt-trades-table td { padding: 8px 12px; border-top: 1px solid var(--border); font-size: 13px; }

/* ---- AI CHAT ---- */
.chat-layout {
  display: flex; flex-direction: column;
  height: calc(100vh - 140px); max-width: 820px;
}
.chat-messages {
  flex: 1; overflow-y: auto; display: flex; flex-direction: column;
  gap: 12px; padding: 4px 4px 16px;
}
.chat-msg { display: flex; }
.chat-msg.user { justify-content: flex-end; }
.chat-bubble {
  max-width: 80%; padding: 12px 16px; border-radius: 14px;
  font-size: 14px; line-height: 1.6; white-space: pre-wrap; word-wrap: break-word;
}
.chat-msg.assistant .chat-bubble {
  background: var(--bg2); border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.chat-msg.user .chat-bubble {
  background: var(--accent); color: #fff; border-bottom-right-radius: 4px;
}
.chat-actions {
  font-size: 11px; color: var(--text2); margin-top: 6px;
  display: flex; gap: 6px; flex-wrap: wrap;
}
.chat-action-chip {
  background: var(--bg3); border: 1px solid var(--border);
  padding: 2px 9px; border-radius: 10px;
}
.chat-input-row {
  display: flex; gap: 10px; padding-top: 12px;
  border-top: 1px solid var(--border);
}
.chat-input-row input {
  flex: 1; background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); padding: 12px 16px; border-radius: 10px;
  font-size: 14px; outline: none;
}
.chat-input-row input:focus { border-color: var(--accent); }
#chat-attach {
  background: var(--bg3) !important; border: 1px solid var(--border) !important;
  color: var(--text2) !important; padding: 12px 14px !important;
  font-size: 16px !important;
}
#chat-attach:hover { border-color: var(--accent) !important; }
.chat-image-preview {
  display: flex; align-items: center; gap: 10px; padding: 8px 0 0;
}
.chat-image-preview img {
  max-height: 70px; border-radius: 8px; border: 1px solid var(--border);
}
.chat-image-preview button {
  background: var(--bg3); border: 1px solid var(--border); color: var(--text2);
  border-radius: 6px; padding: 4px 9px; cursor: pointer; font-size: 12px;
}
.chat-image-preview button:hover { color: var(--red); }
.chat-bubble img.chat-sent-img {
  max-width: 220px; border-radius: 8px; display: block; margin-top: 6px;
}
.chat-input-row button {
  background: var(--accent); color: #fff; border: none;
  padding: 12px 26px; border-radius: 10px; cursor: pointer;
  font-size: 14px; font-weight: 600;
}
.chat-input-row button:hover { background: var(--accent-hover); }
.chat-input-row button:disabled { opacity: .5; cursor: default; }
.chat-typing { color: var(--text2); font-size: 13px; font-style: italic; }

/* ---- AGENT TEAM PANEL ---- */
.agents-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 10px; margin-top: 14px;
}
.agent-report {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.agent-report .agent-name { font-weight: 700; font-size: 13px; margin-bottom: 8px; color: var(--accent); }
.agent-report .agent-text { color: var(--text2); font-size: 12.5px; line-height: 1.6; white-space: pre-wrap; }

/* ---- AI ANALYST ---- */
.ai-card {
  background: linear-gradient(135deg, rgba(59,130,246,0.08), rgba(139,92,246,0.08));
  border: 1px solid rgba(99,102,241,0.35);
  border-radius: var(--radius); padding: 20px;
}
.ai-header { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.ai-rec {
  font-size: 17px; font-weight: 800; padding: 8px 18px; border-radius: 8px;
}
.ai-confidence {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  padding: 4px 10px; border-radius: 12px; background: var(--bg3); color: var(--text2);
}
.ai-summary { font-size: 15px; font-weight: 600; margin-bottom: 10px; line-height: 1.5; }
.ai-reasoning { color: var(--text2); font-size: 13.5px; line-height: 1.65; margin-bottom: 12px; white-space: pre-wrap; }
.ai-risk {
  background: var(--yellow-bg); border-left: 3px solid var(--yellow);
  padding: 10px 14px; border-radius: 6px; font-size: 13px; line-height: 1.5; margin-bottom: 8px;
}
.ai-position {
  background: rgba(59,130,246,0.1); border-left: 3px solid var(--accent);
  padding: 10px 14px; border-radius: 6px; font-size: 13px; line-height: 1.5;
}
.ai-meta { color: var(--text2); font-size: 11px; margin-top: 10px; }

/* ---- TRADE FORM / PORTFOLIO ---- */
.trade-form {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
}
.trade-form input, .trade-form select {
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); padding: 8px 10px; border-radius: 7px;
  font-size: 13.5px; outline: none;
}
.trade-form input:focus, .trade-form select:focus { border-color: var(--accent); }
.trade-form button {
  background: var(--accent); color: #fff; border: none;
  padding: 8px 18px; border-radius: 7px; cursor: pointer;
  font-size: 13.5px; font-weight: 600;
}
.trade-form button:hover { background: var(--accent-hover); }
#tf-side { font-weight: 700; }

.pf-table { width: 100%; border-collapse: collapse; background: var(--bg2); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.pf-table th { background: var(--bg3); padding: 10px 13px; text-align: left; font-size: 11px; color: var(--text2); text-transform: uppercase; letter-spacing: .05em; }
.pf-table td { padding: 10px 13px; border-top: 1px solid var(--border); font-size: 13px; }
.pf-table .sym-cell { font-weight: 700; font-size: 14px; cursor: pointer; }
.pf-table .sym-cell:hover { color: var(--accent); }
.pf-del { background: none; border: none; color: var(--text2); cursor: pointer; font-size: 14px; }
.pf-del:hover { color: var(--red); }
.side-badge { font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 5px; }
.side-badge.BUY { background: var(--green-bg); color: var(--green); }
.side-badge.SELL { background: var(--red-bg); color: var(--red); }

/* ---- MISC ---- */
.empty-state {
  text-align: center; padding: 60px 20px; color: var(--text2);
}
.empty-icon { font-size: 40px; margin-bottom: 12px; }
.loading-msg { color: var(--text2); padding: 20px; text-align: center; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); padding: 10px 20px; border-radius: 8px;
  font-size: 14px; opacity: 0; transition: opacity .3s;
  pointer-events: none; z-index: 1000;
}
.toast.show { opacity: 1; }

/* scrollbar */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ---- TABLET (≤1024px) ---- */
@media (max-width: 1024px) {
  .indices-row { grid-template-columns: 1fr 1fr; }
  .signals-grid { grid-template-columns: 1fr 1fr; }
  .agents-grid { grid-template-columns: 1fr; }
  .sidebar { width: 64px; min-width: 64px; }
  .logo-text, .sidebar-section-title, #sidebar-tickers, .sidebar-watchlist { display: none; }
  .nav-btn { justify-content: center; padding: 12px 0; font-size: 0; gap: 0; }
  .nav-btn svg { width: 22px; height: 22px; }
}

/* ---- PHONE (≤768px) ---- */
@media (max-width: 768px) {
  body { font-size: 13.5px; }

  /* sidebar becomes a fixed bottom tab bar */
  #app { flex-direction: column; }
  .sidebar {
    order: 2; width: 100%; min-width: 0; height: 60px;
    flex-direction: row; border-right: none; border-top: 1px solid var(--border);
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
    padding: 0; overflow: visible;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .logo { display: none; }
  .nav {
    flex-direction: row; width: 100%; padding: 0;
    justify-content: space-around; align-items: center; gap: 0;
  }
  .nav-btn { flex: 1; height: 60px; border-radius: 0; }

  .main { order: 1; height: calc(100vh - 60px); }

  /* topbar */
  .topbar { padding: 10px 12px; gap: 8px; }
  .search-wrap { max-width: none; }
  .search-wrap input { padding: 8px 10px; font-size: 16px; } /* 16px stops iOS zoom */
  .search-wrap button { padding: 8px 12px; }
  .topbar-right { display: none; }

  .page { padding: 14px 12px 80px; }
  .page-title { font-size: 17px; margin-bottom: 14px; }

  /* grids collapse */
  .indices-row { grid-template-columns: 1fr 1fr; gap: 8px; }
  .index-card { padding: 12px; }
  .two-col { grid-template-columns: 1fr; }
  .signals-grid { grid-template-columns: 1fr; }
  .bt-stats { grid-template-columns: 1fr 1fr; }
  .watchlist-grid { grid-template-columns: 1fr 1fr; }

  .featured-inner { grid-template-columns: 1fr; }
  .featured-ticker { font-size: 22px; }
  .signal-badge { font-size: 15px; padding: 10px 16px; }

  .quote-bar { gap: 10px; padding: 12px; }
  .q-ticker, .q-price { font-size: 18px; }
  .chart-wrap { height: 240px; padding: 8px; }
  .overlay-toggles { margin-left: 0; width: 100%; }

  /* tables scroll horizontally instead of overflowing */
  #screener-table-wrap, #pf-positions, #pf-realized, #pf-log, #backtest-panel {
    overflow-x: auto; -webkit-overflow-scrolling: touch;
  }
  .screener-table, .pf-table, .bt-trades-table { min-width: 520px; }

  /* chat fills the phone screen above the tab bar */
  .chat-layout { height: calc(100vh - 60px - 130px); max-width: none; }
  .chat-bubble { max-width: 90%; font-size: 14px; }
  .chat-input-row input { font-size: 16px; padding: 10px 12px; }
  .chat-input-row button { padding: 10px 16px; }

  .trade-form { gap: 6px; }
  .trade-form input, .trade-form select { font-size: 16px; }
}
