/* ========== CSS VARIABLES (LIGHT THEME) ========== */
:root {
    --c9-primary: #0d6efd;
    --c9-secondary: #6c757d;
    --c9-success: #198754;
    --c9-danger: #dc3545;
    --c9-warning: #ffc107;
    --c9-info: #17a2b8;
    --c9-bg: #f8f9fa;
    --c9-surface: #ffffff;
    --c9-text: #212529;
    --c9-text-muted: #6c757d;
    --c9-border: #dee2e6;
    --c9-sidebar-bg: #1e293b;
    --c9-sidebar-text: #e2e8f0;
    --c9-sidebar-hover: #334155;
    --c9-sidebar-active: #0d6efd;
    --c9-header-bg: #1e293b;
    --c9-shadow: 0 2px 8px rgba(0,0,0,0.08);
    --c9-radius: 8px;
    --c9-transition: all 0.2s ease;
}

/* ========== DARK THEME ========== */
[data-bs-theme="dark"] {
    --c9-bg: #0f172a;
    --c9-surface: #1e293b;
    --c9-text: #e2e8f0;
    --c9-text-muted: #94a3b8;
    --c9-border: #334155;
    --c9-sidebar-bg: #0f172a;
    --c9-sidebar-hover: #1e293b;
    --c9-header-bg: #0f172a;
    --c9-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

[data-bs-theme="dark"] body {
    background-color: var(--c9-bg);
    color: var(--c9-text);
}

[data-bs-theme="dark"] #content {
    background-color: var(--c9-bg);
}

[data-bs-theme="dark"] .widget-box {
    background: var(--c9-surface);
    border-color: var(--c9-border);
}

[data-bs-theme="dark"] .widget-title {
    background: var(--c9-surface);
    border-color: var(--c9-border);
}

[data-bs-theme="dark"] .widget-content {
    background: var(--c9-surface);
}

[data-bs-theme="dark"] table.dataTable thead th,
[data-bs-theme="dark"] table.display thead th {
    background: #334155 !important;
    color: #e2e8f0 !important;
}

[data-bs-theme="dark"] table.dataTable tbody tr,
[data-bs-theme="dark"] table.display tbody tr {
    background: var(--c9-surface);
    color: var(--c9-text);
}

[data-bs-theme="dark"] table.dataTable tbody tr:hover,
[data-bs-theme="dark"] table.display tbody tr:hover {
    background: #334155;
}

[data-bs-theme="dark"] .card {
    background: var(--c9-surface);
    border-color: var(--c9-border);
}

[data-bs-theme="dark"] .modal-content {
    background: var(--c9-surface);
    color: var(--c9-text);
}

[data-bs-theme="dark"] .dropdown-menu {
    background: var(--c9-surface);
    border-color: var(--c9-border);
}

[data-bs-theme="dark"] .dropdown-menu a {
    color: var(--c9-text);
}

[data-bs-theme="dark"] .nav-tabs .nav-link {
    color: var(--c9-text-muted);
}

[data-bs-theme="dark"] .nav-tabs .nav-link.active {
    background: var(--c9-surface);
    color: var(--c9-text);
    border-color: var(--c9-border);
}

[data-bs-theme="dark"] input,
[data-bs-theme="dark"] select,
[data-bs-theme="dark"] textarea {
    background-color: #334155 !important;
    color: var(--c9-text) !important;
    border-color: var(--c9-border) !important;
}

/* ========== SIDEBAR ENHANCEMENTS (horizontal nav) ========== */
#sidebar {
    transition: var(--c9-transition);
    background: var(--c9-sidebar-bg);
}

#sidebar > ul > li a {
    transition: var(--c9-transition);
    color: #fff;
    text-decoration: none;
}

#sidebar > ul > li:hover {
    background: var(--c9-sidebar-hover);
}

#sidebar > ul > li.active {
    background: var(--c9-sidebar-hover);
    border-bottom: 2px solid var(--c9-sidebar-active);
}

#sidebar > ul > li.active a,
#sidebar > ul > li a {
    color: #ffffff;
}

#sidebar > ul > li a i {
    color: #ffffff;
    margin-right: 4px;
    font-size: 14px;
}

/* ========== KPI CARDS ========== */
.kpi-card {
    background: var(--c9-surface);
    border-radius: var(--c9-radius);
    box-shadow: var(--c9-shadow);
    padding: 1.5rem;
    transition: var(--c9-transition);
    border: 1px solid var(--c9-border);
}

.kpi-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
}

.kpi-card .kpi-value {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.2;
}

.kpi-card .kpi-label {
    font-size: 0.85rem;
    color: var(--c9-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-top: 0.5rem;
}

.kpi-card .kpi-icon {
    font-size: 2.5rem;
    opacity: 0.2;
    position: absolute;
    right: 1.5rem;
    top: 1.5rem;
}

/* ========== BREADCRUMB ========== */
#breadcrumb {
    background: var(--c9-surface);
    border-radius: var(--c9-radius);
    padding: 0.75rem 1.25rem;
    box-shadow: var(--c9-shadow);
    margin-bottom: 1rem;
}

/* ========== THEME TOGGLE ========== */
.theme-toggle {
    cursor: pointer;
    padding: 8px 12px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: inherit;
    font-size: 1.1rem;
    transition: var(--c9-transition);
}

.theme-toggle:hover {
    background: rgba(255,255,255,0.1);
}

/* ========== TOAST CONTAINER ========== */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 9999;
}

/* ========== SKELETON LOADING ========== */
.skeleton {
    background: linear-gradient(90deg, var(--c9-border) 25%, transparent 50%, var(--c9-border) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 4px;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-text {
    height: 1rem;
    margin-bottom: 0.5rem;
    width: 80%;
}

.skeleton-card {
    height: 120px;
    border-radius: var(--c9-radius);
}

.skeleton-table-row {
    height: 2.5rem;
    margin-bottom: 0.25rem;
}

/* ========== LOADING SPINNER IMPROVEMENT ========== */
.loading {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.4);
    z-index: 9998;
    backdrop-filter: blur(2px);
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 48px;
    height: 48px;
    margin: -24px 0 0 -24px;
    border: 4px solid var(--c9-border);
    border-top-color: var(--c9-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ========== RESPONSIVE ENHANCEMENTS ========== */
@media (max-width: 768px) {
    .kpi-card {
        padding: 1rem;
    }
    .kpi-card .kpi-value {
        font-size: 1.5rem;
    }
    .kpi-card .kpi-icon {
        font-size: 1.5rem;
        right: 1rem;
        top: 1rem;
    }
    #content {
        margin-left: 0 !important;
        padding: 10px !important;
    }
    #sidebar {
        position: fixed;
        z-index: 1050;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        height: 100vh;
        top: 0;
    }
    #sidebar.show {
        transform: translateX(0);
    }
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0,0,0,0.5);
        z-index: 1040;
    }
    .sidebar-overlay.show {
        display: block;
    }
    .sidebar-toggle {
        display: inline-block !important;
    }
    .table-responsive {
        font-size: 0.85rem;
    }
    .widget-title h5 {
        font-size: 1rem;
    }
    #breadcrumb {
        font-size: 0.85rem;
        padding: 0.5rem 0.75rem;
    }
}

@media (min-width: 769px) {
    .sidebar-toggle {
        display: none !important;
    }
    .sidebar-overlay {
        display: none !important;
    }
}

/* ========== ACCESSIBILITY ========== */
/* Focus indicators */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.nav-link:focus-visible {
    outline: 3px solid var(--c9-primary);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(13, 110, 253, 0.25);
}

/* Skip to content link */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--c9-primary);
    color: white;
    padding: 8px 16px;
    z-index: 10000;
    transition: top 0.2s;
    text-decoration: none;
    font-weight: 600;
}

.skip-link:focus {
    top: 0;
}

/* High contrast for screen readers */
.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;
}

/* Improved button tap targets for mobile */
@media (max-width: 768px) {
    .btn {
        min-height: 44px;
        min-width: 44px;
    }
    .nav-link {
        min-height: 44px;
        display: flex;
        align-items: center;
    }
}

/* Reduced motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    .skeleton {
        animation: none;
        background: var(--c9-border);
    }
    .kpi-card:hover {
        transform: none;
    }
    * {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }
}

/* ========== BULK ACTIONS ========== */
.bulk-action-bar {
    animation: slideDown 0.2s ease;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

.bulk-select-row,
.bulk-select-all {
    width: 18px;
    height: 18px;
    cursor: pointer;
    accent-color: var(--c9-primary);
}

table .bulk-select-row:checked {
    background-color: var(--c9-primary);
}

tr:has(.bulk-select-row:checked) {
    background-color: rgba(13, 110, 253, 0.08) !important;
}
