/**
 * WordPress Download Manager - Dark Mode Styles
 *
 * This file contains all dark mode CSS for WPDM.
 * Only enqueued when color scheme is 'dark' or 'system'.
 * For 'light' mode, this file is NOT loaded (performance optimization).
 *
 * @package WPDM
 * @since 7.0.4
 */

/* ==========================================================================
   DARK MODE SUPPORT
   Auto: prefers-color-scheme | Manual: .dark-mode class
   ========================================================================== */

/* Dark mode variables - System preference */
/* Note: --color-primary and other color settings come from user settings, not overridden here */
@media (prefers-color-scheme: dark) {
    .w3eden:not(.light-mode) {
        --dm-bg: #0f172a;
        --dm-bg-secondary: #1e293b;
        --dm-bg-tertiary: #334155;
        --dm-text: #f1f5f9;
        --dm-text-secondary: #cbd5e1;
        --dm-text-muted: #94a3b8;
        --dm-border: #334155;
        --dm-border-light: #475569;
    }
    .w3eden:not(.light-mode) {  color: var(--dm-text); }
    .w3eden:not(.light-mode) .card { background: var(--dm-bg-secondary); border-color: var(--dm-border); }
    .w3eden:not(.light-mode) .card-header { background: var(--dm-bg-tertiary); border-color: var(--dm-border); color: var(--dm-text); }
    .w3eden:not(.light-mode) .form-control { background: var(--dm-bg-secondary); border-color: var(--dm-border); color: var(--dm-text); }
    .w3eden:not(.light-mode) .form-control::placeholder { color: var(--dm-text-muted); }
    .w3eden:not(.light-mode) .table { color: var(--dm-text); }
    .w3eden:not(.light-mode) .table th, .w3eden:not(.light-mode) .table td { border-color: var(--dm-border); }
    .w3eden:not(.light-mode) .table thead th { background: var(--dm-bg-tertiary); color: var(--dm-text-secondary); }
    .w3eden:not(.light-mode) .table tbody tr:hover { background-color: var(--dm-bg-tertiary); }
    .w3eden:not(.light-mode) .table-striped tbody tr:nth-of-type(odd) { background-color: var(--dm-bg-tertiary); }
    .w3eden:not(.light-mode) .table-bordered { border-color: var(--dm-border); }
    .w3eden:not(.light-mode) .list-group-item { background: var(--dm-bg-secondary); border-color: var(--dm-border); color: var(--dm-text); }
    .w3eden:not(.light-mode) .modal-content { background: var(--dm-bg-secondary); border-color: var(--dm-border); }
    .w3eden:not(.light-mode) .modal-header, .w3eden:not(.light-mode) .modal-footer { border-color: var(--dm-border); }
    .w3eden:not(.light-mode) .nav-tabs { border-color: var(--dm-border); }
    .w3eden:not(.light-mode) .nav-tabs .nav-link { color: var(--dm-text-muted); }
    .w3eden:not(.light-mode) .nav-tabs .nav-link:hover { color: var(--dm-text); }
    .w3eden:not(.light-mode) .nav-tabs .nav-link.active { color: var(--color-primary); }
    .w3eden:not(.light-mode) .dropdown-menu { background: var(--dm-bg-secondary); border-color: var(--dm-border); }
    .w3eden:not(.light-mode) .dropdown-item { color: var(--dm-text); }
    .w3eden:not(.light-mode) .dropdown-item:hover { background: var(--dm-bg-tertiary); }
    .w3eden:not(.light-mode) .progress { background: var(--dm-bg-tertiary); }
    .w3eden:not(.light-mode) .input-group-text { background: var(--dm-bg-tertiary); border-color: var(--dm-border); color: var(--dm-text-secondary); }
    .w3eden:not(.light-mode) .alert-secondary, .w3eden:not(.light-mode) .alert-light { background: linear-gradient(180deg, var(--dm-bg-tertiary) 0%, var(--dm-bg-secondary) 100%); color: var(--dm-text-secondary); border-left-color: var(--dm-text-muted); }
    .w3eden:not(.light-mode) .wpdm-changelog { border-color: var(--dm-border); }
    .w3eden:not(.light-mode) .wpdm-changelog__header { border-color: var(--dm-border); }
    .w3eden:not(.light-mode) .wpdm-changelog__title, .w3eden:not(.light-mode) .wpdm-changelog__changes, .w3eden:not(.light-mode) .wpdm-changelog__changes strong { color: var(--dm-text); }
    .w3eden:not(.light-mode) .wpdm-changelog__content { background: var(--dm-bg-secondary); border-color: var(--dm-border); }
    .w3eden:not(.light-mode) .wpdm-changelog__content:hover { border-color: var(--dm-border-light); }
    .w3eden:not(.light-mode) .wpdm-changelog__item-header { background: var(--dm-bg-tertiary); border-color: var(--dm-border); }
    .w3eden:not(.light-mode) .wpdm-changelog__item-header:hover { background: var(--dm-bg); }
    .w3eden:not(.light-mode) .wpdm-changelog__version { background: var(--dm-bg); color: var(--dm-text); }
    .w3eden:not(.light-mode) .wpdm-changelog__date { color: var(--dm-text-muted); }
    .w3eden:not(.light-mode) .wpdm-changelog__line { background: var(--dm-border); }
    .w3eden:not(.light-mode) .wpdm-changelog__toggle { border-color: var(--dm-border); color: var(--dm-text-muted); }
    .w3eden:not(.light-mode) .wpdm-changelog__changes code { background: var(--dm-bg-tertiary); color: var(--dm-text); }
    .w3eden:not(.light-mode) .wpdm-changelog-empty { background: var(--dm-bg-tertiary); border-color: var(--dm-border); color: var(--dm-text-muted); }
    .w3eden:not(.light-mode) .text-muted { color: var(--dm-text-muted) !important; }
    .w3eden:not(.light-mode) hr { border-color: var(--dm-border); }
    .w3eden:not(.light-mode) a:not(.btn) { color: var(--color-primary); }
}

/* Manual dark mode toggle via .dark-mode class */
/* Note: --color-primary and other color settings come from user settings, not overridden here */
.w3eden.dark-mode {
    --dm-bg: #0f172a;
    --dm-bg-secondary: #1e293b;
    --dm-bg-tertiary: #334155;
    --dm-text: #f1f5f9;
    --dm-text-secondary: #cbd5e1;
    --dm-text-muted: #94a3b8;
    --dm-border: #334155;
    --dm-border-light: #475569;
    color: var(--dm-text);
}
.w3eden.dark-mode .card { background: var(--dm-bg-secondary); border-color: var(--dm-border); }
.w3eden.dark-mode .card-header { background: var(--dm-bg-tertiary); border-color: var(--dm-border); color: var(--dm-text); }
.w3eden.dark-mode .card-footer { background: var(--dm-bg-tertiary); border-color: var(--dm-border); color: var(--dm-text); }
.w3eden.dark-mode .form-control { background: var(--dm-bg-secondary); border-color: var(--dm-border); color: var(--dm-text); }
.w3eden.dark-mode .form-control::placeholder { color: var(--dm-text-muted); }
.w3eden.dark-mode .table { color: var(--dm-text); }
.w3eden.dark-mode .table th, .w3eden.dark-mode .table td { border-color: var(--dm-border); }
.w3eden.dark-mode .table thead th { background: var(--dm-bg-tertiary); color: var(--dm-text-secondary); }
.w3eden.dark-mode .table tbody tr:hover { background-color: var(--dm-bg-tertiary); }
.w3eden.dark-mode .table-striped tbody tr:nth-of-type(odd) { background-color: var(--dm-bg-tertiary); }
.w3eden.dark-mode .table-bordered { border-color: var(--dm-border); }
.w3eden.dark-mode .list-group-item { background: var(--dm-bg-secondary); border-color: var(--dm-border); color: var(--dm-text); }
.w3eden.dark-mode .modal-content { background: var(--dm-bg-secondary); border-color: var(--dm-border); }
.w3eden.dark-mode .modal-header, .w3eden.dark-mode .modal-footer { border-color: var(--dm-border); }
.w3eden.dark-mode .nav-tabs { border-color: var(--dm-border); }
.w3eden.dark-mode .nav-tabs .nav-link { color: var(--dm-text-muted); }
.w3eden.dark-mode .nav-tabs .nav-link:hover { color: var(--dm-text); }
.w3eden.dark-mode .nav-tabs .nav-link.active { color: var(--color-primary); }
.w3eden.dark-mode .dropdown-menu { background: var(--dm-bg-secondary); border-color: var(--dm-border); }
.w3eden.dark-mode .dropdown-item { color: var(--dm-text); }
.w3eden.dark-mode .dropdown-item:hover { background: var(--dm-bg-tertiary); }
.w3eden.dark-mode .progress { background: var(--dm-bg-tertiary); }
.w3eden.dark-mode .input-group-text { background: var(--dm-bg-tertiary); border-color: var(--dm-border); color: var(--dm-text-secondary); }
.w3eden.dark-mode .alert-secondary, .w3eden.dark-mode .alert-light { background: linear-gradient(180deg, var(--dm-bg-tertiary) 0%, var(--dm-bg-secondary) 100%); color: var(--dm-text-secondary); border-left-color: var(--dm-text-muted); }
.w3eden.dark-mode .wpdm-changelog { border-color: var(--dm-border); }
.w3eden.dark-mode .wpdm-changelog__header { border-color: var(--dm-border); }
.w3eden.dark-mode .wpdm-changelog__title, .w3eden.dark-mode .wpdm-changelog__changes, .w3eden.dark-mode .wpdm-changelog__changes strong { color: var(--dm-text); }
.w3eden.dark-mode .wpdm-changelog__content { background: var(--dm-bg-secondary); border-color: var(--dm-border); }
.w3eden.dark-mode .wpdm-changelog__content:hover { border-color: var(--dm-border-light); }
.w3eden.dark-mode .wpdm-changelog__item-header { background: var(--dm-bg-tertiary); border-color: var(--dm-border); }
.w3eden.dark-mode .wpdm-changelog__item-header:hover { background: var(--dm-bg); }
.w3eden.dark-mode .wpdm-changelog__version { background: var(--dm-bg); color: var(--dm-text); }
.w3eden.dark-mode .wpdm-changelog__date { color: var(--dm-text-muted); }
.w3eden.dark-mode .wpdm-changelog__line { background: var(--dm-border); }
.w3eden.dark-mode .wpdm-changelog__toggle { border-color: var(--dm-border); color: var(--dm-text-muted); }
.w3eden.dark-mode .wpdm-changelog__changes code { background: var(--dm-bg-tertiary); color: var(--dm-text); }
.w3eden.dark-mode .wpdm-changelog-empty { background: var(--dm-bg-tertiary); border-color: var(--dm-border); color: var(--dm-text-muted); }
.w3eden.dark-mode .text-muted { color: var(--dm-text-muted) !important; }
.w3eden.dark-mode hr { border-color: var(--dm-border); }
.w3eden.dark-mode a:not(.btn) { color: var(--color-primary); }

/* ==========================================================================
   WPDM MODAL DARK MODE
   ========================================================================== */

/* WPDM Modal Dark Mode - Manual */
.wpdm-modal-wrapper.dark-mode .modal-content {
    background: #1e293b;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.wpdm-modal-wrapper.dark-mode .modal-header {
    background: #1e293b;
    border-bottom-color: #334155;
}

.wpdm-modal-wrapper.dark-mode .modal-title {
    color: #f1f5f9;
}

.wpdm-modal-wrapper.dark-mode .wpdm-modal-close {
    color: #94a3b8;
}

.wpdm-modal-wrapper.dark-mode .wpdm-modal-close:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
}

.wpdm-modal-wrapper.dark-mode .modal-body {
    background: #1e293b;
    color: #e2e8f0;
}

.wpdm-modal-wrapper.dark-mode .modal-footer {
    background: #0f172a;
    border-top-color: #334155;
}

.wpdm-modal-wrapper.dark-mode .wpdm-modal-loading .wpdm-spinner {
    border-color: #334155;
    border-top-color: var(--color-primary, #818cf8);
}

.wpdm-modal-wrapper.dark-mode .wpdm-modal-loading .wpdm-loading-text {
    color: #94a3b8;
}

/* Glassmorphic backdrop - dark mode */
body.modal-open.dark-mode .modal-backdrop,
body.dark-mode.modal-open .modal-backdrop {
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px) saturate(120%);
    -webkit-backdrop-filter: blur(8px) saturate(120%);
}

/* System preference dark mode */
@media (prefers-color-scheme: dark) {
    .wpdm-modal-wrapper:not(.light-mode) .modal-content {
        background: #1e293b;
        box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.05);
    }
    .wpdm-modal-wrapper:not(.light-mode) .modal-header {
        background: #1e293b;
        border-bottom-color: #334155;
    }
    .wpdm-modal-wrapper:not(.light-mode) .modal-title {
        color: #f1f5f9;
    }
    .wpdm-modal-wrapper:not(.light-mode) .wpdm-modal-close {
        color: #94a3b8;
    }
    .wpdm-modal-wrapper:not(.light-mode) .wpdm-modal-close:hover {
        background: rgba(239, 68, 68, 0.15);
        color: #f87171;
    }
    .wpdm-modal-wrapper:not(.light-mode) .modal-body {
        background: #1e293b;
        color: #e2e8f0;
    }
    .wpdm-modal-wrapper:not(.light-mode) .modal-footer {
        background: #0f172a;
        border-top-color: #334155;
    }
    .wpdm-modal-wrapper:not(.light-mode) .wpdm-modal-loading .wpdm-spinner {
        border-color: #334155;
        border-top-color: var(--color-primary, #818cf8);
    }
    .wpdm-modal-wrapper:not(.light-mode) .wpdm-modal-loading .wpdm-loading-text {
        color: #94a3b8;
    }
    /* Glassmorphic backdrop - system dark mode */
    body.modal-open:not(.light-mode) .modal-backdrop {
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(8px) saturate(120%);
        -webkit-backdrop-filter: blur(8px) saturate(120%);
    }
}

/* ==========================================================================
   FILE LIST GRID COMPONENT - DARK MODE
   ========================================================================== */

/* Dark Mode - Manual */
.w3eden.dark-mode .wpdm-filelist-toolbar {
    border-bottom-color: var(--dm-border, rgba(255, 255, 255, 0.1));
}

.w3eden.dark-mode .wpdm-filelist-search__input {
    background: var(--dm-bg-secondary, #1e293b);
    border-color: var(--dm-border, rgba(255, 255, 255, 0.1));
    color: var(--dm-text, #f1f5f9);
}

.w3eden.dark-mode .wpdm-filelist-search__input::placeholder {
    color: var(--dm-text-muted, #94a3b8);
}

.w3eden.dark-mode .wpdm-filelist-toggle {
    background: var(--dm-bg-tertiary, #334155);
}

.w3eden.dark-mode .wpdm-filelist-toggle__btn {
    color: var(--dm-text-muted, #94a3b8);
}

.w3eden.dark-mode .wpdm-filelist-toggle__btn:hover {
    color: var(--dm-text, #f1f5f9);
}

.w3eden.dark-mode .wpdm-filelist-toggle__btn.active {
    background: var(--dm-bg-secondary, #1e293b);
    color: var(--color-primary, #818cf8);
}

.w3eden.dark-mode .wpdm-filelist-item {
    background: var(--dm-bg-secondary, #1e293b);
    border-color: var(--dm-border, rgba(255, 255, 255, 0.08));
}

.w3eden.dark-mode .wpdm-filelist-item:hover {
    background: var(--dm-bg-tertiary, #334155);
    border-color: rgba(255, 255, 255, 0.15);
}

.w3eden.dark-mode .wpdm-filelist-item__icon {
    background: rgba(255, 255, 255, 0.05);
}

.w3eden.dark-mode .wpdm-filelist-item__title {
    color: var(--dm-text, #f1f5f9);
}

.w3eden.dark-mode .wpdm-filelist-item__meta {
    color: var(--dm-text-muted, #94a3b8);
}

.w3eden.dark-mode .wpdm-filelist-item__meta > span:not(:last-child)::after {
    color: rgba(255, 255, 255, 0.2);
}

.w3eden.dark-mode .wpdm-filelist-item__password .form-control {
    background: var(--dm-bg-tertiary, #334155);
    border-color: rgba(255, 255, 255, 0.1);
    color: var(--dm-text, #f1f5f9);
}

.w3eden.dark-mode .wpdm-filelist-count {
    color: var(--dm-text-muted, #94a3b8);
}

/* Dark Mode - System Preference */
@media (prefers-color-scheme: dark) {
    .w3eden:not(.light-mode) .wpdm-filelist-toolbar {
        border-bottom-color: var(--dm-border, rgba(255, 255, 255, 0.1));
    }

    .w3eden:not(.light-mode) .wpdm-filelist-search__input {
        background: var(--dm-bg-secondary, #1e293b);
        border-color: var(--dm-border, rgba(255, 255, 255, 0.1));
        color: var(--dm-text, #f1f5f9);
    }

    .w3eden:not(.light-mode) .wpdm-filelist-search__input::placeholder {
        color: var(--dm-text-muted, #94a3b8);
    }

    .w3eden:not(.light-mode) .wpdm-filelist-toggle {
        background: var(--dm-bg-tertiary, #334155);
    }

    .w3eden:not(.light-mode) .wpdm-filelist-toggle__btn {
        color: var(--dm-text-muted, #94a3b8);
    }

    .w3eden:not(.light-mode) .wpdm-filelist-toggle__btn:hover {
        color: var(--dm-text, #f1f5f9);
    }

    .w3eden:not(.light-mode) .wpdm-filelist-toggle__btn.active {
        background: var(--dm-bg-secondary, #1e293b);
        color: var(--color-primary, #818cf8);
    }

    .w3eden:not(.light-mode) .wpdm-filelist-item {
        background: var(--dm-bg-secondary, #1e293b);
        border-color: var(--dm-border, rgba(255, 255, 255, 0.1));
    }

    .w3eden:not(.light-mode) .wpdm-filelist-item:hover {
        border-color: var(--color-primary, #818cf8);
    }

    .w3eden:not(.light-mode) .wpdm-filelist-item__icon {
        background: var(--dm-bg-tertiary, #334155);
    }

    .w3eden:not(.light-mode) .wpdm-filelist-item__title {
        color: var(--dm-text, #f1f5f9);
    }

    .w3eden:not(.light-mode) .wpdm-filelist-item__meta {
        color: var(--dm-text-muted, #94a3b8);
    }

    .w3eden:not(.light-mode) .wpdm-filelist-item__actions {
        border-top-color: var(--dm-border, rgba(255, 255, 255, 0.1));
    }

    .w3eden:not(.light-mode) .wpdm-filelist-count {
        color: var(--dm-text-muted, #94a3b8);
    }
}

/* ==========================================================================
   CUSTOM SELECT / CATEGORY FILTER DROPDOWN - DARK MODE
   ========================================================================== */

/* Dark Mode - Manual */
.w3eden.dark-mode .wpdm-custom-select,
.w3eden.dark-mode .wpdm-dt-category-filter {
    background-color: var(--dm-bg-secondary, #1e293b) !important;
    background-image: url("../images/sort.svg") !important;
    border-color: var(--dm-border, #334155);
    color: var(--dm-text, #f1f5f9);
}

.w3eden.dark-mode .wpdm-custom-select:focus,
.w3eden.dark-mode .wpdm-dt-category-filter:focus {
    border-color: var(--color-primary, #818cf8);
    box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.15);
}

.w3eden.dark-mode .wpdm-custom-select option,
.w3eden.dark-mode .wpdm-dt-category-filter option {
    background: var(--dm-bg-secondary, #1e293b);
    color: var(--dm-text, #f1f5f9);
}

/* Dark Mode - System Preference */
@media (prefers-color-scheme: dark) {
    .w3eden:not(.light-mode) .wpdm-custom-select,
    .w3eden:not(.light-mode) .wpdm-dt-category-filter {
        background-color: var(--dm-bg-secondary, #1e293b) !important;
        background-image: url("../images/sort.svg") !important;
        border-color: var(--dm-border, #334155);
        color: var(--dm-text, #f1f5f9);
    }

    .w3eden:not(.light-mode) .wpdm-custom-select:focus,
    .w3eden:not(.light-mode) .wpdm-dt-category-filter:focus {
        border-color: var(--color-primary, #818cf8);
        box-shadow: 0 0 0 3px rgba(129, 140, 248, 0.15);
    }

    .w3eden:not(.light-mode) .wpdm-custom-select option,
    .w3eden:not(.light-mode) .wpdm-dt-category-filter option {
        background: var(--dm-bg-secondary, #1e293b);
        color: var(--dm-text, #f1f5f9);
    }
}
