/* ===================================================================
   BhavChart theme layer  —  20 Nov 2026, rewritten 21 Nov
   ONE place where dark mode is defined, loaded by every page.

   Why html[data-theme="dark"] and not [data-theme="dark"]:
   each page defines its light tokens in its own inline :root block.
   :root and [data-theme] have the SAME specificity, so the winner
   would depend on whether this file happens to load before or after
   that inline <style> — a trap that breaks silently when someone
   moves a tag. The html prefix is one notch higher and wins
   wherever it sits.

   Why everything is scoped by data-app and nothing is global:
   the two pages grew their own vocabularies, and SOME NAMES MEAN
   DIFFERENT THINGS. --accent is turmeric #E0A100 on the home page
   and indigo on the chart page. One global --accent would silently
   repaint one of them. Rather than rely on remembering which names
   are safe to share, every page gets its own block. Adding a page
   means adding a block; it can never mean breaking another page.

   Each page sets data-app on <html> alongside data-theme.
   =================================================================== */

html[data-theme="dark"]{
  color-scheme:dark;   /* native scrollbars, form controls and the caret follow */
}

/* ---- cross-page aliases ------------------------------------------
   The two pages grew different names for the same surface: the home page
   says --card / --ink / --rule, the chart page says --panel / --text /
   --border. Shared modules (auth_widget, watchlist_widget, help, leadboard)
   load on BOTH, so whichever name they pick is undefined on one of them.
   Each page therefore answers to both names. These alias to the page's own
   token, so they follow the theme automatically and need no dark variant.
   New code should use the page's native name; the alias is for shared code. */
html[data-app="home"]{--panel:var(--card); --text:var(--ink); --border:var(--rule)}
html[data-app="chart"]{--card:var(--panel); --ink:var(--text); --rule:var(--border)}
/* --accent is turmeric on the home page and indigo on the chart page, so
   shared code must never use it. --brand is indigo on both; --amber is the
   turmeric each page already has, under one name. */
html[data-app="home"]{--amber:var(--accent); --down:var(--dn)}
html[data-app="chart"]{--amber:var(--brand-turmeric); --dn:var(--down); --sunk:var(--accent-soft)}
/* 23 Nov 2026: the --danger family is defined only in the home scope, so --danger and
   --danger-ink resolved to NOTHING on the chart page -- which is why trades_overlay fell back to
   a literal #D92D35 and measured 3.57:1 on the dark panel. The chart page already carries a red
   that has been measured on both themes (--down: #EC0000 light, #FF3A3A dark); alias the danger
   names onto it rather than invent a second red that would have to be kept in step with it. */
html[data-app="chart"]{--danger:var(--down); --danger-ink:var(--down)}

/* Soft status fills for shared modules. Page-independent, so they are
   declared once here rather than twice in two vocabularies. */
:root{--soft-up:#E6F3EC; --soft-dn:#FDECEC; --soft-amber:#FBF1DC}
/* --line is used bare (no fallback) by the home page's dropdown menus and was
   never defined anywhere: an unresolvable var() makes the declaration invalid,
   so those borders fell back to currentColor. Pre-existing; aliased here. */
:root{--line:var(--rule)}
html[data-theme="dark"]{--soft-up:#12291F; --soft-dn:#2A1518; --soft-amber:#2C2208}

/* ---- home page (backend/index.html) ------------------------------ */
html[data-theme="dark"][data-app="home"]{
  --ground:#11101E; --tint:#171629; --card:#1A1930;
  --ink:#E8E7F2; --muted:#A6A3C2;
  --faint:#9A97BE;   /* 21 Nov: #7E7BA0 measured 4.27:1 on the panel, under 4.5 */
  --rule:#2A2844;
  --hover:#22203C; --sunk:#2C2A4E; --border-strong:#3A3759; --disabled:#5A5780;
  --brand:#8F8DF0; --brand-soft:#23224A; --brand-ink:#9593D9;
  --accent:#F0B429; --accent-soft:#3A2D08; --accent-ink:#CF8F00;

  /* Up and down ARE brightened here, and this is a correction: the
     home page's greens and reds are dark-on-white (#1B7A43, #B3261E)
     and land near 3.5:1 on this panel, under the 4.5:1 line. The
     chart page's own up/down (#00B050, #FF1A1A) are already bright
     and keep their values in its block below — so the two pages do
     diverge slightly in dark mode. Legibility wins over a shade
     match the eye cannot compare across two screens anyway. */
  --up:#3DD68C; --dn:#FF6B6B;

  --shadow:none; --shadow-hover:none;   /* this page runs flat in light too */

  /* job-named tokens, added with the tokenisation pass */
  --on-brand:#11101E;        /* the brand is LIGHT indigo on dark, so text on a
                                brand-filled control goes dark, not white */
  --danger:#FF8A8A; --danger-ink:#FFB3B3; --danger-soft:#2A1620;
  --danger-line:#5A2430; --danger-hover:#3A1A24;
  --warn-ink:#F0C04A; --warn-soft:#2E2412;
  --ok-ink:#5FD6A0; --ok-soft:#13291F;

  /* ---- status palette (21 Nov) --------------------------------------
     26 text literals collapsed to 21 tokens and 43 chip fills / 21 borders
     to 18 — only merging pairs measured under deltaE 6.5, so light mode is
     unchanged. Each *-ink below keeps its light hue and saturation and was
     lifted only as far as it needed to clear 4.8:1 on this panel; surfaces
     and borders go to a deep tint of the same hue. */
  --badge-bad-ink:#E87973;
  --badge-ok-ink:#26B061;
  --badge-warn-ink:#D18C00;
  --bm-end-ink:#10ACAC;
  --bm-ink:#0FAEAE;
  --catag-ink:#F47600;
  --closed-ink:#C8921E;
  --danger-hover-ink:#E97979;
  --faded-ink:#D08F07;
  --flag-ok-ink:#14B094;
  --flag-warn-ink:#E28222;
  --gap-ix-ink:#E39B1B;
  --ix-ink:#D18A23;
  --line-1:#2C5840;
  --line-2:#312E56;
  --line-3:#562E2E;
  --line-4:#651F1F;
  --line-5:#6E5416;
  --line-6:#78530C;
  --line-7:#6B4C19;
  --line-8:#820202;
  --note-bad-ink:#CA8B8E;
  --note-ok-ink:#66A88A;
  --offline-body-ink:#CC898C;
  --surf-1:#18152D;
  --surf-10:#422700;
  --surf-2:#142E24;
  --surf-3:#1A162C;
  --surf-4:#370B0D;
  --surf-5:#131C2F;
  --surf-6:#390D09;
  --surf-7:#3B2A07;
  --surf-8:#413401;
  --surf-9:#422200;
  --tag-bad-ink:#E27C73;
  --verdict-add:#34B25C;
  --verdict-buy:#1DB054;
  --verdict-exit:#EB7979;
  --verdict-trim:#F37616;
}

/* ---- chart page (chartdesk_v16.html) ----------------------------- */
/* Not wired yet — the chart page pass comes after the home page. */
html[data-theme="dark"][data-app="chart"]{
  --bg:#11101E; --tint:#171629; --panel:#1A1930;
  --border:#2A2844; --border-strong:#3A3759;
  --text:#E8E7F2; --muted:#A6A3C2;
  --faint:#9A97BE;   /* 21 Nov: #7E7BA0 measured 4.27:1 on the panel, just under 4.5 */
  --accent:#8F8DF0; --accent-soft:#23224A;
  --brand:#8F8DF0; --brand-turmeric:#F0B429; --brand-ink:#9593D9;
  --warn-soft:#2E2412; --warn-ink:#F0C04A;
  --logo-1:#E8E7F2; --logo-2:#5AB6F5;
  --icon:#E8E7F2; --icon-hover:#FFFFFF;
  /* A third family this page defines and the first dark pass missed:
     .scanrow .nm and friends paint with these, so without them the scan
     list stayed near-black text on a near-black panel (1.04:1). */
  --ink-deep:#E8E7F2; --ink-soft:#A6A3C2;
  /* The chart legend and the pane controls float ON the candles, so they
     are a translucent panel, not a solid one — a hardcoded
     rgba(255,255,255,.86) that the #fff pass never matched, which left the
     EMA/BASES/VWAP/Vol/LENS chips as white pills with white text. */
  --legend-bg:rgba(26,25,48,.86);
  --on-brand:#11101E;
  /* 21 Nov: the light values had to be darkened (#00B050 was 2.87:1 and
     #FF1A1A 3.88:1 on white), and those darker versions then failed HERE
     at 3.75 and 3.73. So dark now states its own pair — the one case in
     this file where a colour differs by theme because each background
     demanded it, not because anyone preferred it. */
  --up:#009E48; --down:#FF3A3A;
}

/* Images authored on white get a touch less glare without washing out
   real colour. Logos and brand marks opt out with .noinvert. */
html[data-theme="dark"] img:not(.noinvert){filter:brightness(.92)}

/* ---- the switch itself ---------------------------------------------------
   One button, present on every page that wants it (id="themebtn").
   theme.js fills in the icon and wires the click, so a page only has to
   put the button somewhere sensible. */
.themebtn{
  width:30px;height:30px;flex:0 0 auto;
  display:inline-flex;align-items:center;justify-content:center;
  border:1px solid var(--rule,var(--border-strong,#d7deea));
  border-radius:var(--r-ctl,6px);background:transparent;cursor:pointer;
  color:var(--muted,#5a6b87);padding:0;
  transition:color .15s,border-color .15s,background .15s;
}
.themebtn:hover{color:var(--brand,var(--accent,#1f3c88));border-color:currentColor}
.themebtn svg{width:16px;height:16px;display:block}
@media (prefers-reduced-motion:reduce){.themebtn{transition:none}}

/* ---- brand mark ----------------------------------------------------------
   The "B" is a blue gradient with a trend line and arrow drawn OVER it in
   deep navy (#0F1F4B). On a dark header that navy reads as a hole in the
   mark rather than a line on it. The two overlay paths now take their colour
   from a token instead of a hardcoded attribute, so the mark keeps its
   gradient and only the line changes.
   Light keeps the original navy exactly. */
/* 23 Nov 2026: the Deal flow widget's HNI chip was the last df colour with no token
   (#f1e9ff behind #7c3aed, both fixed, so the chip stayed a bright light block on the
   dark page). It has to stay distinguishable from the "sticky" chip, which already owns
   --accent-soft, so it keeps a purple of its own in both themes.
   Measured on the chart page: light 6.04:1, dark 8.06:1. */
:root{--hni-soft:#F1E9FF; --hni-ink:#6D28D9}
html[data-theme="dark"]{--hni-soft:#241A3D; --hni-ink:#C4A8FF}

/* 23 Nov 2026: two jobs that were being done with literal rgba() in a dozen JS modules.
   --scrim is the modal backdrop: a translucent dark veil is right in both themes, it just wants
   to go deeper on a dark page. --shadow-color is the colour of a drop shadow, geometry left to
   each call site. The hover and border washes those modules also hard-coded were plain black at
   low alpha, which LIGHTENS nothing on a dark surface -- hover feedback simply vanished -- so
   those move to the existing --hover and --border instead. */
:root{--scrim:rgba(15,20,30,.45); --shadow-color:rgba(29,27,58,.16)}
html[data-theme="dark"]{--scrim:rgba(0,0,0,.62); --shadow-color:rgba(0,0,0,.55)}
/* --hover was defined only for the HOME page (index.html's :root and the dark home block), so
   when the hover washes above moved onto it, auth_widget -- which loads on BOTH pages -- lost
   its hover background on the chart page entirely. Same shape as --danger. Defined globally
   here with the home values; the home blocks are more specific and hold identical values, so
   nothing changes there. */
:root{--hover:#ECEAF5}
html[data-theme="dark"]{--hover:#22203C}
/* Same story, found by the new per-page check rather than by a user: help.js loads on both
   pages and paints with --brand-soft, which existed only in the home scope. The chart page's
   --accent-soft already holds the identical values (#EFEDF8 / #23224A), so defining it here is
   consistent rather than a new colour. */
:root{--brand-soft:#EFEDF8}
html[data-theme="dark"]{--brand-soft:#23224A}

:root{--logo-mark:#0F1F4B}
/* the chart page wraps the mark in a .logo link, the home page puts it
   straight inside .brand -- match either rather than editing one page. */
.lgm{stroke:var(--logo-mark)}
.lgm-fill{fill:var(--logo-mark)}
.lg1{color:var(--ink,var(--text))}
:root{--logo-2:#0A78CA}   /* 21 Nov: #0B7FD6 measured 4.18:1 on white */
.lg2{color:var(--logo-2)}
html[data-theme="dark"]{--logo-2:#5AB6F5}
html[data-theme="dark"]{--logo-mark:#E8E7F2}
