/* Modern Theme System - JFL */
:root {
    /* Color Palette - Slate & Blue */
    --primary-50: #eff6ff;
    --primary-100: #dbeafe;
    --primary-200: #bfdbfe;
    --primary-300: #93c5fd;
    --primary-400: #60a5fa;
    --primary-500: #3b82f6;
    --primary-600: #2563eb;
    --primary-700: #1d4ed8;
    --primary-800: #1e40af;
    --primary-900: #1e3a8a;

    --slate-50: #f8fafc;
    --slate-100: #f1f5f9;
    --slate-200: #e2e8f0;
    --slate-300: #cbd5e1;
    --slate-400: #94a3b8;
    --slate-500: #64748b;
    --slate-600: #475569;
    --slate-700: #334155;
    --slate-800: #1e293b;
    --slate-900: #0f172a;

    /* Semantic Colors */
    --app-bg: var(--slate-50);
    --app-surface: #ffffff;
    --app-text: var(--slate-900);
    --app-text-muted: var(--slate-500);
    --app-border: var(--slate-200);
    
    --color-primary: var(--primary-600);
    --color-primary-hover: var(--primary-700);
    --color-success: #10b981;
    --color-warning: #f59e0b;
    --color-danger: #ef4444;
    --color-info: #0ea5e9;

    /* Layout */
    --header-height: 64px;
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 70px;
    --border-radius-sm: 0.375rem;
    --border-radius: 0.5rem;
    --border-radius-lg: 1rem;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
}

/* Dark Mode Support */
[data-theme="dark"] {
    --app-bg: #0b1120;
    --app-surface: #1e293b;
    --app-text: #f1f5f9;
    --app-text-muted: #94a3b8;
    --app-border: #334155;
    
    --slate-50: #0f172a; /* Inverted logic for some bg utilities */
}

/* Global Reset & Typography */
body {
    background-color: var(--app-bg);
    color: var(--app-text);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    -webkit-font-smoothing: antialiased;
}

a {
    color: var(--color-primary);
    text-decoration: none;
    transition: color 0.2s;
}

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

/* Layout Structure */
.app-layout {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

.app-sidebar {
    width: var(--sidebar-width) !important;
    background-color: var(--slate-900);
    color: var(--slate-300);
    display: flex;
    flex-direction: column;
    position: fixed !important;
    top: 0;
    bottom: 0;
    left: 0 !important;
    z-index: 1040;
    transition: width 0.3s ease;
    border-right: 1px solid var(--slate-800);
    overflow: hidden;
}

.app-sidebar-scroll {
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: rgba(148, 163, 184, 0.25) transparent;
}

.app-sidebar-scroll::-webkit-scrollbar {
    width: 6px;
}

.app-sidebar-scroll::-webkit-scrollbar-track {
    background: transparent;
}

.app-sidebar-scroll::-webkit-scrollbar-thumb {
    background-color: rgba(148, 163, 184, 0.25);
    border-radius: 999px;
}

.app-sidebar-scroll::-webkit-scrollbar-thumb:hover {
    background-color: rgba(148, 163, 184, 0.45);
}

.app-main {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-width: 0;
    transition: margin-left 0.3s ease;
}

.app-header {
    height: var(--header-height);
    background-color: var(--app-surface);
    border-bottom: 1px solid var(--app-border);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 1030;
    backdrop-filter: blur(8px);
    background-color: rgba(255, 255, 255, 0.9);
}

.app-content {
    padding: 2rem;
    flex: 1;
    margin-left: 0 !important;
    width: 100% !important;
}

/* Components */

/* Cards */
.card {
    background-color: var(--app-surface);
    border: 1px solid var(--app-border);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.5rem;
    transition: transform 0.2s, box-shadow 0.2s;
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-header {
    background-color: transparent;
    border-bottom: 1px solid var(--app-border);
    padding: 1.25rem 1.5rem;
    font-weight: 600;
    color: var(--app-text);
}

.card-body {
    padding: 1.5rem;
}

/* Buttons */
.btn {
    font-weight: 500;
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary {
    background-color: var(--color-primary);
    border-color: var(--color-primary);
    color: white;
}

.btn-primary:hover {
    background-color: var(--color-primary-hover);
    border-color: var(--color-primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.btn-outline-secondary {
    color: var(--slate-600);
    border-color: var(--slate-300);
    background: transparent;
}

.btn-outline-secondary:hover {
    background-color: var(--slate-50);
    color: var(--slate-800);
    border-color: var(--slate-400);
}

/* Tables */
.table-responsive {
    border-radius: var(--border-radius);
    border: 1px solid var(--app-border);
    overflow-x: auto;
    overflow-y: visible;
}

.table {
    width: 100%;
    margin-bottom: 0;
    color: var(--app-text);
}

.table th {
    background-color: var(--slate-50);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.75rem;
    letter-spacing: 0.05em;
    color: var(--slate-500);
    padding: 1rem;
    border-bottom: 1px solid var(--app-border);
}

.table td {
    padding: 1rem;
    vertical-align: middle;
    border-bottom: 1px solid var(--app-border);
    color: var(--slate-700);
}

.table tr:last-child td {
    border-bottom: none;
}

.table-hover tbody tr:hover {
    background-color: var(--slate-50);
}

/* Sidebar Navigation */
.nav-link {
    color: var(--slate-400);
    padding: 0.75rem 1rem;
    border-radius: var(--border-radius);
    margin-bottom: 0.25rem;
    display: flex;
    align-items: center;
    font-weight: 500;
}

.nav-link:hover {
    color: white;
    background-color: rgba(255, 255, 255, 0.05);
}

.nav-link.active {
    color: white;
    background-color: var(--color-primary);
    box-shadow: var(--shadow);
}

.nav-link i {
    font-size: 1.1rem;
    margin-right: 0.75rem;
    opacity: 0.8;
}

/* Utilities */
.text-muted { color: var(--app-text-muted) !important; }
.bg-surface { background-color: var(--app-surface) !important; }
.shadow-soft { box-shadow: var(--shadow-lg) !important; }

/* Mobile Responsive */
@media (max-width: 992px) {
    .app-sidebar {
        transform: translateX(-100%);
    }
    
    .app-sidebar.show {
        transform: translateX(0);
    }
    
    .app-main {
        margin-left: 0;
    }
}

/* --- UI Improvements (Added by AI) --- */

/* 1. Glassmorphism Header */
.app-header {
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--app-border);
    position: sticky;
    top: 0;
    z-index: 100;
    height: var(--header-height);
    padding: 0 1.5rem;
    display: flex;
    align-items: center;
}

[data-theme="dark"] .app-header {
    background: rgba(15, 23, 42, 0.8);
}

/* 2. Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(2px);
}

[data-theme="dark"] .loading-overlay {
    background: rgba(15, 23, 42, 0.8);
}

.loading-overlay.show {
    opacity: 1;
    pointer-events: all;
}

.spinner-jfl {
    width: 48px;
    height: 48px;
    border: 4px solid var(--primary-200);
    border-top-color: var(--primary-600);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* 3. Utility Classes to Replace Inline Styles */
.logo-container {
    width: 32px; 
    height: 32px;
    background-color: white;
    border-radius: var(--border-radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.25rem;
}

.logo-img {
    height: 24px; 
    width: auto;
}

.avatar-sm {
    width: 32px; 
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
}

/* 4. Mobile Sidebar Improvements */
@media (max-width: 991.98px) {
    .app-sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        z-index: 1050;
        box-shadow: var(--shadow-lg);
    }
    
    .app-sidebar.show {
        transform: translateX(0);
    }
    
    .sidebar-backdrop {
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        height: 100vh;
        background: rgba(0,0,0,0.5);
        z-index: 1040;
        opacity: 0;
        pointer-events: none;
        transition: opacity 0.3s;
    }
    
    .sidebar-backdrop.show {
        opacity: 1;
        pointer-events: all;
    }
}

/* Fix for layout shift */
.app-content .container-fluid {
    width: 100%;
    max-width: 100%;
    padding-left: 0;
    padding-right: 0;
    margin-left: 0;
    margin-right: 0;
}

/* Force reset of app-main-container to avoid double padding/margins */
.app-main-container {
    width: 100% !important;
    max-width: 100% !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
}

/* Ensure app-main takes correct space */
.app-main {
    margin-left: var(--sidebar-width) !important;
    width: calc(100% - var(--sidebar-width)) !important;
    flex: 1;
}

/* Mobile reset */
@media (max-width: 991.98px) {
    .app-main {
        margin-left: 0 !important;
        width: 100% !important;
    }
}

/* Handle sidebar hidden state */
body.sidebar-hidden .app-main {
    margin-left: 0 !important;
    width: 100% !important;
}

/* Handle sidebar collapsed state (if used) */
body.sidebar-collapsed .app-main {
    margin-left: var(--sidebar-collapsed-width) !important;
    width: calc(100% - var(--sidebar-collapsed-width)) !important;
}

/* Fix for double margin from site.css */
.app-content {
    margin-left: 0 !important;
    width: 100% !important;
    padding: 2rem; /* Restore padding lost if any */
}

/* Ensure container fluid inside app-content is full width */
.app-content .container-fluid {
    padding: 0;
}

/* Mobile adjustments */
@media (max-width: 767.98px) {
    .app-content {
        padding: 1rem;
    }
}
