/* Central application theme tokens. Dark remains the default for backwards compatibility. */
:root,
:root[data-theme="dark"] {
    color-scheme: dark;
    --theme-bg: #12161d;
    --theme-bg-elevated: #1a1f28;
    --theme-surface: #202630;
    --theme-surface-raised: #29313d;
    --theme-nav: #1a1d23;
    --theme-nav-end: #2d3436;
    --theme-text-primary: #eef2f7;
    --theme-text-secondary: #aeb8c8;
    --theme-text-muted: #8893a5;
    --theme-border: #343c48;
    --theme-divider: rgba(255, 255, 255, .12);
    --theme-input-bg: #171c24;
    --theme-input-text: #eef2f7;
    --theme-input-border: #465163;
    --theme-hover: #29313d;
    --theme-active: #344154;
    --theme-focus: #6ea8fe;
    --theme-disabled: #687386;
    --theme-primary: #4d8df7;
    --theme-primary-hover: #6ea8fe;
    --theme-success: #42c78a;
    --theme-warning: #f3c969;
    --theme-danger: #ef727c;
    --theme-info: #5ec8e5;
    --theme-shadow: 0 .45rem 1.25rem rgba(0, 0, 0, .24);
    --theme-shadow-soft: 0 .2rem .7rem rgba(0, 0, 0, .16);
    --theme-modal: #202630;
    --theme-dropdown: #202630;
    --theme-tooltip: #11161e;
    --theme-on-accent: #fff;
}

:root[data-theme="light"] {
    color-scheme: light;
    --theme-bg: #f3f6fa;
    --theme-bg-elevated: #ffffff;
    --theme-surface: #ffffff;
    --theme-surface-raised: #f8fafc;
    --theme-nav: #ffffff;
    --theme-nav-end: #eef3f8;
    --theme-text-primary: #1d2939;
    --theme-text-secondary: #526174;
    --theme-text-muted: #66758a;
    --theme-border: #d6dee8;
    --theme-divider: #e4eaf1;
    --theme-input-bg: #ffffff;
    --theme-input-text: #1d2939;
    --theme-input-border: #bdc9d8;
    --theme-hover: #eef4fb;
    --theme-active: #e1ecfb;
    --theme-focus: #2877ed;
    --theme-disabled: #9aa7b7;
    --theme-primary: #2877ed;
    --theme-primary-hover: #1557bd;
    --theme-success: #16865c;
    --theme-warning: #a96800;
    --theme-danger: #c83c4a;
    --theme-info: #087f9b;
    --theme-shadow: 0 .45rem 1.25rem rgba(30, 55, 85, .12);
    --theme-shadow-soft: 0 .2rem .7rem rgba(30, 55, 85, .08);
    --theme-modal: #ffffff;
    --theme-dropdown: #ffffff;
    --theme-tooltip: #1d2939;
    --theme-on-accent: #fff;
}

html {
    background: var(--theme-bg);
    color: var(--theme-text-primary);
}

body {
    background-color: var(--theme-bg) !important;
    background-image: none;
    color: var(--theme-text-primary);
    transition: background-color .18s ease, color .18s ease;
}

body p,
body h1, body h2, body h3, body h4, body h5, body h6,
body label, body dt, body dd,
body .form-label {
    color: var(--theme-text-primary);
}

body .text-muted,
body .text-secondary,
body small,
body .form-text {
    color: var(--theme-text-secondary) !important;
}

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

#sidebar {
    background: linear-gradient(180deg, var(--theme-nav), var(--theme-nav-end)) !important;
    border-right: 1px solid var(--theme-divider) !important;
    box-shadow: var(--theme-shadow) !important;
}

.sidebar-logo,
.sidebar-nav + div { border-color: var(--theme-divider) !important; }
.sidebar-link { color: var(--theme-text-primary) !important; }
.sidebar-link:hover,
.sidebar-link:focus-visible { background: var(--theme-hover) !important; color: var(--theme-text-primary) !important; }
.sidebar-link.active,
.sidebar-link[aria-current="page"] { background: var(--theme-active) !important; }
.sidebar-logo .logo-link { background: #fff !important; }

.theme-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    margin: 0 0 1rem;
    padding: .65rem .8rem;
    border: 1px solid var(--theme-border);
    border-radius: .6rem;
    background: var(--theme-surface);
    color: var(--theme-text-primary);
    font: inherit;
    cursor: pointer;
    transition: background-color .18s ease, border-color .18s ease, color .18s ease;
}
.theme-toggle:hover { background: var(--theme-hover); border-color: var(--theme-primary); }
.theme-toggle:focus-visible { outline: 3px solid color-mix(in srgb, var(--theme-focus) 32%, transparent); outline-offset: 2px; }
.theme-toggle-label { display: flex; align-items: center; gap: .55rem; font-size: .82rem; font-weight: 650; }
.theme-toggle-icon { color: var(--theme-warning); }
.theme-toggle-state { color: var(--theme-text-secondary); font-size: .73rem; }

.card,
.modal-content,
.offcanvas,
.accordion-item,
.list-group-item,
.dropdown-menu,
.popover,
.toast {
    color: var(--theme-text-primary);
    background-color: var(--theme-surface) !important;
    border-color: var(--theme-border) !important;
    box-shadow: var(--theme-shadow-soft);
}
.card-header, .card-footer, .modal-header, .modal-footer { border-color: var(--theme-divider) !important; }
.dropdown-menu { --bs-dropdown-bg: var(--theme-dropdown); --bs-dropdown-color: var(--theme-text-primary); }
.dropdown-item { color: var(--theme-text-primary); }
.dropdown-item:hover, .dropdown-item:focus { color: var(--theme-text-primary); background: var(--theme-hover); }
.modal-backdrop { --bs-backdrop-bg: #0b1017; }
.modal-title, .popover-header, .toast-header { color: var(--theme-text-primary); }
.tooltip-inner { background: var(--theme-tooltip); color: #fff; }

body .form-control,
body .form-select,
body .form-control-plaintext,
body input:not([type="checkbox"]):not([type="radio"]),
body textarea,
body select {
    color: var(--theme-input-text);
    background-color: var(--theme-input-bg);
    border-color: var(--theme-input-border);
}
body .form-control::placeholder,
body input::placeholder,
body textarea::placeholder { color: var(--theme-text-muted); opacity: 1; }
body .form-control:focus,
body .form-select:focus,
body input:focus,
body textarea:focus,
body select:focus {
    color: var(--theme-input-text);
    background-color: var(--theme-input-bg);
    border-color: var(--theme-focus);
    box-shadow: 0 0 0 .2rem color-mix(in srgb, var(--theme-focus) 22%, transparent);
}
body .form-control:disabled,
body .form-select:disabled,
body input:disabled,
body textarea:disabled,
body select:disabled { color: var(--theme-disabled); background: var(--theme-surface-raised); }

.table {
    --bs-table-color: var(--theme-text-primary);
    --bs-table-bg: var(--theme-surface);
    --bs-table-border-color: var(--theme-border);
    --bs-table-striped-bg: var(--theme-surface-raised);
    --bs-table-striped-color: var(--theme-text-primary);
    --bs-table-hover-bg: var(--theme-hover);
    --bs-table-hover-color: var(--theme-text-primary);
    color: var(--theme-text-primary);
    border-color: var(--theme-border);
}
.table thead th { color: var(--theme-text-secondary); background: var(--theme-surface-raised); border-color: var(--theme-border); }
.table tbody td { border-color: var(--theme-border); }
.table-hover > tbody > tr:hover > * { color: var(--theme-text-primary); }

.btn-primary { --bs-btn-bg: var(--theme-primary); --bs-btn-border-color: var(--theme-primary); --bs-btn-hover-bg: var(--theme-primary-hover); --bs-btn-hover-border-color: var(--theme-primary-hover); }
.btn-success { --bs-btn-bg: var(--theme-success); --bs-btn-border-color: var(--theme-success); }
.btn-warning { --bs-btn-color: var(--theme-on-accent); --bs-btn-bg: var(--theme-warning); --bs-btn-border-color: var(--theme-warning); }
.btn-danger { --bs-btn-bg: var(--theme-danger); --bs-btn-border-color: var(--theme-danger); }
.btn-info { --bs-btn-color: var(--theme-on-accent); --bs-btn-bg: var(--theme-info); --bs-btn-border-color: var(--theme-info); }
.btn-outline-primary { --bs-btn-color: var(--theme-primary); --bs-btn-border-color: var(--theme-primary); --bs-btn-hover-bg: var(--theme-primary); --bs-btn-hover-border-color: var(--theme-primary); }
.btn:disabled, .btn.disabled { opacity: .58; }
.btn:focus-visible, .form-check-input:focus-visible { box-shadow: 0 0 0 .2rem color-mix(in srgb, var(--theme-focus) 30%, transparent); }

.alert { color: var(--theme-text-primary); border-color: var(--theme-border); }
.alert-warning { --bs-alert-color: var(--theme-warning); }
.alert-danger { --bs-alert-color: var(--theme-danger); }
.alert-success { --bs-alert-color: var(--theme-success); }
.alert-info { --bs-alert-color: var(--theme-info); }
.partner-filter-summary { color: var(--theme-text-primary) !important; }
.logo-setting-label, .logo-replace-warning-text { color: var(--theme-text-primary) !important; }
.pagination { --bs-pagination-bg: var(--theme-surface); --bs-pagination-color: var(--theme-text-primary); --bs-pagination-border-color: var(--theme-border); --bs-pagination-hover-bg: var(--theme-hover); --bs-pagination-hover-color: var(--theme-text-primary); --bs-pagination-focus-bg: var(--theme-hover); --bs-pagination-active-bg: var(--theme-primary); --bs-pagination-active-border-color: var(--theme-primary); }
.nav-tabs { --bs-nav-tabs-border-color: var(--theme-border); --bs-nav-tabs-link-hover-border-color: var(--theme-border); --bs-nav-tabs-link-active-bg: var(--theme-surface); --bs-nav-tabs-link-active-border-color: var(--theme-border); }
.nav-link { color: var(--theme-primary); }
.border, .border-top, .border-end, .border-bottom, .border-start { border-color: var(--theme-border) !important; }
hr { border-color: var(--theme-divider); opacity: 1; }
.footer { color: var(--theme-text-secondary) !important; border-color: var(--theme-border) !important; }
.footer a { color: var(--theme-primary); }

/* Compatibility for older views which still carry dark inline declarations. */
:root[data-theme="light"] body [style*="color: white"]:not(.btn):not(button),
:root[data-theme="light"] body [style*="color: #fff"]:not(.btn):not(button),
:root[data-theme="light"] body [style*="color:#fff"]:not(.btn):not(button) { color: var(--theme-text-primary) !important; }
:root[data-theme="light"] body [style*="background: rgba(255, 255, 255"] { background: var(--theme-surface-raised) !important; }
:root[data-theme="light"] body .text-white { color: var(--theme-text-primary) !important; }
:root[data-theme="light"] body .text-white-50 { color: var(--theme-text-secondary) !important; }

@media (max-width: 768px) {
    .theme-toggle { margin-bottom: .75rem; }
    .modal-dialog { margin: .75rem; }
    .table-responsive { border-color: var(--theme-border); }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}
