:root {
    color-scheme: light;
    --app-bg: #f4f7f6;
    --app-surface: #ffffff;
    --app-surface-2: #f8fafc;
    --app-border: #e5eaf0;
    --app-text: #172033;
    --app-muted: #64748b;
    --app-heading: #111827;
    --app-link: #0d6efd;
    --app-input-bg: #ffffff;
    --app-input-text: #172033;
    --app-input-border: #cfd8e3;
    --app-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
}

html[data-theme="dark"] {
    color-scheme: dark;
    --app-bg: #0f141b;
    --app-surface: #171d26;
    --app-surface-2: #202837;
    --app-border: #303b4f;
    --app-text: #e5edf7;
    --app-muted: #9aa8bc;
    --app-heading: #f8fafc;
    --app-link: #7db4ff;
    --app-input-bg: #111821;
    --app-input-text: #e5edf7;
    --app-input-border: #3a465a;
    --app-shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
}

html[data-theme="dark"] body {
    background: var(--app-bg) !important;
    color: var(--app-text) !important;
}

html[data-theme="dark"] a:not(.btn):not(.dropdown-item):not(.menu-item) {
    color: var(--app-link);
}

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"] .text-dark,
html[data-theme="dark"] .fw-bold,
html[data-theme="dark"] .fw-semibold {
    color: var(--app-heading) !important;
}

html[data-theme="dark"] .text-muted,
html[data-theme="dark"] .form-text,
html[data-theme="dark"] small,
html[data-theme="dark"] .small {
    color: var(--app-muted) !important;
}

html[data-theme="dark"] .card,
html[data-theme="dark"] .panel,
html[data-theme="dark"] .report-row,
html[data-theme="dark"] .box,
html[data-theme="dark"] .page,
html[data-theme="dark"] .topbar,
html[data-theme="dark"] .top-bar,
html[data-theme="dark"] .hero,
html[data-theme="dark"] .metric,
html[data-theme="dark"] .claim,
html[data-theme="dark"] .muted-box,
html[data-theme="dark"] .status-box,
html[data-theme="dark"] .asset-preview,
html[data-theme="dark"] .icon-thumb,
html[data-theme="dark"] .scene-voice,
html[data-theme="dark"] .background-picker-dialog,
html[data-theme="dark"] .background-pick-card,
html[data-theme="dark"] .export-panel,
html[data-theme="dark"] details.agent-detail,
html[data-theme="dark"] .menu-panel,
html[data-theme="dark"] .modal-content,
html[data-theme="dark"] .dropdown-menu,
html[data-theme="dark"] .list-group-item,
html[data-theme="dark"] .accordion-item,
html[data-theme="dark"] .toast {
    background: var(--app-surface) !important;
    border-color: var(--app-border) !important;
    color: var(--app-text) !important;
    box-shadow: var(--app-shadow);
}

html[data-theme="dark"] .card-header,
html[data-theme="dark"] .panel-header,
html[data-theme="dark"] details.agent-detail summary,
html[data-theme="dark"] .modal-header,
html[data-theme="dark"] .modal-footer,
html[data-theme="dark"] .accordion-button {
    background: var(--app-surface-2) !important;
    border-color: var(--app-border) !important;
    color: var(--app-heading) !important;
}

html[data-theme="dark"] .bg-white,
html[data-theme="dark"] .bg-light,
html[data-theme="dark"] .table-light,
html[data-theme="dark"] .asset-table th,
html[data-theme="dark"] .badge-soft,
html[data-theme="dark"] .legend-pill,
html[data-theme="dark"] pre,
html[data-theme="dark"] code:not(pre code) {
    background-color: var(--app-surface-2) !important;
    color: var(--app-text) !important;
    border-color: var(--app-border) !important;
}

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(--app-border) !important;
}

html[data-theme="dark"] .form-control,
html[data-theme="dark"] .form-select,
html[data-theme="dark"] .form-check-input,
html[data-theme="dark"] textarea,
html[data-theme="dark"] input,
html[data-theme="dark"] select {
    background-color: var(--app-input-bg) !important;
    border-color: var(--app-input-border) !important;
    color: var(--app-input-text) !important;
}

html[data-theme="dark"] .form-control::placeholder,
html[data-theme="dark"] textarea::placeholder,
html[data-theme="dark"] input::placeholder {
    color: #7f8da3 !important;
}

html[data-theme="dark"] .input-group-text {
    background: var(--app-surface-2) !important;
    border-color: var(--app-input-border) !important;
    color: var(--app-muted) !important;
}

html[data-theme="dark"] .table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--app-text);
    --bs-table-border-color: var(--app-border);
    color: var(--app-text) !important;
}

html[data-theme="dark"] .table > :not(caption) > * > * {
    background-color: transparent !important;
    border-color: var(--app-border) !important;
    color: var(--app-text) !important;
}

html[data-theme="dark"] .dropdown-item,
html[data-theme="dark"] .menu-item,
html[data-theme="dark"] .menu-group > summary,
html[data-theme="dark"] .list-group-item-action,
html[data-theme="dark"] .section-link {
    color: var(--app-text) !important;
}

html[data-theme="dark"] .dropdown-item:hover,
html[data-theme="dark"] .menu-item:hover,
html[data-theme="dark"] .menu-group > summary:hover,
html[data-theme="dark"] .list-group-item-action:hover,
html[data-theme="dark"] .section-link:hover {
    background: var(--app-surface-2) !important;
    color: var(--app-link) !important;
}

html[data-theme="dark"] .metric-label,
html[data-theme="dark"] .metric-sub,
html[data-theme="dark"] .chart-legend,
html[data-theme="dark"] .chart-note {
    color: var(--app-muted) !important;
}

html[data-theme="dark"] .metric-value,
html[data-theme="dark"] .text-block,
html[data-theme="dark"] .clean-list,
html[data-theme="dark"] .agent-content {
    color: var(--app-text) !important;
}

html[data-theme="dark"] .progress {
    background: #273244 !important;
}

html[data-theme="dark"] .agent-content {
    border-color: var(--app-border) !important;
}

html[data-theme="dark"] .menu-section-label {
    color: var(--app-muted) !important;
}

html[data-theme="dark"] .menu-separator {
    background: var(--app-border) !important;
}

html[data-theme="dark"] .menu-item-danger {
    color: #ff9aa8 !important;
}

html[data-theme="dark"] .menu-item-danger:hover {
    background: #3b151b !important;
    color: #ffc1c8 !important;
}

html[data-theme="dark"] .btn-light,
html[data-theme="dark"] .btn-outline-secondary,
html[data-theme="dark"] .btn-outline-dark {
    background: var(--app-surface-2) !important;
    border-color: var(--app-border) !important;
    color: var(--app-text) !important;
}

html[data-theme="dark"] .btn-light:hover,
html[data-theme="dark"] .btn-outline-secondary:hover,
html[data-theme="dark"] .btn-outline-dark:hover {
    background: #2a3546 !important;
    color: var(--app-heading) !important;
}

html[data-theme="dark"] .alert {
    border-color: var(--app-border) !important;
}

html[data-theme="dark"] .alert-info {
    background: #10263a !important;
    color: #b9dcff !important;
}

html[data-theme="dark"] .alert-success {
    background: #103223 !important;
    color: #bff3d4 !important;
}

html[data-theme="dark"] .alert-warning {
    background: #392b0d !important;
    color: #ffe0a3 !important;
}

html[data-theme="dark"] .alert-danger {
    background: #3b151b !important;
    color: #ffc1c8 !important;
}

.theme-toggle {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 1080;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 9px 12px;
    border: 1px solid var(--app-border);
    border-radius: 999px;
    background: var(--app-surface);
    color: var(--app-text);
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.18);
    font: 600 13px/1.1 "Segoe UI", Arial, sans-serif;
}

.theme-toggle:hover {
    background: var(--app-surface-2);
}

.theme-toggle:focus-visible {
    outline: 3px solid rgba(13, 110, 253, 0.35);
    outline-offset: 2px;
}

.theme-toggle-icon {
    font-size: 15px;
    line-height: 1;
}

@media (max-width: 575.98px) {
    .theme-toggle {
        right: 12px;
        bottom: 12px;
        padding: 9px 10px;
    }

    .theme-toggle-label {
        display: none;
    }
}
