/* ===================================
   AGRILAIT DESIGN SYSTEM - MOONLIGHT EDITION (v2.0)
   Refined Dark Mode: Clearer, Cleaner, Pixel-Perfect
   =================================== */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&display=swap');

*,
*::before,
*::after {
    box-sizing: border-box;
}

:root {
    /* --- COLOR PALETTE (Lighter Dark Mode) --- */
    /* Backgrounds: Shifted from pitch black to rich slate/navy for better clarity */
    --bg-body: #0F172A;
    /* Slate 900 - Rich dark blue-gray */
    --bg-surface: #1E293B;
    /* Slate 800 - Lighter, more visible surface */
    --bg-surface-hover: #334155;
    /* Slate 700 */

    /* Primary Accent: "Electric Emerald" */
    --primary: #34D399;
    /* Bright Mint */
    --primary-hover: #10B981;
    --primary-light: rgba(52, 211, 153, 0.2);
    --primary-text: #022C22;
    /* Dark green for text on primary buttons */

    /* Text - Increased Contrast */
    --text-main: #F8FAFC;
    /* Slate 50 - Almost white */
    --text-muted: #94A3B8;
    /* Slate 400 - Readable gray */
    --text-invert: #0F172A;

    /* Borders - Sharper Definition */
    --border-light: rgba(255, 255, 255, 0.12);
    --border-highlight: rgba(255, 255, 255, 0.2);

    /* Functional Colors - Vibrant & Clear */
    --accent-purple: #C084FC;
    --accent-blue: #60A5FA;
    --accent-orange: #FBBF24;
    --accent-red: #F87171;

    /* Color Aliases for Compatibility */
    --success: var(--primary);
    --danger: var(--accent-red);
    --warning: var(--accent-orange);
    --info: var(--accent-blue);
    --gray-600: var(--text-muted);
    --gray-700: var(--text-muted);
    --primary-dark: var(--primary);

    /* --- METRICS --- */
    --radius-md: 12px;
    --radius-lg: 16px;
    /* Slightly reduced for tighter feel */
    --radius-xl: 24px;

    /* --- SHADOWS (Refined Glows) --- */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4), 0 2px 4px -1px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    --glow-primary: 0 0 20px rgba(52, 211, 153, 0.25);

    /* --- FONTS --- */
    --font-main: 'Plus Jakarta Sans', sans-serif;
}

[data-theme="light"] {
    /* --- LIGHT THEME (Nature/Daylight) --- */
    --bg-body: #F1F5F9;
    /* Slate 100 */
    --bg-surface: #FFFFFF;
    /* Pure White */
    --bg-surface-hover: #F8FAFC;
    /* Slate 50 */

    /* Primary: Emerald Green (Restored from Deep Earth) */
    --primary: #059669;
    /* Emerald 600 */
    --primary-hover: #047857;
    /* Emerald 700 */
    --primary-light: rgba(5, 150, 105, 0.1);
    --primary-text: #FFFFFF;
    /* White text on green */

    /* Text - High Contrast */
    --text-main: #0F172A;
    /* Slate 900 */
    --text-muted: #64748B;
    /* Slate 500 */
    --text-invert: #FFFFFF;

    /* Borders */
    --border-light: #E2E8F0;
    /* Slate 200 */
    --border-highlight: #CBD5E1;
    /* Slate 300 */

    /* Functional Colors */
    --accent-purple: #9333EA;
    --accent-blue: #2563EB;
    --accent-orange: #D97706;
    --accent-red: #DC2626;

    /* Badges Backgrounds - customized for light mode visibility */
    --success-bg: #D1FAE5;
    --warning-bg: #FEF3C7;
    --danger-bg: #FEE2E2;
    --info-bg: #DBEAFE;

    /* Shadows - softer for light mode */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    --glow-primary: 0 0 15px rgba(5, 150, 105, 0.2);
}


body {
    font-family: var(--font-main);
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.6;
    margin: 0;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
    transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
    /* Prevent horizontal scroll */
}

/* --- LAYOUT STRUCTURE (Pixel Perfect) --- */
.app-container {
    display: flex;
    min-height: 100vh;
}

.main-content {
    flex: 1;
    padding: 2.5rem;
    /* More breathing room */
    padding-bottom: 100px;
    margin-left: 260px;
    /* Fixed width matching sidebar */
    width: calc(100% - 260px);
    /* Explicit width calculation */
    max-width: 1400px;
    /* Prevent stretching on huge screens */
}

/* --- SIDEBAR (Fixed & Clean) --- */
.sidebar {
    width: 260px;
    background-color: var(--bg-surface);
    border-right: 1px solid var(--border-light);
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    z-index: 50;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.2);
    /* Depth */
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0.5rem 0.5rem 2rem 0.5rem;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-light);
}

.logo-icon {
    width: 36px;
    height: 36px;
    background: var(--primary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary-text);
    font-size: 20px;
}

.logo-text {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--text-main);
    letter-spacing: -0.02em;
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius-md);
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid transparent;
    /* Prevent layout shift on hover */
}

.nav-link:hover {
    background-color: rgba(255, 255, 255, 0.03);
    color: var(--text-main);
    border-color: var(--border-light);
}

.nav-link.active {
    background-color: var(--primary-light);
    color: var(--primary);
    border-color: rgba(52, 211, 153, 0.3);
    box-shadow: 0 0 15px rgba(52, 211, 153, 0.1);
}

/* --- CARDS (Clearer & More Defined) --- */
.card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 1.75rem;
    /* Increased padding */
    box-shadow: var(--shadow-md);
    margin-bottom: 1.5rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
    position: relative;
    overflow: hidden;
    /* Keep content contained */
}

.card::before {
    /* Subtle top highlight for depth (Glass feel) */
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0), rgba(255, 255, 255, 0.1), rgba(255, 255, 255, 0));
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    border-color: var(--border-highlight);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    padding-bottom: 1rem;
    margin-left: -1.75rem;
    margin-right: -1.75rem;
    padding-left: 1.75rem;
    padding-right: 1.75rem;
}

.card-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-main);
    margin: 0;
}

/* --- STATS GRID (Bento Box Style) --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2.5rem;
}

.stat-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
    transition: all 0.2s ease;
}

.stat-card:hover {
    border-color: var(--border-highlight);
    background-color: var(--bg-surface-hover);
}

.stat-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.stat-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

/* Icon Variations - Lighter & Clearer */
.stat-icon.primary {
    background: rgba(52, 211, 153, 0.1);
    color: var(--primary);
    border: 1px solid rgba(52, 211, 153, 0.2);
}

.stat-icon.warning {
    background: rgba(251, 191, 36, 0.1);
    color: var(--accent-orange);
    border: 1px solid rgba(251, 191, 36, 0.2);
}

.stat-icon.info {
    background: rgba(96, 165, 250, 0.1);
    color: var(--accent-blue);
    border: 1px solid rgba(96, 165, 250, 0.2);
}

.stat-icon.danger {
    background: rgba(248, 113, 113, 0.1);
    color: var(--accent-red);
    border: 1px solid rgba(248, 113, 113, 0.2);
}

.stat-value {
    font-size: 2rem;
    /* Adjusted for better proportion */
    font-weight: 700;
    color: var(--text-main) !important;
    margin: 0.25rem 0 0.5rem 0;
    letter-spacing: -0.01em;
}

.stat-trend {
    font-size: 0.85rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px;
    border-radius: 6px;
    width: fit-content;
}

.stat-trend.trend-up {
    background: rgba(52, 211, 153, 0.1);
    color: var(--primary);
}

.stat-trend.trend-down {
    background: rgba(248, 113, 113, 0.1);
    color: var(--accent-red);
}

/* --- TYPOGRAPHY UTILITIES --- */
.page-header {
    margin-bottom: 2rem;
}

.page-title {
    font-size: 1.875rem;
    /* 30px */
    font-weight: 800;
    color: var(--text-main);
    margin: 0 0 0.5rem 0;
    letter-spacing: -0.02em;
}

.page-subtitle {
    color: var(--text-muted);
    font-size: 1rem;
    margin: 0;
}

/* --- BUTTONS (High Contrast) --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius-md);
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
    text-decoration: none;
    line-height: 1;
}

.btn-primary {
    background-color: var(--primary);
    color: var(--primary-text) !important;
    box-shadow: 0 4px 12px rgba(52, 211, 153, 0.3);
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(52, 211, 153, 0.4);
}

.btn-secondary {
    background-color: transparent;
    color: var(--text-main) !important;
    border: 1px solid var(--border-light);
}

.btn-secondary:hover {
    background-color: rgba(255, 255, 255, 0.05);
    border-color: var(--text-muted);
}

.btn-danger {
    background-color: rgba(239, 68, 68, 0.1);
    color: var(--accent-red) !important;
    border-color: rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
    background-color: var(--accent-red);
    color: #fff !important;
}

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    border-radius: 8px;
}

/* --- TABLES (Clearer List View) --- */
.table-container {
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-light);
}

.table {
    width: 100%;
    border-collapse: collapse;
    color: var(--text-main);
}

.table th {
    background-color: rgba(0, 0, 0, 0.2);
    text-align: left;
    padding: 1.25rem 1.5rem;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    border-bottom: 1px solid var(--border-light);
}

.table td {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-light);
    vertical-align: middle;
}

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

.table tr:hover td {
    background-color: rgba(255, 255, 255, 0.02);
}

/* --- BADGES (Vibrant) --- */
.badge {
    padding: 0.35rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.badge-success {
    background: rgba(52, 211, 153, 0.15);
    color: var(--primary);
    border: 1px solid rgba(52, 211, 153, 0.2);
}

.badge-warning {
    background: rgba(251, 191, 36, 0.15);
    color: var(--accent-orange);
    border: 1px solid rgba(251, 191, 36, 0.2);
}

.badge-danger {
    background: rgba(248, 113, 113, 0.15);
    color: var(--accent-red);
    border: 1px solid rgba(248, 113, 113, 0.2);
}

.badge-info {
    background: rgba(96, 165, 250, 0.15);
    color: var(--accent-blue);
    border: 1px solid rgba(96, 165, 250, 0.2);
}

/* --- DISCRETE DATE FILTERS --- */
.filter-date-form .form-control {
    background-color: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-light);
    color: var(--text-muted);
    font-size: 0.8rem;
    padding: 0.4rem 0.75rem;
    height: auto;
    border-radius: var(--radius-md);
    transition: all 0.2s;
    min-width: 120px;
}

[data-theme="light"] .filter-date-form .form-control {
    background-color: rgba(0, 0, 0, 0.03);
}

.filter-date-form .form-control:focus,
.filter-date-form .form-control:hover {
    background-color: var(--bg-surface);
    color: var(--text-main);
    border-color: var(--primary);
    box-shadow: none;
}

.filter-date-form .form-control::-webkit-calendar-picker-indicator {
    opacity: 0.5;
    filter: invert(1);
    cursor: pointer;
}

[data-theme="light"] .filter-date-form .form-control::-webkit-calendar-picker-indicator {
    filter: invert(0);
}

/* --- RESPONSIVE RESET --- */
/* --- RESPONSIVE RESET & OPTIMIZATIONS --- */
@media (max-width: 1024px) {
    .sidebar {
        display: none;
    }

    .main-content {
        margin-left: 0;
        width: 100%;
        padding: 1.5rem;
        padding-top: 84px;
        padding-bottom: 88px;
    }
}

/* Mobile (Phones) */
@media (max-width: 640px) {
    .main-content {
        padding: 1rem;
        padding-bottom: 120px;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
        margin-bottom: 1.5rem;
    }

    .page-header .d-flex {
        /* Bootstrap/Utility flex containers in header */
        flex-direction: column;
        align-items: stretch;
        width: 100%;
        gap: 1rem;
    }

    .page-header .btn {
        width: 100%;
        justify-content: center;
    }

    .page-title {
        font-size: 1.5rem;
        /* Smaller title */
    }

    .stats-grid,
    .card-grid {
        grid-template-columns: 1fr;
        /* Force single column */
        gap: 1rem;
    }

    .card,
    .stat-card,
    .profile-card {
        padding: 1.25rem;
        /* Tighter padding */
    }

    .stat-value {
        font-size: 1.75rem;
        /* Smaller stats */
    }

    .table th,
    .table td {
        padding: 1rem;
        /* Compact table cells */
        font-size: 0.85rem;
    }

    /* Improve form elements */
    .form-control {
        font-size: 16px;
        /* Prevent iOS zoom on focus */
    }

    /* Make search bars full width */
    .smart-search-wrapper,
    .smart-table-controls {
        width: 100%;
        margin-bottom: 1rem;
    }

    .smart-search-input {
        max-width: 100%;
    }

    /* Improve filter section on mobile */
    /* Improve filter section on mobile */
    .filter-container {
        flex-direction: column;
        align-items: center;
        /* Center everything */
    }

    .filter-label {
        width: 100%;
        margin-bottom: 0.5rem;
        text-align: center;
        display: block;
    }

    .filter-scroll-wrapper {
        display: flex;
        overflow-x: auto;
        padding-bottom: 0.5rem;
        margin-bottom: 0.75rem;
        gap: 0.5rem;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
        width: 100%;
        justify-content: center;
        /* Center if fits */
    }

    .filter-scroll-wrapper::-webkit-scrollbar {
        height: 0px;
        background: transparent;
    }

    .filter-scroll-wrapper .btn {
        flex-shrink: 0;
        white-space: nowrap;
        scroll-snap-align: start;
    }

    /* Reset Date Container Margins */
    .filter-date-container {
        margin: 0 !important;
        width: 100%;
    }

    /* Better Date Form Layout */
    .filter-date-form {
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
        width: 100%;
        margin-top: 0.5rem;
    }

    .filter-date-form .form-control {
        width: 100% !important;
        margin: 0;
    }

    .filter-date-form button {
        grid-column: 1 / -1;
        width: 100%;
    }

}

/* --- EXPENSE CATEGORY ICONS --- */
/* Mapping icons to specific styles based on content passed via style attribute */
.category-icon {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}

.category-icon.alimentation {
    background: rgba(16, 185, 129, 0.15);
    color: #10B981;
}

.category-icon.veterinaire {
    background: rgba(239, 68, 68, 0.15);
    color: #EF4444;
}

.category-icon.electricite {
    background: rgba(245, 158, 11, 0.15);
    color: #F59E0B;
}

.category-icon.eau {
    background: rgba(59, 130, 246, 0.15);
    color: #3B82F6;
}

.category-icon.maintenance {
    background: rgba(99, 102, 241, 0.15);
    color: #6366F1;
}

.category-icon.transport {
    background: rgba(236, 72, 153, 0.15);
    color: #EC4899;
}

.category-icon.default {
    background: rgba(107, 114, 128, 0.15);
    color: #6B7280;
}

/* --- MOBILE NAV (Bottom Bar - 5 Items) --- */
.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 64px;
    background-color: var(--bg-surface);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--border-light);
    z-index: 1000;
    padding: 0;
    padding-bottom: env(safe-area-inset-bottom);
    align-items: stretch;
    justify-content: space-around;
    box-shadow: 0 -2px 16px rgba(0, 0, 0, 0.15);
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 500;
    gap: 2px;
    flex: 1;
    height: 100%;
    transition: color 0.2s ease;
    position: relative;
    -webkit-tap-highlight-color: transparent;
}

.mobile-nav-item.active {
    color: var(--primary);
    font-weight: 700;
}

.mobile-nav-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 32px;
    height: 3px;
    background: var(--primary);
    border-radius: 0 0 4px 4px;
}

.mobile-nav-icon {
    font-size: 22px;
    line-height: 1;
    transition: transform 0.2s ease;
}

.mobile-nav-item.active .mobile-nav-icon {
    transform: scale(1.1);
}

.mobile-nav-item span {
    letter-spacing: 0.01em;
}

[data-theme="light"] .mobile-nav {
    background-color: rgba(255, 255, 255, 0.95);
    border-color: #E2E8F0;
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.06);
}

/* --- MOBILE DRAWER --- */
.mobile-drawer-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.3s ease, visibility 0.3s ease;
}

.mobile-drawer-overlay.open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.mobile-drawer {
    display: none;
    position: fixed;
    top: 0;
    right: 0;
    width: 300px;
    max-width: 85vw;
    height: 100vh;
    height: 100dvh;
    background-color: var(--bg-surface);
    z-index: 2001;
    flex-direction: column;
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.3);
    overflow-y: auto;
    overscroll-behavior: contain;
    transform: translateX(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    visibility: hidden;
}

.mobile-drawer.open {
    transform: translateX(0);
    visibility: visible;
}

.drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border-light);
    background: rgba(0, 0, 0, 0.1);
}

.drawer-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.drawer-avatar {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--primary), var(--accent-blue));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.drawer-username {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-main);
    line-height: 1.2;
}

.drawer-role {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 500;
}

.drawer-close {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: 1px solid var(--border-light);
    background: transparent;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    cursor: pointer;
    transition: all 0.2s;
}

.drawer-close:active {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-main);
}

.drawer-body {
    flex: 1;
    padding: 0.75rem 0;
    overflow-y: auto;
}

.drawer-section-label {
    padding: 1rem 1.5rem 0.5rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.drawer-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0.85rem 1.5rem;
    color: var(--text-muted);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.95rem;
    transition: all 0.15s ease;
    border-left: 3px solid transparent;
}

.drawer-item:active {
    background: rgba(255, 255, 255, 0.03);
}

.drawer-item.active {
    color: var(--primary);
    background: var(--primary-light);
    border-left-color: var(--primary);
    font-weight: 600;
}

.drawer-item i {
    font-size: 1.2rem;
    width: 24px;
    text-align: center;
}

.drawer-footer {
    margin-top: auto;
    padding: 0.5rem 0;
    border-top: 1px solid var(--border-light);
}

.drawer-logout {
    color: var(--accent-red) !important;
}

.drawer-logout:active {
    background: rgba(248, 113, 113, 0.1) !important;
}

/* Light theme for drawer */
[data-theme="light"] .mobile-drawer {
    background-color: #FFFFFF;
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .drawer-header {
    background: #F8FAFC;
}

[data-theme="light"] .drawer-close:active {
    background: rgba(0, 0, 0, 0.05);
}

[data-theme="light"] .drawer-item:active {
    background: rgba(0, 0, 0, 0.03);
}

/* Back to Top Button */
.btn-back-to-top {
    position: fixed;
    bottom: 84px;
    right: 20px;
    width: 44px;
    height: 44px;
    border-radius: 14px;
    background: var(--bg-surface);
    color: var(--text-main);
    border: 1px solid var(--border-light);
    box-shadow: var(--shadow-lg);
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
}

.btn-back-to-top:hover {
    background: var(--primary);
    color: white;
    transform: translateY(-4px);
}

.btn-back-to-top.visible {
    opacity: 1;
    pointer-events: all;
    transform: translateY(0);
}

/* --- SMART FORMS --- */
.form-group {
    margin-bottom: 2rem;
    position: relative;
    /* For icon positioning if needed */
}

.form-label {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    color: var(--text-muted);
    transition: all 0.2s;
}

.form-control {
    width: 100%;
    padding: 1rem 1.25rem;
    /* More spacious */
    font-size: 1rem;
    font-weight: 500;
    background-color: rgba(0, 0, 0, 0.2);
    /* Darker input bg */
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    color: var(--text-main);
    transition: 300ms cubic-bezier(0.4, 0, 0.2, 1);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    background-color: rgba(52, 211, 153, 0.05);
    /* Very subtle tint */
    box-shadow: 0 0 0 2px rgba(52, 211, 153, 0.1), 0 10px 20px -5px rgba(0, 0, 0, 0.4);
    transform: translateY(-1px);
}

.form-control::placeholder {
    color: rgba(255, 255, 255, 0.2);
}

/* --- SMART TABLE CONTROLS --- */
.smart-table-controls {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 1.5rem;
}

.smart-search-wrapper {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 1.5rem;
}

.smart-search-input {
    width: 100%;
    max-width: 300px;
    padding: 0.75rem 1rem;
    padding-left: 2.5rem;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    color: var(--text-main);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%2394A3B8'%3E%3Cpath d='M18.031 16.6168L22.3137 20.8995L20.8995 22.3137L16.6168 18.031C15.0769 19.263 13.124 20 11 20C6.032 20 2 15.968 2 11C2 6.032 6.032 2 11 2C15.968 2 20 6.032 20 11C20 13.124 19.263 15.0769 18.031 16.6168ZM16.0247 15.8748C17.2475 14.6146 18 12.8956 18 11C18 7.13401 14.866 4 11 4C7.13401 4 4 7.13401 4 11C4 14.866 7.13401 18 11 18C12.8956 18 14.6146 17.2475 15.8748 16.0247L16.0247 15.8748Z'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 0.75rem center;
    background-size: 16px;
    transition: all 0.2s;
}

.smart-search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.15);
}

/* Form Card Specifics */
.form-card {
    background: var(--bg-surface);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-light);
    padding: 3rem;
    position: relative;
    overflow: hidden;
}

.form-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 6px;
    background: linear-gradient(90deg, var(--primary), var(--accent-blue));
}

.form-actions {
    display: flex;
    gap: 1rem;
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border-light);
}

/* --- SMART SEARCH FOR CARDS (Custom Grid Support) --- */
.smart-search-wrapper {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 1.5rem;
}

.smart-search-input {
    width: 100%;
    max-width: 300px;
    padding: 0.75rem 1rem;
    padding-left: 2.5rem;
    /* Space for icon */
    background-color: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    color: var(--text-main);
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="%2394A3B8"><path d="M18.031 16.6168L22.3137 20.8995L20.8995 22.3137L16.6168 18.031C15.0769 19.263 13.124 20 11 20C6.032 20 2 15.968 2 11C2 6.032 6.032 2 11 2C15.968 2 20 6.032 20 11C20 13.124 19.263 15.0769 18.031 16.6168ZM16.0247 15.8748C17.2475 14.6146 18 12.8956 18 11C18 7.13401 14.866 4 11 4C7.13401 4 4 7.13401 4 11C4 14.866 7.13401 18 11 18C12.8956 18 14.6146 17.2475 15.8748 16.0247L16.0247 15.8748Z"></path></svg>');
    background-repeat: no-repeat;
    background-position: 0.75rem center;
    background-size: 16px;
    transition: all 0.2s;
}

.smart-search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.15);
}

/* --- PROFILE CARDS (Clients, Users) --- */
.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1.5rem;
}

.profile-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    transition: all 0.2s ease;
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
    overflow: hidden;
}

.profile-card:hover {
    transform: translateY(-2px);
    border-color: var(--border-highlight);
    box-shadow: var(--shadow-lg);
}

.profile-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.profile-avatar {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--primary), var(--accent-blue));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    font-weight: 700;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.profile-info {
    flex: 1;
    min-width: 0;
}

.profile-name {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-main);
    margin: 0 0 0.25rem 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.profile-meta {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.meta-icon {
    color: var(--primary);
    font-size: 1rem;
    width: 16px;
    display: flex;
    justify-content: center;
}

.profile-stats {
    background: rgba(0, 0, 0, 0.1);
    border-radius: var(--radius-md);
    padding: 1rem;
    margin-top: auto;
    margin-bottom: 1.25rem;
    border: 1px solid var(--border-light);
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
}

.stat-val {
    font-size: 1rem;
    color: var(--text-main);
    font-weight: 700;
}

.profile-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-top: auto;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border-light);
}

/* --- CHARTS GRID --- */
.dashboard-charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2.5rem;
}

.chart-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    position: relative;
    overflow: hidden;
}

.chart-container {
    position: relative;
    height: 300px;
    width: 100%;
}

@media (max-width: 768px) {
    .dashboard-charts-grid {
        grid-template-columns: 1fr;
    }
}

/* Hover effect for clickable cards */
a.card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--border-highlight);
    background-color: var(--bg-surface-hover);
}

/* --- MOBILE HEADER & NAV ACTIVATION --- */

.mobile-header {
    display: none;
}

@media (max-width: 1024px) {
    .mobile-header {
        display: flex !important;
        flex-direction: row !important;
        align-items: center;
        justify-content: space-between !important;
        padding: 0 1.25rem;
        background-color: var(--bg-surface);
        border-bottom: 1px solid var(--border-light);
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1500;
        height: 64px;
        width: 100%;
        box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
    }

    .mobile-logo {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        text-decoration: none;
        color: var(--text-main);
        font-weight: 800;
        font-size: 1.3rem;
        letter-spacing: -0.03em;
    }

    .mobile-logo i {
        color: var(--primary) !important;
    }

    .mobile-logo span {
        background: linear-gradient(135deg, var(--primary), var(--primary-hover));
        -webkit-background-clip: text;
        background-clip: text;
        -webkit-text-fill-color: transparent;
        color: transparent;
        display: inline-block;
    }

    .mobile-header-actions {
        display: flex;
        align-items: center;
        gap: 0.5rem;
    }

    .btn-icon {
        width: 40px;
        height: 40px;
        border-radius: 10px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: var(--text-muted);
        text-decoration: none;
        background: transparent;
        border: 1px solid var(--border-light);
        transition: all 0.2s;
        font-size: 1.2rem;
        cursor: pointer;
    }

    .btn-icon:active {
        background: var(--primary-light);
        color: var(--primary);
        border-color: var(--primary);
        transform: scale(0.95);
    }

    /* Enable drawer & overlay (hidden by default via visibility) */
    .mobile-drawer {
        display: flex;
    }

    .mobile-drawer-overlay {
        display: block;
    }

    /* Show bottom nav */
    .mobile-nav {
        display: flex !important;
    }

    /* Fix Main Content Spacing */
    .main-content {
        padding-top: 84px !important;
        padding-bottom: 88px !important;
        margin-left: 0 !important;
        width: 100% !important;
    }
}

/* Light theme mobile header */
[data-theme="light"] .mobile-header {
    background-color: #FFFFFF;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .btn-icon {
    border-color: #E2E8F0;
}

[data-theme="light"] .btn-icon:active {
    background: rgba(5, 150, 105, 0.1);
}