/* ==========================================================================
   White Silence Design System — Complete Standalone CSS
   Replaces Bootstrap CSS entirely across all pages.
   ========================================================================== */

/* ==========================================================================
   1. CSS Variables — White Silence light palette (contrast-boosted)
   ========================================================================== */
:root {
    --bg-body: #F5F6F9;
    --bg-surface: #FFFFFF;
    --bg-elevated: #EDF0F4;
    --bg-input: #FFFFFF;
    --bg-hover: rgba(107, 123, 152, 0.10);
    --bg-active: rgba(107, 123, 152, 0.15);
    --text-primary: #2C3345;
    --text-secondary: #536178;
    --text-muted: #7B8BA0;
    --accent: #6B7B98;
    --accent-hover: #5A6A85;
    --accent-glow: rgba(107, 123, 152, 0.15);
    --accent-glow-strong: rgba(107, 123, 152, 0.25);
    --border: rgba(44, 51, 69, 0.14);
    --border-subtle: rgba(44, 51, 69, 0.08);
    --border-focus: rgba(107, 123, 152, 0.4);
    --success: #6B987E;
    --success-bg: #e8f0eb;
    --danger: #986B6B;
    --danger-bg: #f0e8e8;
    --warning: #98906B;
    --warning-bg: #f0eee8;
    --info: #6B8598;
    --info-bg: #e8eef0;
    --font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    --font-mono: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", "SFMono-Regular", Menlo, Consolas, monospace;
    --radius: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --shadow-card: 0 0 0 1px rgba(44, 51, 69, 0.05), 0 2px 8px rgba(44, 51, 69, 0.06);
    --shadow-glow: 0 0 40px rgba(211, 215, 226, 0.3);
    --transition: 150ms ease;
}

/* ==========================================================================
   2. Reset & Base
   ========================================================================== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-stack);
    color: var(--text-primary);
    background: var(--bg-body);
    line-height: 1.6;
    overflow-x: hidden;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

a {
    color: var(--text-secondary);
    text-decoration: none;
    transition: color var(--transition);
}

a:hover {
    color: var(--text-primary);
}

table {
    border-collapse: collapse;
    width: 100%;
}

button {
    font-family: inherit;
    font-size: inherit;
    cursor: pointer;
    border: none;
    background: none;
    color: inherit;
}

select {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
}

img {
    max-width: 100%;
    height: auto;
}

/* ==========================================================================
   3. Top Navigation Bar
   ========================================================================== */
.top-nav {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(245, 246, 249, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
}

.nav-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.nav-left {
    display: flex;
    align-items: center;
    gap: 32px;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-primary);
    font-weight: 600;
    font-size: 15px;
    letter-spacing: -0.01em;
}

.nav-brand i {
    font-size: 22px;
    color: var(--accent);
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 4px;
}

.nav-links a {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border-radius: var(--radius);
    font-size: 14px;
    color: var(--text-secondary);
    transition: background var(--transition), color var(--transition);
}

.nav-links a:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-links a.active {
    background: var(--bg-active);
    color: var(--text-primary);
}

.nav-links a i {
    font-size: 17px;
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

#user-info {
    font-size: 13px;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
}

#logout-btn {
    font-size: 13px;
    color: var(--text-secondary);
    padding: 6px 12px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    transition: background var(--transition), color var(--transition), border-color var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

#logout-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: rgba(44, 51, 69, 0.12);
}

/* --- Mobile Navigation --- */

.nav-hamburger {
    display: none;
    padding: 6px 8px;
    font-size: 22px;
    color: var(--text-secondary);
    border-radius: var(--radius);
    border: none;
    background: none;
    cursor: pointer;
    transition: background var(--transition), color var(--transition);
}

.nav-hamburger:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-hamburger.active {
    background: var(--bg-active);
    color: var(--text-primary);
}

.nav-mobile-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: rgba(245, 246, 249, 0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    padding: 8px 16px;
    box-shadow: 0 4px 16px rgba(44, 51, 69, 0.08);
}

.nav-mobile-menu.active {
    display: block;
}

.nav-mobile-menu a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 15px;
    color: var(--text-secondary);
    transition: background var(--transition), color var(--transition);
}

.nav-mobile-menu a:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-mobile-menu a.active {
    background: var(--bg-active);
    color: var(--text-primary);
}

.nav-mobile-menu a i {
    font-size: 20px;
}

/* ==========================================================================
   4. Main Content Container
   ========================================================================== */
.main-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 32px 24px 48px;
    width: 100%;
}

.page-header {
    margin-bottom: 28px;
}

.page-header h1 {
    font-size: 28px;
    font-weight: 300;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.page-header p {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* ==========================================================================
   20. Bootstrap Utility Shims — Display
   ========================================================================== */
.d-none { display: none !important; }
.d-flex { display: flex !important; }

@media (min-width: 992px) {
    .d-lg-none { display: none !important; }
    .d-none.d-lg-flex,
    .d-lg-flex.d-none { display: flex !important; }
}

/* ==========================================================================
   21. Bootstrap Utility Shims — Flex
   ========================================================================== */
.align-items-center { align-items: center !important; }
.flex-grow-1 { flex-grow: 1 !important; }
.flex-wrap { flex-wrap: wrap !important; }
.gap-1 { gap: 4px !important; }
.gap-2 { gap: 8px !important; }
.justify-content-between { justify-content: space-between !important; }
.justify-content-center { justify-content: center !important; }

/* ==========================================================================
   22. Bootstrap Utility Shims — Spacing
   ========================================================================== */
.me-1 { margin-right: 4px !important; }
.me-2 { margin-right: 8px !important; }
.ms-1 { margin-left: 4px !important; }
.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: 4px !important; }
.mb-2 { margin-bottom: 8px !important; }
.mb-3 { margin-bottom: 16px !important; }
.mb-4 { margin-bottom: 24px !important; }
.mt-3 { margin-top: 16px !important; }
.py-2 { padding-top: 8px !important; padding-bottom: 8px !important; }
.py-4 { padding-top: 24px !important; padding-bottom: 24px !important; }
.p-3 { padding: 16px !important; }
.p-4 { padding: 24px !important; }
.p-5 { padding: 32px !important; }

@media (min-width: 768px) {
    .px-md-4 { padding-left: 24px !important; padding-right: 24px !important; }
}

/* ==========================================================================
   23. Bootstrap Utility Shims — Text
   ========================================================================== */
.text-center { text-align: center !important; }
.text-muted { color: var(--text-muted) !important; }
.text-dark { color: var(--text-primary) !important; }
.text-light { color: var(--text-muted) !important; }
.text-white { color: #fff !important; }
.text-uppercase { text-transform: uppercase !important; }
.small { font-size: 12px !important; }
.fw-bold { font-weight: 700 !important; }
.fw-semibold { font-weight: 600 !important; }
.font-monospace { font-family: var(--font-mono) !important; }

/* ==========================================================================
   24. Bootstrap Utility Shims — Background
   ========================================================================== */
.bg-white { background: var(--bg-surface) !important; }
.bg-light { background: rgba(211, 215, 226, 0.3) !important; }
.bg-success { background: var(--success) !important; }
.bg-secondary { background: var(--text-muted) !important; }
.bg-danger { background: var(--danger) !important; }
.bg-primary { background: var(--accent) !important; }
.bg-warning { background: var(--warning) !important; }
.bg-info { background: var(--info) !important; }
.bg-dark { background: var(--text-primary) !important; }
.bg-opacity-10 { opacity: 0.1; }

/* ==========================================================================
   25. Bootstrap Utility Shims — Position
   ========================================================================== */
.position-fixed { position: fixed !important; }
.position-absolute { position: absolute !important; }
.position-relative { position: relative !important; }
.top-0 { top: 0 !important; }
.end-0 { right: 0 !important; }
.top-50 { top: 50% !important; }
.translate-middle-y { transform: translateY(-50%) !important; }

/* ==========================================================================
   26. Bootstrap Utility Shims — Layout
   ========================================================================== */
.container-fluid {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
}

.row {
    display: flex;
    flex-wrap: wrap;
}

.g-2 { gap: 8px; }
.g-3 { gap: 16px; }

.col-md-2 { flex: 0 0 16.6667%; max-width: 16.6667%; }
.col-md-4 { flex: 0 0 33.3333%; max-width: 33.3333%; }
.col-md-6 { flex: 0 0 50%; max-width: 50%; }
.col-md-9 { flex: 0 0 75%; max-width: 75%; }
.col-lg-6 { flex: 0 0 50%; max-width: 50%; }
.col-lg-10 { flex: 0 0 83.3333%; max-width: 83.3333%; }
.col-sm-4 { flex: 0 0 33.3333%; max-width: 33.3333%; }
.col-sm-8 { flex: 0 0 66.6667%; max-width: 66.6667%; }
.col-auto { flex: 0 0 auto; width: auto; }

.min-vh-100 { min-height: 100vh !important; }
.h-100 { height: 100% !important; }
.w-100 { width: 100% !important; }

/* ==========================================================================
   27. Bootstrap Utility Shims — Borders
   ========================================================================== */
.border-0 { border: 0 !important; }
.border-top { border-top: 1px solid var(--border) !important; }
.border-bottom { border-bottom: 1px solid var(--border) !important; }
.rounded-3 { border-radius: var(--radius-lg) !important; }
.rounded { border-radius: var(--radius) !important; }

/* ==========================================================================
   28. Bootstrap Utility Shims — Misc
   ========================================================================== */
.overflow-hidden { overflow: hidden !important; }
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ==========================================================================
   29. Responsive Breakpoints
   ========================================================================== */
@media (max-width: 768px) {
    .nav-inner {
        padding: 0 16px;
        height: 52px;
    }

    .nav-links {
        display: none;
    }

    .nav-hamburger {
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .nav-left {
        gap: 16px;
    }

    .main-content {
        padding: 20px 16px 32px;
    }

    .page-header h1 {
        font-size: 22px;
    }

    .stats-grid {
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }

    .upload-card {
        grid-column: 1 / -1;
    }

    .stat-card.upload-card {
        padding: 0;
    }

    .stat-card {
        padding: 20px;
    }

    .stat-card-value {
        font-size: 26px;
    }

    .search-wrapper {
        flex-wrap: wrap;
    }

    .search-input-group {
        flex-basis: 100%;
    }

    .search-actions {
        width: 100%;
    }

    .search-actions .btn-search {
        flex: 1;
        justify-content: center;
    }

    /* Design section header responsive */
    .design-section-header {
        flex-direction: column;
        gap: 12px;
    }

    .files-table thead th,
    .files-table tbody td {
        padding: 10px 12px;
        font-size: 12px;
    }

    .pagination-footer {
        flex-direction: column;
        align-items: flex-start;
    }

    .pagination-right-group {
        width: 100%;
        justify-content: space-between;
    }

    #user-info {
        display: none;
    }

    /* Stack grid columns on mobile */
    .row {
        flex-direction: column;
    }

    [class^="col-md-"],
    [class^="col-lg-"],
    [class^="col-sm-"] {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* Login page stacking */
    .login-branding-panel {
        display: none;
    }

    /* Modal full width on mobile */
    .modal {
        padding: 16px;
    }

    .modal-dialog {
        max-width: 100%;
    }

    .modal-body {
        padding: 16px;
    }

    .modal-header,
    .modal-footer {
        padding: 12px 16px;
    }

    /* Table responsive */
    .table-responsive {
        margin: 0 -16px;
        padding: 0 16px;
    }

    /* Card adjustments */
    .card-body {
        padding: 16px;
    }

    /* Form full width */
    .form-control,
    .form-select {
        font-size: 16px; /* Prevent iOS zoom */
    }

    /* File Cards responsive */
    .file-card-specs {
        grid-template-columns: 1fr;
    }

    .file-card-header {
        padding: 16px 16px 0 16px;
    }

    .file-card-divider {
        margin: 12px 16px;
    }

    .file-card-specs {
        padding: 0 16px;
    }

    .file-card-actions {
        padding: 12px 16px 16px 16px;
    }

    /* File Row Layout - Mobile Responsive */
    .file-card.file-row {
        flex-wrap: wrap;
        gap: 12px;
        padding: 12px 16px;
    }

    .file-card.file-row .file-strip {
        height: 32px;
    }

    .file-card.file-row .file-icon {
        width: 32px;
        height: 32px;
        font-size: 16px;
    }

    .file-card.file-row .file-info {
        width: 100%;
        order: 1;
        min-width: 0;
    }

    .file-card.file-row .file-expiry {
        order: 2;
        align-items: flex-start;
        margin-right: 0;
        margin-left: auto;
    }

    .file-card.file-row .file-actions {
        width: 100%;
        justify-content: flex-end;
        order: 3;
        padding-top: 8px;
        border-top: 1px solid var(--border-subtle);
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: 1fr 1fr 2fr;
        gap: 12px;
    }

    .stat-card {
        padding: 20px;
    }

    .stat-card-value {
        font-size: 28px;
    }
}

@media (min-width: 1025px) {
    /* Login page side-by-side layout */
    .authentication-bg {
        display: flex;
    }
}

/* ==========================================================================
   31. Dark Mode — [data-theme="dark"] overrides
   ========================================================================== */

/* --- 31a. Custom Property Overrides --- */
[data-theme="dark"] {
    --bg-body: #0f1117;
    --bg-surface: #1a1d27;
    --bg-elevated: #22252f;
    --bg-input: #1a1d27;
    --bg-hover: rgba(255, 255, 255, 0.06);
    --bg-active: rgba(255, 255, 255, 0.10);
    --text-primary: #e2e4e9;
    --text-secondary: #a0a6b4;
    --text-muted: #6b7280;
    --accent: #8b9cc5;
    --accent-hover: #9dadc8;
    --accent-glow: rgba(139, 156, 197, 0.15);
    --accent-glow-strong: rgba(139, 156, 197, 0.25);
    --border: rgba(255, 255, 255, 0.10);
    --border-subtle: rgba(255, 255, 255, 0.05);
    --border-focus: rgba(139, 156, 197, 0.50);
    --success: #7dbd95;
    --success-bg: rgba(125, 189, 149, 0.12);
    --danger: #c47d7d;
    --danger-bg: rgba(196, 125, 125, 0.12);
    --warning: #c4b67d;
    --warning-bg: rgba(196, 182, 125, 0.12);
    --info: #7d9dbd;
    --info-bg: rgba(125, 157, 189, 0.12);
    --shadow-card: 0 0 0 1px rgba(255, 255, 255, 0.04), 0 2px 8px rgba(0, 0, 0, 0.30);
    --shadow-glow: 0 0 40px rgba(139, 156, 197, 0.08);
}

/* --- 31b. Navigation Dark Overrides --- */
[data-theme="dark"] .top-nav {
    background: rgba(15, 17, 23, 0.92);
}

[data-theme="dark"] .nav-mobile-menu {
    background: rgba(15, 17, 23, 0.98);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.30);
}

/* --- 31c. Stat Cards & Frosted Glass Dark --- */
[data-theme="dark"] .stat-card {
    background: rgba(26, 29, 39, 0.80);
}

[data-theme="dark"] .stat-card::before {
    background: linear-gradient(90deg, transparent, rgba(139, 156, 197, 0.25), transparent);
}

[data-theme="dark"] .stat-card:hover {
    border-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .stat-card-icon {
    background: rgba(255, 255, 255, 0.06);
}

/* --- 31d. Search Input Dark --- */
[data-theme="dark"] #search-input:focus {
    box-shadow: 0 0 0 3px var(--accent-glow), 0 0 20px rgba(139, 156, 197, 0.06);
}

/* --- 31e. Table Dark Overrides --- */
[data-theme="dark"] .files-table thead th,
[data-theme="dark"] .table thead th {
    background: rgba(255, 255, 255, 0.04);
}

[data-theme="dark"] .table-light {
    background: rgba(255, 255, 255, 0.04);
}

/* --- 31f. File Type Icon Backgrounds (hardcoded light tints) --- */
[data-theme="dark"] .file-icon.pdf {
    background: linear-gradient(135deg, rgba(220, 38, 38, 0.15), rgba(220, 38, 38, 0.25));
}

[data-theme="dark"] .file-icon.image {
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.15), rgba(37, 99, 235, 0.25));
}

[data-theme="dark"] .file-icon.csv {
    background: linear-gradient(135deg, rgba(22, 163, 74, 0.15), rgba(22, 163, 74, 0.25));
}

[data-theme="dark"] .file-icon.audio {
    background: linear-gradient(135deg, rgba(124, 58, 237, 0.15), rgba(124, 58, 237, 0.25));
}

[data-theme="dark"] .file-icon.video {
    background: linear-gradient(135deg, rgba(234, 88, 12, 0.15), rgba(234, 88, 12, 0.25));
}

[data-theme="dark"] .file-icon.code {
    background: linear-gradient(135deg, rgba(202, 138, 4, 0.15), rgba(202, 138, 4, 0.25));
}

[data-theme="dark"] .file-icon.default {
    background: linear-gradient(135deg, var(--bg-elevated), rgba(255, 255, 255, 0.06));
}

/* --- 31g. User Icon Dark --- */
[data-theme="dark"] .user-icon.active {
    background: linear-gradient(135deg, rgba(125, 189, 149, 0.15), rgba(125, 189, 149, 0.25));
}

[data-theme="dark"] .user-icon.inactive {
    background: linear-gradient(135deg, var(--bg-elevated), rgba(255, 255, 255, 0.06));
}

/* --- 31h. File Action Button Hover Dark --- */
[data-theme="dark"] .file-action-btn.btn-extend:hover {
    background: rgba(37, 99, 235, 0.15);
    border-color: rgba(37, 99, 235, 0.35);
}

[data-theme="dark"] .file-action-btn.btn-delete:hover {
    background: rgba(220, 38, 38, 0.15);
    border-color: rgba(220, 38, 38, 0.35);
}

/* --- 31i. Card Header / Footer Dark --- */
[data-theme="dark"] .card-header {
    background: rgba(255, 255, 255, 0.04);
}

[data-theme="dark"] .card-footer {
    background: rgba(255, 255, 255, 0.03);
}

/* --- 31j. Main Card Header Dark --- */
[data-theme="dark"] .main-card-header {
    background: rgba(255, 255, 255, 0.04);
}

/* --- 31k. Modal Dark --- */
[data-theme="dark"] .modal-backdrop {
    background: rgba(0, 0, 0, 0.60);
}

[data-theme="dark"] .modal-content {
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.40);
}

/* --- 31l. Profile Sidebar & Premium Cards Dark --- */
[data-theme="dark"] .profile-sidebar {
    background: rgba(26, 29, 39, 0.80);
}

[data-theme="dark"] .premium-card {
    background: rgba(26, 29, 39, 0.80);
}

[data-theme="dark"] .premium-card:hover {
    border-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .profile-card {
    background: rgba(26, 29, 39, 0.80);
}

[data-theme="dark"] .profile-card:hover {
    border-color: rgba(255, 255, 255, 0.08);
}

[data-theme="dark"] .premium-card::before,
[data-theme="dark"] .profile-card::before {
    background: linear-gradient(90deg, transparent, rgba(139, 156, 197, 0.25), transparent);
}

/* --- 31m. Upload Drop Zone Dark --- */
[data-theme="dark"] .upload-drop-zone {
    background: rgba(26, 29, 39, 0.50);
}

/* --- 31n. Action Buttons Dark (hardcoded colors) --- */
[data-theme="dark"] .btn-action {
    color: #8b95a5;
}

[data-theme="dark"] .btn-action:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.12);
}

[data-theme="dark"] .btn-extend:hover {
    background: rgba(37, 99, 235, 0.15);
    border-color: rgba(37, 99, 235, 0.35);
}

[data-theme="dark"] .btn-delete:hover {
    background: rgba(220, 38, 38, 0.15);
    border-color: rgba(220, 38, 38, 0.35);
}

/* --- 31o. Form Select Dropdown Arrow Dark --- */
[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='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3E%3C/svg%3E");
}

/* --- 31p. Code / Pre Block Dark --- */
[data-theme="dark"] .upload-result-json {
    background: var(--bg-elevated);
    border-color: rgba(255, 255, 255, 0.06);
}

/* --- 31q. Site Footer Dark --- */
[data-theme="dark"] .site-footer {
    background: var(--bg-surface);
}

/* --- 31r. Login Branding Panel (dark-mode gradient adjustment) --- */
[data-theme="dark"] .login-branding-panel {
    background: linear-gradient(135deg, #1a2030 0%, #222838 50%, #2a3040 100%);
}

/* --- 31s. Expiry Warning Dark --- */
[data-theme="dark"] .expiry-date.warning {
    color: #f59e0b;
}

/* --- 31t. API Input Dark --- */
[data-theme="dark"] .api-input {
    background: var(--bg-elevated);
}

/* --- 31u. Setting Icon Dark --- */
[data-theme="dark"] .setting-icon {
    background: rgba(255, 255, 255, 0.06);
}

/* --- 31v. Background Utility Dark --- */
[data-theme="dark"] .bg-light {
    background: rgba(255, 255, 255, 0.04) !important;
}

/* ==========================================================================
     32. Theme Toggle Switch (flex layout: sun | track | moon)
     ========================================================================== */

/* --- Button wrapper --- */
.theme-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    vertical-align: middle;
}

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

/* --- Track (pill background) --- */
.theme-toggle-track {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
    border-radius: 10px;
    background: #e8d5a3;
    border: 1px solid rgba(0, 0, 0, 0.06);
    transition: background 0.3s ease, box-shadow 0.3s ease;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* --- Thumb (sliding circle) --- */
.theme-toggle-thumb {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
    transition: transform 0.3s ease, background 0.3s ease;
}

/* --- Sun icon (visible in light mode) --- */
.theme-icon-sun {
    font-size: 12px;
    color: #a08030;
    opacity: 1;
    transition: opacity 0.3s ease, color 0.3s ease;
    pointer-events: none;
}

/* --- Moon icon (hidden in light mode) --- */
.theme-icon-moon {
    font-size: 12px;
    color: #d0d5e8;
    opacity: 0;
    transition: opacity 0.3s ease, color 0.3s ease;
    pointer-events: none;
}

/* --- Hover / Active states (light mode) --- */
.theme-toggle:hover .theme-toggle-track {
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.08), 0 0 0 3px rgba(232, 213, 163, 0.25);
}

.theme-toggle:active .theme-toggle-thumb {
    transform: scale(0.95);
}

/* --- Dark mode overrides --- */
[data-theme="dark"] .theme-toggle-track {
    background: #4a5578;
    border-color: rgba(255, 255, 255, 0.08);
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.25), 0 0 12px rgba(74, 85, 120, 0.25);
}

[data-theme="dark"] .theme-toggle-thumb {
    transform: translateX(16px);
    background: #d8dce8;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3), 0 0 8px rgba(139, 156, 197, 0.3);
}

[data-theme="dark"] .theme-icon-sun {
    opacity: 0;
}

[data-theme="dark"] .theme-icon-moon {
    opacity: 1;
    color: #d0d5e8;
}

/* --- Hover / Active states (dark mode) --- */
[data-theme="dark"] .theme-toggle:hover .theme-toggle-track {
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.25), 0 0 12px rgba(74, 85, 120, 0.25), 0 0 0 3px rgba(74, 85, 120, 0.25);
}

[data-theme="dark"] .theme-toggle:active .theme-toggle-thumb {
    transform: translateX(16px) scale(0.95);
}

/* ==========================================================================
   33. System Preference Fallback — prefers-color-scheme: dark
   Applies only when html has no data-theme attribute set.
   ========================================================================== */
@media (prefers-color-scheme: dark) {
    html:not([data-theme]) {
        --bg-body: #0f1117;
        --bg-surface: #1a1d27;
        --bg-elevated: #22252f;
        --bg-input: #1a1d27;
        --bg-hover: rgba(255, 255, 255, 0.06);
        --bg-active: rgba(255, 255, 255, 0.10);
        --text-primary: #e2e4e9;
        --text-secondary: #a0a6b4;
        --text-muted: #6b7280;
        --accent: #8b9cc5;
        --accent-hover: #9dadc8;
        --accent-glow: rgba(139, 156, 197, 0.15);
        --accent-glow-strong: rgba(139, 156, 197, 0.25);
        --border: rgba(255, 255, 255, 0.10);
        --border-subtle: rgba(255, 255, 255, 0.05);
        --border-focus: rgba(139, 156, 197, 0.50);
        --success: #7dbd95;
        --success-bg: rgba(125, 189, 149, 0.12);
        --danger: #c47d7d;
        --danger-bg: rgba(196, 125, 125, 0.12);
        --warning: #c4b67d;
        --warning-bg: rgba(196, 182, 125, 0.12);
        --info: #7d9dbd;
        --info-bg: rgba(125, 157, 189, 0.12);
        --shadow-card: 0 0 0 1px rgba(255, 255, 255, 0.04), 0 2px 8px rgba(0, 0, 0, 0.30);
        --shadow-glow: 0 0 40px rgba(139, 156, 197, 0.08);
    }

    html:not([data-theme]) .top-nav {
        background: rgba(15, 17, 23, 0.92);
    }

    html:not([data-theme]) .nav-mobile-menu {
        background: rgba(15, 17, 23, 0.98);
        box-shadow: 0 4px 16px rgba(0, 0, 0, 0.30);
    }

    html:not([data-theme]) .stat-card {
        background: rgba(26, 29, 39, 0.80);
    }

    html:not([data-theme]) .stat-card::before {
        background: linear-gradient(90deg, transparent, rgba(139, 156, 197, 0.25), transparent);
    }

    html:not([data-theme]) .stat-card:hover {
        border-color: rgba(255, 255, 255, 0.08);
    }

    html:not([data-theme]) .stat-card-icon {
        background: rgba(255, 255, 255, 0.06);
    }

    html:not([data-theme]) #search-input:focus {
        box-shadow: 0 0 0 3px var(--accent-glow), 0 0 20px rgba(139, 156, 197, 0.06);
    }

    html:not([data-theme]) .files-table thead th,
    html:not([data-theme]) .table thead th {
        background: rgba(255, 255, 255, 0.04);
    }

    html:not([data-theme]) .table-light {
        background: rgba(255, 255, 255, 0.04);
    }

    html:not([data-theme]) .file-icon.pdf {
        background: linear-gradient(135deg, rgba(220, 38, 38, 0.15), rgba(220, 38, 38, 0.25));
    }

    html:not([data-theme]) .file-icon.image {
        background: linear-gradient(135deg, rgba(37, 99, 235, 0.15), rgba(37, 99, 235, 0.25));
    }

    html:not([data-theme]) .file-icon.csv {
        background: linear-gradient(135deg, rgba(22, 163, 74, 0.15), rgba(22, 163, 74, 0.25));
    }

    html:not([data-theme]) .file-icon.audio {
        background: linear-gradient(135deg, rgba(124, 58, 237, 0.15), rgba(124, 58, 237, 0.25));
    }

    html:not([data-theme]) .file-icon.video {
        background: linear-gradient(135deg, rgba(234, 88, 12, 0.15), rgba(234, 88, 12, 0.25));
    }

    html:not([data-theme]) .file-icon.code {
        background: linear-gradient(135deg, rgba(202, 138, 4, 0.15), rgba(202, 138, 4, 0.25));
    }

    html:not([data-theme]) .file-icon.default {
        background: linear-gradient(135deg, var(--bg-elevated), rgba(255, 255, 255, 0.06));
    }

    html:not([data-theme]) .user-icon.active {
        background: linear-gradient(135deg, rgba(125, 189, 149, 0.15), rgba(125, 189, 149, 0.25));
    }

    html:not([data-theme]) .user-icon.inactive {
        background: linear-gradient(135deg, var(--bg-elevated), rgba(255, 255, 255, 0.06));
    }

    html:not([data-theme]) .file-action-btn.btn-extend:hover {
        background: rgba(37, 99, 235, 0.15);
        border-color: rgba(37, 99, 235, 0.35);
    }

    html:not([data-theme]) .file-action-btn.btn-delete:hover {
        background: rgba(220, 38, 38, 0.15);
        border-color: rgba(220, 38, 38, 0.35);
    }

    html:not([data-theme]) .card-header {
        background: rgba(255, 255, 255, 0.04);
    }

    html:not([data-theme]) .card-footer {
        background: rgba(255, 255, 255, 0.03);
    }

    html:not([data-theme]) .main-card-header {
        background: rgba(255, 255, 255, 0.04);
    }

    html:not([data-theme]) .modal-backdrop {
        background: rgba(0, 0, 0, 0.60);
    }

    html:not([data-theme]) .modal-content {
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.40);
    }

    html:not([data-theme]) .profile-sidebar {
        background: rgba(26, 29, 39, 0.80);
    }

    html:not([data-theme]) .premium-card {
        background: rgba(26, 29, 39, 0.80);
    }

    html:not([data-theme]) .premium-card:hover {
        border-color: rgba(255, 255, 255, 0.08);
    }

    html:not([data-theme]) .profile-card {
        background: rgba(26, 29, 39, 0.80);
    }

    html:not([data-theme]) .profile-card:hover {
        border-color: rgba(255, 255, 255, 0.08);
    }

    html:not([data-theme]) .premium-card::before,
    html:not([data-theme]) .profile-card::before {
        background: linear-gradient(90deg, transparent, rgba(139, 156, 197, 0.25), transparent);
    }

    html:not([data-theme]) .upload-drop-zone {
        background: rgba(26, 29, 39, 0.50);
    }

    html:not([data-theme]) .btn-action {
        color: #8b95a5;
    }

    html:not([data-theme]) .btn-action:hover {
        background: rgba(255, 255, 255, 0.08);
        border-color: rgba(255, 255, 255, 0.12);
    }

    html:not([data-theme]) .btn-extend:hover {
        background: rgba(37, 99, 235, 0.15);
        border-color: rgba(37, 99, 235, 0.35);
    }

    html:not([data-theme]) .btn-delete:hover {
        background: rgba(220, 38, 38, 0.15);
        border-color: rgba(220, 38, 38, 0.35);
    }

    html:not([data-theme]) .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='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3E%3C/svg%3E");
    }

    html:not([data-theme]) .upload-result-json {
        background: var(--bg-elevated);
        border-color: rgba(255, 255, 255, 0.06);
    }

    html:not([data-theme]) .site-footer {
        background: var(--bg-surface);
    }

    html:not([data-theme]) .login-branding-panel {
        background: linear-gradient(135deg, #1a2030 0%, #222838 50%, #2a3040 100%);
    }

    html:not([data-theme]) .expiry-date.warning {
        color: #f59e0b;
    }

    html:not([data-theme]) .api-input {
        background: var(--bg-elevated);
    }

    html:not([data-theme]) .setting-icon {
        background: rgba(255, 255, 255, 0.06);
    }

    html:not([data-theme]) .bg-light {
        background: rgba(255, 255, 255, 0.04) !important;
    }
}
