:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-alt: #f8f9fb;
  --surface-sunk: #eef0f3;
  --border: #e1e4ea;
  --text: #161b26;
  --text-muted: #5f6878;
  --text-faint: #98a0ad;
  --primary: #3563e9;
  --primary-hover: #2748b8;
  --buy: #12925a;
  --buy-soft: rgba(18, 146, 90, .12);
  --sell: #d23a4b;
  --sell-soft: rgba(210, 58, 75, .12);
  --warn: #b7791f;
  --warn-soft: rgba(183, 121, 31, .12);
  --neutral: #7c8796;
  --radius-sm: 6px;
  --radius-md: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .07);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1218;
    --surface: #171b23;
    --surface-alt: #1d222c;
    --surface-sunk: #12161d;
    --border: #2a303c;
    --text: #e6e9ef;
    --text-muted: #9aa3b2;
    --text-faint: #687180;
    --primary: #5b84f5;
    --primary-hover: #7898f7;
    --buy: #2fbf7c;
    --buy-soft: rgba(47, 191, 124, .15);
    --sell: #f0606f;
    --sell-soft: rgba(240, 96, 111, .15);
    --warn: #e0a440;
    --warn-soft: rgba(224, 164, 64, .15);
    --neutral: #6b7585;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1218;
  --surface: #171b23;
  --surface-alt: #1d222c;
  --surface-sunk: #12161d;
  --border: #2a303c;
  --text: #e6e9ef;
  --text-muted: #9aa3b2;
  --text-faint: #687180;
  --primary: #5b84f5;
  --primary-hover: #7898f7;
  --buy: #2fbf7c;
  --buy-soft: rgba(47, 191, 124, .15);
  --sell: #f0606f;
  --sell-soft: rgba(240, 96, 111, .15);
  --warn: #e0a440;
  --warn-soft: rgba(224, 164, 64, .15);
  --neutral: #6b7585;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
}

.num, .ltp, .mode-price, .stat-val, .depth td, .orders td.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-muted); font-size: 12px; }
.hidden { display: none !important; }

/* ── Top bar ─────────────────────────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: baseline; gap: 8px; }
.brand h1 { font-size: 16px; margin: 0; font-weight: 700; }
.brand-sub { color: var(--text-faint); font-size: 12px; }
.summary { display: flex; gap: 6px; flex-wrap: wrap; }
.stat {
  display: flex;
  flex-direction: column;
  padding: 0 10px;
  border-left: 1px solid var(--border);
  min-width: 0;
}
.stat:first-child { border-left: 0; }
.stat-label { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint); font-weight: 600; }
.stat-val { font-size: 15px; font-weight: 700; }
.stat-val.buy { color: var(--buy); }
.stat-val.sell { color: var(--sell); }
.stat-val.bad { color: var(--sell); }
.stat-val.attn { color: var(--warn); }
.topbar-actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.summary { margin-left: auto; flex-wrap: nowrap; }
.summary + .topbar-actions { margin-left: 0; }

/* ── Layout ──────────────────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 16px;
  padding: 16px 20px 24px;
  align-items: start;
}
@media (max-width: 1000px) {
  .layout { grid-template-columns: 1fr; padding: 12px 16px; }
}

/* ── Ticket ──────────────────────────────────────────────────────── */
.ticket {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: sticky;
  top: 64px;
  max-height: calc(100vh - 80px);
  overflow-y: auto;
}
@media (max-width: 1000px) { .ticket { position: static; max-height: none; } }
.ticket-head { display: flex; align-items: center; justify-content: space-between; }
.ticket-head h2 { font-size: 14px; margin: 0; }

.fld { display: flex; flex-direction: column; gap: 4px; position: relative; min-width: 0; }
.fld > label {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: .04em;
  display: flex;
  align-items: center;
  gap: 6px;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

select, input[type="text"], input[type="number"], input[type="date"], input[type="search"] {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 9px;
  font-size: 13px;
  font-family: inherit;
  min-width: 0;
  width: 100%;
}
select:focus, input:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }
input[readonly] { background: var(--surface-alt); color: var(--text-muted); }

.ticker-wrap { display: flex; gap: 6px; }
.ticker-wrap input { text-transform: uppercase; font-weight: 600; }
.ticker-wrap input::placeholder { text-transform: none; font-weight: 400; }

.link-btn {
  background: none;
  border: 0;
  padding: 0;
  color: var(--primary);
  font: inherit;
  font-size: 11px;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 600;
  cursor: pointer;
}
.link-btn:hover { text-decoration: underline; }
.link-btn:disabled { color: var(--text-faint); cursor: default; }

/* segmented control */
.seg { display: inline-flex; background: var(--surface-sunk); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 2px; }
.seg-btn {
  border: 0;
  background: none;
  color: var(--text-muted);
  font: inherit;
  font-weight: 600;
  font-size: 12px;
  padding: 5px 14px;
  border-radius: 4px;
  cursor: pointer;
  flex: 1;
}
.seg-btn.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.side-seg .seg-btn[data-side="BUY"].active { background: var(--buy); color: #fff; }
.side-seg .seg-btn[data-side="SELL"].active { background: var(--sell); color: #fff; }

/* suggestions */
.ticker-suggest {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 40;
  margin-top: 2px;
  max-height: 300px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
}
.ts-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 12.5px;
}
.ts-item.active, .ts-item:hover { background: var(--surface-alt); }
.ts-item b { min-width: 90px; }
.ts-company { color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.ts-badge { font-size: 10px; font-weight: 600; padding: 1px 6px; border-radius: 4px; white-space: nowrap; }
.ts-badge.open { background: var(--buy-soft); color: var(--buy); }
.ts-badge.closed { background: var(--surface-sunk); color: var(--text-muted); }
.ts-empty { padding: 8px 10px; color: var(--text-faint); font-size: 12px; }

/* holdings line */
.holding {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  border: 1px solid var(--border);
}
.holding b { font-variant-numeric: tabular-nums; }
.holding.none { color: var(--text-muted); }

/* quote + depth */
.quote { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px; background: var(--surface-alt); }
.quote-head { display: flex; justify-content: space-between; align-items: baseline; }
.ltp { font-size: 20px; font-weight: 700; }
.chg { font-size: 12px; font-weight: 600; margin-left: 6px; }
.chg.up { color: var(--buy); }
.chg.down { color: var(--sell); }
.quote-meta { display: flex; gap: 6px; align-items: center; }
[data-q=age].live { color: var(--buy); font-weight: 600; }
[data-q=ltp].tick-up { animation: tick-up 0.8s ease-out; }
[data-q=ltp].tick-down { animation: tick-down 0.8s ease-out; }
@keyframes tick-up { from { background: var(--buy-soft); } to { background: transparent; } }
@keyframes tick-down { from { background: var(--sell-soft); } to { background: transparent; } }
.src-badge { font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 4px; background: var(--surface-sunk); color: var(--text-muted); border: 1px solid var(--border); }
.quote-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px 10px; margin: 6px 0 8px; font-size: 11px; }
.quote-stats span { color: var(--text-faint); }
.quote-stats b { font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; }

.depth { width: 100%; border-collapse: collapse; font-size: 11.5px; table-layout: fixed; }
.depth th { font-size: 9.5px; color: var(--text-faint); font-weight: 600; text-transform: uppercase; padding: 2px 4px; text-align: right; }
.depth th:nth-child(n+4) { text-align: left; }
.depth td { padding: 2px 4px; position: relative; text-align: right; }
.depth td:nth-child(n+4) { text-align: left; }
.depth td.bid-px { color: var(--buy); font-weight: 600; }
.depth td.ask-px { color: var(--sell); font-weight: 600; }
.depth td.o { color: var(--text-faint); }
.depth tr.bar-row td { background: none; }
.depth .qbar { position: absolute; top: 2px; bottom: 2px; z-index: 0; border-radius: 2px; }
.depth .qbar.bid { right: 0; background: var(--buy-soft); }
.depth .qbar.ask { left: 0; background: var(--sell-soft); }
.depth td > span { position: relative; z-index: 1; }
.depth tr.mine td { outline: 1px dashed var(--primary); outline-offset: -1px; }

.obi { margin-top: 8px; }
.obi-bar { display: flex; height: 5px; border-radius: 3px; overflow: hidden; background: var(--surface-sunk); }
.obi-bar span:first-child { background: var(--buy); }
.obi-bar span:last-child { background: var(--sell); }
.obi-labels { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--text-muted); margin-top: 3px; }

/* pricing modes */
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.mode {
  display: flex;
  flex-direction: column;
  gap: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 9px;
  cursor: pointer;
  position: relative;
  background: var(--surface);
}
.mode input[type="radio"] { position: absolute; opacity: 0; pointer-events: none; }
.mode:has(input[type="radio"]:checked) { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.mode:has(input[type="radio"]:focus-visible) { outline: 2px solid var(--primary); outline-offset: 1px; }
.mode-name { font-size: 10.5px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .03em; }
.mode-price { font-size: 14px; font-weight: 700; }
.mode-input { padding: 2px 6px !important; font-size: 14px !important; font-weight: 700; }
.rationale { font-size: 11px; color: var(--text-muted); min-height: 0; }
.rationale div + div { margin-top: 2px; }
.rationale .w { color: var(--warn); }
#e-mode-field.disabled .modes { opacity: .45; pointer-events: none; }

.estimate { font-size: 12.5px; color: var(--text-muted); min-height: 18px; }
.estimate b { color: var(--text); }
.warn-line { font-size: 12px; color: var(--warn); background: var(--warn-soft); padding: 6px 9px; border-radius: var(--radius-sm); }

.right-col { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.sheet-hist {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  padding: 10px 12px;
}
.sheet-hist-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-hist-head h2 { font-size: 13px; margin: 0; }
.sheet-hist.collapsed .ticker-txns { display: none; }
.tk-link { background: none; border: 0; padding: 0; font: inherit; font-weight: 700; color: var(--primary); cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }
.ticker-txns tr.pick-row { cursor: pointer; }
.ticker-txns tr.pick-row:hover td { background: var(--surface-2, rgba(0,0,0,.04)); }
.ticker-txns { overflow-x: auto; margin-top: 8px; max-height: 260px; overflow-y: auto; }
.ticker-txns table { width: 100%; border-collapse: collapse; font-size: 12px; }
.ticker-txns th, .ticker-txns td { padding: 5px 10px; text-align: left; white-space: nowrap; border-top: 1px solid var(--border); }
.ticker-txns th { color: var(--text-faint); font-size: 10px; text-transform: uppercase; letter-spacing: .03em; border-top: 0; position: sticky; top: 0; background: var(--surface); }
.ticker-txns td.num, .ticker-txns th.num { text-align: right; font-variant-numeric: tabular-nums; }
.ticker-txns td.up { color: var(--buy); }
.ticker-txns td.down { color: var(--sell); }
.ticker-txns tr.closed td { color: var(--text-faint); }

/* ── Buttons ─────────────────────────────────────────────────────── */
.btn {
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
  font-family: inherit;
  white-space: nowrap;
}
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-buy { background: var(--buy); color: #fff; }
.btn-sell { background: var(--sell); color: #fff; }
.btn-buy:hover:not(:disabled), .btn-sell:hover:not(:disabled) { filter: brightness(1.08); }
.btn-danger { background: var(--sell); color: #fff; }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-alt); }
.btn-sm { padding: 4px 10px; font-size: 11.5px; }
.btn-xs { padding: 2px 8px; font-size: 11px; }
.btn-icon { padding: 5px 10px; font-size: 15px; line-height: 1; }
.btn-block { width: 100%; padding: 10px; font-size: 13.5px; }
.act { display: flex; gap: 4px; flex-wrap: nowrap; }
.act .btn-xs.ghost-danger { color: var(--sell); }

/* ── Blotter ─────────────────────────────────────────────────────── */
.blotter {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  min-width: 0;
}
.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.filters input[type="search"] { width: 190px; }
.filters input[type="date"] { width: 132px; }
.filters select { width: auto; }
.filters .spacer { flex: 1; }
.date-filters { display: contents; }
.date-filters[hidden] { display: none; }
#f-more-btn .arrow { display: inline-block; transition: transform .15s; }
#f-more-btn[aria-expanded="true"] .arrow { transform: rotate(90deg); }
.chips { display: inline-flex; gap: 4px; }
.chip {
  cursor: pointer;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  font: inherit;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
}
.chip:hover { background: var(--surface-sunk); }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.table-scroll { overflow: auto; max-height: calc(100vh - 150px); }
table.orders { width: 100%; border-collapse: collapse; min-width: 860px; }
.orders thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  text-align: left;
  background: var(--surface-alt);
  color: var(--text-muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 8px 10px;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.orders th[data-sort] { cursor: pointer; user-select: none; }
.orders th[data-sort]:hover { color: var(--text); }
.orders th.sorted-asc::after { content: " ▲"; font-size: 8px; }
.orders th.sorted-desc::after { content: " ▼"; font-size: 8px; }
.orders th.num, .orders td.num { text-align: right; }
.orders td { padding: 7px 10px; border-top: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
.orders tbody tr:hover td { background: var(--surface-alt); }
.orders tr.flash td { animation: flash 1.6s ease-out; }
@keyframes flash { from { background: var(--warn-soft); } to { background: transparent; } }
.orders .tk { font-weight: 700; }
.orders .sub { display: block; font-size: 10.5px; color: var(--text-faint); }
.orders .side { font-weight: 700; font-size: 11px; }
.orders .side.BUY { color: var(--buy); }
.orders .side.SELL { color: var(--sell); }
.orders input.cell-in { width: 78px; padding: 3px 6px; text-align: right; font-size: 12px; }
.orders .away { display: block; font-size: 10.5px; color: var(--text-faint); }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .02em;
  background: var(--surface-sunk);
  color: var(--text-muted);
}
.badge-success { background: var(--buy-soft); color: var(--buy); }
.badge-failed { background: var(--sell-soft); color: var(--sell); }
.badge-pending, .badge-processing, .badge-queued, .badge-o_pending, .badge-sl_pending, .badge-modified { background: var(--warn-soft); color: var(--warn); }
.badge-partially_filled { background: var(--warn-soft); color: var(--warn); outline: 1px solid var(--warn); }
.badge-cancelled, .badge-expired, .badge-draft { background: var(--surface-sunk); color: var(--text-muted); }

.err-text {
  display: block;
  color: var(--sell);
  font-size: 10.5px;
  margin-top: 2px;
  max-width: 280px;
  white-space: normal;
  word-break: break-word;
}
.err-text.soft { color: var(--text-faint); }
.empty { color: var(--text-faint); padding: 40px; text-align: center; }

/* ── Dialog ──────────────────────────────────────────────────────── */
.dlg {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  padding: 18px 20px;
  width: min(420px, calc(100vw - 32px));
  box-shadow: var(--shadow-lg);
}
.dlg::backdrop { background: rgba(10, 14, 22, .45); }
.dlg h3 { margin: 0 0 12px; font-size: 15px; }
.dlg-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; font-size: 13px; }
.kv span { color: var(--text-muted); }
.kv b { text-align: right; font-variant-numeric: tabular-nums; }
.kv b.buy { color: var(--buy); }
.kv b.sell { color: var(--sell); }
.dlg .note { font-size: 11.5px; color: var(--text-muted); margin-top: 10px; }
.dlg .warn-line { margin-top: 10px; }

/* ── Toasts ──────────────────────────────────────────────────────── */
#toasts {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
  max-width: min(380px, calc(100vw - 32px));
}
.toast {
  background: var(--text);
  color: var(--bg);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  box-shadow: var(--shadow-lg);
  animation: toast-in .2s ease-out;
}
.toast.error { background: var(--sell); color: #fff; }
.toast.ok { background: var(--buy); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

@media (max-width: 600px) {
  .topbar { padding: 8px 16px; gap: 10px; }
  .stat { padding: 2px 8px; min-width: 0; }
  .filters input[type="search"] { width: 100%; }
}

/* ── Navigation ──────────────────────────────────────────────────── */
.nav { display: flex; gap: 2px; }
.nav a, .tab {
  color: var(--text-muted);
  text-decoration: none;
  font: inherit;
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 9px;
  border-radius: var(--radius-sm);
  background: none;
  border: 0;
  cursor: pointer;
}
.nav a:hover, .tab:hover { background: var(--surface-alt); color: var(--text); }
.nav a.active { background: var(--surface-sunk); color: var(--text); }
.tabs { display: flex; gap: 2px; border-left: 1px solid var(--border); padding-left: 12px; }
.tab.active { color: var(--primary); box-shadow: inset 0 -2px 0 var(--primary); border-radius: 0; }

/* ── Ops page ────────────────────────────────────────────────────── */
.page { padding: 16px 20px 24px; }
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
}
.panel-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.panel-bar .spacer { flex: 1; }
.panel-bar select, .panel-bar input[type="search"], .panel-bar input[type="date"] { width: auto; }
.check { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-muted); }
.mini-in { width: 56px !important; padding: 3px 6px !important; }
.meta { font-size: 11.5px; color: var(--text-muted); padding: 8px 12px; }
.meta.inline { padding: 0; }
.meta .warn-line { margin-top: 6px; }
.src-line { margin-top: 4px; }
.src-line.stored { color: var(--warn); background: var(--warn-soft); padding: 5px 9px; border-radius: var(--radius-sm); }
.src-line.down { color: var(--sell); background: var(--sell-soft); padding: 5px 9px; border-radius: var(--radius-sm); font-weight: 600; }
.sheet-check { margin: 0 12px 10px; font-size: 12px; padding: 6px 10px; border-radius: var(--radius-sm); }
.sheet-check.ok { color: var(--buy); background: var(--buy-soft); }
.sheet-check.bad { color: var(--sell); background: var(--sell-soft); }
.sheet-check summary { cursor: pointer; }
.sheet-check ul { margin: 6px 0; padding-left: 18px; color: var(--text); }
.sheet-check .muted { font-weight: 400; }
.table-scroll.tall { max-height: calc(100vh - 230px); }

.bucket-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 12px 10px; }
.bchip {
  font: inherit; font-size: 11.5px; font-weight: 600; cursor: pointer;
  padding: 4px 10px; border-radius: 999px;
  background: var(--surface-alt); color: var(--text-muted); border: 1px solid var(--border);
}
.bchip b { margin-left: 3px; color: var(--text); }
.bchip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.bchip.active b { color: #fff; }
.tone-bad { --tone: var(--sell); --tone-soft: var(--sell-soft); }
.tone-warn { --tone: var(--warn); --tone-soft: var(--warn-soft); }
.tone-ok { --tone: var(--buy); --tone-soft: var(--buy-soft); }
.tone-info { --tone: var(--primary); --tone-soft: rgba(53, 99, 233, .12); }
.bchip[class*="tone-"]:not(.active) { border-color: var(--tone-soft); }
.badge[class*="tone-"] { background: var(--tone-soft); color: var(--tone); }
.recon td { vertical-align: top; }
.recon td:nth-child(2) { white-space: normal; max-width: 240px; word-break: break-word; }
.recon td:nth-child(2) .sub { white-space: normal; }
.recon td.fix { white-space: normal; min-width: 340px; }
.hint { display: block; font-size: 11px; color: var(--warn); margin-top: 3px; }
.pos { color: var(--buy); font-weight: 600; }
.neg { color: var(--sell); font-weight: 600; }

.fund-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; padding: 12px; }
.fund-card { border: 1px solid var(--border); border-radius: var(--radius-md); padding: 12px; background: var(--surface-alt); }
.fund-card { cursor: pointer; }
.fund-card:hover { border-color: var(--accent, var(--border)); }
.fund-card.loading { opacity: .5; pointer-events: none; }
.fund-card.neg { border-color: var(--sell); box-shadow: 0 0 0 1px var(--sell-soft); }
.fund-head { display: flex; justify-content: space-between; align-items: center; gap: 6px; }
.fund-cash { font-size: 22px; font-weight: 700; margin: 6px 0 2px; font-variant-numeric: tabular-nums; }
.fund-cash .sub { font-size: 11px; font-weight: 500; color: var(--text-faint); margin-left: 6px; }
.fund-cash.neg, .fund-proj.neg { color: var(--sell); }
.fund-proj { font-size: 12px; color: var(--text-muted); }
.fund-lines { display: grid; grid-template-columns: 1fr auto; gap: 3px 10px; font-size: 12px; margin-top: 8px; }
.fund-lines span { color: var(--text-muted); }
.fund-lines b { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

.job-groups { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; padding: 12px; align-items: start; }
.job-group { border: 1px solid var(--border); border-radius: var(--radius-md); padding: 10px 12px; background: var(--surface-alt); }
.job-group-head { display: flex; justify-content: space-between; align-items: center; gap: 6px; margin-bottom: 8px; }
.job { padding: 5px 0; border-top: 1px solid var(--border); }
.job-group-head + .job { border-top: 0; }
.job-main { display: flex; align-items: center; gap: 8px; }
.job-main .btn { flex: 1; min-width: 0; text-align: left; white-space: normal; height: auto; padding-top: 5px; padding-bottom: 5px; }
.job-last { font-size: 11px; color: var(--text-faint); margin: 2px 0 0 2px; }
.job-sched { font-size: 11px; color: var(--text-faint); margin: 1px 0 0 2px; }
.job-last.done { color: var(--buy); }
.job-last.failed { color: var(--sell); }
.job-last.running { color: var(--warn); }
.pill { font-size: 10px; font-weight: 600; padding: 1px 7px; border-radius: 999px; }
.pill.ok { background: var(--buy-soft); color: var(--buy); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--sell-soft, rgba(220,60,60,.15)); color: var(--sell, #d33); }
.pill.info { background: var(--surface-sunk); color: var(--text); }
.job-log { margin: 0 12px 12px; border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }
.job-log-head { display: flex; justify-content: space-between; padding: 6px 10px; background: var(--surface-alt); font-size: 12px; }
.job-log pre { margin: 0; padding: 10px; max-height: 360px; overflow: auto; font-size: 11.5px; background: var(--surface-sunk); white-space: pre-wrap; word-break: break-word; }
.tx-ranges { display: inline-flex; gap: 4px; }
.tx-stock { position: relative; min-width: 220px; }
.tx-stock input { width: 100%; }
.orders.tx th[data-tsort] { cursor: pointer; user-select: none; white-space: nowrap; }
.orders.tx tfoot td { font-weight: 600; border-top: 2px solid var(--border); background: var(--surface-alt); }
.tx-sub { color: var(--text-muted); font-size: 11.5px; margin-left: 6px; }

/* order-ticket cash line */
.cash-line { font-size: 12px; color: var(--text-muted); display: flex; justify-content: space-between; }
.cash-line b { font-variant-numeric: tabular-nums; color: var(--text); }
.cash-line b.neg { color: var(--sell); }

@media (max-width: 700px) {
  .tabs { border-left: 0; padding-left: 0; width: 100%; overflow-x: auto; }
  .page { padding: 12px 16px; }
}

/* ── Reconcile fixes ─────────────────────────────────────────────── */
.dlg.dlg-wide { width: min(620px, calc(100vw - 32px)); }
.fx-modes { display: flex; gap: 14px; margin-bottom: 10px; }
.fx-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 12px; }
.fx-field { display: flex; flex-direction: column; gap: 3px; font-size: 11.5px; color: var(--text-muted); }
.fx-field select, .fx-field input { width: 100%; }
.fx-wide, .fx-modes { grid-column: 1 / -1; }
.fx-preview { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 10px; max-height: 46vh; overflow: auto; }
.fx-summary { font-size: 12.5px; font-weight: 600; margin-bottom: 8px; }
table.orders.fx-cells { min-width: 0; }
.fx-cells td, .fx-cells th { padding: 4px 8px; font-size: 12px; }
.fx-cells td { white-space: normal; word-break: break-word; }
.fx-force { margin-top: 8px; color: var(--text); }
.err-line { font-size: 12px; color: var(--sell); background: var(--sell-soft); padding: 6px 9px; border-radius: var(--radius-sm); margin-top: 8px; }
.written { display: block; font-size: 11px; color: var(--buy); margin-top: 3px; }
.fix-btn { margin-top: 6px; display: block; }
.writes { border-top: 1px solid var(--border); padding: 10px 12px; }
.writes summary { cursor: pointer; font-size: 12.5px; font-weight: 600; margin-bottom: 6px; }
.writes .meta.inline { display: block; margin-bottom: 8px; }
tr.undone td { color: var(--text-faint); text-decoration: line-through; }
tr.undone td:last-child { text-decoration: none; }
@media (max-width: 600px) { .fx-fields { grid-template-columns: 1fr; } }

/* ── Health strip ────────────────────────────────────────────────── */
.health-wrap { position: relative; }
.health {
  display: inline-flex; align-items: center; gap: 6px; max-width: 260px;
  font: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
  padding: 5px 10px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface-alt); color: var(--text-muted);
}
.health span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); flex: none; }
.h-ok .dot { background: var(--buy); }
.h-info .dot { background: var(--primary); }
.h-warn .dot { background: var(--warn); }
.h-bad .dot { background: var(--sell); }
.health.h-bad { border-color: var(--sell); color: var(--sell); background: var(--sell-soft); }
.health.h-warn { border-color: var(--warn); color: var(--warn); background: var(--warn-soft); }
.health-pop {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 50;
  width: min(420px, calc(100vw - 32px)); max-height: 70vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg); padding: 10px 12px;
}
.hp-head { display: flex; gap: 8px; align-items: baseline; font-size: 12.5px; font-weight: 600; margin-bottom: 6px; }
.hp-head a { margin-left: auto; font-weight: 500; color: var(--primary); text-decoration: none; }
.hp-row { display: grid; grid-template-columns: 8px 110px 1fr; gap: 8px; align-items: baseline; font-size: 12px; padding: 4px 0; border-top: 1px solid var(--border); }
.hp-row .dot { transform: translateY(1px); }
.hp-row > span:last-child { color: var(--text-muted); word-break: break-word; }

/* ── Order ticket: advisor ───────────────────────────────────────── */
.ask-tag { font-size: 10px; font-weight: 700; color: var(--warn); background: var(--warn-soft); padding: 1px 6px; border-radius: 999px; margin-left: 4px; }
.advisor-note { font-size: 11.5px; color: var(--text-muted); margin: -4px 0 8px; }

/* ── EOD + missed days ───────────────────────────────────────────── */
.eod-box { border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--surface-alt); padding: 12px; margin: 12px; }
.eod-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.eod-head .spacer { flex: 1; }
.eod-steps { display: grid; grid-template-columns: 16px minmax(160px, 220px) 1fr auto; gap: 4px 10px; margin-top: 10px; font-size: 12px; align-items: baseline; }
.eod-steps .st { font-weight: 700; text-align: center; }
.st-DONE { color: var(--buy); } .st-FAILED { color: var(--sell); } .st-RUNNING { color: var(--primary); }
.st-SKIPPED, .st-PENDING { color: var(--text-faint); }
.eod-steps .det { color: var(--text-muted); word-break: break-word; }
.eod-hist { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; font-size: 11.5px; }
.catchup { margin: 0 12px 10px; border: 1px solid var(--warn); background: var(--warn-soft); border-radius: var(--radius-md); padding: 8px 10px; }
.catchup.ok { border-color: var(--border); background: var(--surface-alt); }
.catchup-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; font-size: 12.5px; }
.catchup-head .spacer { flex: 1; }
.catchup table.orders { min-width: 0; margin-top: 8px; background: var(--surface); }
.catchup td { white-space: normal; }
@media (max-width: 600px) { .eod-steps { grid-template-columns: 16px 1fr; } .eod-steps .det, .eod-steps .tm { grid-column: 2; } }

/* ── ACA trade book ──────────────────────────────────────────────── */
.cu-scroll { max-height: 46vh; }
.catchup td .badge { white-space: nowrap; }
.tb-changes { font-size: 12px; margin-top: 6px; }
.tb-changes summary { cursor: pointer; font-weight: 600; color: var(--warn); }
.tb-changes ul { margin: 6px 0 0; padding-left: 18px; }
.tb-changes li.added { color: var(--buy); }
.tb-changes li.removed { color: var(--sell); }
.cu-rt { font-size: 12px; margin: 6px 0; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; color: var(--text-muted); }

/* Missed days: expandable stock view */
.cu-row { cursor: pointer; }
.cu-row:hover td { background: var(--surface-alt); }
.cu-caret { width: 14px; color: var(--text-muted); }
.cu-row.open td { border-bottom: 0; }
.cu-detail > td { padding-top: 0; }
.sv { display: grid; gap: 8px; padding: 6px 0 12px; font-size: 12.5px; }
.sv-sugg { display: grid; gap: 4px; }
.sv-s { padding: 5px 8px; border-radius: 6px; border-left: 3px solid var(--text-muted); background: rgba(127,127,127,.07); }
.sv-s.tone-good { border-left-color: var(--buy); }
.sv-s.tone-warn { border-left-color: var(--warn); }
.sv-s.tone-info { border-left-color: var(--primary); }
.sv-line b, .sv-sugg > b { margin-right: 6px; }
.sv-lot { display: inline-block; padding: 1px 6px; margin: 1px 2px; border-radius: 10px; background: rgba(127,127,127,.1); }
.sv-lot.here { background: rgba(74,124,240,.16); }
.sv-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 900px) { .sv-cols { grid-template-columns: 1fr; } }
.sv-h { font-weight: 600; margin-bottom: 4px; }
.sv-t { width: 100%; border-collapse: collapse; font-size: 12px; }
.sv-t th, .sv-t td { padding: 2px 6px; border-bottom: 1px solid var(--border); text-align: left; }
.sv-t td.num { text-align: right; }
.sv-t tr.here td { background: rgba(74,124,240,.07); }
.sv-t tr.this td { font-weight: 600; background: var(--warn-soft); }
.sv-t td, .sv-t th { white-space: nowrap; }

.copy-btn { border: 0; background: none; padding: 0 3px; margin-left: 2px; cursor: pointer; font-size: 12px; line-height: 1;
  color: var(--text-faint); opacity: .55; vertical-align: baseline; }
.copy-btn:hover, .copy-btn:focus-visible { opacity: 1; color: var(--primary); }
.copy-btn.done { opacity: 1; color: var(--buy); }

/* Portfolio tab */
.pf-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; padding: 12px; }
.pf-card { cursor: pointer; }
.pf-card:hover { border-color: var(--primary); }
.pf-card .fund-cash { font-size: 18px; }
.pf td .sub.pos, .pf td .sub.neg { font-weight: 500; }
.pf tr.pf-closed td { color: var(--text-muted); }
.pf td.pf-check { white-space: normal; min-width: 180px; }
.pf td.pf-check .badge { display: inline-block; margin: 1px 0; white-space: normal; }

.cu-toggle { font-size: 14px; width: 18px; text-align: center; text-decoration: none; }
.cu-title { cursor: pointer; }

.accepted-note { display: block; font-size: 12px; color: var(--buy); margin-top: 3px; white-space: normal; }

/* ── Multi-select filter (advisors / demats) ─────────────────────── */
.mpick { position: relative; display: inline-block; }
.mpick-btn {
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 7px 26px 7px 9px; font-size: 13px; font-family: inherit; cursor: pointer; white-space: nowrap; position: relative;
}
.mpick-btn::after { content: "▾"; position: absolute; right: 9px; color: var(--text-muted); }
.mpick-btn.narrowed { border-color: var(--primary); color: var(--primary); }
.mpick-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: -1px; }
.mpick-pop {
  position: absolute; left: 0; top: calc(100% + 4px); z-index: 50; min-width: 200px; max-width: calc(100vw - 32px);
  max-height: 60vh; overflow: auto; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-lg); padding: 6px 0;
}
.mpick-pop[hidden] { display: none; }
.mpick-acts { display: flex; gap: 12px; padding: 2px 12px 6px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.mpick-acts button { background: none; border: 0; padding: 0; color: var(--primary); font: inherit; font-size: 12px; cursor: pointer; }
.mpick-pop label { display: flex; align-items: center; gap: 8px; padding: 4px 12px; font-size: 13px; cursor: pointer; white-space: nowrap; }
.mpick-pop label:hover { background: var(--surface-alt); }
.mpick-pop label .only { margin-left: auto; padding-left: 12px; font-size: 11px; color: var(--primary); visibility: hidden; }
.mpick-pop label:hover .only { visibility: visible; }

/* ── Floating quote boxes ─────────────────────────────────────────────── */
.qbox { position: fixed; width: 340px; max-width: calc(100vw - 16px); background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: 0 8px 28px rgba(0, 0, 0, .18); }
.qbox .quote { border: 0; border-radius: 0 0 var(--radius-sm) var(--radius-sm); }
.qbox-head { display: flex; align-items: center; gap: 8px; padding: 5px 6px 5px 10px; border-bottom: 1px solid var(--border);
  cursor: move; user-select: none; touch-action: none; }
.qbox-tk { font: inherit; font-weight: 700; font-size: 13px; color: var(--text); background: none; border: 0; padding: 0; cursor: pointer; }
.qbox-tk:hover { color: var(--primary); text-decoration: underline; }
.qbox-mini { flex: 1; font-size: 12px; font-variant-numeric: tabular-nums; display: none; }
.qbox-mini .chg { margin-left: 4px; }
.qbox.collapsed .qbox-mini { display: block; }
.qbox.collapsed .quote { display: none; }
.qbox.collapsed .qbox-head { border-bottom: 0; }
.qbox:not(.collapsed) .qbox-tk { flex: 1; text-align: left; }
.qbox-btn { width: 24px; height: 22px; border: 0; border-radius: 4px; background: none; color: var(--text-muted); font-size: 15px; line-height: 1; cursor: pointer; }
.qbox-btn:hover { background: var(--surface-sunk); color: var(--text); }
.qbox-btn[data-act="close"]:hover { color: var(--sell); }
.qbox-chk { margin: 0 6px 0 0; vertical-align: middle; cursor: pointer; accent-color: var(--primary); }

/* Missed days: bulk record */
.cu-bulk { display: flex; justify-content: flex-end; margin: 6px 0; }
th.cu-chk, td.cu-chk { width: 28px; text-align: center; }

/* depth: biggest order count per side, clickable levels in the floating boxes */
.depth td.o.max-bid { color: var(--buy); font-weight: 700; background: var(--buy-soft); border-radius: 3px; }
.depth td.o.max-ask { color: var(--sell); font-weight: 700; background: var(--sell-soft); border-radius: 3px; }
.qbox .depth tbody tr { cursor: pointer; }
.qbox .depth tbody tr:hover td { background: rgba(127, 127, 127, .10); }
.cur-price { display: block; font-size: 11px; color: var(--text-faint); text-align: right; }

/* ticket: narrow Broker, wide Account so 'SSA24-Piyush(Aveek, Inflec)' fits without widening the panel */
.row2.acct-row { grid-template-columns: 96px minmax(0, 1fr); }
#e-demat { font-size: 12.5px; text-overflow: ellipsis; }
.pf-summary .mtm-pct { font-size: 11px; margin-left: 6px; font-weight: 500; }

/* Demat Holdings: today's trades */
.star { color: #e0a800; font-weight: 700; }
.hd td.star { width: 18px; text-align: center; }
.hd tr.hd-star td { background: var(--surface-alt); }

.hd th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.hd th.sorted { color: var(--text); }
.hd .filter-row th { padding: 2px 4px; position: static; }
.hd .col-filter { width: 100%; min-width: 56px; font-size: 11px; padding: 2px 4px; }
.hd .col-filter.num { text-align: right; }
.hd .col-filter.bad { border-color: var(--sell); }
.hd .hd-sym { min-width: 170px; width: 190px; max-width: 190px; white-space: normal; overflow-wrap: break-word; line-height: 1.25; }
.hd .hd-co { min-width: 160px; width: 200px; max-width: 200px; white-space: normal; line-height: 1.25; color: var(--text-muted); }

.pf-sum .catchup-head { padding: 8px 12px 0; }
.pf-sum.collapsed #pf-cards { display: none !important; }

.pf th[data-lsort], th[data-csort], th[data-asort] { cursor: pointer; user-select: none; white-space: nowrap; }

.review-row td { background: rgba(255, 193, 7, .16); }
.review-cell { background: rgba(255, 193, 7, .35); padding: 0 4px; border-radius: 3px; }

.ad-cmp { table-layout: fixed; max-width: none; }
.ad-cmp thead th { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.2; vertical-align: bottom; padding: 8px 5px; }
.ad-cmp td { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; vertical-align: top; padding: 7px 5px; }
.copy-btn { display: inline-flex; align-items: center; margin-left: 5px; padding: 1px 3px; border: 0; background: transparent; color: var(--muted, #888); cursor: pointer; border-radius: 3px; vertical-align: middle; opacity: .65; }
.copy-btn:hover { opacity: 1; background: var(--surface-sunk); }
.copy-btn.copied { color: var(--buy); opacity: 1; }
.lad-tog { padding: 0 2px; font-size: 11px; }
.ad-cmp tr.lad-row > td { white-space: normal; overflow: visible; text-overflow: clip; background: var(--surface-sunk); padding: 8px 10px 12px; }
.lad { display: flex; flex-wrap: wrap; gap: 16px; align-items: flex-start; position: sticky; left: 10px; max-width: calc(100vw - 90px); }
.lad-t { border-collapse: collapse; font-size: 12px; max-width: 900px; }
.lad-t th, .lad-t td { padding: 4px 8px; border-bottom: 1px solid var(--border, rgba(128,128,128,.25)); text-align: left; vertical-align: top; white-space: normal; }
.lad-t td:last-child { min-width: 260px; }
.lad-t tr.lad-on td { background: rgba(46, 160, 67, .16); font-weight: 600; }
.lad-t tr.lad-off td { opacity: .6; }
.lad-facts { font-size: 12px; max-width: 520px; display: grid; gap: 4px; }
#ad-notes details { margin: 2px 0; }
#ad-notes ul { margin: 4px 0 6px 18px; padding: 0; }

/* ── Draft orders (top-bar tray + add dialog, drafts.js) ─────────── */
.drafts-wrap { position: relative; }
.drafts-btn { position: relative; display: inline-flex; align-items: center; justify-content: center; }
.drafts-btn svg { display: block; }
.drafts-btn.pulse { animation: dp-pulse .6s ease-out; }
@keyframes dp-pulse { 0% { box-shadow: 0 0 0 0 var(--primary); } 100% { box-shadow: 0 0 0 8px transparent; } }
.drafts-badge {
  position: absolute; top: -5px; right: -5px; min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 999px; background: var(--primary); color: #fff; font-size: 10px; font-weight: 700;
  line-height: 16px; text-align: center; font-variant-numeric: tabular-nums;
}
.drafts-pop {
  position: fixed; right: 16px; top: 56px; z-index: 60;   /* top is set from the button when it opens */
  width: min(820px, calc(100vw - 32px)); max-height: 75vh; display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg); padding: 10px 12px;
}
.dp-head { display: flex; align-items: center; gap: 8px; font-size: 13px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.dp-head .spacer { flex: 1; }
.dp-head .buy { color: var(--buy); font-weight: 600; }
.dp-head .sell { color: var(--sell); font-weight: 600; }
.dp-scroll { overflow: auto; }
.dp-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.dp-table th { color: var(--text-faint); font-size: 10px; text-transform: uppercase; letter-spacing: .03em; text-align: left; padding: 6px 6px; position: sticky; top: 0; background: var(--surface); }
.dp-table td { padding: 6px 6px; border-top: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
.dp-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.dp-table .act { display: table-cell; text-align: right; }
.dp-table .act .btn + .btn { margin-left: 4px; }
.dp-src { font-size: 10.5px; color: var(--text-faint); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dp-src.pos, .dp-src.neg { font-weight: 500; }
.dp-in { width: 84px !important; padding: 4px 6px !important; text-align: right; font-variant-numeric: tabular-nums; }
.dp-confirm { margin-top: 2px; }
.dp-inline-ico { display: inline-flex; vertical-align: -2px; color: var(--primary); }
.side-tag { font-size: 10.5px; font-weight: 700; padding: 1px 7px; border-radius: 999px; }
.side-tag.buy { background: var(--buy-soft); color: var(--buy); }
.side-tag.sell { background: var(--sell-soft); color: var(--sell); }
.draft-dlg { width: min(440px, calc(100vw - 32px)); }
/* non-modal and movable: dragged by its header, the page (and quote boxes) stay usable */
.draft-dlg[open] { position: fixed; inset: auto; margin: 0; z-index: 58; max-height: calc(100vh - 16px); overflow-y: auto; }
.draft-dlg .dd-drag { cursor: move; user-select: none; touch-action: none; gap: 8px; }
.draft-dlg .dd-drag h3 { flex: 1; }
.dd-mode { display: flex; align-items: center; gap: 10px; margin: 6px 0 8px; }
.dd-mode .seg-btn[data-mode="direct"].active { background: var(--warn); color: #fff; }
.draft-dlg .ticket-head { margin-bottom: 4px; }
.draft-dlg .ticket-head h3 { margin: 0; }
.dd-src { font-size: 11.5px; color: var(--text-muted); margin-bottom: 10px; }
.dd-grid { display: flex; flex-direction: column; gap: 10px; }
.dd-grid .advisor-note { margin: -4px 0 0; }
.dd-cmp { margin-left: auto; text-transform: none; letter-spacing: 0; color: var(--text); font-weight: 600; }
.dd-ticker { text-transform: uppercase; font-weight: 600; }
.dd-off { opacity: .5; }
/* "add to drafts" icon button for table rows (any page) */
.draft-add { border: 0; background: none; padding: 2px; cursor: pointer; color: var(--text-faint); border-radius: 4px; display: inline-flex; vertical-align: middle; }
.draft-add:hover, .draft-add:focus-visible { color: var(--primary); background: var(--surface-sunk); }
.draft-add.in { color: var(--primary); }

/* stock codes: Ctrl/Cmd+click opens TradingView */
.tvc:hover { text-decoration: underline dotted; text-underline-offset: 3px; }
body.tv-ready .tvc { cursor: pointer; color: var(--primary); text-decoration: underline; }

/* Advisors: mailed recommendations */
.nav-badge { display: inline-block; min-width: 18px; margin-left: 6px; padding: 0 5px; border-radius: 9px; background: var(--bad, #d64545);
  color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; }
.ad-new-banner { border: 1px solid var(--warn, #d9a400); background: var(--surface-alt); border-radius: 8px; padding: 8px 10px; margin: 4px 0; }
.ad-new-banner #ad-seen { margin-left: 8px; }
.ad-mail { margin-top: 6px; font-size: 12px; }
.ad-mail-body { white-space: pre-wrap; margin: 2px 0 0 10px; color: var(--text); }
tr.ad-new-row td { background: color-mix(in srgb, var(--warn, #d9a400) 14%, transparent); }
details.why summary { cursor: pointer; list-style: none; }
details.why summary::before { content: "▸ "; color: var(--muted); }
details.why[open] summary::before { content: "▾ "; }
details.why[open] summary { display: none; }
details.why[open]::before { content: ""; }
.why-full { white-space: pre-wrap; }

/* A / B / CMP re-price choice under a live limit price */
.row-modes { display: flex; gap: 3px; justify-content: flex-end; margin-top: 3px; }
.row-modes .rm { font-size: 10px; line-height: 1; padding: 3px 6px; border: 1px solid var(--border); border-radius: 4px; background: var(--surface); color: var(--muted, #666); cursor: pointer; }
.row-modes .rm:hover { border-color: var(--primary); }
.row-modes .rm.on { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 700; }

/* your open orders drawn in the depth table: a line between levels, or a strike through the matched level */
.depth tr.my-line td { padding: 0; height: 0; font-size: 10px; font-weight: 700; line-height: 1.1; }
.depth tr.my-line td.ml { border-top: 1px solid; padding: 0 4px 1px; white-space: nowrap; }
.depth tr.my-line.buy td.ml { color: var(--buy); border-color: var(--buy); }
.depth tr.my-line.sell td.ml { color: var(--sell); border-color: var(--sell); }
.depth td.mine-hit { position: relative; background: rgba(0,0,0,.05); }
.depth td.mine-hit::after { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 1px; background: currentColor; pointer-events: none; }
.depth td.mine-hit.buy::after { background: var(--buy); }
.depth td.mine-hit.sell::after { background: var(--sell); }
.depth .mtag { font-style: normal; font-size: 9px; margin-left: 4px; padding: 0 3px; border-radius: 3px; background: var(--primary); color: #fff; }

/* Positions page */
.pos td.up { color: var(--buy); }
.pos td.down { color: var(--sell); }
.pos .total-row td { border-top: 1px solid var(--border); background: var(--surface-alt); }
.ps-acct { padding-bottom: 6px; border-bottom: 1px solid var(--border); }
.ps-acct-head { display: flex; gap: 10px; align-items: baseline; padding: 12px 12px 0; }
.ps-sub { margin: 10px 12px 4px; font-size: 11.5px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.ps-total { padding: 8px 12px; text-align: right; font-variant-numeric: tabular-nums; }
.ps-total .up { color: var(--buy); }
.ps-total .down { color: var(--sell); }
.ps-grand { font-size: 15px; border-top: 2px solid var(--border); }
.ps-refresh { display: inline-block; padding: 0 3px; border-radius: 4px; }
.ps-refresh:hover { background: var(--surface-sunk); }
.ps-refresh.spin { animation: ps-spin 1s linear infinite; }
@keyframes ps-spin { to { transform: rotate(360deg); } }
#ps-tabs { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; }
#ps-tabs .chip { flex: 0 0 auto; display: inline-flex; flex-direction: row; align-items: center; gap: 4px; white-space: nowrap; }

/* ── Read-only banner (sync.py: the other side holds the edit lock) ───── */
.ro-banner {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  padding: 7px 16px; background: var(--warn-soft); color: var(--warn);
  border-bottom: 1px solid var(--border); font-size: 13px; font-weight: 600;
  position: sticky; top: 0; z-index: 29;
}
.ro-banner a { color: inherit; }
.inline-form { display: inline; margin: 0; }

/* ── Login (AWS) ─────────────────────────────────────────────────── */
.login-body { min-height: 100vh; display: grid; place-items: center; background: var(--bg); padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-lg); padding: 22px 22px 18px;
}
.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; }
.login-card label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-muted); font-weight: 600; }
.login-card input { font-size: 16px; padding: 9px 10px; }
.login-card .btn { padding: 10px; font-size: 15px; }
.login-error { margin-top: 12px; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--sell-soft); color: var(--sell); font-size: 13px; }

/* ── Sync page ──────────────────────────────────────────────────── */
.sync-title { margin: 0; font-size: 15px; }
.sync-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; padding: 14px 12px 4px; }
.sync-card { border: 1px solid var(--border); border-radius: var(--radius-md); padding: 12px 14px; background: var(--surface-alt); }
.sync-big { font-size: 20px; font-weight: 700; margin: 4px 0 2px; }
.sync-big.buy { color: var(--buy); }
.sync-big.warn { color: var(--warn); }
.sync-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px; }
.sync-help { padding: 0 12px 14px; max-width: 760px; line-height: 1.5; }
#sy-error { padding: 0 12px 8px; color: var(--sell); }

/* ── Phone ──────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  .sync-grid { grid-template-columns: 1fr; }
  .page { padding: 10px 8px 20px; }
  .topbar { gap: 8px; padding: 6px 10px; }
  .topbar .nav { order: 3; width: 100%; overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .topbar .nav::-webkit-scrollbar { display: none; }
  .topbar .nav a { white-space: nowrap; flex: 0 0 auto; }
  .summary { order: 4; width: 100%; overflow-x: auto; margin-left: 0; }
  .panel-bar { gap: 6px; padding: 8px; }
  .panel-bar input[type="search"] { width: 100%; }
  .table-scroll, .table-scroll.tall { max-height: none; }
  .btn { min-height: 36px; }
  .ro-banner { padding: 6px 10px; font-size: 12px; }

  /* Stock search: the portfolio-sheet lots as cards, one per lot, all fields visible. */
  .ticket .sheet-hist { margin: 0; padding: 0; border: 0; box-shadow: none; background: none; }
  .sheet-hist-head h2 { font-size: 15px; }
  .ticker-txns { max-height: none; overflow: visible; }
  .ticker-txns table, .ticker-txns tbody { display: block; }
  .ticker-txns thead { display: none; }
  .ticker-txns tr.pick-row {
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px 10px;
    padding: 10px 12px; margin-bottom: 8px; border: 1px solid var(--border);
    border-radius: var(--radius-md); background: var(--surface);
  }
  .ticker-txns td { display: block; padding: 0; border: 0; white-space: normal; text-align: left !important; font-size: 14px; font-weight: 600; min-width: 0; overflow-wrap: anywhere; }
  .ticker-txns td::before {
    content: attr(data-l); display: block; font-size: 10px; font-weight: 600; color: var(--text-faint);
    text-transform: uppercase; letter-spacing: .03em; margin-bottom: 1px;
  }
  .ticker-txns td:empty { display: none; }
  .ticker-txns td[data-f="advisory"] { grid-column: 1 / 3; font-size: 16px; }
  .ticker-txns td[data-f="status"] { grid-column: 3; }
  .ticker-txns tr.closed { opacity: .65; }

  /* Holdings: one card per holding - stock and demat on top, then the figures with labels. */
  table.hd thead { display: none; }
  table.hd, table.hd tbody { display: block; width: 100%; min-width: 0 !important; }
  table.hd tbody tr { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px 10px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
  table.hd tbody td { display: block; padding: 0; border: 0; background: none !important; position: static !important; text-align: left !important; white-space: normal; min-width: 0; overflow-wrap: anywhere; font-size: 13px; }
  table.hd tbody td[data-l]::before { content: attr(data-l); display: block; font-size: 10px; font-weight: 600; color: var(--text-faint); text-transform: uppercase; letter-spacing: .03em; }
  table.hd tbody td:empty, table.hd tbody td.star { display: none; }
  table.hd tbody td.hd-sym { order: -2; grid-column: 1 / 3; font-size: 16px; }
  table.hd tbody td:nth-child(2) { order: -1; text-align: right !important; font-weight: 600; }
  table.hd tbody td.hd-sym::before, table.hd tbody td:nth-child(2)::before, table.hd tbody td.hd-co::before { display: none; }
  table.hd tbody td.hd-co { grid-column: 1 / -1; color: var(--text-muted); font-size: 12px; margin-top: -4px; }
  table.hd tbody tr.hd-star td.hd-sym b::after { content: " ★"; color: var(--warn); }
  table.hd tbody td[colspan] { grid-column: 1 / -1; }

  #al-file { overflow-wrap: anywhere; }

  /* Live quote boxes dock at the bottom instead of floating over the search field. */
  .qbox { left: 8px !important; right: 8px; top: auto !important; bottom: 8px; width: auto; max-width: none; max-height: 55vh; overflow-y: auto; }
  body { padding-bottom: 72px; }

  /* Read-only (the other side holds edit): searching is all the ticket can do, so hide the order form. */
  body:has(.ro-banner) .ticket > :not(.ticket-head):not(#e-ticker-field):not(.acct-row):not(#e-holding):not(.sheet-hist):not(.cash-line) { display: none !important; }
  body:has(.ro-banner) .ticket-head .side-seg { display: none; }
  body:has(.ro-banner) .ticket-head h2::after { content: " (read-only: search)"; font-weight: 400; color: var(--text-faint); font-size: 12px; }
}

/* ── Portfolio page ──────────────────────────────────────────────── */
/* chart series colours (fixed order, never cycled) - light / dark */
:root { --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #c98500; --s5: #d55181; --s6: #008300; --s7: #6250d6; --s8: #e34948; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #eda100; --s5: #e87ba4; --s6: #2ea043; --s7: #9085e9; --s8: #e66767; }
}
:root[data-theme="dark"] { --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #eda100; --s5: #e87ba4; --s6: #2ea043; --s7: #9085e9; --s8: #e66767; }

.pfp { display: flex; flex-direction: column; gap: 14px; }
.pfp-view { display: flex; flex-direction: column; gap: 14px; }
.pfp-view[hidden] { display: none; }
.pfp-view.panel { gap: 0; }
.pfp-views { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; border-bottom: 1px solid var(--border); }
.pfp-views a { padding: 8px 14px; color: var(--text-muted); text-decoration: none; font-weight: 600; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.pfp-views a:hover { color: var(--text); }
.pfp-views a.active { color: var(--primary); border-bottom-color: var(--primary); }
.pfp-views .spacer { flex: 1; }
.panel-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: 13px; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 10px 14px; box-shadow: var(--shadow); min-width: 0; }
.kpi-l { font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-faint); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: 2px; }
.kpi-v.pos { color: var(--buy); } .kpi-v.neg { color: var(--sell); }
.kpi-s { font-size: 11.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tr-bar .seg-btn { padding: 5px 11px; flex: 0 0 auto; }
.tr-chips { padding: 8px 12px 0; display: flex; flex-direction: column; gap: 6px; }
.tr-chip-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.tr-chip-row .spacer { flex: 1; }
.tr-chip-label { width: 78px; font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.tr-chip-set { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.tr-chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; border: 1px dashed var(--border);
  background: none; color: var(--text-faint); font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; }
.tr-chip.on { border-style: solid; border-color: var(--text-faint); color: var(--text); background: var(--surface-alt); }
.tr-chip:disabled { opacity: .45; cursor: not-allowed; }
.tr-sw { display: inline-block; width: 16px; height: 0; border-top: 2.5px solid var(--text-faint); vertical-align: middle; margin-right: 6px; }
.tr-chip .tr-sw { margin-right: 0; }
.tr-sw.dashed { border-top-width: 2px; border-color: var(--text-faint); }
.tr-chart { padding: 8px 8px 0 4px; min-height: 240px; }
.dot-legend { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--warn); vertical-align: middle; }

.lc { position: relative; }
.lc svg { display: block; overflow: visible; }
.lc-grid { stroke: var(--border); stroke-width: 1; }
.lc-zero { stroke: var(--text-faint); stroke-width: 1; }
.lc-tick { fill: var(--text-faint); font-size: 11px; font-variant-numeric: tabular-nums; }
.lc-cross { stroke: var(--text-faint); stroke-width: 1; stroke-dasharray: 3 3; }
.lc-dot { stroke: var(--surface); stroke-width: 2; }
.lc-marker { stroke: var(--surface); stroke-width: 2; }
.lc-tip { position: absolute; z-index: 5; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); padding: 7px 10px; font-size: 12px; min-width: 170px; }
.lc-date { color: var(--text-muted); margin-bottom: 4px; font-weight: 600; }
.lc-row { display: flex; align-items: center; gap: 8px; padding: 1px 0; font-variant-numeric: tabular-nums; }
.lc-row .lc-name { flex: 1; color: var(--text-muted); }
.lc-sw { width: 14px; border-top: 2.5px solid; }

.ov-grid { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 14px; align-items: start; }
table.orders.ov-adv, table.orders.al, table.orders.heat, table.orders.mo { min-width: 0; }
.ov-adv tbody tr { cursor: pointer; }
.ov-adv tbody tr:hover td { background: var(--surface-alt); }
.ov-adv tr:not(.shown) td:first-child { color: var(--text-muted); }
.ov-total td { font-weight: 700; }
.spark { display: block; }

.bars { padding: 8px 12px 0; }
.bar-row { display: grid; grid-template-columns: 130px minmax(0, 1fr) 92px; gap: 10px; align-items: center; padding: 4px 0; font-size: 12px; }
.bar-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-muted); }
.bar-track { height: 10px; background: var(--surface-sunk); border-radius: 3px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--s1); border-radius: 0 3px 3px 0; }
.bar-val { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.bar-val .sub { display: inline; margin-left: 6px; font-size: 11px; font-weight: 500; }
.bars .meta { padding: 8px 0 10px; }

.al-bar { display: inline-block; width: 70px; height: 8px; background: var(--surface-sunk); border-radius: 2px; margin-right: 8px; vertical-align: middle; overflow: hidden; }
.al-bar span { display: block; height: 100%; background: var(--s1); }
.al th[data-asort] { cursor: pointer; user-select: none; white-space: nowrap; }
.heat-c { background: color-mix(in srgb, var(--s1) var(--w), transparent); }
.heat-c[data-dark] { color: #fff; }

.mo th, .mo td { padding: 6px 9px; }
.mo .mo-name { position: sticky; left: 0; background: var(--surface); z-index: 1; white-space: nowrap; }
.mo-c.up { background: color-mix(in srgb, var(--buy) var(--w), transparent); }
.mo-c.down { background: color-mix(in srgb, var(--sell) var(--w), transparent); }
.mo-bench td { color: var(--text-muted); }

.pf tr.bad-day td { background: var(--sell-soft); }
.pf tr.bad-week td { background: var(--warn-soft); }
.legend-sw { display: inline-block; width: 12px; height: 10px; border-radius: 2px; vertical-align: middle; }
.legend-sw.bad-day { background: var(--sell-soft); border: 1px solid var(--sell); }
.legend-sw.bad-week { background: var(--warn-soft); border: 1px solid var(--warn); }

@media (max-width: 900px) {
  .ov-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 700px) {
  .pfp-views { overflow-x: auto; flex-wrap: nowrap; }
  .pfp-views a { white-space: nowrap; padding: 8px 10px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpi-v { font-size: 18px; }
  .tr-chip-label { width: 100%; }
  .tr-bar .seg { overflow-x: auto; max-width: 100%; }
  .bar-row { grid-template-columns: 96px minmax(0, 1fr) 84px; }
}
.tr-notes { margin-top: 6px; }
.tr-notes summary { cursor: pointer; color: var(--warn); font-weight: 600; }
.tr-notes .warn-line { white-space: normal; overflow-wrap: anywhere; }
.mo thead th.mo-name { z-index: 3; background: var(--surface-alt); }
.tr-chip-row .check { white-space: nowrap; }

/* login: passkey */
.pk-btn { width: 100%; margin-top: 14px; }
.pw-login { margin-top: 14px; }
.pw-login summary { cursor: pointer; color: var(--text-muted); font-size: 12.5px; font-weight: 600; }
.login-lbl { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-muted); font-weight: 600; margin-top: 12px; }
.login-lbl input { font-size: 16px; padding: 9px 10px; }
.login-actions { display: flex; gap: 10px; margin-top: 14px; }
.login-actions .btn { flex: 1; text-align: center; text-decoration: none; padding: 10px; font-size: 15px; }
#pk-panel { margin-top: 16px; }
