/**
 * Global theme contrast protection — prevents invisible text on mismatched backgrounds.
 */
:root {
    --theme-primary: #0f4c81;
    --theme-secondary: #2563eb;
    --theme-background: #ffffff;
    --theme-surface: #f8fafc;
    --theme-card: #ffffff;
    --theme-text-primary: #111827;
    --theme-text-secondary: #475569;
    --theme-border: #e2e8f0;
    --theme-sidebar-background: #0f172a;
    --theme-sidebar-text: #ffffff;
    --theme-sidebar-hover: #1e40af;
    --theme-success: #16a34a;
    --theme-warning: #ca8a04;
    --theme-danger: #dc2626;
}

.card,
.panel,
.table,
.modal-content,
.dropdown-menu,
.admin-card,
.stat-card,
.list-group-item {
    background: var(--theme-card);
    color: var(--theme-text-primary);
}

.card *,
.panel *,
.table *,
.modal-content *,
.dropdown-menu *,
.admin-card *,
.stat-card * {
    color: inherit;
}

.card .text-muted,
.panel .text-muted,
.table .text-muted,
.modal-content .text-muted,
.dropdown-menu .text-muted,
.admin-card .text-muted {
    color: var(--theme-text-secondary) !important;
}

.card-header,
.modal-header,
.modal-footer {
    background: var(--theme-card);
    color: var(--theme-text-primary);
    border-color: var(--theme-border);
}

.table thead th {
    color: var(--theme-text-secondary);
    background: var(--theme-surface);
}

.form-control,
.form-select {
    background: var(--theme-card);
    color: var(--theme-text-primary);
    border-color: var(--theme-border);
}

.form-control::placeholder {
    color: var(--theme-text-secondary);
    opacity: 0.85;
}

.form-control:focus,
.form-select:focus {
    border-color: var(--form-focus-color, var(--theme-primary));
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--form-focus-color, var(--theme-primary)) 18%, transparent);
}

.form-control.is-valid,
.form-select.is-valid {
    border-color: var(--form-success-color);
}

.form-control.is-invalid,
.form-select.is-invalid {
    border-color: var(--form-error-color);
}

.valid-feedback {
    color: var(--form-success-color);
}

.invalid-feedback {
    color: var(--form-error-color);
}

.btn-primary {
    background-color: var(--btn-primary-bg, var(--theme-primary));
    border-color: var(--btn-primary-bg, var(--theme-primary));
    color: var(--btn-primary-text, #fff);
}

.btn-outline-primary {
    color: var(--btn-outline-text, var(--theme-primary));
    border-color: var(--btn-outline-border, var(--theme-primary));
}

.btn-outline-primary:hover {
    background-color: var(--btn-outline-border, var(--theme-primary));
    color: var(--btn-primary-text, #fff);
}

.alert-success {
    background-color: color-mix(in srgb, var(--theme-success) 12%, var(--theme-card));
    color: color-mix(in srgb, var(--theme-success) 85%, #000);
    border-color: color-mix(in srgb, var(--theme-success) 35%, var(--theme-border));
}

.alert-warning {
    background-color: color-mix(in srgb, var(--theme-warning) 12%, var(--theme-card));
    color: color-mix(in srgb, var(--theme-warning) 85%, #000);
    border-color: color-mix(in srgb, var(--theme-warning) 35%, var(--theme-border));
}

.alert-danger {
    background-color: color-mix(in srgb, var(--theme-danger) 12%, var(--theme-card));
    color: color-mix(in srgb, var(--theme-danger) 85%, #000);
    border-color: color-mix(in srgb, var(--theme-danger) 35%, var(--theme-border));
}

.badge.bg-primary {
    background-color: var(--theme-primary) !important;
}

.admin-theme-dark {
    --theme-background: #0f172a;
    --theme-surface: #1e293b;
    --theme-card: #1e293b;
    --theme-text-primary: #f1f5f9;
    --theme-text-secondary: #94a3b8;
    --theme-border: #334155;
}

.admin-theme-dark .admin-topbar,
.admin-theme-dark .admin-card,
.admin-theme-dark .stat-card,
.admin-theme-dark .modal-content,
.admin-theme-dark .dropdown-menu {
    background: var(--theme-card);
    color: var(--theme-text-primary);
}

.admin-theme-dark .admin-page-header h1,
.admin-theme-dark .stat-card .stat-value {
    color: var(--theme-text-primary);
}

.admin-theme-dark .form-control,
.admin-theme-dark .form-select {
    background: var(--theme-surface);
    color: var(--theme-text-primary);
    border-color: var(--theme-border);
}

.admin-theme-dark .admin-table-wrap--sticky thead th {
    background: var(--theme-card);
}

html.is-app-loading body {
    visibility: hidden;
}

html.is-app-loading #siteHeader,
html.is-app-loading .site-header,
html.is-app-loading .site-nav {
    visibility: visible !important;
}

html.is-app-loading .cm-app-loading-overlay,
html.is-app-loading .admin-app-loading-overlay {
    visibility: visible;
    opacity: 1;
    z-index: 9998;
}

.cm-app-loading-overlay,
.admin-app-loading-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--theme-background, #fff);
    color: var(--theme-text-primary, #111827);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease;
}

.cm-app-loading-overlay__spinner,
.admin-app-loading-overlay__spinner {
    width: 2.5rem;
    height: 2.5rem;
    border: 3px solid var(--theme-border, #e2e8f0);
    border-top-color: var(--theme-primary, #0f4c81);
    border-radius: 50%;
    animation: cm-loading-spin 0.8s linear infinite;
}

@keyframes cm-loading-spin {
    to { transform: rotate(360deg); }
}
