/* ─────────────────────────────────────────────────────────────────────────
 *  THEME — light-mode overrides
 *  ─────────────────────────────────────────────────────────────────────────
 *  The app is built for dark mode by default (Tailwind classes use direct
 *  slate-900/950 values, not `dark:` variants).  When the user toggles to
 *  light mode, theme.js REMOVES the `dark` class from <html> — these rules
 *  then take over and re-skin the surfaces to a light palette.
 *
 *  Implementation note: we override the most-used slate utility classes.
 *  This catches ~95% of surfaces.  Accent colours (indigo, emerald, red,
 *  amber) work unchanged on both themes.
 * ──────────────────────────────────────────────────────────────────────── */

html:not(.dark) {
  color-scheme: light;
}

/* ── Body / page background ─────────────────────────────────────────── */
html:not(.dark) body                 { background-color: #f8fafc !important; color: #0f172a !important; }

/* ── Background surfaces (slate-950 down to slate-700) ──────────────── */
html:not(.dark) .bg-slate-950        { background-color: #f8fafc !important; }
html:not(.dark) .bg-slate-900        { background-color: #ffffff !important; }
html:not(.dark) .bg-slate-800        { background-color: #f1f5f9 !important; }
html:not(.dark) .bg-slate-700        { background-color: #e2e8f0 !important; }

/* Semi-transparent surface variants used widely (cards / hovers) */
html:not(.dark) .bg-slate-950\/95    { background-color: rgba(248,250,252,0.95) !important; }
html:not(.dark) .bg-slate-950\/80    { background-color: rgba(248,250,252,0.92) !important; }
html:not(.dark) .bg-slate-900\/95    { background-color: rgba(255,255,255,0.95) !important; }
html:not(.dark) .bg-slate-900\/80    { background-color: rgba(255,255,255,0.92) !important; }
html:not(.dark) .bg-slate-900\/60    { background-color: rgba(241,245,249,0.85) !important; }
html:not(.dark) .bg-slate-900\/50    { background-color: rgba(241,245,249,0.7)  !important; }
html:not(.dark) .bg-slate-900\/40    { background-color: rgba(241,245,249,0.6)  !important; }
html:not(.dark) .bg-slate-800\/60    { background-color: rgba(226,232,240,0.7)  !important; }
html:not(.dark) .bg-slate-800\/50    { background-color: rgba(226,232,240,0.55) !important; }
html:not(.dark) .bg-slate-800\/40    { background-color: rgba(226,232,240,0.45) !important; }
html:not(.dark) .bg-slate-800\/30    { background-color: rgba(226,232,240,0.4)  !important; }
html:not(.dark) .bg-slate-700\/60    { background-color: rgba(203,213,225,0.6)  !important; }

/* Hover states */
html:not(.dark) .hover\:bg-slate-800:hover    { background-color: #e2e8f0 !important; }
html:not(.dark) .hover\:bg-slate-700:hover    { background-color: #cbd5e1 !important; }
html:not(.dark) .hover\:bg-slate-600:hover    { background-color: #94a3b8 !important; }
html:not(.dark) .hover\:bg-slate-800\/40:hover { background-color: rgba(226,232,240,0.6) !important; }
html:not(.dark) .hover\:bg-slate-800\/30:hover { background-color: rgba(226,232,240,0.5) !important; }

/* ── Text colours ───────────────────────────────────────────────────── */
/* Mapping principle: preserve the dark→bright spectrum but bumped UP for
 * legibility on a white/light background.  Lowest tiers (600/700) are still
 * muted but always readable, never invisible. */
html:not(.dark) .text-white          { color: #0f172a !important; }
html:not(.dark) .text-slate-100      { color: #0f172a !important; }
html:not(.dark) .text-slate-200      { color: #1e293b !important; }
html:not(.dark) .text-slate-300      { color: #334155 !important; }
html:not(.dark) .text-slate-400      { color: #475569 !important; }
html:not(.dark) .text-slate-500      { color: #475569 !important; }
html:not(.dark) .text-slate-600      { color: #64748b !important; }
html:not(.dark) .text-slate-700      { color: #94a3b8 !important; }

/* Hover-text colours referenced in inline <style> blocks need overrides too */
html:not(.dark) .hover\:text-white:hover         { color: #0f172a !important; }
html:not(.dark) .hover\:text-slate-100:hover     { color: #0f172a !important; }
html:not(.dark) .hover\:text-slate-200:hover     { color: #1e293b !important; }
html:not(.dark) .hover\:text-slate-300:hover     { color: #334155 !important; }

/* Slate-500/600/700 used for background tints flip to lightly-tinted grays */
html:not(.dark) .text-slate-700.shrink-0,
html:not(.dark) .text-slate-600 svg { color: #94a3b8 !important; }

/* ── Borders ────────────────────────────────────────────────────────── */
html:not(.dark) .border-slate-700    { border-color: #cbd5e1 !important; }
html:not(.dark) .border-slate-800    { border-color: #e2e8f0 !important; }
html:not(.dark) .border-slate-800\/60{ border-color: rgba(226,232,240,0.7) !important; }
html:not(.dark) .border-slate-800\/50{ border-color: rgba(226,232,240,0.65) !important; }
html:not(.dark) .divide-slate-800\/60 > * + * { border-color: rgba(226,232,240,0.7) !important; }
html:not(.dark) .border-t.border-slate-800 { border-top-color: #e2e8f0 !important; }
html:not(.dark) .border-b.border-slate-800 { border-bottom-color: #e2e8f0 !important; }
html:not(.dark) .border-r.border-slate-800 { border-right-color: #e2e8f0 !important; }

/* ── Inputs / placeholders ──────────────────────────────────────────── */
html:not(.dark) input,
html:not(.dark) select,
html:not(.dark) textarea {
  color: #0f172a;
  background-color: #ffffff;
  border-color: #cbd5e1;
}
html:not(.dark) input::placeholder,
html:not(.dark) textarea::placeholder { color: #94a3b8 !important; }

html:not(.dark) .placeholder-slate-500::placeholder { color: #94a3b8 !important; }
html:not(.dark) .placeholder-slate-600::placeholder { color: #cbd5e1 !important; }

/* ── Accent overlays that look great on dark but harsh on light ─────── */
html:not(.dark) .shadow-2xl           { box-shadow: 0 8px 24px rgba(15,23,42,0.08) !important; }
html:not(.dark) .shadow-lg            { box-shadow: 0 4px 12px rgba(15,23,42,0.08) !important; }

/* Sidebar contrast pop in light mode */
html:not(.dark) #sidebar              { background-color: #f1f5f9 !important; border-right-color: #cbd5e1 !important; }
html:not(.dark) .nav-link             { color: #475569; }
html:not(.dark) .nav-link:hover       { color: #0f172a; background: #e2e8f0; }
html:not(.dark) .nav-link.nav-active  { color: #0f172a !important; background: rgba(99,102,241,0.12); }

/* Indigo brand logo block keeps its dark blue background */
html:not(.dark) .bg-indigo-600        { background-color: #6366f1 !important; }

/* ── Theme toggle button (auto-injected) ────────────────────────────── */
.theme-toggle-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border-radius: 0.5rem;
  border: 1px solid transparent;
  background: transparent;
  color: #94a3b8;
  cursor: pointer;
  transition: color 0.15s, background-color 0.15s, border-color 0.15s;
}
.theme-toggle-btn:hover {
  color: #e2e8f0;
  background-color: rgba(51,65,85,0.4);
  border-color: rgba(71,85,105,0.6);
}
html:not(.dark) .theme-toggle-btn         { color: #475569; }
html:not(.dark) .theme-toggle-btn:hover   { color: #0f172a; background-color: #e2e8f0; border-color: #cbd5e1; }
.theme-toggle-btn svg { width: 18px; height: 18px; }
.theme-toggle-btn .icon-moon { display: none; }
html:not(.dark) .theme-toggle-btn .icon-sun  { display: none; }
html:not(.dark) .theme-toggle-btn .icon-moon { display: inline; }

/* ── Inline-style component overrides ─────────────────────────────────
 * Several inline <style> blocks and app.css rules use hard-coded slate
 * hex values (e.g. #e2e8f0, #fff) that look fine on a dark background but
 * become invisible white-on-white in light mode.  Override them here. */

/* Tab buttons (paper-trading.html inline style) */
html:not(.dark) .tab-btn               { color: #64748b !important; }
html:not(.dark) .tab-btn:hover         { color: #0f172a !important; border-bottom-color: #94a3b8 !important; }
html:not(.dark) .tab-active            { color: #0f172a !important; border-bottom-color: #6366f1 !important; }

/* Screener table headers (app.css .th-cell) */
html:not(.dark) .th-cell               { color: #64748b !important; }
html:not(.dark) .th-cell:hover         { color: #0f172a !important; }
html:not(.dark) .th-cell.sort-active   { color: #0f172a !important; }

/* Rule-dot indicators (app.css) — fail dot bg+color */
html:not(.dark) .rule-dot.fail         { background: #f1f5f9 !important; color: #94a3b8 !important; }
html:not(.dark) .rule-dot.pass         { background: rgba(16,185,129,0.18) !important; color: #047857 !important; }

/* Skeleton loader bars (app.css) */
html:not(.dark) .skeleton              { background: #e2e8f0 !important; }
html:not(.dark) .skeleton-row td       { color: #64748b !important; }

/* Sidebar collapse-button icon (was almost-white, hard to see) */
html:not(.dark) #sidebarToggle svg     { color: #475569 !important; }

/* Tailwind backdrop-blur surfaces — make sure header borders stand out */
html:not(.dark) .border-b              { border-bottom-color: #e2e8f0; }

/* Ring colors used for live-price flash + active highlights */
html:not(.dark) .ring-amber-500\/40    { --tw-ring-color: rgba(245,158,11,0.4); }

/* Hard-coded white text in places like the brand logo + tab-active need to
 * stay dark in light mode.  app.css uses `text-white` directly. */
html:not(.dark) .text-white            { color: #0f172a !important; }

/* Brand logo block - keep its colored bg, but ensure SVG inside is white */
html:not(.dark) .bg-indigo-600 svg     { color: #ffffff !important; }
html:not(.dark) .bg-indigo-600 .text-white { color: #ffffff !important; }

/* Sidebar danger button (sign out) */
html:not(.dark) .nav-link.nav-danger   { color: #dc2626 !important; }
html:not(.dark) .nav-link.nav-danger:hover { background: #fee2e2; color: #b91c1c !important; }

/* Login page card on light bg */
html:not(.dark) .grid-bg               { background-color: #f8fafc; }
html:not(.dark) #loginCard             { background: #ffffff; border-color: #e2e8f0; box-shadow: 0 8px 24px rgba(15,23,42,0.06); }
html:not(.dark) .field-input           { background: #ffffff; border-color: #cbd5e1; color: #0f172a; }
html:not(.dark) .field-input:focus     { border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99,102,241,0.12); }
html:not(.dark) .field-input::placeholder { color: #94a3b8; }

/* "PAPER ONLY" badge - emerald looks fine on both, no override */

/* Strategy cards (strategies.html) - bg-slate-900/60 already remapped above,
 * but ring colors used on hover need a light-friendly value */
html:not(.dark) [class*="ring-blue-500"]    { --tw-ring-color: rgba(59,130,246,0.4); }
html:not(.dark) [class*="ring-emerald-500"] { --tw-ring-color: rgba(16,185,129,0.4); }
html:not(.dark) [class*="ring-orange-500"]  { --tw-ring-color: rgba(249,115,22,0.4); }
html:not(.dark) [class*="ring-violet-500"]  { --tw-ring-color: rgba(139,92,246,0.4); }
html:not(.dark) [class*="ring-amber-500"]   { --tw-ring-color: rgba(245,158,11,0.4); }
html:not(.dark) [class*="ring-teal-500"]    { --tw-ring-color: rgba(20,184,166,0.4); }
html:not(.dark) [class*="ring-red-500"]     { --tw-ring-color: rgba(239,68,68,0.4); }
html:not(.dark) [class*="ring-rose-500"]    { --tw-ring-color: rgba(244,63,94,0.4); }
html:not(.dark) [class*="ring-fuchsia-500"] { --tw-ring-color: rgba(217,70,239,0.4); }
html:not(.dark) [class*="ring-pink-500"]    { --tw-ring-color: rgba(236,72,153,0.4); }
html:not(.dark) [class*="ring-sky-500"]     { --tw-ring-color: rgba(14,165,233,0.4); }
html:not(.dark) [class*="ring-lime-500"]    { --tw-ring-color: rgba(132,204,22,0.4); }
html:not(.dark) [class*="ring-purple-500"]  { --tw-ring-color: rgba(168,85,247,0.4); }
html:not(.dark) [class*="ring-cyan-500"]    { --tw-ring-color: rgba(6,182,212,0.4); }
html:not(.dark) [class*="ring-indigo-500"]  { --tw-ring-color: rgba(99,102,241,0.4); }
