/* =============================================================================
   Monochrome — Dark mode
   Defensive overrides for WordPress core, Gutenberg blocks, and WooCommerce
   that would otherwise render hardcoded white backgrounds in dark mode.
   ============================================================================= */

/* -------------------------------------- Auto mode (respect OS preference) */
@media (prefers-color-scheme: dark) {
    body.color-mode-auto img[src$=".svg"] { filter: none; }
    body.color-mode-auto .custom-logo     { filter: invert(0) brightness(1); }

    body.color-mode-auto input[type="text"],
    body.color-mode-auto input[type="email"],
    body.color-mode-auto input[type="search"],
    body.color-mode-auto input[type="url"],
    body.color-mode-auto input[type="password"],
    body.color-mode-auto input[type="number"],
    body.color-mode-auto input[type="tel"],
    body.color-mode-auto input[type="date"],
    body.color-mode-auto textarea,
    body.color-mode-auto select,
    body.color-mode-auto .wp-block-search__input {
        background: var(--mono-surface) !important;
        color: var(--mono-text) !important;
        border-color: var(--mono-border) !important;
    }
    body.color-mode-auto .select2-container--default .select2-selection--single,
    body.color-mode-auto .select2-container--default .select2-selection--multiple,
    body.color-mode-auto .select2-dropdown,
    body.color-mode-auto .select2-container--default .select2-search--dropdown .select2-search__field {
        background: var(--mono-surface) !important;
        color: var(--mono-text) !important;
        border-color: var(--mono-border) !important;
    }
}

/* -------------------------------------- Forced dark mode */
body.color-mode-dark,
body[data-theme="dark"] { color-scheme: dark; }

body[data-theme="dark"] .no-invert { filter: none !important; }

body[data-theme="dark"] input[type="text"],
body[data-theme="dark"] input[type="email"],
body[data-theme="dark"] input[type="search"],
body[data-theme="dark"] input[type="url"],
body[data-theme="dark"] input[type="password"],
body[data-theme="dark"] input[type="number"],
body[data-theme="dark"] input[type="tel"],
body[data-theme="dark"] input[type="date"],
body[data-theme="dark"] textarea,
body[data-theme="dark"] select,
body[data-theme="dark"] .wp-block-search__input,
body.color-mode-dark input[type="text"],
body.color-mode-dark input[type="email"],
body.color-mode-dark input[type="search"],
body.color-mode-dark input[type="url"],
body.color-mode-dark input[type="password"],
body.color-mode-dark input[type="number"],
body.color-mode-dark input[type="tel"],
body.color-mode-dark input[type="date"],
body.color-mode-dark textarea,
body.color-mode-dark select,
body.color-mode-dark .wp-block-search__input {
    background: var(--mono-surface) !important;
    color: var(--mono-text) !important;
    border-color: var(--mono-border) !important;
}

/* Placeholder contrast */
body[data-theme="dark"] ::placeholder,
body.color-mode-dark ::placeholder { color: var(--mono-muted); opacity: .8; }

/* WooCommerce select2 */
body[data-theme="dark"] .select2-container--default .select2-selection--single,
body[data-theme="dark"] .select2-container--default .select2-selection--multiple,
body[data-theme="dark"] .select2-dropdown,
body[data-theme="dark"] .select2-container--default .select2-search--dropdown .select2-search__field,
body.color-mode-dark .select2-container--default .select2-selection--single,
body.color-mode-dark .select2-container--default .select2-selection--multiple,
body.color-mode-dark .select2-dropdown,
body.color-mode-dark .select2-container--default .select2-search--dropdown .select2-search__field {
    background: var(--mono-surface) !important;
    color: var(--mono-text) !important;
    border-color: var(--mono-border) !important;
}
body[data-theme="dark"] .select2-container--default .select2-selection--single .select2-selection__rendered,
body[data-theme="dark"] .select2-results__option,
body.color-mode-dark .select2-container--default .select2-selection--single .select2-selection__rendered,
body.color-mode-dark .select2-results__option { color: var(--mono-text) !important; }
body[data-theme="dark"] .select2-container--default .select2-results__option--highlighted[aria-selected],
body.color-mode-dark .select2-container--default .select2-results__option--highlighted[aria-selected] {
    background: var(--mono-text) !important;
    color: var(--mono-bg) !important;
}

/* WC notices */
body[data-theme="dark"] .woocommerce-message,
body[data-theme="dark"] .woocommerce-info,
body[data-theme="dark"] .woocommerce-error,
body.color-mode-dark .woocommerce-message,
body.color-mode-dark .woocommerce-info,
body.color-mode-dark .woocommerce-error {
    background: var(--mono-surface);
    color: var(--mono-text);
}

/* Gutenberg core block surfaces */
body[data-theme="dark"] .wp-block-table table,
body[data-theme="dark"] .wp-block-preformatted,
body[data-theme="dark"] .wp-block-code,
body[data-theme="dark"] .wp-block-pullquote,
body[data-theme="dark"] .wp-block-quote,
body.color-mode-dark .wp-block-table table,
body.color-mode-dark .wp-block-preformatted,
body.color-mode-dark .wp-block-code,
body.color-mode-dark .wp-block-pullquote,
body.color-mode-dark .wp-block-quote {
    background: var(--mono-surface);
    color: var(--mono-text);
    border-color: var(--mono-border);
}

/* Calendar widget */
body[data-theme="dark"] .calendar_wrap table,
body[data-theme="dark"] .wp-calendar-table,
body.color-mode-dark .calendar_wrap table,
body.color-mode-dark .wp-calendar-table {
    background: transparent;
    color: var(--mono-text);
}
body[data-theme="dark"] .wp-calendar-table td,
body[data-theme="dark"] .wp-calendar-table th,
body.color-mode-dark .wp-calendar-table td,
body.color-mode-dark .wp-calendar-table th {
    border-color: var(--mono-border);
}

/* Opt-in image invert helper for logos that need contrast */
body[data-theme="dark"] .mono-invert-dark,
body.color-mode-dark .mono-invert-dark { filter: invert(1) hue-rotate(180deg); }
