/* Keep light mode unchanged; dark overrides cover the shared portal components.
   !important is scoped to dark mode because older views have inline colors. */
:root {
    color-scheme: light;
}

.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: transparent;
    color: #475569;
    cursor: pointer;
}

.theme-toggle:hover { background: #f8fafc; }
.theme-toggle:focus-visible { outline: 2px solid #006543; outline-offset: 3px; }
.theme-icon-sun { display: none; }
html[data-theme="dark"] .theme-icon-moon { display: none; }
html[data-theme="dark"] .theme-icon-sun { display: block; }

html[data-theme="dark"] {
    color-scheme: dark;
    /* Shared with the Rob30 GDP dashboard. Color roles keep controls, data and
       changes in value visually distinct on the same blue-black canvas. */
    --portal-canvas: #00131f;
    --portal-surface: #0b1f2c;
    --portal-raised: #10293a;
    --portal-hover: #153449;
    --portal-border: #1e3a4d;
    --portal-border-strong: #2c4b60;
    --portal-heading: #f2f6f8;
    --portal-text: #dbe5ec;
    --portal-secondary: #b9cbd7;
    --portal-muted: #93abba;
    --portal-accent: #86bdde;
    --portal-active: #1d5e84;
    --portal-active-hover: #24709c;
    --portal-positive: #4cc38a;
    --portal-negative: #ff7a70;
    --growth-loss-fill: #542c3c;
    --growth-gain-fill: #153f3b;
    --portal-gold: #eac47e;
    --portal-series-1: #3987e5;
    --portal-series-2: #d95926;
    --portal-series-3: #199e70;
    --portal-series-4: #c98500;
    --portal-series-5: #d55181;
    --portal-series-6: #9085e9;
    --portal-series-7: #86bdde;
    --portal-series-8: #ebac75;
    --portal-series-9: #65bbad;
    --portal-series-10: #d2a9df;
    --portal-axis: var(--portal-muted);
    --portal-bar: var(--portal-accent);
    --portal-neutral: #6f8696;
    --portal-grid: #183245;
    --portal-tooltip: #244357;
    --portal-tooltip-border: #456478;
    background: var(--portal-canvas);
    color: var(--portal-text);
}

html[data-theme="dark"] body {
    background: var(--portal-canvas);
    color: var(--portal-text);
    scrollbar-color: var(--portal-border) var(--portal-canvas);
}
html[data-theme="dark"] .logo img { filter: brightness(0) invert(1); }
html[data-theme="dark"] :is(.bg-blue-50, .bg-green-50) > .lucide { color: var(--portal-accent) !important; }

/* Tailwind surfaces used by server-rendered pages and dynamically added rows. */
html[data-theme="dark"] :is(.bg-white, .bg-gray-50, .bg-slate-50) {
    background-color: var(--portal-surface) !important;
}
html[data-theme="dark"] :is(main > .bg-gray-50, .dashboard-container) {
    background-color: var(--portal-canvas) !important;
}
html[data-theme="dark"] :is(.bg-gray-100, .bg-slate-100, .bg-gray-200, .bg-slate-200) {
    background-color: var(--portal-raised) !important;
}
html[data-theme="dark"] :is(.text-black, .text-gray-900, .text-gray-800,
    .text-slate-900, .text-slate-800, .dashboard-title, .card-title) {
    color: var(--portal-heading) !important;
}
html[data-theme="dark"] :is(.text-gray-700, .text-slate-700) {
    color: var(--portal-text) !important;
}
html[data-theme="dark"] :is(.text-gray-600, .text-gray-500, .text-gray-400,
    .text-slate-600, .text-slate-500, .text-slate-400) {
    color: var(--portal-muted) !important;
}
html[data-theme="dark"] :is(.border, .border-t, .border-b, .border-l, .border-r,
    .border-gray-100, .border-gray-200, .border-gray-300, .border-slate-100,
    .border-slate-200, .border-slate-300, hr),
html[data-theme="dark"] :is(.divide-gray-100, .divide-gray-200, .divide-slate-200) > * + * {
    border-color: var(--portal-border) !important;
}
html[data-theme="dark"] :is(.hover\:bg-gray-50, .hover\:bg-gray-100,
    .hover\:bg-slate-50, .hover\:bg-slate-100, .hover\:bg-primary-50):hover {
    background-color: var(--portal-hover) !important;
}

/* Preserve meaningful status colors with readable dark-mode equivalents. */
html[data-theme="dark"] :is(.text-green-600, .text-green-700, .text-green-800,
    .text-emerald-600, .text-emerald-700, .text-emerald-800, .status-badge.success) { color: var(--portal-positive) !important; }
html[data-theme="dark"] :is(.text-red-600, .text-red-700, .text-red-800) { color: var(--portal-negative) !important; }
html[data-theme="dark"] :is(.text-primary, .text-blue-600, .text-blue-700, .text-blue-800,
    .quick-stat-icon .lucide-icon, .gf-pills-icon, .gf-pills-label-text, .gf-pill-label,
    .hover\:text-primary:hover, .hover\:text-primary-600:hover, .hover\:text-primary-700:hover) { color: var(--portal-accent) !important; }
html[data-theme="dark"] :is(.text-amber-600, .text-amber-700, .text-amber-800,
    .text-yellow-600, .text-yellow-700, .text-yellow-800) { color: var(--portal-gold) !important; }
html[data-theme="dark"] :is(.bg-green-50, .bg-green-100, .bg-emerald-50, .bg-emerald-100) {
    background-color: #113536 !important;
}
html[data-theme="dark"] :is(.bg-red-50, .bg-red-100) { background-color: #3d2831 !important; }
html[data-theme="dark"] :is(.bg-blue-50, .bg-blue-100, .bg-green-50:has(> .lucide)) { background-color: var(--portal-hover) !important; }
html[data-theme="dark"] :is(.bg-amber-50, .bg-amber-100, .bg-yellow-50, .bg-yellow-100) {
    background-color: #433b24 !important;
}

/* Header, desktop/mobile navigation, flyouts and filters. */
html[data-theme="dark"] :is(.theme-toggle, .sidebar, .sidebar-flyout, #sidebar-toggle,
    .gf-sidebar-wrapper, .gf-sidebar-tab, .gf-panel, .gf-header, .gf-footer,
    .gf-pill-overflow-popover) {
    background-color: var(--portal-surface) !important;
    border-color: var(--portal-border) !important;
    color: var(--portal-text) !important;
}
html[data-theme="dark"] :is(.sidebar .nav-link, .sidebar-flyout-item,
    .sidebar-flyout-title, .sidebar .sub-heading, .gf-sidebar-tab-text,
    .gf-header h3, .gf-group label, .gf-pill-popover-title,
    .gf-pill-popover-label, .gf-pill-popover-item) { color: var(--portal-text) !important; }
html[data-theme="dark"] :is(.sidebar .nav-link:hover,
    .sidebar-flyout-item:hover, .theme-toggle:hover,
    .gf-sidebar-tab:hover) {
    background-color: var(--portal-hover) !important;
    color: var(--portal-text) !important;
}
html[data-theme="dark"] :is(.sidebar .nav-separator, .sidebar-flyout-title, .gf-header,
    .gf-footer, .gf-group-divider) { border-color: var(--portal-border) !important; }
html[data-theme="dark"] :is(.gf-pill, .gf-pill-overflow, .gf-reset-btn,
    .gf-panel .select2-selection__choice) {
    background-color: var(--portal-raised) !important;
    border-color: var(--portal-border-strong) !important;
    color: var(--portal-secondary) !important;
}
html[data-theme="dark"] .sidebar .nav-separator { background-color: var(--portal-border); }
html[data-theme="dark"] .theme-toggle:focus-visible { outline-color: var(--portal-accent); }
html[data-theme="dark"] :is(.sidebar .nav-link.active, .sidebar-flyout-item.active,
    .bg-primary, .gf-apply-btn, .gf-badge, .last-update-badge,
    .sparkline-toolbar-button-active, .sales-expanded-metric-checkbox:checked,
    .shoprite-collapse-checkbox:checked, .sparkline-year-input:checked + .sparkline-year-box,
    .nm-only-checkbox:checked + .nm-only-toggle-switch, .peer:checked ~ .peer-checked\:bg-primary) {
    background-color: var(--portal-active) !important;
    color: var(--portal-heading) !important;
}
html[data-theme="dark"] :is(.gf-apply-btn, button.bg-primary, .hover\:bg-primary-700):hover {
    background-color: var(--portal-active-hover) !important;
}
html[data-theme="dark"] :is(.border-primary, .peer:checked ~ .peer-checked\:border-primary,
    .focus\:border-primary:focus) { border-color: var(--portal-accent) !important; }
html[data-theme="dark"] .focus\:ring-primary:focus { --tw-ring-color: var(--portal-accent); }
html[data-theme="dark"] :is(input[type="radio"], input[type="checkbox"]) { accent-color: var(--portal-accent); }

/* Form controls, Select2 menus and dialogs. Leave button and checkbox fills alone. */
html[data-theme="dark"] :is(input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]):not([type="button"]):not([type="range"]):not([type="color"]):not([type="hidden"]),
    textarea, select, .select2-dropdown, .select2-selection, .select2-search__field,
    .swal2-popup, .swal2-input, .swal2-textarea, .swal2-select) {
    background-color: var(--portal-surface) !important;
    border-color: var(--portal-border) !important;
    color: var(--portal-text) !important;
}
html[data-theme="dark"] :is(input, textarea)::placeholder { color: var(--portal-muted) !important; }
html[data-theme="dark"] :is(.select2-selection__rendered, .select2-selection__placeholder,
    .select2-results__option, .swal2-title, .swal2-html-container) { color: var(--portal-text) !important; }
html[data-theme="dark"] .select2-results__option--selected { background-color: var(--portal-raised) !important; }
html[data-theme="dark"] .select2-results__option--highlighted.select2-results__option--selectable {
    background-color: var(--portal-active) !important;
    color: #fff !important;
}

html[data-theme="dark"] :is(.quick-stat, .card, .card-header, .modal-content, .dropdown-menu,
    .banner-tile, .banner-tile-radio, .so-tab) {
    background-color: var(--portal-surface) !important;
    border-color: var(--portal-border) !important;
    color: var(--portal-text) !important;
}
html[data-theme="dark"] :is(.card-subtitle, .card-text, .dropdown-item, .banner-tile-name) {
    color: var(--portal-text) !important;
}
html[data-theme="dark"] :is(.banner-tile-format, .sidebar-edge-toggle-icon, .gf-close-btn,
    .gf-input-icon, .gf-sidebar-tab-arrow, .dashboard-subtitle, .card-footer) { color: var(--portal-muted) !important; }
html[data-theme="dark"] :is(.banner-tile:hover, .so-tab:hover) { background-color: var(--portal-hover) !important; }
html[data-theme="dark"] :is(.banner-tile:has(input:checked), .so-tab[aria-current="page"]) {
    border-color: var(--portal-accent) !important;
    background-color: var(--portal-raised) !important;
    box-shadow: inset 0 0 0 1px var(--portal-border-strong);
}
html[data-theme="dark"] .banner-tile:has(input:checked) .banner-tile-radio { background-color: var(--portal-active) !important; }

/* Home's custom controls and expanded chart workspaces have their own colors. */
html[data-theme="dark"] :is(.bubble-axis-menu, .expanded-workspace-primary,
    .expanded-workspace-panel, .sales-sparkline-primary-panel, .pie-expanded-primary,
    .sales-expanded-metric-button, .sales-expanded-metric-panel,
    [data-home-framed-expanded="true"] > [data-card-expand-inner]) {
    background-color: var(--portal-surface) !important;
    border-color: var(--portal-border) !important;
}
html[data-theme="dark"] :is(#overviewStickyBar.is-stuck, body.card-expanded #overviewStickyBar,
    body.card-expanded-sparkline #overviewStickyBar, [data-home-framed-expanded="true"],
    [data-expandcard][style*="position: fixed"], [data-expandcard][style*="position:fixed"]) {
    background-color: var(--portal-canvas) !important;
    border-color: var(--portal-border) !important;
}
html[data-theme="dark"] :is(.visual-header-select, .bubble-axis-label, .bubble-axis-menu-item,
    .bubble-size-button, .sales-expanded-metric-button, .sales-expanded-metric-option,
    .sales-expanded-comparison-option, .sparkline-year-option, .sparkline-toolbar-button-inactive,
    .sticky-period-button, .period-date-button, .period-fdates-button, .period-date-fiscal,
    .period-same-fy-notice, #stickyPeriodSameFyNotice) {
    color: var(--portal-text) !important;
}
html[data-theme="dark"] :is(.bubble-axis-menu-item:hover, .sparkline-toolbar-button-inactive,
    .sparkline-toolbar-button-inactive:hover, .sales-expanded-metric-option:hover,
    .sales-expanded-metric-button:hover) { background-color: var(--portal-raised) !important; }
html[data-theme="dark"] :is(.sales-expanded-metric-checkbox, .sparkline-year-box) {
    background-color: var(--portal-surface);
    border-color: var(--portal-muted);
}
html[data-theme="dark"] [data-visual-loading]::after { background: rgb(0 19 31 / 65%) !important; }
html[data-theme="dark"] .ms-pie-spinner::after { border-color: var(--portal-border); border-top-color: var(--portal-accent); }

/* Chart chrome is shared by native dashboard graphs, including filtered views. */
html[data-theme="dark"] .highcharts-background { fill: transparent !important; }
html[data-theme="dark"] :is(.highcharts-axis-labels text, .highcharts-axis-title,
    .highcharts-title, .highcharts-subtitle, .highcharts-legend-item text,
    .highcharts-data-label text, .highcharts-data-label span, .highcharts-stack-labels text) {
    fill: var(--portal-text) !important;
    color: var(--portal-text) !important;
}
html[data-theme="dark"] .highcharts-text-outline { stroke: var(--portal-surface) !important; }
html[data-theme="dark"] .highcharts-grid-line { stroke: var(--portal-grid) !important; }
html[data-theme="dark"] :is(.highcharts-axis-line, .highcharts-tick) {
    stroke: var(--portal-border-strong) !important;
}
html[data-theme="dark"] .highcharts-axis-labels text { fill: var(--portal-axis) !important; }
html[data-theme="dark"] .highcharts-legend-item-hidden text {
    color: var(--portal-muted) !important;
    fill: var(--portal-muted) !important;
    text-decoration: line-through;
}
html[data-theme="dark"] .highcharts-pie-series .highcharts-point { stroke: var(--portal-surface) !important; }
html[data-theme="dark"] .highcharts-tooltip-box {
    fill: var(--portal-tooltip) !important;
    stroke: var(--portal-tooltip-border) !important;
}
html[data-theme="dark"] :is(.highcharts-tooltip text, .highcharts-tooltip > span) {
    fill: var(--portal-text) !important;
    color: var(--portal-text) !important;
}
