/* ===========================================================================
   app.css — THE design system. One source of truth for every page.
   Created 2026-07-31.

   WHY THIS FILE EXISTS
   --------------------
   The site had FIVE parallel design systems: base.html plus four standalone
   pages (login, stock_detail, admin, ib_portal) that each re-declared their
   own :root block. They had already drifted apart in ways a customer sees:

     token      base.html   login/stock_detail/admin   ib_portal
     --bg-0     #12151c     #07080a  (pre-April value)  (own palette)
     --bg-1     #1a1e27     #0f1117  (pre-April value)  (own palette)
     --accent   #7c5ff7     #7c5ff7                     #e94560

   base.html was deliberately lightened in April ("Was too dark (#07080a was
   nearly pure black). Lifted ~40%") and that decision never reached the three
   pages that copied the old values — so the same product rendered in two
   different darks depending on the page, and the trading portal used a
   different brand colour entirely.

   Worse, no page ever set data-bs-theme, so Bootstrap 5.3 was running in its
   default LIGHT theme on all 11 pages. Every .card, .table, .modal and
   .accordion that wasn't hand-overridden rendered as Bootstrap intends it:
   white background, #6c757d grey text — 3.56:1 contrast, below the WCAG AA
   minimum of 4.5:1. That is the "grey text on white" that looks unfinished.

   HOW IT WORKS
   ------------
   1. The 85 canonical tokens live here, and ONLY here.
   2. Bootstrap's own --bs-* variables are mapped onto those tokens, so
      Bootstrap's native dark theme renders in OUR brand rather than its
      default slate. Pages set data-bs-theme="dark" on <html>.
   3. A small override layer covers the few components Bootstrap's dark theme
      leaves light.

   Mapping Bootstrap's variables beats overriding its components: it is far
   less CSS, it cannot lose a specificity fight, and it keeps working when
   Bootstrap is upgraded.

   RULE: never re-declare these tokens in a template. Add them here.
   =========================================================================== */

:root {
    /* ── SURFACES ── */
    --bg-0:         #12151c;    /* page background */
    --bg-1:         #1a1e27;    /* elevated cards */
    --bg-2:         #232834;    /* hovered cards / table headers */
    --bg-3:         #2d3340;    /* nested / input bg */
    --bg-4:         #363c4b;    /* deep nested */
    --bg-elevated:  #1f242f;    /* table rows / stat values */

    /* ── TEXT (all pass WCAG AA on --bg-0 and --bg-1) ── */
    --text-0:       #f0f2f7;    /* headings, values      15.3:1 */
    --text-1:       #c4c9d8;    /* body copy, labels     10.1:1 */
    --text-2:       #8e95a8;    /* muted captions         5.6:1 */
    --text-3:       #565d70;    /* disabled — decorative only, never body text */

    /* ── SEMANTIC (trading P&L) ── */
    --green:        #00d084;
    --green-dim:    #00a668;
    --green-soft:   rgba(0, 208, 132, 0.10);
    --red:          #ff3b52;
    --red-dim:      #cc2f41;
    --red-soft:     rgba(255, 59, 82, 0.10);
    --amber:        #f0b429;
    --amber-soft:   rgba(240, 180, 41, 0.12);
    --blue:         #3d9fff;
    --blue-soft:    rgba(61, 159, 255, 0.10);
    --cyan:         #00c8d4;
    --cyan-soft:    rgba(0, 200, 212, 0.10);

    /* ── BRAND ACCENT ── */
    --accent:       #7c5ff7;
    --accent-hover: #6d4fe8;
    --accent-soft:  rgba(124, 95, 247, 0.11);

    /* ── TICKER BAR ── */
    --ticker-h:     34px;
    --ticker-bg:    #16191f;

    /* ── BORDERS ── */
    --border:        rgba(255, 255, 255, 0.075);
    --border-strong: rgba(255, 255, 255, 0.14);
    --border-accent: rgba(124, 95, 247, 0.30);

    /* ── TYPOGRAPHY ── */
    --font-sans:    'Inter', 'Heebo', -apple-system, system-ui, sans-serif;
    --font-mono:    'JetBrains Mono', 'SF Mono', 'Menlo', monospace;
    --fs-xs:        12px;
    --fs-sm:        13px;
    --fs-base:      15px;
    --fs-md:        17px;
    --fs-lg:        19px;
    --fs-xl:        23px;
    --fs-2xl:       30px;
    --fs-3xl:       38px;
    --lh-tight:     1.2;
    --lh-normal:    1.5;
    --fw-normal:    400;
    --fw-medium:    500;
    --fw-semibold:  600;
    --fw-bold:      700;

    /* ── SPACING ── */
    --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px;
    --s-5: 20px; --s-6: 24px; --s-8: 32px; --s-10: 40px;
    --s-12: 48px; --s-16: 64px;

    /* ── RADIUS ── */
    --r-sm: 3px; --r-md: 6px; --r-lg: 10px; --r-xl: 14px; --r-full: 999px;

    /* ── ELEVATION ── */
    --shadow-sm:   0 1px 3px rgba(0,0,0,0.35);
    --shadow-md:   0 4px 16px rgba(0,0,0,0.45);
    --shadow-lg:   0 12px 36px rgba(0,0,0,0.55);
    --glow-accent: 0 0 16px rgba(124,95,247,0.15);

    /* ── MOTION ── */
    --ease:      cubic-bezier(0.2, 0.7, 0.2, 1);
    --dur-fast:  110ms;
    --dur-norm:  190ms;

    /* ── LAYOUT ── */
    --sidebar-w:     256px;
    --topbar-h:      var(--ticker-h);
    --mobile-nav-h:  60px;
    --content-max:   1440px;

    /* ── LEGACY ALIASES (older templates reference these names) ── */
    --primary-color:     var(--bg-0);
    --secondary-color:   var(--bg-1);
    --accent-color:      var(--accent);
    --highlight-color:   var(--accent);
    --success-color:     var(--green);
    --warning-color:     var(--amber);
    --danger-color:      var(--red);
    --text-color:        var(--text-0);
    --text-muted:        var(--text-2);
    --border-color:      var(--border);
    --sidebar-width:     var(--sidebar-w);
    --header-height:     var(--topbar-h);
    --mobile-nav-height: var(--mobile-nav-h);

    /* ── SHORT ALIASES used by the formerly-standalone pages ──
       Each of these was defined per-page with a different value for the same
       intent — --primary alone meant #0f1117 in stock_detail, var(--bg-1) in
       admin and #1a1a2e in ib_portal. All three meant "elevated surface", so
       they collapse onto one token here rather than three near-misses. */
    --primary:    var(--bg-1);
    --secondary:  var(--bg-2);
    --success:    var(--green);
    --danger:     var(--red);
    --warning:    var(--amber);
    --info:       var(--cyan);
    --ib-blue:    var(--blue);
}

/* 2026-11-21: the whole site is English, left-to-right (it was Hebrew RTL). */
html, body { direction: ltr; text-align: left; }

/* ===========================================================================
   BOOTSTRAP BRIDGE
   Map Bootstrap 5.3's own variables onto our tokens. With
   data-bs-theme="dark" on <html>, every Bootstrap component then renders in
   our palette instead of Bootstrap's default slate — no per-component CSS.
   =========================================================================== */
[data-bs-theme="dark"] {
    --bs-body-bg:              var(--bg-0);
    --bs-body-color:           var(--text-1);
    --bs-emphasis-color:       var(--text-0);
    --bs-secondary-color:      var(--text-2);   /* .text-muted / .text-secondary */
    --bs-tertiary-color:       var(--text-3);
    --bs-body-bg-rgb:          18, 21, 28;
    --bs-secondary-bg:         var(--bg-2);
    --bs-tertiary-bg:          var(--bg-1);
    --bs-border-color:         var(--border-strong);
    --bs-border-color-translucent: var(--border);
    --bs-link-color:           var(--blue);
    --bs-link-hover-color:     #6ab0ff;
    --bs-code-color:           var(--cyan);
    --bs-heading-color:        var(--text-0);

    --bs-primary:              var(--accent);
    --bs-success:              var(--green);
    --bs-danger:               var(--red);
    --bs-warning:              var(--amber);
    --bs-info:                 var(--cyan);

    --bs-font-sans-serif:      var(--font-sans);
    --bs-font-monospace:       var(--font-mono);
    --bs-border-radius:        var(--r-md);
    --bs-border-radius-lg:     var(--r-lg);
    --bs-box-shadow:           var(--shadow-md);
}

/* ===========================================================================
   COMPONENT LAYER
   Only what Bootstrap's dark theme leaves light or renders off-brand.
   =========================================================================== */

/* Cards — Bootstrap's dark card is near-black; ours sits above the page. */
[data-bs-theme="dark"] .card {
    background-color: var(--bg-1);
    border: 1px solid var(--border);
    border-radius: var(--r-lg);
    color: var(--text-1);
}
[data-bs-theme="dark"] .card-header,
[data-bs-theme="dark"] .card-footer {
    background-color: var(--bg-2);
    border-color: var(--border);
    color: var(--text-0);
    font-weight: var(--fw-semibold);
}

/* Tables — dense financial data: readable rows, clear header separation. */
[data-bs-theme="dark"] .table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--text-1);
    --bs-table-border-color: var(--border);
    --bs-table-striped-bg: rgba(255, 255, 255, 0.022);
    --bs-table-striped-color: var(--text-1);
    --bs-table-hover-bg: var(--accent-soft);
    --bs-table-hover-color: var(--text-0);
}
[data-bs-theme="dark"] .table > thead {
    background-color: var(--bg-2);
    color: var(--text-0);
}
[data-bs-theme="dark"] .table > thead th {
    font-weight: var(--fw-semibold);
    font-size: var(--fs-sm);
    letter-spacing: 0.02em;
    border-bottom: 1px solid var(--border-strong);
}
/* Digits in columns must line up — this is a trading product. */
[data-bs-theme="dark"] .table td,
[data-bs-theme="dark"] .table th { font-variant-numeric: tabular-nums; }

/* Forms */
[data-bs-theme="dark"] .form-control,
[data-bs-theme="dark"] .form-select {
    background-color: var(--bg-3);
    border-color: var(--border-strong);
    color: var(--text-0);
}
[data-bs-theme="dark"] .form-control:focus,
[data-bs-theme="dark"] .form-select:focus {
    background-color: var(--bg-3);
    border-color: var(--accent);
    color: var(--text-0);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
[data-bs-theme="dark"] .form-control::placeholder { color: var(--text-3); }
[data-bs-theme="dark"] .input-group-text {
    background-color: var(--bg-2);
    border-color: var(--border-strong);
    color: var(--text-2);
}

/* Modals / offcanvas / dropdowns */
[data-bs-theme="dark"] .modal-content,
[data-bs-theme="dark"] .offcanvas,
[data-bs-theme="dark"] .dropdown-menu {
    background-color: var(--bg-1);
    border: 1px solid var(--border-strong);
    color: var(--text-1);
    box-shadow: var(--shadow-lg);
}
[data-bs-theme="dark"] .modal-header,
[data-bs-theme="dark"] .modal-footer { border-color: var(--border); }
[data-bs-theme="dark"] .dropdown-item { color: var(--text-1); }
[data-bs-theme="dark"] .dropdown-item:hover,
[data-bs-theme="dark"] .dropdown-item:focus {
    background-color: var(--accent-soft);
    color: var(--text-0);
}

/* List groups and accordions — these had ZERO overrides and rendered white. */
[data-bs-theme="dark"] .list-group-item {
    background-color: var(--bg-1);
    border-color: var(--border);
    color: var(--text-1);
}
[data-bs-theme="dark"] .accordion {
    --bs-accordion-bg: var(--bg-1);
    --bs-accordion-color: var(--text-1);
    --bs-accordion-border-color: var(--border);
    --bs-accordion-btn-bg: var(--bg-2);
    --bs-accordion-btn-color: var(--text-0);
    --bs-accordion-active-bg: var(--accent-soft);
    --bs-accordion-active-color: var(--text-0);
}

/* Tabs */
[data-bs-theme="dark"] .nav-tabs {
    border-bottom-color: var(--border-strong);
}
[data-bs-theme="dark"] .nav-tabs .nav-link {
    color: var(--text-2);
    border: 1px solid transparent;
}
[data-bs-theme="dark"] .nav-tabs .nav-link:hover { color: var(--text-0); }
[data-bs-theme="dark"] .nav-tabs .nav-link.active {
    background-color: var(--bg-1);
    border-color: var(--border-strong) var(--border-strong) var(--bg-1);
    color: var(--text-0);
}

/* Alerts — Bootstrap's pastel alerts are unreadable on a dark ground. */
[data-bs-theme="dark"] .alert-success {
    background-color: var(--green-soft); border-color: var(--green-dim); color: var(--green);
}
[data-bs-theme="dark"] .alert-danger {
    background-color: var(--red-soft);   border-color: var(--red-dim);   color: var(--red);
}
[data-bs-theme="dark"] .alert-warning {
    background-color: var(--amber-soft); border-color: var(--amber);     color: var(--amber);
}
[data-bs-theme="dark"] .alert-info,
[data-bs-theme="dark"] .alert-primary {
    background-color: var(--blue-soft);  border-color: var(--blue);      color: var(--blue);
}

/* Utility classes that hardcode light surfaces */
[data-bs-theme="dark"] .bg-light,
[data-bs-theme="dark"] .bg-white { background-color: var(--bg-2) !important; }
[data-bs-theme="dark"] .text-dark { color: var(--text-0) !important; }
[data-bs-theme="dark"] .text-muted,
[data-bs-theme="dark"] .text-secondary { color: var(--text-2) !important; }
[data-bs-theme="dark"] .border { border-color: var(--border) !important; }

/* The close button ships as a dark glyph — invert it on dark surfaces. */
[data-bs-theme="dark"] .btn-close { filter: invert(1) grayscale(100%) brightness(200%); }

/* Badges: solid brand fills, readable text. */
[data-bs-theme="dark"] .badge.bg-success { background-color: var(--green) !important; color: #04140d; }
[data-bs-theme="dark"] .badge.bg-danger  { background-color: var(--red)   !important; color: #fff; }
[data-bs-theme="dark"] .badge.bg-warning { background-color: var(--amber) !important; color: #1a1400; }
[data-bs-theme="dark"] .badge.bg-info    { background-color: var(--cyan)  !important; color: #04161a; }

/* ── P&L semantics: one definition, every page ── */
.pnl-pos, .text-gain  { color: var(--green) !important; font-variant-numeric: tabular-nums; }
.pnl-neg, .text-loss  { color: var(--red)   !important; font-variant-numeric: tabular-nums; }
.pnl-flat             { color: var(--text-2) !important; font-variant-numeric: tabular-nums; }

/* ── Accessibility ── */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: var(--r-sm);
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* Wide financial tables must scroll inside their own container, never the
   page body — horizontal page scroll on a dashboard reads as broken. */
.table-responsive, .table-scroll { overflow-x: auto; max-width: 100%; }

/* ─────────────────────────────────────────────────────────────────────────
   MOBILE TABLE CARDS  (2026-08-14)

   The owner reported the site was unusable on a phone. The cause was
   structural, not cosmetic: signals.html carries a THIRTEEN column table,
   portfolio/demo/ib_portal carry nine, and the only mobile CSS any of them
   had shrank the padding. Reducing padding cannot fit 13 columns on a 390px
   screen — the table either scrolls sideways or squeezes the numbers until
   they are unreadable, and a trading table you cannot read is worse than no
   table.

   Below 768px a table marked `.m-cards` renders each row as a CARD: the
   header row is hidden and every cell is labelled from its own data-label.
   Same data, stacked — the way brokerage apps show holdings on a phone.

   Lives HERE, not per page: the design tokens were duplicated across
   templates until 2026-07-31 and had silently drifted apart, which is
   exactly the bug this file exists to prevent. One implementation, applied
   with a class.

   Usage:  <table class="ds-table m-cards">
           <td data-label="Value">…</td>
           <td class="m-card-title">…</td>   <- the row's headline cell
   ───────────────────────────────────────────────────────────────────────── */
@media (max-width: 767.98px) {
    table.m-cards thead { display: none; }
    table.m-cards,
    table.m-cards tbody,
    table.m-cards tr,
    table.m-cards td { display: block; width: 100%; }
    /* Several of these tables carry an inline `min-width: 900px` that exists
       to stop desktop columns collapsing. Inline styles beat a class, so
       without !important the card layout would render inside a 900px box and
       still scroll sideways — the exact fault being fixed. */
    table.m-cards { min-width: 0 !important; }
    /* The wrapper's own overflow-x would keep a scrollbar under a stack of
       cards that no longer overflows. */
    .positions-wrap, .tx-wrap, .signals-table-wrap { overflow-x: visible; }
    /* Same problem, inline: the JS-built tables in portfolio.html sit in a
       div carrying style="overflow-x:auto". An inline style beats a class, so
       those kept a horizontal scrollbar under a stack of cards that no longer
       overflowed. !important is the only thing that reaches an inline rule. */
    .m-cards-wrap { overflow-x: visible !important; }
    table.m-cards tr {
        background: var(--bg-1);
        border: 1px solid var(--border);
        border-radius: var(--r-md);
        margin-bottom: var(--s-3);
        padding: var(--s-2) var(--s-3);
    }
    table.m-cards td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: var(--s-3);
        border: none !important;
        border-bottom: 1px solid rgba(255, 255, 255, .05) !important;
        padding: 7px 0 !important;
        text-align: start;
        white-space: normal;
    }
    table.m-cards td:last-child { border-bottom: none !important; }
    table.m-cards td::before {
        content: attr(data-label);
        color: var(--text-2);
        font-size: var(--fs-xs);
        font-weight: 600;
        flex: 0 0 auto;
    }
    /* Headline cell: no label, full width, reads as the card's title. */
    table.m-cards td.m-card-title {
        display: block;
        border-bottom: 1px solid var(--border) !important;
        padding-bottom: var(--s-2) !important;
        margin-bottom: var(--s-1);
        font-size: var(--fs-md);
    }
    table.m-cards td.m-card-title::before { content: none; }
    /* An empty cell inside a card reads as a rendering fault, not as "no
       value" — hide it rather than show a labelled blank line. */
    table.m-cards td:empty { display: none; }
    /* A cell whose only content is a placeholder dash says nothing and
       costs a whole labelled row in card form. Hidden on phones only -
       the desktop table keeps its column alignment. */
    table.m-cards td.m-card-empty { display: none; }
    /* A cell with no data-label and no content adds nothing but height. */
    table.m-cards td:not([data-label]):not(.m-card-title) { justify-content: flex-end; }
}

/* ── ROW SELL ACTION ────────────────────────────────────────────────────────
   Lives here rather than in a template because it is on the signals table and
   the stock page, and a component copied into two templates is how the design
   tokens drifted apart in the first place.

   Muted until hover on purpose: a sell table is already a wall of red rows,
   and eight saturated buttons in it read as eight alarms rather than as one
   action you can take per row.
   ───────────────────────────────────────────────────────────────────────── */
.btn-sell-row {
    background: var(--red-soft);
    color: var(--red);
    border: 1px solid transparent;
    border-radius: var(--r-sm);
    padding: 3px 10px;
    font-size: var(--fs-xs);
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background .12s ease, color .12s ease;
}
.btn-sell-row:hover { background: var(--red); color: #fff; }
.btn-sell-row:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

td.row-actions { text-align: end; white-space: nowrap; }

/* ── DEMO CONTENT, VISIBLY NOT YOURS ────────────────────────────────────────
   The demo sections carried the right words - "demo portfolio", "not an
   instruction for your portfolio" - in the same h3 and the same table as the reader own sections, so at
   a glance they were indistinguishable from his book. Asked directly to
   separate the demo from customer portfolios.

   A container, a rail and a corner label do what a caption could not: the eye
   sees the boundary before it reads anything.
   ───────────────────────────────────────────────────────────────────────── */
.demo-block {
    position: relative;
    border: 1px dashed var(--border-strong, var(--border));
    border-inline-start: 3px solid var(--text-3, #888);
    border-radius: var(--r-md);
    background: color-mix(in srgb, var(--bg-2) 55%, transparent);
    padding: var(--s-4) var(--s-4) var(--s-3);
    margin-block: var(--s-5);
}
.demo-block::before {
    content: attr(data-demo-label);
    position: absolute; top: -9px; inset-inline-start: 14px;
    background: var(--bg-1); padding: 0 8px;
    font-size: var(--fs-xs); font-weight: 700; letter-spacing: .04em;
    color: var(--text-2); text-transform: uppercase;
}
.demo-block > h3:first-of-type { margin-top: 0 !important; }

/* Why the buy button is not there. Muted on purpose: this is an
   explanation, not an alarm - the reader has done nothing wrong by
   looking at the market-wide list. */
.cant-take {
    display: inline-block; font-size: var(--fs-xs); color: var(--text-2);
    background: var(--bg-3); border-radius: var(--r-sm);
    padding: 2px 8px; white-space: nowrap;
}

/* The reader whose holdings we cannot see. Loud on purpose: this is the one
   state where the page is actively incomplete about his risk. */
.no-book {
    border: 2px solid var(--red); background: var(--red-soft);
    border-radius: var(--r-md); padding: 14px 16px; margin-bottom: var(--s-4);
}
.no-book__title { font-weight: 700; color: var(--red); font-size: var(--fs-md); margin-bottom: 6px; }
.no-book__body  { font-size: var(--fs-sm); color: var(--text-1); line-height: 1.7; }
.no-book__cta   { margin-top: 8px; color: var(--text-2); }

/* ── RESTING EXITS (2026-09-13) ──────────────────────────────────────────────
   An exit that fired and was not acted on. Amber, not red, and deliberately
   not styled like the sell table: red plus a symbol plus a price reads as an
   instruction, and this is a RECORD that a trigger fired on dates that have
   since passed. Acting on expired evidence is the opposite of the problem it
   exists to fix, so it must not look like the thing it is not.
   ───────────────────────────────────────────────────────────────────────── */
.resting-exits {
    border: 1px solid var(--amber, #B8860B); border-left: 4px solid var(--amber, #B8860B);
    background: var(--amber-soft, rgba(184, 134, 11, .09));
    border-radius: var(--r-md); padding: 14px 16px; margin-bottom: var(--s-4);
}
.resting-exits__title { font-weight: 700; color: var(--amber, #B8860B);
    font-size: var(--fs-md); margin-bottom: 6px; }
.resting-exits__body  { font-size: var(--fs-sm); color: var(--text-1); line-height: 1.7; }
.resting-exits__list  { margin-top: 10px; display: flex; flex-direction: column; gap: 7px; }
.resting-exit {
    display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: baseline;
    padding: 8px 10px; border-radius: var(--r-sm, 4px);
    background: var(--bg-1, rgba(0,0,0,.03));
}
.resting-exit__sym { font-weight: 700; font-size: var(--fs-md); min-width: 4.5em; }
.resting-exit__when, .resting-exit__px {
    font-size: var(--fs-xs); color: var(--text-2);
    font-variant-numeric: tabular-nums;
}
.resting-exit__state {
    font-size: var(--fs-xs); font-weight: 600; text-transform: uppercase;
    letter-spacing: .06em; color: var(--amber, #B8860B);
}


/* ── MOBILE INPUT + TARGET SIZING (2026-09-01) ───────────────────────────────
   The viewport tag used to carry maximum-scale=1.0 and user-scalable=no, which
   forbids pinch-zoom. On a page this data-dense that is not a nicety - it is
   the only way to read a crowded row on a 360px screen.

   The reason that flag gets set is real though: iOS Safari zooms the page in
   when you focus an input whose font-size is under 16px, and it does not zoom
   back out. Blocking zoom entirely "fixes" that by taking the capability away
   from everyone. Sizing the inputs fixes the cause, so both work.

   44px is the minimum comfortable touch target on both platforms' guidelines.
   These are trade controls - a mis-tap here submits an order.
   ───────────────────────────────────────────────────────────────────────── */
@media (max-width: 767.98px) {
    input, select, textarea,
    .form-control, .form-select {
        font-size: 16px;          /* exactly the iOS auto-zoom threshold */
    }
    input[type="date"] { min-height: 44px; }
    .ds-btn, .btn, button,
    .form-control, .form-select { min-height: 44px; }
    /* A modal on a phone should use the screen, not float in the middle of it
       with the keyboard covering the confirm button. */
    .modal-dialog { margin: 0.5rem; }
    .modal-body   { max-height: 70vh; overflow-y: auto; }
    /* Nothing may push the page sideways. A single overflowing element makes
       every page on the site feel broken, and it is always something small. */
    html, body { overflow-x: hidden; overflow-x: clip; }   /* clip: the window still scrolls (R6-08) */
}

/* ══ VIEW MODE: TABLE ⇄ CARDS (2026-09-04) ═══════════════════════════════════
   The owner: "there is no table list view and the site is hard to work with on mobile".

   Below 768px every .m-cards table became a stack of cards. That is right for
   reading one holding and wrong for COMPARING twelve — which is most of what
   this product is for. A card stack cannot be scanned down a column, so
   "which of these has the worst stop distance" stops being answerable.

   So the card transform becomes a CHOICE rather than a rule. In table mode the
   table stays a table and scrolls sideways with the FIRST COLUMN FROZEN, which
   is how every brokerage terminal handles a wide grid on a narrow screen: the
   symbol stays anchored while the numbers move under it.

   One implementation on the shared class, not per page — the same reason
   .m-cards itself lives here.
   ────────────────────────────────────────────────────────────────────────── */
@media (max-width: 767.98px) {
    /* TABLE MODE — undo the card transform, restore a real grid. */
    body.view-table table.m-cards thead { display: table-header-group; }
    body.view-table table.m-cards,
    body.view-table table.m-cards tbody { display: table; width: 100%; }
    body.view-table table.m-cards tr { display: table-row; }
    body.view-table table.m-cards td,
    body.view-table table.m-cards th { display: table-cell; width: auto; }
    body.view-table table.m-cards td::before { content: none; }
    body.view-table table.m-cards td.m-card-empty { display: table-cell; }

    /* The grid needs room to be a grid; the wrapper provides the scroll. */
    body.view-table table.m-cards { min-width: max-content !important; }
    /* The scroll must live INSIDE the wrapper. Without an explicit width the
       wrapper simply grows to its content and the whole PAGE scrolls sideways
       instead - measured at scrollWidth 1846 against a 390 viewport on the
       first attempt. max-width:100% plus a min-width of 0 is what actually
       contains a wide grid child. */
    body.view-table .positions-wrap,
    body.view-table .tx-wrap,
    body.view-table .signals-table-wrap,
    body.view-table .m-cards-wrap {
        overflow-x: auto !important;
        max-width: 100%; min-width: 0; width: 100%;
        -webkit-overflow-scrolling: touch;
    }
    /* A flex/grid parent hands a child unlimited basis, which is the other
       half of the same overflow. */
    body.view-table .main-content > *,
    body.view-table .ds-card { min-width: 0; }

    /* FROZEN SYMBOL COLUMN. Without this the row loses its identity two
       columns in and the numbers belong to nobody. */
    /* --bg-elevated is the token this design system actually defines for
       table surfaces. The first version reached for --surface-1 and --bg-card,
       neither of which exists here, so the chain fell through to #fff and
       painted a WHITE column down a dark page - the exact failure mode of a
       colour that is only correct in one theme. */
    body.view-table table.m-cards th:first-child,
    body.view-table table.m-cards td:first-child {
        position: sticky; inset-inline-start: 0; z-index: 2;
        background: var(--bg-elevated);
        box-shadow: 1px 0 0 var(--border);
    }
    body.view-table table.m-cards thead th:first-child { z-index: 3; }

    body.view-table table.m-cards th,
    body.view-table table.m-cards td {
        white-space: nowrap; padding: 9px 11px; font-size: var(--fs-sm);
    }
}

/* The toggle itself is desktop-irrelevant — the table is already a table. */
.view-toggle { display: none; }
@media (max-width: 767.98px) { .view-toggle { display: inline-flex; } }
.view-toggle{
    align-items: center; gap: 2px; border: 1px solid var(--border, #ddd);
    border-radius: var(--r-sm, 6px); overflow: hidden; background: var(--surface-1, #fff);
}
.view-toggle button{
    appearance: none; border: 0; background: transparent; cursor: pointer;
    padding: 7px 12px; min-height: 40px; font: inherit; font-size: 13px;
    font-weight: 600; color: var(--text-2, #666); display: inline-flex;
    align-items: center; gap: 6px;
}
.view-toggle button[aria-pressed="true"]{
    background: var(--accent, #6c5ce7); color: #fff;
}
.view-toggle button:focus-visible{ outline: 2px solid var(--accent, #6c5ce7); outline-offset: -2px; }

/* ══ TABLE CRAFT (2026-09-04) ════════════════════════════════════════════════
   "I asked for professional UI/UX and got something really amateurish."

   A data table is judged on whether it can be SCANNED, and three things
   decide that: knowing which column you are in after scrolling, seeing which
   column is sorted, and the row under your eye staying distinguishable. None
   of the tables here had any of them.

   Shared rules, so every table gains them at once.
   ────────────────────────────────────────────────────────────────────────── */

/* 1. The header stays while the rows move. Scroll a 30-row holdings table and
      the column meanings are gone by row 12; every terminal pins them. */
.positions-wrap, .tx-wrap, .signals-table-wrap, .m-cards-wrap { position: relative; }
.ds-table thead th {
    position: sticky; top: 0; z-index: 4;
    background: var(--bg-elevated);
    box-shadow: inset 0 -1px 0 var(--border-strong);
}

/* 2. A sortable header must look sortable, and say which way it is sorted.
      Direction is shown with a real caret, not left to be guessed. */
.ds-table th.sortable { cursor: pointer; user-select: none; padding-inline-end: 22px; position: sticky; }
.ds-table th.sortable::after {
    content: '⌃'; position: absolute; inset-inline-end: 8px; top: 50%;
    transform: translateY(-60%) rotate(180deg);
    font-size: 11px; opacity: .25; transition: opacity .15s ease, transform .15s ease;
}
.ds-table th.sortable[aria-sort="ascending"]::after { opacity: 1; transform: translateY(-40%) rotate(0deg); }
.ds-table th.sortable[aria-sort="descending"]::after { opacity: 1; transform: translateY(-60%) rotate(180deg); }
.ds-table th.sortable:hover::after { opacity: .6; }
.ds-table th.sortable:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* 3. The row under the eye. Zebra is quiet enough not to fight the numbers,
      hover is only for devices that have one. */
.ds-table tbody tr:nth-child(even) > td { background: rgba(255,255,255,0.014); }
@media (hover: hover) {
    .ds-table tbody tr:hover > td { background: rgba(255,255,255,0.045); }
}

/* 4. Numbers line up or they cannot be compared down a column. */
.ds-table td.num, .ds-table th.num { font-variant-numeric: tabular-nums; text-align: end; }

@media (max-width: 767.98px) {
    /* Card mode has no header row to pin, and a sticky header inside a card
       stack would float over nothing. */
    body:not(.view-table) .ds-table thead th { position: static; box-shadow: none; }
    /* In table mode the frozen first column and the sticky header meet at the
       corner; the corner must sit above both or it renders under the rows. */
    body.view-table .ds-table thead th:first-child { z-index: 6; }
}

/* ── Reason chips (labels.js reasonChips): engine codes shown as short
   customer English; the raw code is in the chip's title. ── */
.reason-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.reason-chip {
    display: inline-block; padding: 2px 8px; border-radius: var(--r-full);
    background: var(--bg-elevated); border: 1px solid var(--border);
    color: var(--text-1); font-size: var(--fs-xs);
    line-height: 1.6; cursor: default;
    /* Short codes stay on one line; a long sentence wraps inside the chip
       instead of running off a phone screen. */
    white-space: normal; overflow-wrap: anywhere; max-width: 100%;
}
.reason-chip.reason-more { color: var(--accent); border-color: var(--border-accent); }

/* Numbers: when the site was right-to-left "-$2,730.32" rendered as
   "$2,730.32-". plaintext lets each value take its own direction from its
   first strong character; kept for old stored text. The site is LTR now. */
.ds-stat-card__value, .stat-value { unicode-bidi: plaintext; text-align: left; }

/* The admin-only server bar sat on top of the mobile bottom nav. */
@media (max-width: 767.98px) { .server-info-bar { display: none !important; } }

/* Signed values in tables: in the old right-to-left layout '+$6' rendered
   as '$6+', '-1.40%' as '1.40%-' (portfolio holdings, 2026-10-01). plaintext
   gives each line its own direction from its first strong character.
   The site is LTR now: text cells align left (start), .num cells keep the
   end-alignment (right in an LTR table). */
.ds-table td:not(.num) { unicode-bidi: plaintext; text-align: left; }
.ds-table td.num { direction: ltr; text-align: right; }

/* ═══ 2026-10-02 UI pass: one rhythm for numbers, labels and phones ═══ */
/* Numbers scale with the screen instead of a fixed 28-32px wall. */
.ds-stat-card__value, .stat-value { font-size: clamp(20px, 1.9vw, 27px) !important; line-height: 1.15; }
/* Stat labels: no uppercase tracking, readable size (kept from the Hebrew layout). */
.ds-stat-card__label { font-size: 12.5px !important; letter-spacing: 0 !important; text-transform: none !important;
                       font-weight: 500 !important; color: var(--text-2); }
.ds-stat-card__footer { font-size: 12px !important; line-height: 1.45; }
.ds-stat-card { padding: 16px 18px !important; }

@media (max-width: 575.98px) {
    /* Two stat cards per row on a phone instead of one very long column. */
    .row > [class*="col-"]:has(> .ds-stat-card) { flex: 0 0 50%; max-width: 50%; }
    .row:has(> [class*="col-"] > .ds-stat-card) { --bs-gutter-x: 10px; --bs-gutter-y: 10px; }
    .ds-stat-card { padding: 12px 12px !important; border-radius: 12px; }
    .ds-stat-card__value, .stat-value { font-size: 18px !important; }
    .ds-stat-card__label { font-size: 11.5px !important; }
    .ds-stat-card__footer { font-size: 11px !important; }
    /* Page header actions: one compact row, not a stack of giant buttons. */
    .page-header { gap: 10px !important; }
    .page-actions { width: 100%; display: flex; flex-wrap: wrap; gap: 8px !important; }
    .page-actions > .btn, .page-actions > button, .page-actions > a {
        flex: 1 1 0; min-width: 0; min-height: 40px; padding: 8px 10px !important; font-size: 13px !important; }
    .page-title { font-size: 22px !important; }
}
@media (min-width: 576px) and (max-width: 991.98px) {
    .ds-stat-card__value, .stat-value { font-size: 22px !important; }
}

/* Collapsible "more details" / "tools" blocks (signals page, 2026-10-02):
   explanatory and operational content one click away, below the actions. */
details.more-details {
    margin: 22px 0 8px; border: 1px solid var(--border); border-radius: 12px;
    background: var(--bg-1); padding: 0 16px;
}
details.more-details > summary {
    cursor: pointer; list-style: none; padding: 14px 0; font-size: 14px;
    font-weight: 600; color: var(--text-1); display: flex; align-items: center; gap: 8px;
}
details.more-details > summary::-webkit-details-marker { display: none; }
details.more-details > summary::before {
    content: '▸'; color: var(--text-2); transition: transform .15s ease; display: inline-block;
}
details.more-details[open] > summary::before { transform: rotate(90deg); }
details.more-details[open] { padding-bottom: 12px; }
details.tools-details { background: transparent; }


/* Dashboard toolbar (2026-10-02): the real actions, slim; reset small and apart. */
.dash-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
                padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--bg-1); }
.dash-reset { background: none; border: none; color: var(--text-2); font-size: 12px; cursor: pointer; padding: 6px 8px; }
.dash-reset:hover { color: var(--red); }

/* Phones: an odd last stat card takes the full row instead of half of it. */
@media (max-width: 575.98px) {
    .row > [class*="col-"]:has(> .ds-stat-card):last-child:nth-child(odd) { flex: 0 0 100%; max-width: 100%; }
}
