/*
 * #281: dark mode for the Bubbly (Bootstrap 5.2) theme. Bootstrap 5.2 has no color modes, so this re-maps its
 * variables and the components GovLine uses when <html data-theme="dark"> (set by js/theme.js before the page draws).
 * The gray scale is flipped (gray-100 is now the darkest surface, gray-900 the brightest text), which also
 * re-colors GovLine's own styles because they use var(--bs-gray-*). Loaded last so it wins.
 */
html[data-theme="dark"] {
    color-scheme: dark;

    --gov-page: #15171c;
    --gov-surface: #1e2229;
    --gov-surface-2: #262b33;
    --gov-border: #363c46;
    --gov-text: #dfe3e8;
    --gov-muted: #9aa3ad;

    --bs-gray-100: #1a1d23;
    --bs-gray-200: #262b33;
    --bs-gray-300: #363c46;
    --bs-gray-400: #4a525d;
    --bs-gray-500: #6f7883;
    --bs-gray-600: #9aa3ad;
    --bs-gray-700: #b6bdc5;
    --bs-gray-800: #d1d6dc;
    --bs-gray-900: #e8ebee;
    --bs-gray: #2b3038;
    --bs-gray-dark: #e8ebee;
    --bs-light: #262b33;
    --bs-light-rgb: 38, 43, 51;
    --bs-dark: #e8ebee;
    --bs-dark-rgb: 232, 235, 238;

    --bs-body-color: var(--gov-text);
    --bs-body-color-rgb: 223, 227, 232;
    --bs-body-bg: var(--gov-page);
    --bs-body-bg-rgb: 21, 23, 28;
    --bs-border-color: var(--gov-border);
    --bs-border-color-translucent: rgba(255, 255, 255, 0.12);
    --bs-secondary-color: var(--gov-muted);
    --bs-tertiary-bg: var(--gov-surface-2);
    --bs-heading-color: var(--gov-text);
}

html[data-theme="dark"] body {
    background-color: var(--gov-page);
    color: var(--gov-text);
}

html[data-theme="dark"] h1, html[data-theme="dark"] h2, html[data-theme="dark"] h3,
html[data-theme="dark"] h4, html[data-theme="dark"] h5, html[data-theme="dark"] h6,
html[data-theme="dark"] .h1, html[data-theme="dark"] .h2, html[data-theme="dark"] .h3,
html[data-theme="dark"] .h4, html[data-theme="dark"] .h5, html[data-theme="dark"] .h6,
html[data-theme="dark"] .page-heading, html[data-theme="dark"] label {
    color: inherit;
}

/* Surfaces */
html[data-theme="dark"] .page-holder,
html[data-theme="dark"] .bg-light,
html[data-theme="dark"] .bg-gray-100 {
    background-color: var(--gov-page) !important;
}

html[data-theme="dark"] .bg-white {
    background-color: var(--gov-surface) !important;
}

/* Bubbly's blue (#4650dd) is hard to read as text on dark; buttons keep it, links and blue text get a lighter one. */
html[data-theme="dark"] a:not(.btn):not(.nav-link):not(.dropdown-item):not(.list-group-item),
html[data-theme="dark"] .text-primary,
html[data-theme="dark"] .gov-card-number {
    color: #9aa1ff !important;
}

html[data-theme="dark"] .text-dark { color: var(--gov-text) !important; }
html[data-theme="dark"] .text-muted,
html[data-theme="dark"] .text-gray-500,
html[data-theme="dark"] .text-gray-600,
html[data-theme="dark"] .form-text { color: var(--gov-muted) !important; }
html[data-theme="dark"] .text-black { color: var(--gov-text) !important; }

html[data-theme="dark"] .card {
    --bs-card-bg: var(--gov-surface);
    --bs-card-color: var(--gov-text);
    --bs-card-cap-bg: var(--gov-surface);
    --bs-card-border-color: var(--gov-border);
    box-shadow: 0 0.125rem 0.5rem rgba(0, 0, 0, 0.35);
}

html[data-theme="dark"] .card-header,
html[data-theme="dark"] .card-footer {
    background-color: var(--gov-surface);
    border-color: var(--gov-border);
    color: var(--gov-text);
}

html[data-theme="dark"] .modal {
    --bs-modal-bg: var(--gov-surface);
    --bs-modal-color: var(--gov-text);
    --bs-modal-footer-bg: var(--gov-surface);
    --bs-modal-header-border-color: var(--gov-border);
    --bs-modal-footer-border-color: var(--gov-border);
}

html[data-theme="dark"] .modal-content,
html[data-theme="dark"] .modal-footer {
    background-color: var(--gov-surface);
    color: var(--gov-text);
}

html[data-theme="dark"] .btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
}

html[data-theme="dark"] .dropdown-menu {
    --bs-dropdown-bg: var(--gov-surface-2);
    --bs-dropdown-color: var(--gov-text);
    --bs-dropdown-border-color: var(--gov-border);
    --bs-dropdown-divider-bg: var(--gov-border);
    --bs-dropdown-link-color: var(--gov-text);
    --bs-dropdown-link-hover-color: #fff;
    --bs-dropdown-link-hover-bg: #323843;
    --bs-dropdown-header-color: var(--gov-muted);
}

html[data-theme="dark"] .list-group {
    --bs-list-group-bg: var(--gov-surface);
    --bs-list-group-color: var(--gov-text);
    --bs-list-group-border-color: var(--gov-border);
    --bs-list-group-action-color: var(--gov-text);
    --bs-list-group-action-hover-color: #fff;
    --bs-list-group-action-hover-bg: var(--gov-surface-2);
    --bs-list-group-action-active-color: #fff;
    --bs-list-group-action-active-bg: #323843;
    --bs-list-group-disabled-bg: var(--gov-surface);
    --bs-list-group-disabled-color: var(--gov-muted);
}

html[data-theme="dark"] .table {
    --bs-table-color: var(--gov-text);
    --bs-table-bg: transparent;
    --bs-table-border-color: var(--gov-border);
    --bs-table-striped-color: var(--gov-text);
    --bs-table-striped-bg: rgba(255, 255, 255, 0.035);
    --bs-table-active-color: var(--gov-text);
    --bs-table-active-bg: rgba(255, 255, 255, 0.08);
    --bs-table-hover-color: #fff;
    --bs-table-hover-bg: rgba(255, 255, 255, 0.06);
    border-color: var(--gov-border);
}

html[data-theme="dark"] .table > :not(caption) > * > * {
    color: var(--bs-table-color);
    border-color: var(--gov-border);
}

html[data-theme="dark"] .table-light {
    --bs-table-color: var(--gov-text);
    --bs-table-bg: var(--gov-surface-2);
    --bs-table-border-color: var(--gov-border);
}

html[data-theme="dark"] .nav-tabs {
    --bs-nav-tabs-border-color: var(--gov-border);
    --bs-nav-tabs-link-active-bg: transparent;
}

html[data-theme="dark"] .nav-link { color: var(--gov-muted); }
html[data-theme="dark"] .nav-link:hover { color: var(--gov-text); }
html[data-theme="dark"] .nav-tabs .nav-link.active { color: #8d95ff; border-bottom-color: #8d95ff; }

/* Forms */
html[data-theme="dark"] .form-control,
html[data-theme="dark"] .form-select,
html[data-theme="dark"] .input-group-text {
    background-color: #12141a;
    color: var(--gov-text);
    border-color: var(--gov-border);
}

html[data-theme="dark"] .form-control::placeholder { color: #737c87; }

/* Floating-label fields hide their placeholder behind the label, as in the light theme. */
html[data-theme="dark"] .form-floating > .form-control::placeholder,
html[data-theme="dark"] .form-floating > .form-control-plaintext::placeholder { color: transparent; }

/* Plain fields without Bootstrap classes (e.g. the Ops card's Notes) */
html[data-theme="dark"] textarea:not(.form-control),
html[data-theme="dark"] input:not(.form-control):not(.form-check-input):not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]),
html[data-theme="dark"] select:not(.form-select) {
    background-color: #12141a;
    color: var(--gov-text);
    border-color: var(--gov-border);
}

html[data-theme="dark"] .form-control:disabled,
html[data-theme="dark"] .form-control[readonly],
html[data-theme="dark"] .form-select:disabled {
    background-color: var(--gov-surface-2);
    color: var(--gov-muted);
}

html[data-theme="dark"] .form-select {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23b6bdc5' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
}

html[data-theme="dark"] .form-check-input:not(:checked) {
    background-color: #12141a;
    border-color: #5a626d;
}

html[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator,
html[data-theme="dark"] input[type="datetime-local"]::-webkit-calendar-picker-indicator {
    filter: invert(0.8);
}

/* Buttons that are white or black in the light theme */
html[data-theme="dark"] .btn-light {
    --bs-btn-bg: var(--gov-surface-2);
    --bs-btn-border-color: var(--gov-border);
    --bs-btn-color: var(--gov-text);
    --bs-btn-hover-bg: #323843;
    --bs-btn-hover-border-color: #4a525d;
    --bs-btn-hover-color: #fff;
}

html[data-theme="dark"] .btn-outline-dark,
html[data-theme="dark"] .btn-outline-secondary {
    --bs-btn-color: var(--gov-text);
    --bs-btn-border-color: #5a626d;
    --bs-btn-hover-bg: var(--gov-surface-2);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-border-color: #6f7883;
}

html[data-theme="dark"] .btn-dark {
    --bs-btn-bg: #2b3038;
    --bs-btn-border-color: #2b3038;
    --bs-btn-color: #fff;
    --bs-btn-hover-bg: #363c46;
    --bs-btn-hover-border-color: #363c46;
}

html[data-theme="dark"] .accordion {
    --bs-accordion-bg: var(--gov-surface);
    --bs-accordion-color: var(--gov-text);
    --bs-accordion-border-color: var(--gov-border);
    --bs-accordion-button-bg: var(--gov-surface);
    --bs-accordion-button-color: var(--gov-text);
    --bs-accordion-active-bg: var(--gov-surface-2);
    --bs-accordion-active-color: var(--gov-text);
}

html[data-theme="dark"] .toast,
html[data-theme="dark"] .popover {
    --bs-toast-bg: var(--gov-surface-2);
    --bs-toast-color: var(--gov-text);
    --bs-popover-bg: var(--gov-surface-2);
    --bs-popover-body-color: var(--gov-text);
    --bs-popover-header-bg: var(--gov-surface);
}

html[data-theme="dark"] .alert-light,
html[data-theme="dark"] .alert-secondary {
    background-color: var(--gov-surface-2);
    color: var(--gov-text);
    border-color: var(--gov-border);
}

html[data-theme="dark"] .border,
html[data-theme="dark"] .border-top,
html[data-theme="dark"] .border-bottom,
html[data-theme="dark"] .border-start,
html[data-theme="dark"] .border-end {
    border-color: var(--gov-border) !important;
}

html[data-theme="dark"] hr { color: var(--gov-border); opacity: 1; }

html[data-theme="dark"] .bg-light .text-dark,
html[data-theme="dark"] .badge.bg-light { color: var(--gov-text) !important; }

/* Third-party pieces */
html[data-theme="dark"] .blazored-typeahead,
html[data-theme="dark"] .blazored-typeahead__controls,
html[data-theme="dark"] .blazored-typeahead__input,
html[data-theme="dark"] .blazored-typeahead__input-mask,
html[data-theme="dark"] .blazored-typeahead__results {
    background-color: #12141a;
    color: var(--gov-text);
    border-color: var(--gov-border);
}

/* #289: the AP and AR invoice pages force typeahead results to black (!important) for the light theme. */
html[data-theme="dark"] .blazored-typeahead__result {
    color: var(--gov-text) !important;
}

html[data-theme="dark"] .blazored-typeahead__result:hover,
html[data-theme="dark"] .blazored-typeahead__active-item,
html[data-theme="dark"] .blazored-typeahead__result-selected {
    background-color: var(--gov-surface-2);
    color: #fff !important;
}

/* Submenus (Filter By / Order By) only carry the --default class, not .blazor-context-menu, so they need naming too. */
html[data-theme="dark"] .blazor-context-menu,
html[data-theme="dark"] .blazor-context-menu--default,
html[data-theme="dark"] .blazor-context-submenu {
    background-color: var(--gov-surface-2);
    color: var(--gov-text);
    border-color: var(--gov-border);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.5), 0 0 0 1px var(--gov-border);
}

html[data-theme="dark"] .blazor-context-menu__seperator,
html[data-theme="dark"] .blazor-context-menu__seperator__hr {
    color: var(--gov-border);
    border-color: var(--gov-border);
}

html[data-theme="dark"] .blazor-context-menu__item--with-submenu:after {
    border-left-color: var(--gov-text);
}

html[data-theme="dark"] .blazor-context-menu__item:hover,
html[data-theme="dark"] .blazor-context-menu__wrapper li:hover {
    background-color: #323843;
}

html[data-theme="dark"] .blazored-toast {
    box-shadow: 0 0.25rem 0.75rem rgba(0, 0, 0, 0.5);
}

/* The Google calendar on Home can't be themed; dim it a little so it isn't a glaring white block. */
html[data-theme="dark"] iframe[title="GovLine calendar"] {
    filter: brightness(0.88);
}

::selection {
    background: rgba(70, 80, 221, 0.35);
}

/* Header logo: the white-lettered one in dark mode (both are in the header; one is hidden). */
.gov-logo-dark { display: none !important; }
html[data-theme="dark"] .gov-logo-light { display: none !important; }
html[data-theme="dark"] .gov-logo-dark { display: inline !important; }
