:root {
  --bg: #14161a; --panel: #1b1e23; --panel2: #22262c; --line: #323840; --line2: #2a2f36;
  --text: #eceef1; --muted: #9aa4af; --gold: #d4a537; --gold2: #f0c454;
  --teal: #26b5a4; --blue: #4b93ea; --purple: #a57ae6; --amber: #e8a531;
  --pos: #39d273; --neg: #ff6262; --old: #e3ad45; --stale: #8d8466;
  --fs: 12px; --fs-compact: 11.5px; --row-h: 21px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: var(--fs)/1.35 "Segoe UI", "Inter", Roboto, "Helvetica Neue", Arial, sans-serif; }
body { font-variant-numeric: tabular-nums; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--gold2); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 11px; }
.spacer { flex: 1; }
.warn-text { color: var(--old); }

/* ---------------------------------------------------------------- nav */
.topnav { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 10px; padding: 2px 10px;
  min-height: 38px; background: #202124; border-bottom: 1px solid #000; box-shadow: 0 1px 0 #2c2f33; }
.brand { color: var(--gold); font-weight: 800; letter-spacing: 2px; font-size: 17px; white-space: nowrap; }
.brand-sub { color: #8a7a4f; font-size: 10px; letter-spacing: .5px; font-weight: 500; margin-left: 6px; }
.brand.big { font-size: 30px; text-align: center; }
.nav { display: flex; flex-wrap: wrap; gap: 2px; flex: 1; min-width: 0; }   /* menu may use two rows */
.nav-item { display: inline-flex; align-items: center; padding: 0 9px; height: 30px; border-radius: 4px; color: #cfd3d8;
  text-decoration: none; white-space: nowrap; background: none; border: 0; cursor: pointer; }
.nav-item:hover { background: #2d3035; color: #fff; }
.nav-item.active { background: #33363b; color: #fff; box-shadow: inset 0 -2px 0 var(--gold); }
.nav-edge.active { box-shadow: inset 0 -2px 0 var(--teal); }
.nav-stock.active, .nav-quarterly.active { box-shadow: inset 0 -2px 0 var(--blue); }
.nav-future.active { box-shadow: inset 0 -2px 0 var(--purple); }
.nav-bidask.active { box-shadow: inset 0 -2px 0 var(--amber); }
.nav-refresh { color: var(--gold2); }
.nav-status { display: flex; gap: 6px; align-items: center; white-space: nowrap; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 7px; border-radius: 10px; font-size: 11px;
  border: 1px solid var(--line); background: var(--panel2); color: var(--text); text-decoration: none; }
.chip-live { border-color: #1f6b3d; background: #12301f; color: #7cf0a6; }
.chip-old { border-color: #6b5422; background: #2d2512; color: var(--old); }
.chip-bad { border-color: #7a2626; background: #351414; color: #ff9b9b; }
.chip-sim { border-color: #6a4c9b; background: #261d38; color: #cdb2ff; font-weight: 700; }
.clock { color: var(--muted); font-size: 11px; }

/* ---------------------------------------------------------------- pages */
main { padding: 6px 8px 40px; }
.page-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin: 2px 0 6px; }
.page-head h2 { margin: 0; font-size: 15px; }
.sc-title { cursor: pointer; }
.sc-teal .sc-title, .sc-teal > .panel-head .panel-title, .tab.sc-teal.active { color: var(--teal); }
.sc-blue .sc-title, .sc-blue > .panel-head .panel-title, .tab.sc-blue.active { color: var(--blue); }
.sc-purple .sc-title, .sc-purple > .panel-head .panel-title, .tab.sc-purple.active { color: var(--purple); }
.sc-amber .sc-title, .sc-amber > .panel-head .panel-title, .tab.sc-amber.active { color: var(--amber); }
.scanner-page.sc-teal { --accent: var(--teal); } .scanner-page.sc-blue { --accent: var(--blue); }
.scanner-page.sc-purple { --accent: var(--purple); } .scanner-page.sc-amber { --accent: var(--amber); }
.scanner-page .dt-head th { border-top: 2px solid var(--accent, var(--gold)); }
.sc-info { color: var(--muted); font-size: 11px; }
.seg-toggle { display: inline-flex; border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.seg-toggle .seg { padding: 2px 10px; color: var(--muted); text-decoration: none; background: var(--panel2); }
.seg-toggle .seg.active { background: #12352f; color: #7ff0dd; font-weight: 600; }
.seg-toggle .seg + .seg { border-left: 1px solid var(--line); }

.btn { padding: 3px 10px; border-radius: 4px; border: 1px solid var(--line); background: var(--panel2); cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: #4a525c; background: #2a2f36; }
.btn.primary { background: #3b3216; border-color: #7d6420; color: var(--gold2); }
.btn.danger, .mini.danger { border-color: #7a2c2c; color: #ff9b9b; }
.btn:disabled { opacity: .45; cursor: default; }
.mini { padding: 0 6px; height: 19px; font-size: 11px; border-radius: 3px; border: 1px solid var(--line); background: var(--panel2); cursor: pointer; white-space: nowrap; }
.mini.warn { border-color: #7d6420; color: var(--gold2); }
.mini.active { background: #3b3216; color: var(--gold2); }
.icon-btn { background: none; border: 0; font-size: 18px; cursor: pointer; color: var(--muted); }
.in-text, .in-num, select, textarea { background: #101215; border: 1px solid var(--line); border-radius: 3px; padding: 2px 5px; }
.in-num { text-align: right; }
select { padding: 2px 3px; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 1px solid var(--gold); outline-offset: 0; }

/* filter bar: one row, scrolls horizontally instead of adding rows */
.filter-bar { display: flex; gap: 6px; align-items: center; flex-wrap: nowrap; overflow-x: auto; padding: 4px 6px; margin-bottom: 4px;
  background: var(--panel); border: 1px solid var(--line2); border-radius: 4px; }
.fb { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.fb-l { color: var(--muted); font-size: 11px; }
.fb-check { color: var(--muted); }
.fb-hint { color: var(--muted); font-size: 10.5px; white-space: nowrap; }

/* ---------------------------------------------------------------- tables */
.dt-wrap { overflow: auto; max-height: calc(100vh - 150px); border: 1px solid var(--line2); border-radius: 4px; background: var(--panel); }
.dt { border-collapse: separate; border-spacing: 0; width: max-content; }   /* each column = max(2-line header, data); never stretched */
.dt th, .dt td { padding: 1px 5px; border-bottom: 1px solid var(--line2); border-right: 1px solid #262a30; white-space: nowrap; height: var(--row-h); }
.dt thead th { position: sticky; top: 0; z-index: 2; background: #262a31; color: #d7dbe0; font-weight: 600; font-size: 11px;
  text-align: center; vertical-align: bottom; white-space: normal; line-height: 1.15; padding: 2px 4px; user-select: none; }
.dt thead tr.dt-totals td { position: sticky; top: 0; z-index: 3; background: #1d2126; font-weight: 700; text-align: right; height: 18px; border-bottom: 0; font-size: 11px; }
.dt thead tr.dt-totals + tr.dt-head th { top: 18px; }
.th-label { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.th-sort { color: var(--gold2); font-size: 9px; margin-left: 2px; }
.dt th.sortable { cursor: pointer; }
.dt th.sortable:hover { background: #2e333b; }
.dt th { position: sticky; }
.th-resize { position: absolute; right: -3px; top: 0; bottom: 0; width: 7px; cursor: col-resize; z-index: 4; }
.dt th.dragging { opacity: .5; }
.dt th.drop { box-shadow: inset 2px 0 0 var(--gold); }
.dt tbody tr:nth-child(even) td { background: #1e2126; }
.dt tbody tr:hover td { background: #262b32; }
.dt tbody tr.fav td.c-sym { box-shadow: inset 3px 0 0 var(--gold); }
.dt tbody tr.selected td { background: #2b2a1d !important; }
.dt tbody tr.squared td { color: #aab1ba; }
.dt td.k-num, .dt td.k-int, .dt td.k-pct, .dt td.k-px, .dt td.k-money, .dt td.k-age { text-align: right; }
.dt td.k-px { color: #ffffff; font-weight: 600; }
.dt td.k-book { text-align: right; }
.book-used { color: #ffffff; font-weight: 800; text-decoration: underline; text-underline-offset: 2px; }
.book-other { color: #b9c0c8; }
.book-sep { color: #6f7781; }
.dt td.k-date, .dt td.k-capture { color: #c9ced4; }
.dt td.pos { color: var(--pos); }
.dt td.neg { color: var(--neg); }
.dt td.k-money.pos, .dt td.k-money.neg { font-weight: 700; }
.dt td.st-old, .dt td.st-old.k-px { color: var(--old); }
.dt td.st-stale { color: var(--stale); font-style: italic; }
.dt td.st-closed { color: #c2b48f; }
.dt td.st-na { color: #6f7781; text-align: center; }
.dt td.st-wait { color: #6f7781; }
.st-tag { font-size: 8px; color: var(--old); margin-left: 2px; font-weight: 600; text-transform: uppercase; }
.dt td.fl-up { animation: flup .7s ease-out; }
.dt td.fl-dn { animation: fldn .7s ease-out; }
@keyframes flup { from { background: rgba(57, 210, 115, .35); } to { background: transparent; } }
@keyframes fldn { from { background: rgba(255, 98, 98, .35); } to { background: transparent; } }
.dt td.c-sym { font-weight: 700; }
.c-sym .sym { margin: 0 3px; }
.star { background: none; border: 0; padding: 0 1px; cursor: pointer; color: #5c636c; font-size: 13px; line-height: 1; }
.star.on { color: var(--gold2); }
.ss-btn { font-size: 9.5px; padding: 0 4px; height: 15px; border-radius: 3px; border: 1px solid #6a5722; background: #2b2412; color: var(--gold2); cursor: pointer; vertical-align: 1px; }
.dt td.k-input { padding: 1px 3px; vertical-align: middle; }

.cell-in { min-width: 0; box-sizing: content-box; background: #0f1114; border: 1px solid #3a414a; border-radius: 2px; padding: 0 3px; height: 17px; text-align: right; font-size: 11.5px; }
.cell-in.saved-ok { border-color: var(--pos); }
.cell-in.inherited { font-style: italic; color: #9aa4af; border-style: dashed; }
.cell-sel { height: 18px; font-size: 11px; padding: 0; }
.legtext { font-size: 9.5px; color: var(--muted); line-height: 1.1; white-space: nowrap; }
.badge { display: inline-block; padding: 0 5px; border-radius: 3px; font-size: 10px; font-weight: 700; letter-spacing: .3px; }
.b-open { background: #12301f; color: #7cf0a6; }
.b-sq { background: #2d2512; color: var(--old); }
.b-auto { background: #3a1a1a; color: #ffb0b0; }
.b-err { background: #3a1a1a; color: #ff9b9b; }
.dt-empty td { color: var(--muted); text-align: center; padding: 10px; }
.dt.plain { width: 100%; }
.dt.plain td.wrap, .dt td.wrap { white-space: normal; }
.dt-compact { --row-h: 19px; }
.dt-compact .dt td, .dt-compact .dt th { font-size: var(--fs-compact); padding: 0 4px; }

/* ---------------------------------------------------------------- live screen */
.live-grid { display: grid; gap: 6px; }
.live-grid.layout-default { grid-template-columns: 1fr 1fr; grid-template-rows: auto auto auto; }
.live-grid.layout-default .live-panel.main { grid-row: 1 / span 3; }
.live-grid.layout-ss1 { grid-template-columns: 1fr 1fr; }
.live-grid.layout-ss2 { grid-template-columns: 1fr 1fr; }
.live-grid.layout-ss3 { grid-template-columns: 5fr 3fr; }
.live-grid.has-large { grid-template-columns: 1fr; }
.live-panel { display: flex; flex-direction: column; min-width: 0; background: var(--panel); border: 1px solid var(--line2); border-radius: 4px; }
.live-panel.sc-teal { border-top: 2px solid var(--teal); } .live-panel.sc-blue { border-top: 2px solid var(--blue); }
.live-panel.sc-purple { border-top: 2px solid var(--purple); } .live-panel.sc-amber { border-top: 2px solid var(--amber); }
.panel-head { display: flex; align-items: center; gap: 5px; padding: 2px 5px; border-bottom: 1px solid var(--line2); }
.panel-title { background: none; border: 0; font-weight: 700; font-size: 12.5px; cursor: pointer; padding: 0; }
.panel-count { color: var(--muted); font-size: 10.5px; }
.panel-body .dt-wrap { border: 0; border-radius: 0; max-height: calc(var(--rows, 5) * 19px + 60px); }
.live-panel.large .panel-body .dt-wrap { max-height: calc(100vh - 120px); }
.pager { display: inline-flex; gap: 3px; }

/* ---------------------------------------------------------------- saved */
.tabs { display: flex; gap: 2px; flex-wrap: wrap; margin-bottom: 4px; }
.tab { padding: 3px 10px; border: 1px solid var(--line); background: var(--panel2); border-radius: 4px 4px 0 0; cursor: pointer; }
.tab.active { background: #2e333b; border-bottom-color: var(--gold); color: var(--gold2); font-weight: 600; }
.views-bar, .defaults-box, .bulk-bar { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; padding: 3px 6px; margin-bottom: 4px;
  background: var(--panel); border: 1px solid var(--line2); border-radius: 4px; }
.defaults-box { border-color: #4b3f1d; }
.view-tab { padding: 1px 8px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel2); cursor: pointer; }
.view-tab.active { border-color: var(--gold); color: var(--gold2); }
.view-tab small { color: var(--muted); }
.alert-history { margin-top: 8px; }
.alert-history summary { cursor: pointer; color: var(--muted); }
.saved-host .dt-wrap { max-height: calc(100vh - 230px); }

/* ---------------------------------------------------------------- alerts */
.alerts { position: fixed; right: 14px; bottom: 14px; z-index: 60; display: flex; flex-direction: column-reverse; gap: 6px; width: min(460px, calc(100vw - 28px)); max-height: 70vh; overflow-y: auto; }
.alert-card { background: #3a1212; border: 2px solid #ff6262; border-radius: 6px; padding: 8px 10px; box-shadow: 0 6px 24px rgba(0,0,0,.6); animation: pulse 1.6s ease-in-out 3; }
.alert-card.kind-target { background: #13321f; border-color: var(--pos); }
.alert-title { font-weight: 800; letter-spacing: .4px; color: #fff; }
.alert-msg { margin: 3px 0; font-size: 13px; }
.alert-meta { color: #d0d4d9; font-size: 11px; margin-bottom: 4px; }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px rgba(240, 196, 84, .55); } }

/* ---------------------------------------------------------------- modal */
.modal-wrap { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 50; display: flex; align-items: flex-start; justify-content: center; padding: 50px 16px; overflow: auto; }
.modal { background: var(--panel); border: 1px solid #454c55; border-radius: 6px; width: min(520px, 100%); box-shadow: 0 10px 40px rgba(0,0,0,.6); }
.modal-wide { width: min(980px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 6px 10px; border-bottom: 1px solid var(--line); font-weight: 700; color: var(--gold2); }
.modal-body { padding: 10px; max-height: calc(100vh - 200px); overflow: auto; }
.modal-foot { display: flex; gap: 6px; justify-content: flex-end; padding: 6px 10px; border-top: 1px solid var(--line); }
.form-grid { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: flex-end; }
.form-grid label { display: flex; flex-direction: column; gap: 2px; color: var(--muted); font-size: 11px; }
.form-grid label.inline-check { flex-direction: row; align-items: center; gap: 4px; }
.form-grid h4 { width: 100%; margin: 4px 0 0; color: var(--text); }
.form-grid p { width: 100%; margin: 0; }
.checks { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; width: 100%; color: var(--muted); }
.cond-row { display: flex; gap: 5px; align-items: center; margin-bottom: 4px; flex-wrap: wrap; }
.cond-join { width: 46px; text-align: center; color: var(--gold2); font-weight: 700; }
.leg-line { display: flex; align-items: center; gap: 8px; margin: 5px 0; flex-wrap: wrap; }
.leg-role { min-width: 160px; color: var(--muted); }
.save-title { font-weight: 700; font-size: 13px; margin-bottom: 6px; color: var(--gold2); }
.col-list { list-style: none; padding: 0; margin: 0 0 8px; columns: 2; }
.col-list li { display: flex; gap: 6px; align-items: center; padding: 1px 3px; break-inside: avoid; }
.col-list .grip { color: var(--muted); cursor: grab; width: 14px; }
.col-move { display: inline-flex; gap: 2px; margin-left: auto; }
.confirm-msg { margin: 0; }

/* ---------------------------------------------------------------- setup / cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 8px; }
.card { background: var(--panel); border: 1px solid var(--line2); border-radius: 6px; padding: 8px 10px; }
.card h3 { margin: 0 0 6px; font-size: 13px; color: var(--gold2); }
.card h4 { margin: 8px 0 4px; }
.kv { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 3px 0; }
.btn-row { display: flex; gap: 6px; flex-wrap: wrap; margin: 6px 0; }
.forms form { border-top: 1px solid var(--line2); padding-top: 6px; margin-top: 6px; }
.forms textarea { width: 100%; min-width: 260px; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0; }
.chip-x { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 0 2px; }
.inline-form { display: flex; gap: 6px; }
.scroll-box { max-height: 260px; overflow: auto; border: 1px solid var(--line2); border-radius: 4px; }
.scroll-box.short { max-height: 160px; }
.search-results { max-height: 160px; overflow: auto; }
.sr { display: flex; gap: 6px; align-items: center; padding: 1px 0; }

/* ---------------------------------------------------------------- login / toast */
.login { display: flex; min-height: 100vh; align-items: center; justify-content: center; background: radial-gradient(circle at 50% 30%, #23262b, #121316); }
.login-card { display: flex; flex-direction: column; gap: 8px; width: min(340px, calc(100vw - 32px)); padding: 22px; background: var(--panel); border: 1px solid #3b3216; border-radius: 8px; }
.login-card label { display: flex; flex-direction: column; gap: 3px; color: var(--muted); }
.toast { position: fixed; bottom: 14px; left: 50%; transform: translateX(-50%); z-index: 70; padding: 6px 14px; border-radius: 5px; background: #2a2f36; border: 1px solid var(--line); max-width: calc(100vw - 32px); }
.toast-ok { border-color: #1f6b3d; }
.toast-error { border-color: #a33; background: #3a1616; }

@media (max-width: 900px) {
  .live-grid.layout-default, .live-grid.layout-ss1, .live-grid.layout-ss2, .live-grid.layout-ss3 { grid-template-columns: minmax(0, 1fr); }
  .live-grid.layout-default .live-panel.main { grid-row: auto; }
  .topnav { height: auto; flex-wrap: wrap; padding: 4px 8px; }
  .nav { order: 3; flex-basis: 100%; }
  .cards { grid-template-columns: minmax(0, 1fr); }
  .col-list { columns: 1; }
  main { padding: 6px 4px 40px; }
}
