:root {
  --bg: #f6f7f9; --panel: #fff; --ink: #1b1f24; --muted: #66707c; --line: #e3e6ea;
  --accent: #2f5bea; --pos: #12805c; --neg: #c2322b; --warn: #a86400;
  --sb: #0b7a4b; --b: #33a06f; --h: #8a8f98; --s: #e0703a; --ss: #c2322b;
  --c-cons: #2f5bea; --c-neu: #8e44ad; --c-off: #d9822b; --c-cus: #16a39a;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111418; --panel: #191d23; --ink: #e6e9ed; --muted: #8d96a2; --line: #2a3038;
    --accent: #6d8dff; --pos: #3cc48f; --neg: #ff6b61; --h: #9aa1ab; color-scheme: dark; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
header { display: flex; align-items: center; gap: 24px; padding: 12px 24px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; font-size: 18px; letter-spacing: -.3px; } .brand span { color: var(--accent); }
nav { display: flex; gap: 4px; }
nav button, .seg button { border: 0; background: transparent; color: var(--muted); padding: 7px 12px; border-radius: 6px; cursor: pointer; font: inherit; }
nav button.active, nav button:hover { background: var(--bg); color: var(--ink); }
.markets { margin-left: auto; display: flex; gap: 10px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.markets .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 4px; background: var(--line); }
.markets .open .dot { background: var(--pos); }
main { padding: 20px 24px; max-width: 1400px; margin: 0 auto; }
.tab { display: none; } .tab.active { display: block; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; margin-bottom: 18px; }
h2 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 0 0 12px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; margin-bottom: 18px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 14px 16px; border-top: 3px solid var(--accent); }
.card.conservative { border-top-color: var(--c-cons); } .card.custom { border-top-color: var(--c-cus); } .card.neutral { border-top-color: var(--c-neu); } .card.offensive { border-top-color: var(--c-off); }
.card .label { color: var(--muted); font-size: 12px; text-transform: capitalize; }
.card .big { font-size: 24px; font-weight: 650; font-variant-numeric: tabular-nums; margin: 2px 0; }
.card .sub { font-size: 12px; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } header { gap: 10px; } main { padding: 14px; } }
.chart-box { position: relative; height: 280px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th { text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); padding: 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 7px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td.name { max-width: 240px; overflow: hidden; text-overflow: ellipsis; }
.r { text-align: right; }
tbody tr.click { cursor: pointer; } tbody tr.click:hover { background: var(--bg); }
.pos { color: var(--pos); } .neg { color: var(--neg); } .muted { color: var(--muted); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; color: #fff; }
.badge.sb { background: var(--sb); } .badge.b { background: var(--b); } .badge.h { background: var(--h); }
.badge.s { background: var(--s); } .badge.ss { background: var(--ss); } .badge.ns { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
select, input { font: inherit; padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); color: var(--ink); }
input { min-width: 220px; }
.seg { display: inline-flex; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 3px; margin-bottom: 10px; }
.seg button.on { background: var(--accent); color: #fff; }
.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin-top: 12px; }
button { font: inherit; padding: 7px 14px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); cursor: pointer; }
button.danger { color: var(--neg); }
.notice { background: color-mix(in srgb, var(--warn) 12%, var(--panel)); border: 1px solid color-mix(in srgb, var(--warn) 40%, var(--panel)); padding: 12px 16px; border-radius: 10px; margin-bottom: 18px; }
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; } .bar > i { display: block; height: 100%; background: var(--accent); }
.factors { display: grid; grid-template-columns: 130px 1fr 40px; gap: 6px 10px; align-items: center; font-size: 13px; }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; z-index: 10; }
.modal[hidden] { display: none; }
.modal-body { background: var(--panel); border-radius: 12px; max-width: 900px; width: 100%; padding: 22px 24px; position: relative; }
.close { position: absolute; right: 12px; top: 10px; border: 0; font-size: 22px; background: none; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px 16px; font-size: 13px; }
.kv div > span:first-child { display: block; color: var(--muted); font-size: 11px; }
.log { font: 12px/1.5 ui-monospace, monospace; max-height: 400px; overflow-y: auto; white-space: pre-wrap; }
.log .error { color: var(--neg); } .log .warning { color: var(--warn); }
.method p { max-width: 80ch; }
ul.reasons { margin: 6px 0; padding-left: 18px; }
footer { text-align: center; color: var(--muted); font-size: 12px; padding: 20px; }
.timing { font-size: 12px; white-space: nowrap; } .timing.ok { color: var(--pos); } .timing.wait { color: var(--warn); }
td .timing.wait { display: inline-block; max-width: 220px; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }
.dq { cursor: help; font-size: 12px; } .dq.warn { color: var(--warn); } .dq.poor { color: var(--neg); }
.notice.bad { background: color-mix(in srgb, var(--neg) 10%, var(--panel)); border-color: color-mix(in srgb, var(--neg) 40%, var(--panel)); }
#logout { font-size: 13px; text-decoration: none; }
th.grp { text-align: center; border-bottom: 1px solid var(--line); }
details summary { cursor: pointer; } .why { margin: 6px 0 2px; font-size: 12px; line-height: 1.6; white-space: normal; max-width: 520px; }
ul.news { padding-left: 0; list-style: none; font-size: 13px; } ul.news li { margin-bottom: 8px; }
.sev { font-weight: 600; text-transform: none; } .sev.critical, .sev.major { color: var(--neg); } .sev.minor { color: var(--warn); } .sev.none { color: var(--pos); }

/* ---- phase 5 */
.btn { display: inline-block; padding: 7px 12px; border-radius: 6px; border: 1px solid var(--line); background: var(--panel); color: var(--ink); text-decoration: none; font-size: 13px; }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.link { border: 0; background: none; color: var(--muted); padding: 2px 6px; }
button.link:hover { color: var(--neg); }
.warn { color: var(--warn); }
.export-row { margin: 0 0 14px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; color: var(--muted); }
.bell { position: relative; border: 0; background: none; font-size: 18px; padding: 4px 8px; }
#bell-count { position: absolute; top: -2px; right: -4px; background: var(--neg); color: #fff; border-radius: 9px; font-size: 10px; padding: 1px 5px; font-weight: 700; }
.notif-panel { position: fixed; right: 16px; top: 60px; width: min(420px, calc(100vw - 32px)); max-height: 70vh; overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.18); z-index: 8; padding: 10px 14px; }
.notif-panel[hidden] { display: none; }
.notif-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.notif { padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 13px; cursor: default; }
.notif[data-open] { cursor: pointer; } .notif.unread b { color: var(--accent); }
.custom-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px 14px; margin-bottom: 8px; }
.custom-grid label { display: flex; flex-direction: column; font-size: 12px; color: var(--muted); gap: 3px; }
.custom-grid label:has(input[type=checkbox]) { flex-direction: row; align-items: center; gap: 6px; color: var(--ink); }
.custom-grid input { min-width: 0; }
h3 { font-size: 13px; margin: 14px 0 6px; }
label { font-size: 13px; }
.flt select.f-field { min-width: 200px; }

input[type=checkbox] { min-width: 0; width: auto; }
#alert-kinds label { display: inline-flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.account-btn { font-size: 13px; color: var(--muted); }
body:not(.is-admin) .admin-only { display: none !important; }
#custom-form fieldset { border: 0; padding: 0; margin: 0; }

/* ---- tab labels: full names on wide screens, icon + short name in the phone tab bar */
nav .ico, nav .short { display: none; }
/* grid and flex children may shrink, so wide tables scroll inside their panel instead of pushing it off-screen */
.grid2 > *, .panel { min-width: 0; }
#top-picks, #recent-trades, #my-ideas, #watch-list { overflow-x: auto; }
#modal-content table { display: block; overflow-x: auto; }

/* ---- phones */
@media (max-width: 700px) {
  html, body { overflow-x: hidden; }
  body { padding-bottom: calc(62px + env(safe-area-inset-bottom)); }
  /* compact header that scrolls away; the tabs move to a bar at the bottom */
  header { position: static; padding: 8px 12px; gap: 4px 8px; padding-top: max(8px, env(safe-area-inset-top)); }
  .brand { font-size: 17px; margin-right: auto; }
  .markets { order: 3; width: 100%; margin: 0; font-size: 11px; gap: 10px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .markets::-webkit-scrollbar { display: none; }
  .markets > span { white-space: nowrap; }
  .account-btn { max-width: 40vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 9; gap: 0; justify-content: space-around;
        background: var(--panel); border-top: 1px solid var(--line); padding: 4px 2px calc(4px + env(safe-area-inset-bottom)); }
  nav button { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 1px;
               padding: 5px 0 3px; font-size: 10.5px; border-radius: 8px; }
  nav .lbl { display: none; } nav .ico, nav .short { display: block; } nav .ico { font-size: 19px; line-height: 1.1; }
  nav button.active { color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
  .notif-panel { top: 52px; right: 8px; left: 8px; width: auto; max-height: calc(100vh - 140px); }

  main { padding: 10px 10px 4px; }
  .panel { padding: 12px; border-radius: 10px; margin-bottom: 12px; }
  .notice { padding: 10px 12px; margin-bottom: 12px; }
  /* two cards per row instead of one tall column */
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-bottom: 12px; }
  .card { padding: 10px 12px; }
  .card .big { font-size: 18px; }
  .card .sub { font-size: 11px; }
  .chart-box { height: 230px; }

  /* profile switchers: one row, scrolls sideways if needed */
  .seg { display: flex; width: 100%; overflow-x: auto; scrollbar-width: none; }
  .seg::-webkit-scrollbar { display: none; }
  .seg button { flex: 1 0 auto; padding: 7px 8px; white-space: nowrap; font-size: 13px; }

  /* 16px inputs stop iPhones zooming in on every field */
  input, select, textarea { font-size: 16px; min-width: 0; }
  .filters > * { flex: 1 1 140px; }
  .filters > .seg { flex-basis: 100%; }
  button, .btn { min-height: 38px; }
  button.link, .close, .bell { min-height: 0; }

  /* tables: keep the first column (the symbol) in view while scrolling sideways */
  th, td { padding: 7px 6px; }
  .table-wrap td:first-child, .table-wrap th:first-child { position: sticky; left: 0; background: var(--panel); z-index: 1; }
  .table-wrap tbody tr.click:hover td:first-child { background: var(--bg); }
  .tab > .table-wrap td:first-child, .tab > .table-wrap th:first-child { background: var(--bg); }
  td.name { max-width: 120px; }

  .modal { padding: 0; }
  .modal-body { border-radius: 0; min-height: 100vh; padding: 14px 14px calc(24px + env(safe-area-inset-bottom)); }
  .modal-body h1 { font-size: 21px; line-height: 1.25; padding-right: 36px; }
  .close { position: fixed; right: 10px; top: 8px; z-index: 11; background: var(--panel); border-radius: 50%; width: 38px; height: 38px; padding: 0; }
  .kv { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .custom-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 10px; }
  .custom-grid label:has(input[type=checkbox]) { grid-column: 1 / -1; }
  /* settings: label above its field, full width */
  #my-settings > label { display: flex; flex-direction: column; gap: 3px; flex: 1 1 100%; color: var(--muted); font-size: 12px; }
  #my-settings > label > input, #my-settings > label > select { width: 100%; min-width: 0 !important; }
  .factors { grid-template-columns: 96px 1fr 34px; }
  .method p { font-size: 13px; }
  footer { padding: 14px 14px 8px; }
}
.why-cell { white-space: normal; min-width: 220px; font-size: 12px; }
.cmp-tray { position: fixed; right: 16px; bottom: 16px; z-index: 8; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px 8px 14px; box-shadow: 0 6px 24px rgba(0,0,0,.15); display: flex; gap: 8px; align-items: center; font-size: 13px; max-width: calc(100vw - 32px); }
.cmp-tray[hidden] { display: none; }
#cmp-list { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.cmp th { white-space: nowrap; } table.cmp td.best { font-weight: 700; }
table.cmp thead .name { font-weight: 400; font-size: 11px; max-width: 140px; margin-left: auto; }
@media (max-width: 700px) { .cmp-tray { left: 10px; right: 10px; bottom: calc(66px + env(safe-area-inset-bottom)); } }
