:root {
  --bg: #14161c;
  --panel: #1c1f27;
  --panel2: #232733;
  --border: #2c3140;
  --text: #e8eaf0;
  --muted: #9aa3b5;
  --c1: #4f8cff; /* categorical series 1 */
  --c2: #d96f24;
  --c3: #11a394;
  --c4: #9a6dff;
  --c5: #d84f92;
  --c6: #9d8400;
  --up: #1e9e7e;   /* status: gains / long */
  --down: #e05260; /* status: losses / short */
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column;
  /* extend into display-cutout areas (Samsung punch-hole in landscape) without
     content hiding under them */
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
}
/* the page is a bounded-height column flexbox: chrome rows must NEVER be
   flex-squeezed by tall content (overflow:auto zeroes their min-size — that
   collapsed the tab bar to 1px on phones and clipped the ticker) */
header, .ticker-strip, #tabs { flex-shrink: 0; }

header {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.brand { font-weight: 700; font-size: 16px; letter-spacing: .2px; }
.brand span { color: var(--c1); }
.controls { display: flex; gap: 8px; align-items: center; flex: 1; }
.right { display: flex; gap: 12px; align-items: center; }
.live { color: var(--muted); font-size: 12px; display: inline-flex; align-items: center; gap: 5px; }
.live .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--c3); animation: pulse 2s infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }
#status { color: var(--muted); font-size: 12px; }

select, input[type="number"], input[type="text"] {
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 8px; font-size: 13px;
}
select[multiple] { width: 100%; }
.btn {
  background: var(--panel2); color: var(--text);
  border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 14px; font-size: 13px; cursor: pointer;
}
.btn:hover { border-color: var(--c1); }
.btn.primary { background: var(--c1); border-color: var(--c1); color: #0b1020; font-weight: 600; width: 100%; margin-top: 12px; }
.btn.primary:hover { filter: brightness(1.1); }
.btn:disabled { opacity: .5; cursor: wait; }
.btn-stop, .btn.primary.btn-stop { background: var(--down); border-color: var(--down); color: #fff; }
.btn-stop:hover { filter: brightness(1.1); border-color: var(--down); }
.btn-stop:disabled { opacity: .7; cursor: wait; }

/* live prices (eToro-style ticker) */
.ticker-strip {
  display: flex; gap: 16px; overflow-x: auto; padding: 5px 16px;
  background: #101218; border-bottom: 1px solid var(--border);
  font-size: 12px; white-space: nowrap; scrollbar-width: none;
}
.ticker-strip:empty { display: none; }
.ticker-strip::-webkit-scrollbar { display: none; }
.tick-item { display: inline-flex; gap: 6px; align-items: baseline; cursor: pointer; flex: 0 0 auto; }
.tick-item .ts { color: var(--muted); }
.tick-item .tp { font-weight: 600; font-variant-numeric: tabular-nums; }
.tick-item .tc { font-variant-numeric: tabular-nums; }
.tick-item .tc.pos { color: var(--up); }
.tick-item .tc.neg { color: var(--down); }
.live-quote { font-variant-numeric: tabular-nums; font-size: 13px; }
.live-quote #lq-chg.pos { color: var(--up); }
.live-quote #lq-chg.neg { color: var(--down); }
@keyframes flash-up { 0% { background: rgba(30,158,126,.35); } 100% { background: transparent; } }
@keyframes flash-dn { 0% { background: rgba(224,82,96,.35); } 100% { background: transparent; } }
.flash-up { animation: flash-up 0.9s ease-out; }
.flash-dn { animation: flash-dn 0.9s ease-out; }

/* global market search (header) */
.gs-wrap { max-width: 340px; min-width: 170px; }
.gs-wrap input { font-size: 12.5px; }
.rs-sug .badge247 {
  font-size: 10px; padding: 1px 6px; border-radius: 8px;
  background: rgba(17,163,148,.18); color: var(--c3); border: 1px solid var(--c3);
  white-space: nowrap;
}
.mkt-state { font-size: 11.5px; display: inline-flex; align-items: center; gap: 5px; color: var(--muted); white-space: nowrap; }
.mkt-state .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.mkt-state.open .dot { background: var(--up); }
.mkt-state.always .dot { background: var(--c3); animation: pulse 2s infinite; }
.mkt-state.closed .dot { background: var(--down); }

/* portfolio scope chips */
.pf-scope { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.pf-scope .chip {
  padding: 5px 12px; border-radius: 16px; border: 1px solid var(--border);
  background: var(--panel); color: var(--muted); cursor: pointer; font-size: 12.5px;
}
.pf-scope .chip.active { background: #24314e; border-color: var(--c1); color: var(--text); }

/* Shariah tab */
.sh-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 10px; }
.sh-top label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.sh-section { margin-top: 18px; }
.sh-scan-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.sh-card { border: 1px solid var(--border); border-left-width: 3px; border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; background: var(--panel); }
.sh-card.compliant { border-left-color: var(--up); }
.sh-card.review { border-left-color: var(--c6); }
.sh-card.non_compliant { border-left-color: var(--down); }
.sh-card.unknown { border-left-color: var(--muted); }
.sh-card .sh-h { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.sh-card .sh-sym { font-weight: 700; font-size: 15px; }
.sh-card .sh-name { color: var(--muted); font-size: 12.5px; }
.sh-verdict { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; padding: 3px 9px; border-radius: 10px; margin-left: auto; }
.sh-verdict.compliant { background: rgba(30,158,126,.16); color: var(--up); }
.sh-verdict.review { background: rgba(157,132,0,.18); color: #cbb04a; }
.sh-verdict.non_compliant { background: rgba(224,82,96,.16); color: var(--down); }
.sh-verdict.unknown { background: var(--panel2); color: var(--muted); }
.sh-checks { margin-top: 8px; display: flex; flex-direction: column; gap: 4px; }
.sh-chk { font-size: 12.5px; display: flex; gap: 8px; align-items: baseline; }
.sh-chk .ic { min-width: 16px; }
.sh-chk.ok .ic { color: var(--up); }
.sh-chk.no .ic { color: var(--down); }
.sh-chk.na .ic { color: var(--muted); }
.sh-chk .lbl { min-width: 130px; color: var(--text); }
.sh-chk .dt { color: var(--muted); }
.sh-grid-head { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 12px 0 6px; }

/* system self-check results */
.sc-head { padding: 10px 14px; border-radius: 8px; font-weight: 700; margin-bottom: 10px; }
.sc-head.pass { background: rgba(30,158,126,.14); color: var(--up); border: 1px solid var(--up); }
.sc-head.fail { background: rgba(224,82,96,.14); color: var(--down); border: 1px solid var(--down); }
.sc-row { display: flex; gap: 12px; align-items: flex-start; padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 6px; background: var(--panel); }
.sc-row.fail { border-color: var(--down); }
.sc-badge { font-weight: 700; font-size: 12px; white-space: nowrap; min-width: 62px; }
.sc-row.pass .sc-badge { color: var(--up); }
.sc-row.fail .sc-badge { color: var(--down); }
.sc-cat { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); background: var(--panel2); padding: 2px 7px; border-radius: 10px; white-space: nowrap; align-self: center; min-width: 70px; text-align: center; }

/* paper-trading book cards */
.pbook-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; margin: 8px 0 14px; }
.pbook {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; cursor: pointer; position: relative; transition: border-color .15s;
}
.pbook:hover { border-color: var(--c1); }
.pbook.selected { border-color: var(--c1); box-shadow: 0 0 0 1px var(--c1); }
.pbook .pb-name { font-weight: 600; font-size: 13.5px; margin-bottom: 2px; padding-right: 22px; }
.pbook .pb-meta { color: var(--muted); font-size: 11px; margin-bottom: 8px; }
.pbook .pb-eq { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.pbook .pb-pnl { font-size: 13px; font-variant-numeric: tabular-nums; }
.pbook .pb-stats { color: var(--muted); font-size: 11px; margin-top: 6px; }
.pbook .pb-del {
  position: absolute; top: 8px; right: 8px; background: none; border: none;
  color: var(--muted); cursor: pointer; font-size: 14px; padding: 2px 6px; border-radius: 6px;
}
.pbook .pb-del:hover { color: var(--down); background: rgba(224,82,96,.12); }
.pbook svg { display: block; margin-top: 6px; width: 100%; }
.pbook-empty {
  grid-column: 1 / -1; border: 1px dashed var(--border); border-radius: 10px;
  padding: 22px; text-align: center; color: var(--muted);
}

/* walk-forward family group headers */
.wf-famhead {
  margin: 6px 0 2px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .5px; color: var(--muted); display: flex; gap: 8px; align-items: baseline;
}
.wf-famhead a { cursor: pointer; color: var(--c1); font-size: 11px; text-transform: none; }

#tabs { display: flex; gap: 2px; background: var(--panel); padding: 0 16px; border-bottom: 1px solid var(--border); }
.tab {
  background: none; border: none; color: var(--muted);
  padding: 10px 16px; font-size: 13.5px; cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--text); border-bottom-color: var(--c1); }

main { flex: 1; overflow: auto; padding: 14px 16px; }
/* Portfolio/Paper/Guide live outside <main>; when no in-main pane is active,
   collapse it — otherwise it stretches an empty screen above those tabs */
main:not(:has(.tabpane.active)) { display: none; }
.tabpane { display: none; }
.tabpane.active { display: block; }

.chart-toolbar { display: flex; gap: 16px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.chk { color: var(--muted); font-size: 13px; display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.sep { width: 1px; height: 18px; background: var(--border); }
.chart-main { height: calc(100vh - 220px); min-height: 420px; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.chk.ma { gap: 5px; }
.ma-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--mac, #4f8cff); display: inline-block; flex: 0 0 auto; }
.ma-per { width: 54px; padding: 3px 5px; }
.legend { font-size: 12.5px; color: var(--muted); min-height: 20px; margin-bottom: 4px; font-variant-numeric: tabular-nums; }
.legend b { color: var(--text); }

/* chart key — explains the drawn lines/zones/markers */
.chart-key {
  display: flex; flex-wrap: wrap; gap: 5px 16px; align-items: center;
  padding: 8px 12px; margin-bottom: 8px;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  font-size: 12px; color: var(--text);
}
.chart-key.hidden { display: none; }
.chart-key .ck-h { font-weight: 700; color: var(--muted); text-transform: uppercase; font-size: 11px; letter-spacing: .5px; }
.chart-key .ck-item { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.chart-key .ck-line { display: inline-block; width: 22px; border-top: 2px solid; }
.chart-key .ck-dash { border-top-style: dashed; }
.chart-key .ck-dot { border-top-style: dotted; border-top-width: 2px; }
.chart-key .ck-sub { color: var(--muted); }
.chart-key .ck-sep { width: 1px; height: 15px; background: var(--border); }

.bt-layout { display: grid; grid-template-columns: 300px 1fr; gap: 14px; align-items: start; }
.panel {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 14px; display: flex; flex-direction: column; gap: 8px;
  position: sticky; top: 0;
}
.panel h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin-top: 8px; }
.panel h3:first-child { margin-top: 0; }
.params { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.params label, .row label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.params input, .params select { width: 100%; }
.row { display: flex; gap: 8px; }
.row label { flex: 1; }
.row input, .row select { width: 100%; }
.checklist { display: flex; flex-direction: column; gap: 4px; max-height: 220px; overflow: auto; }
.checklist label { font-size: 13px; display: flex; gap: 7px; align-items: center; cursor: pointer; }
.checklist .fam { color: var(--muted); font-size: 11px; margin-left: auto; }
.wf-quick { font-size: 11px; font-weight: 400; text-transform: none; letter-spacing: 0; }
.wf-quick a { color: var(--c1); cursor: pointer; }
.wf-quick a:hover { text-decoration: underline; }
.wf-symlist { max-height: 260px; }
.wf-cathead { font-size: 10px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 8px 0 2px; position: sticky; top: 0; background: var(--panel); padding: 1px 0; }
.wf-symrow { font-size: 12.5px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; margin-bottom: 14px; }
.tile {
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px;
}
.tile .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.tile .v { font-size: 20px; font-weight: 650; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile .v.pos { color: var(--up); }
.tile .v.neg { color: var(--down); }

.chart-eq { height: 320px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 14px; overflow: hidden; }

table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: 7px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child, th.l, td.l { text-align: left; }
th { color: var(--muted); font-weight: 500; font-size: 12px; position: sticky; top: 0; background: var(--bg); }
th.wf-th { cursor: pointer; user-select: none; white-space: nowrap; }
th.wf-th:hover { color: var(--text); }
th.wf-th.active { color: var(--c1); }
.wf-th-hint { opacity: .3; }
th.sort-th { cursor: pointer; user-select: none; white-space: nowrap; }
th.sort-th:hover { color: var(--text); }
th.sort-th.sort-active { color: var(--c1); }
.sort-ind { opacity: .3; }
th.sort-active .sort-ind { opacity: 1; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--panel2); }
tr.selected td { background: var(--panel2); }
td.pos { color: var(--up); }
td.neg { color: var(--down); }
.tablewrap { overflow-x: auto; max-height: 420px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; } /* must beat .login-overlay's display:flex (same specificity, later in file) */
h3 { font-size: 14px; margin: 10px 0; }

.etoro-info {
  background: var(--panel); border: 1px solid var(--border); border-left: 3px solid var(--c2);
  border-radius: 8px; padding: 8px 12px; margin-bottom: 8px; font-size: 12.5px; color: var(--muted);
}
.etoro-info b { color: var(--text); }
.tile .v.small-text { font-size: 13px; font-weight: 500; line-height: 1.35; }

.pf-header { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin-bottom: 12px; flex-wrap: wrap; }
.pf-slider { display: flex; align-items: center; gap: 14px; }
.slider-wrap { width: 260px; }
.slider-wrap input[type="range"] { width: 100%; accent-color: var(--c1); }
.slider-labels { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 2px; }
.slider-val { color: var(--text); font-weight: 600; }
.pf-slider { display: flex; flex-direction: column; gap: 2px; }
.slider-wrap { width: 200px; }
.pf-hz { font-size: 13px; color: var(--text); font-weight: 600; min-width: 120px; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.badge.new { background: rgba(79,140,255,.18); color: var(--c1); }
.badge.long { background: rgba(30,158,126,.18); color: var(--up); }
.badge.short { background: rgba(224,82,96,.18); color: var(--down); }

/* ---------- asset research ---------- */
.rs-head h2 { font-size: 20px; }
.rs-tiles { margin-top: 12px; }
.rs-sec { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; margin-top: 12px; }
.rs-sec h3 { margin: 0 0 8px; font-size: 14px; color: var(--c1); }
.rs-about { color: var(--text); line-height: 1.55; max-width: 900px; }
.rs-reco { font-size: 15px; font-weight: 600; text-transform: capitalize; margin-bottom: 8px; }
.rs-bar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: var(--panel2); }
.rs-bar span { display: block; height: 100%; }
.rs-barleg { display: flex; gap: 16px; margin-top: 6px; font-size: 12px; }
.rs-barleg span:nth-child(2) { color: var(--muted); }
.rs-target { margin-top: 10px; font-size: 13px; }
.rs-news { display: flex; flex-direction: column; }
.rs-newsrow { display: flex; justify-content: space-between; gap: 14px; padding: 8px 0; border-bottom: 1px solid var(--border); text-decoration: none; color: var(--text); }
.rs-newsrow:last-child { border-bottom: none; }
a.rs-newsrow:hover .rs-newst { color: var(--c1); }
.rs-newst { flex: 1; }

/* ---------- research ticker search ---------- */
.rs-search { position: relative; flex: 1; max-width: 440px; }
.rs-search input { width: 100%; }
.rs-suggest { position: absolute; top: 100%; left: 0; right: 0; z-index: 20;
  background: var(--panel2); border: 1px solid var(--border); border-radius: 8px;
  margin-top: 4px; max-height: 340px; overflow-y: auto; box-shadow: 0 8px 24px rgba(0,0,0,.45); }
.rs-sug { padding: 8px 12px; cursor: pointer; display: flex; align-items: baseline; gap: 8px; border-bottom: 1px solid var(--border); }
.rs-sug:last-child { border-bottom: none; }
.rs-sug:hover { background: var(--panel); }
.rs-sug b { color: var(--text); }
.rs-sug-name { color: var(--muted); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rs-sug-meta { color: var(--muted); font-size: 11px; white-space: nowrap; }

/* ---------- sentiment gauge ---------- */
.sent-gauge { margin: 6px 0 12px; }
.sent-score { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.sent-max { font-size: 14px; color: var(--muted); font-weight: 400; margin-left: 1px; }
.sent-label { font-size: 15px; margin-left: 10px; color: var(--text); }
.sent-meter { position: relative; height: 10px; border-radius: 5px; margin: 10px 0 4px;
  background: linear-gradient(90deg, var(--down), var(--c2) 50%, var(--up)); }
.sent-marker { position: absolute; top: -3px; width: 4px; height: 16px; border-radius: 2px;
  background: var(--text); transform: translateX(-50%); box-shadow: 0 0 0 2px var(--panel); }
.sent-scale { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
.sent-comps { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 22px; margin-top: 12px; }
.sent-comp { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.sent-comp .muted { margin-left: auto; }
.sent-dot { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.sent-dot.bull { background: var(--up); }
.sent-dot.bear { background: var(--down); }
.sent-dot.neut { background: var(--muted); }
.sent-extra { margin-top: 12px; font-size: 13px; display: flex; flex-direction: column; gap: 5px; }
@media (max-width: 640px) { .sent-comps { grid-template-columns: 1fr; } }

.guide { max-width: 860px; margin: 0 auto; }
.guide h2 { font-size: 20px; margin-bottom: 4px; }
.gsub { color: var(--muted); margin-bottom: 18px; }
.gsec { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 14px 18px; margin-bottom: 12px; }
.gsec h3 { margin: 0 0 8px; font-size: 15px; color: var(--c1); }
.gsec.warn h3 { color: var(--down); }
.gsec ul, .gsec ol { margin: 6px 0 6px 20px; }
.gsec li { margin-bottom: 5px; }
.gsec p { margin: 6px 0; }
.gsec code { background: var(--panel2); padding: 1px 5px; border-radius: 4px; font-size: 12px; }

.login-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 17, 22, 0.96);
  display: flex; align-items: center; justify-content: center;
}
.login-box {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 28px; width: 340px; max-width: 92vw;
  display: flex; flex-direction: column; gap: 10px;
}
.login-box input { width: 100%; padding: 9px 10px; }

.toast {
  position: fixed; bottom: 18px; right: 18px; max-width: 440px;
  background: #3a2530; border: 1px solid var(--down); color: var(--text);
  padding: 10px 14px; border-radius: 8px; font-size: 13px; z-index: 50;
  white-space: pre-wrap;
}
.spinner { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--border); border-top-color: var(--c1); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; margin-right: 6px; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .bt-layout { grid-template-columns: 1fr; }
  .panel { position: static; }
}

/* ---------- landscape phone (short viewport, any width) ---------- */
@media (max-height: 520px) {
  header { padding: 5px 10px; gap: 8px; }
  .brand { font-size: 14px; }
  /* landscape: header must fit one row — drop decorations, let selects shrink */
  #who, .live { display: none; }
  .controls { min-width: 0; } /* lift the flex auto-min so the row can compress */
  .right { flex-shrink: 0; }  /* bar count + Log out never get squeezed out */
  .controls select { min-width: 0; }
  #symbol { flex: 0 10 auto; } /* the wide one absorbs the squeeze */
  #status { white-space: nowrap; }
  .right { gap: 8px; }
  #tabs { overflow-x: auto; scrollbar-width: none; }
  #tabs::-webkit-scrollbar { display: none; }
  .tab { padding: 6px 10px; font-size: 12px; white-space: nowrap; }
  main { padding: 6px 10px; }
  .chart-toolbar { margin-bottom: 4px; gap: 10px; font-size: 12px; }
  .legend { min-height: 14px; margin-bottom: 2px; font-size: 11px; }
  #levels-info { display: none; } /* landscape: every vertical pixel goes to the chart */
  .chart-key { display: none; }   /* toggle it back on in portrait; landscape needs the height */
  .chart-toolbar { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .chart-toolbar::-webkit-scrollbar { display: none; }
  .chk, .chart-toolbar label { white-space: nowrap; }
  .chart-main { height: calc(100vh - 118px); height: calc(100dvh - 118px); min-height: 220px; }
  .chart-eq { height: 180px; }
  .tiles { grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 6px; }
  .tile { padding: 6px 10px; }
  .tile .v { font-size: 15px; }
  .panel { position: static; }
}

/* ---------- phone layout ---------- */
@media (max-width: 640px) {
  header { flex-wrap: wrap; gap: 8px; padding: 8px 10px; }
  .controls { flex-wrap: wrap; width: 100%; order: 3; }
  .controls select { flex: 1; min-width: 90px; }
  #tabs { overflow-x: auto; padding: 0 6px; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  #tabs::-webkit-scrollbar { display: none; }
  .tab { padding: 10px 10px; font-size: 12.5px; white-space: nowrap; }
  main { padding: 10px 8px; }
  .chart-main { height: 52vh; height: 52dvh; min-height: 300px; }
  .chart-eq { height: 220px; }
  .chart-toolbar { gap: 10px; font-size: 12px; }
  .legend { font-size: 11px; }
  .tiles { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .tile .v { font-size: 16px; }
  .pf-header { flex-direction: column; align-items: stretch; gap: 12px; }
  .pf-slider { width: 100%; }
  .slider-wrap { width: 100%; }
  .btn.primary { width: 100%; }
  table { font-size: 11.5px; }
  th, td { padding: 5px 6px; }
  .guide { padding: 0 2px; }

  /* --- 2026-07-06 mobile pass --------------------------------------- */
  /* simple-mode bar: its inline flex-basis values are DESKTOP widths; in a
     stacked column the main axis is vertical, so those bases would become
     ~340px of HEIGHT each (the giant-gaps bug). Force natural sizing. */
  #pf-simple { flex-direction: column; align-items: stretch; }
  #pf-simple > * { flex: 0 0 auto !important; min-width: 0 !important;
                   max-width: none !important; }
  #pf-simple .pf-slider { width: 100%; }
  #pf-go { width: 100%; font-size: 16px; padding: 12px 16px !important; }
  #pf-adv-toggle { text-align: center; padding: 6px 0; }
  /* compact header: every vertical pixel is chart/decision space on a phone */
  #status, #who, .live { display: none; }
  header { padding: 6px 8px; }
  .brand { font-size: 16px; }
  #logout { padding: 6px 10px; }
  /* advanced rows + meta/frontier panels stay inside the viewport */
  #pf-advanced .pf-header { gap: 10px; }
  #pf-meta-out .tablewrap, #pf-frontier-out .tablewrap { overflow-x: auto; }
  #pf-meta-eq { height: 200px !important; }
  /* touch targets */
  select, .btn { min-height: 38px; }
  .btn.tiny, .pb-maxloss { min-height: 0; }
  input[type="range"] { height: 28px; }
  /* paper book cards: one per row reads better than a cramped grid */
  .pbook { width: 100%; max-width: none; }
}

/* broker panel (real account) */
.bk-banner { border: 1px solid #d96f24; border-left: 4px solid #d96f24; border-radius: 8px;
  padding: 8px 12px; margin: 8px 0; font-size: 13px; color: var(--text); background: rgba(217,111,36,0.08); }
.bk-banner.armed { border-color: var(--down); border-left-color: var(--down); background: rgba(224,82,96,0.10); }
.bk-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 8px 0; font-size: 13px; }
.bk-row input[type="password"] { background: var(--panel); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 8px; }

/* live bots: per-book mode control + pending approvals */
.btn.tiny { padding: 2px 8px; font-size: 11px; border-radius: 5px; }
.pb-bot { margin-top: 8px; padding-top: 7px; border-top: 1px solid var(--border); font-size: 12px; }
.pb-botmode { color: var(--muted); }
.pb-botmode.live { color: var(--c1); font-weight: 600; }
.pb-botmode.live.auto { color: var(--c3); }
.pb-botform { margin-top: 7px; display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.pb-botform.hidden { display: none; }
.pb-botform label { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 11px; }
.pb-botform select, .pb-botform input { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 5px; padding: 3px 5px; font-size: 11px; }
.pending-box { border: 1px solid var(--c1); border-radius: 8px; padding: 10px 12px; margin: 8px 0 4px; background: rgba(79,140,255,0.06); }
.pending-box h3 { margin: 0 0 8px; font-size: 14px; }
.pending-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 5px 0; border-top: 1px solid var(--border); flex-wrap: wrap; }
.pending-row:first-of-type { border-top: none; }

/* drag-to-reorder table columns (open positions) */
.drag-th { cursor: grab; user-select: none; }
.drag-th:active { cursor: grabbing; }
th.col-drag { opacity: 0.45; }
th.col-over { box-shadow: inset 3px 0 0 var(--c1); }
.col-grip { cursor: grab; opacity: 0.35; margin-right: 4px; font-size: 10px; touch-action: none; }
.col-grip:hover { opacity: 0.9; }
.col-grip:active { cursor: grabbing; }

/* book-of-books correlation heatmap */
table.corr { border-collapse: collapse; font-size: 11px; }
table.corr th, table.corr td { padding: 3px 6px; text-align: center; border: 1px solid var(--surface); }
table.corr th.l { text-align: right; color: var(--muted); }
