:root,
:root[data-theme="light"] {
    color-scheme: light;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --sidebar-bg: #101318;
    --sidebar-hover: #1d2430;
    --sidebar-active: #60a5fa;
    --sidebar-text: #cbd5e1;
    --topbar-bg: #151a22;
    --page-bg: #0f141b;
    --card-bg: #171d26;
    --card-border: #2a3442;
    --accent: #60a5fa;
    --accent-soft: rgba(96, 165, 250, .14);
    --green: #4ade80;
    --red: #fb7185;
}

:root[data-theme="dark"] body {
    background: var(--page-bg);
    color: #e5edf7;
}

:root[data-theme="dark"] .topbar,
:root[data-theme="dark"] .card-panel,
:root[data-theme="dark"] .login-panel,
:root[data-theme="dark"] .stat-box,
:root[data-theme="dark"] .modal-content,
:root[data-theme="dark"] .dropdown-menu,
:root[data-theme="dark"] .list-group-item,
:root[data-theme="dark"] .table {
    color: #e5edf7;
}

:root[data-theme="dark"] .login-panel {
    background: var(--card-bg);
    border-color: var(--card-border);
    box-shadow: 0 20px 50px rgba(0, 0, 0, .24);
}

:root[data-theme="dark"] .login-theme-toggle {
    background: var(--card-bg);
    border-color: var(--card-border);
    color: #e5edf7;
}

:root[data-theme="dark"] .login-theme-toggle:hover {
    background: #202938;
    color: #fff;
}

:root[data-theme="dark"] .topbar-title,
:root[data-theme="dark"] .card-panel-header .title,
:root[data-theme="dark"] .stat-box .stat-value,
:root[data-theme="dark"] .history-info .hi-title,
:root[data-theme="dark"] h1,
:root[data-theme="dark"] h2,
:root[data-theme="dark"] h3,
:root[data-theme="dark"] h4,
:root[data-theme="dark"] h5,
:root[data-theme="dark"] h6,
:root[data-theme="dark"] label,
:root[data-theme="dark"] .form-label,
:root[data-theme="dark"] .fw-semibold,
:root[data-theme="dark"] .fw-bold {
    color: #f8fafc !important;
}

:root[data-theme="dark"] .text-muted,
:root[data-theme="dark"] .card-panel-header .subtitle,
:root[data-theme="dark"] .stat-box .stat-label,
:root[data-theme="dark"] .history-info .hi-artist,
:root[data-theme="dark"] .history-time,
:root[data-theme="dark"] .small.text-muted {
    color: #9aa8bb !important;
}

:root[data-theme="dark"] .form-control,
:root[data-theme="dark"] .form-select,
:root[data-theme="dark"] textarea,
:root[data-theme="dark"] input {
    background-color: #111722;
    border-color: #334155;
    color: #e5edf7;
}

:root[data-theme="dark"] .form-control:focus,
:root[data-theme="dark"] .form-select:focus {
    background-color: #111722;
    border-color: #60a5fa;
    color: #f8fafc;
    box-shadow: 0 0 0 .2rem rgba(96, 165, 250, .18);
}

:root[data-theme="dark"] .form-control::placeholder {
    color: #7d8ca1;
}

:root[data-theme="dark"] .btn-outline-secondary {
    --bs-btn-color: #cbd5e1;
    --bs-btn-border-color: #475569;
    --bs-btn-hover-bg: #263244;
    --bs-btn-hover-border-color: #64748b;
    --bs-btn-hover-color: #fff;
}

:root[data-theme="dark"] .btn-outline-primary {
    --bs-btn-color: #93c5fd;
    --bs-btn-border-color: #3b82f6;
    --bs-btn-hover-bg: #2563eb;
    --bs-btn-hover-border-color: #60a5fa;
    --bs-btn-hover-color: #fff;
}

:root[data-theme="dark"] .bg-white,
:root[data-theme="dark"] .accordion-item,
:root[data-theme="dark"] .accordion-button {
    background-color: var(--card-bg) !important;
    color: #e5edf7;
}

:root[data-theme="dark"] .border,
:root[data-theme="dark"] .border-top,
:root[data-theme="dark"] .border-bottom {
    border-color: var(--card-border) !important;
}

:root[data-theme="dark"] .table > :not(caption) > * > * {
    background-color: transparent;
    border-color: var(--card-border);
    color: #e5edf7;
}

:root[data-theme="dark"] .disk-bar,
:root[data-theme="dark"] .history-num {
    background: #263244;
}

:root[data-theme="dark"] .topbar-status.on {
    background: rgba(34, 197, 94, .18);
    color: #86efac;
}

:root[data-theme="dark"] .topbar-status.off {
    background: rgba(248, 113, 113, .18);
    color: #fca5a5;
}

.theme-toggle {
    appearance: none;
    width: calc(100% - 24px);
    margin: 4px 12px 8px;
    border: 1px solid rgba(148, 163, 184, .24);
    background: rgba(255, 255, 255, .06);
    color: var(--sidebar-text);
    border-radius: 8px;
    padding: 7px 9px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: .82rem;
    font-weight: 700;
    line-height: 1.2;
    transition: background .15s ease, border-color .15s ease, color .15s ease, transform .15s ease;
}

.theme-toggle:hover {
    background: var(--sidebar-hover);
    border-color: rgba(148, 163, 184, .42);
    color: #fff;
    transform: translateY(-1px);
}

.theme-toggle:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.theme-toggle .theme-toggle-icon {
    width: 22px;
    height: 22px;
    min-width: 22px;
    border-radius: 7px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    background: linear-gradient(135deg, #0ea5e9, #6366f1);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, .18), 0 6px 14px rgba(0, 0, 0, .18);
}

.theme-toggle .theme-toggle-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 767px) {
    .theme-toggle {
        flex: 0 0 auto;
        width: auto;
        min-width: 112px;
        margin: 6px 4px;
        padding: 10px;
    }

    .theme-toggle .theme-toggle-icon {
        width: 28px;
        height: 28px;
        min-width: 28px;
    }
}
