/* ── Dark Mode Overrides ───────────────────────────────────────────────────────
   Applied when <body> has class "dark-mode".

   Colour hierarchy (darkest → lightest):
     Nav bar         #1e2a3a  (set via Python inline style — CSS just preserves it)
     Tab bar         #0a0f1a  (chrome behind inactive tabs)
     Page background #0f1b2d  (main canvas)
     Filter row      #0a1520  (control surface, dropdown menus)
     Table surface   #1a2a3d  (raised content area)
     Table header    #0f1b2d  (step back from body)
     Borders         #1e3048  (separation without contrast)

   Selector strategy:
     - Class-based   (.page-wrapper) where className is set in Python
     - Structural    (#tab-content > div) for page content panels
     - rgb()         for scattered white/light inline-style divs
       (React serialises `backgroundColor: "#f5f5f5"` as
        `background-color: rgb(245, 245, 245)` in the DOM attribute —
        camelCase hex selectors never match.)
──────────────────────────────────────────────────────────────────────────── */


/* ── Page wrapper (outermost layout div, className set in dashboard.py) ───── */
body.dark-mode .page-wrapper,
body.dark-mode #_dash-app-content > div {
    background-color: #0f1b2d !important;
    color: #e8f0f8 !important;
}

/* Fallback: catch the f0f2f5 wrapper by its rgb serialisation */
body.dark-mode [style*="background-color: rgb(240, 242, 245)"] {
    background-color: #0f1b2d !important;
}


/* ── Tab content panels (the #f5f5f5 div returned by each tab callback) ───── */
body.dark-mode #tab-content > div,
body.dark-mode #nsw-tab-content > div {
    background-color: #0f1b2d !important;
}

/* rgb fallback for any other #f5f5f5 divs */
body.dark-mode [style*="background-color: rgb(245, 245, 245)"] {
    background-color: #0f1b2d !important;
}


/* ── White card / panel divs ──────────────────────────────────────────────── */
/* React normalises "white" → rgb(255,255,255) in DOM style attribute */
body.dark-mode [style*="background-color: rgb(255, 255, 255)"],
body.dark-mode [style*="background-color: white"],
body.dark-mode [style*="backgroundColor: white"],
body.dark-mode [style*="backgroundColor: rgb(255, 255, 255)"] {
    background-color: #1a2a3d !important;
    color: #e8f0f8 !important;
}

/* ── Stat cards (Player Profile summary row) ──────────────────────────────── */
/* Structural selector — immune to React style serialisation quirks */
body.dark-mode .stat-cards-row > div {
    background-color: #1a2a3d !important;
    border-color: #1e3048 !important;
    color: #e8f0f8 !important;
}

body.dark-mode .stat-cards-row > div h3,
body.dark-mode .stat-cards-row > div p {
    color: inherit !important;
}

/* ── Trend chart wrappers (Player Profile bottom row) ─────────────────────── */
body.dark-mode .trend-charts-row > div {
    background-color: #1a2a3d !important;
}


/* ── Borders ──────────────────────────────────────────────────────────────── */
body.dark-mode [style*="border: 1px solid #e0e0e0"],
body.dark-mode [style*="border: 1px solid #ddd"] {
    border-color: #1e3048 !important;
}


/* ── Primary text ─────────────────────────────────────────────────────────── */
body.dark-mode [style*="color: #1a1a1a"],
body.dark-mode [style*="color: rgb(26, 26, 26)"] {
    color: #e8f0f8 !important;
}

/* Secondary / muted text */
body.dark-mode [style*="color: #666"],
body.dark-mode [style*="color: #555"],
body.dark-mode [style*="color: #888"],
body.dark-mode [style*="color: rgb(102, 102, 102)"],
body.dark-mode [style*="color: rgb(85, 85, 85)"] {
    color: #5c7a99 !important;
}

body.dark-mode label {
    color: #c8dae8 !important;
}

body.dark-mode h3,
body.dark-mode h4,
body.dark-mode p {
    color: #c8dae8 !important;
}

/* Keep intentional coloured headings */
body.dark-mode [style*="color: #1d4ed8"] { color: #60a5fa !important; }
body.dark-mode [style*="color: #00b894"] { color: #00b894 !important; }
body.dark-mode [style*="color: #ff9900"] { color: #ff9900 !important; }

/* Column legend abbreviation labels — React converts #1e2a3a → rgb(30, 42, 58) in DOM */
body.dark-mode [style*="color: rgb(30, 42, 58)"] { color: #7eb8d4 !important; }


/* ── Dash Tabs ────────────────────────────────────────────────────────────── */

/* Selected tab + nav header preserve their dark background */
body.dark-mode .tab--selected,
body.dark-mode [style*="backgroundColor: #1e2a3a"],
body.dark-mode [style*="background-color: #1e2a3a"] {
    background-color: #1e2a3a !important;
}

/* Inactive tabs */
body.dark-mode .tab:not(.tab--selected) {
    background-color: #0a0f1a !important;
    color: #5c7a99 !important;
    border-color: #1e3048 !important;
}


/* ── Dropdowns (React-Select) ──────────────────────────────────────────────── */
body.dark-mode .Select-control,
body.dark-mode .Select--single > .Select-control {
    background-color: #0a1520 !important;
    border-color: #1e3048 !important;
    color: #c8dae8 !important;
}

/* Selected value and placeholder text */
body.dark-mode .Select-value,
body.dark-mode .Select-value-label,
body.dark-mode .Select-placeholder,
body.dark-mode .Select-input input {
    color: #c8dae8 !important;
    background-color: transparent !important;
}

body.dark-mode .Select-menu-outer {
    background-color: #0a1520 !important;
    border: 1px solid #1e3048 !important;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5) !important;
}

body.dark-mode .Select-option,
body.dark-mode .VirtualizedSelectOption {
    background-color: #0a1520 !important;
    color: #c8dae8 !important;
}

body.dark-mode .Select-option.is-focused,
body.dark-mode .VirtualizedSelectOption.is-focused {
    background-color: #1a2a3d !important;
    color: #1d9e75 !important;
}

body.dark-mode .Select-option.is-selected,
body.dark-mode .VirtualizedSelectOption.is-selected {
    background-color: #1d9e75 !important;
    color: white !important;
}

/* Catch-all: any text inside the dropdown menu */
body.dark-mode .Select-menu-outer *,
body.dark-mode .Select-menu * {
    color: #c8dae8 !important;
    background-color: #0a1520 !important;
}

body.dark-mode .Select-arrow {
    border-top-color: #5c7a99 !important;
}

/* DataTable native page-size <select> and any other native selects */
body.dark-mode select {
    background-color: #0a1520 !important;
    color: #c8dae8 !important;
    border: 1px solid #1e3048 !important;
}

/* DataTable column filter row inputs */
body.dark-mode .dash-filter input,
body.dark-mode .dash-spreadsheet input {
    background-color: #0a1520 !important;
    color: #c8dae8 !important;
    border-color: #1e3048 !important;
}


/* ── DataTable ────────────────────────────────────────────────────────────── */

/* Cell body — base style + explicit bottom border for row separation */
body.dark-mode .dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner td {
    background-color: #1a2a3d !important;
    color: #c8dae8 !important;
    border-color: #1e3048 !important;
    border-bottom: 1px solid #1e3048 !important;
}

/* Alternating rows: odd = table surface, even = page background (darker) */
body.dark-mode .dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner tr:nth-child(odd) td {
    background-color: #1a2a3d !important;
}

body.dark-mode .dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner tr:nth-child(even) td {
    background-color: #0f1b2d !important;
}

/* Header row */
body.dark-mode .dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner th {
    background-color: #0f1b2d !important;
    color: #5c7a99 !important;
    border-color: #1e3048 !important;
}

/* ── Score colour bands (NF Score, SC Score, Rankings, WPA) ───────────────────
   Light-mode pastels become invisible on dark backgrounds.
   React serialises hex → rgb() in DOM style attributes, so we match on rgb().
   Each band maps to a dark equivalent of the same semantic hue.
──────────────────────────────────────────────────────────────────────────── */

/* Band 1 — deep green (#16a34a = rgb 22,163,74) — already dark, just ensure text */
body.dark-mode .dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner tr td[style*="background-color: rgb(22, 163, 74)"] {
    background-color: #16a34a !important;
    color: white !important;
}

/* Band 2 — light green (#86efac = rgb 134,239,172) → dark green bg, light text */
body.dark-mode .dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner tr td[style*="background-color: rgb(134, 239, 172)"] {
    background-color: #166534 !important;
    color: #86efac !important;
}

/* Band 3 — very light green (#dcfce7 = rgb 220,252,231) → deep green bg, mint text */
body.dark-mode .dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner tr td[style*="background-color: rgb(220, 252, 231)"] {
    background-color: #14532d !important;
    color: #bbf7d0 !important;
}

/* Band 4 — very light red (#fee2e2 = rgb 254,226,226) → deep red bg, light text */
body.dark-mode .dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner tr td[style*="background-color: rgb(254, 226, 226)"] {
    background-color: #450a0a !important;
    color: #fecaca !important;
}

/* Band 5 — medium red (#fca5a5 = rgb 252,165,165) → dark red bg, light text */
body.dark-mode .dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner tr td[style*="background-color: rgb(252, 165, 165)"] {
    background-color: #7f1d1d !important;
    color: #fca5a5 !important;
}

/* Band 6 — deep red (#dc2626 = rgb 220,38,38) — already dark, ensure text */
body.dark-mode .dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner tr td[style*="background-color: rgb(220, 38, 38)"] {
    background-color: #dc2626 !important;
    color: white !important;
}

/* Neutral WPA band (#f3f4f6 = rgb 243,244,246) → dark neutral */
body.dark-mode .dash-table-container .dash-spreadsheet-container .dash-spreadsheet-inner tr td[style*="background-color: rgb(243, 244, 246)"] {
    background-color: #1e2a3a !important;
    color: #c8dae8 !important;
}

/* Sort arrows */
body.dark-mode .column-header--sort span {
    color: #5c7a99 !important;
}

/* Scrollbar */
body.dark-mode .dash-table-container ::-webkit-scrollbar {
    background: #0a1520;
}
body.dark-mode .dash-table-container ::-webkit-scrollbar-thumb {
    background: #1e3048;
    border-radius: 4px;
}


/* ── DataTable column header tooltips ────────────────────────────────────── */
body.dark-mode .dash-tooltip {
    border-color: #1e3048 !important;
}

body.dark-mode .dash-tooltip .dash-table-tooltip {
    background-color: #0a1520 !important;
    color: #c8dae8 !important;
}

/* Arrow pointing up (tooltip below header) */
body.dark-mode .dash-tooltip[data-attr-anchor='top']:after {
    border-bottom-color: #0a1520 !important;
}
body.dark-mode .dash-tooltip[data-attr-anchor='top']:before {
    border-bottom-color: #1e3048 !important;
}

/* Arrow pointing down (tooltip above — included for completeness) */
body.dark-mode .dash-tooltip[data-attr-anchor='bottom']:after {
    border-top-color: #0a1520 !important;
}
body.dark-mode .dash-tooltip[data-attr-anchor='bottom']:before {
    border-top-color: #1e3048 !important;
}


/* ── Plotly charts ────────────────────────────────────────────────────────── */
body.dark-mode .js-plotly-plot .plotly .bg {
    fill: #1a2a3d !important;
}

body.dark-mode .js-plotly-plot .plotly .gtitle,
body.dark-mode .js-plotly-plot .plotly .xtitle,
body.dark-mode .js-plotly-plot .plotly .ytitle,
body.dark-mode .js-plotly-plot text {
    fill: #c8dae8 !important;
}

body.dark-mode .js-plotly-plot .plotly .gridlayer path,
body.dark-mode .js-plotly-plot .plotly .zerolinelayer path {
    stroke: #1e3048 !important;
}

body.dark-mode .js-plotly-plot .plotly .draglayer,
body.dark-mode .js-plotly-plot .bg {
    background-color: #1a2a3d !important;
}

/* ── Plotly legend ────────────────────────────────────────────────────────── */
body.dark-mode .js-plotly-plot .legend text,
body.dark-mode .js-plotly-plot .legend .legendtext {
    fill: #c8dae8 !important;
}

body.dark-mode .js-plotly-plot .legend rect {
    fill: #1a2a3d !important;
    stroke: #1e3048 !important;
}


/* ── Theme toggle button ──────────────────────────────────────────────────── */
#theme-toggle {
    background: rgba(255,255,255,0.10);
    border: 1px solid rgba(255,255,255,0.20);
    color: #cce8df;
    font-size: 16px;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 6px;
    line-height: 1;
    transition: background 0.15s;
}

#theme-toggle:hover {
    background: rgba(255,255,255,0.18);
    color: white;
}


/* ── React entry-point fallback ───────────────────────────────────────────── */
body.dark-mode > div,
body.dark-mode #react-entry-point > div,
body.dark-mode #react-entry-point > div > div {
    background-color: #0f1b2d !important;
}
