:root {
    /* Base Colors - Premium Dark Mode */
    --bg-primary: #0F172A;
    /* Deep slate */
    --bg-secondary: #1E293B;
    /* Lighter slate */
    --bg-tertiary: #334155;

    /* Accents */
    --accent-primary: #8B5CF6;
    /* Purple */
    --accent-secondary: #6366F1;
    /* Indigo */
    --accent-gradient: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));

    /* Semantic Colors - SaaS Refinement */
    --success: #10B981;
    --success-soft: rgba(16, 185, 129, 0.1);
    --danger: #F43F5E;
    /* Softer, more modern red */
    --danger-soft: rgba(244, 63, 94, 0.1);
    --warning: #F59E0B;
    --warning-soft: rgba(245, 158, 11, 0.1);
    --info: #0EA5E9;
    /* Softer blue */
    --info-soft: rgba(14, 165, 233, 0.1);

    /* Text Colors */
    --text-primary: #F8FAFC;
    --text-secondary: #94A3B8;
    --text-muted: #64748B;

    /* UI Elements */
    --border-color: rgba(255, 255, 255, 0.08);
    --border-light: rgba(255, 255, 255, 0.15);
    --glass-bg: rgba(30, 41, 59, 0.7);
    --glass-border: 1px solid rgba(255, 255, 255, 0.05);

    /* Spacing & Sizing */
    --sidebar-width: 260px;
    --header-height: 70px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    /* Animations */
    --transition-fast: 0.2s ease;
    --transition-normal: 0.3s ease;

    /* Shadows */
    --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.15), 0 10px 10px -5px rgba(0, 0, 0, 0.1);
    --glow-primary: 0 0 15px rgba(139, 92, 246, 0.4);
    --glow-success: 0 0 15px rgba(16, 185, 129, 0.3);
    --glow-danger: 0 0 15px rgba(239, 68, 68, 0.3);

    /* Sidebar Theme Variables - Default Dark */
    --sidebar-bg: rgba(30, 41, 59, 0.4);
    --sidebar-text: var(--text-secondary);
    --sidebar-text-active: #ffffff;
    --sidebar-logo: linear-gradient(135deg, #fff, #a78bfa);
}

/* Light Mode Overrides (Optional toggle) */
[data-theme="light"] {
    --bg-primary: #F8FAFC;
    --bg-secondary: #FFFFFF;
    --bg-tertiary: #F1F5F9;
    --text-primary: #0F172A;
    --text-secondary: #334155;
    --text-muted: #64748B;
    /* Darker than before (#94A3B8) */
    --border-color: rgba(0, 0, 0, 0.08);
    --border-light: rgba(0, 0, 0, 0.15);
    --glass-bg: rgba(255, 255, 255, 0.8);
    --glass-border: 1px solid rgba(0, 0, 0, 0.05);
    --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.05);
    --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.05);

    /* Sidebar Theme Variables - Light */
    --sidebar-bg: rgba(255, 255, 255, 0.4);
    --sidebar-text: #475569;
    --sidebar-text-active: var(--accent-primary);
    --sidebar-logo: linear-gradient(135deg, var(--accent-primary), var(--accent-secondary));
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* Typography Utilities */
h1,
h2,
h3,
h4,
h5,
h6 {
    color: var(--text-primary);
    font-weight: 600;
}

/* Layout */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: var(--transition-normal);
    z-index: 100;
    box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
}

.sidebar-header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    padding: 0 24px;
    border-bottom: 1px solid var(--border-color);
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.5rem;
    font-weight: 800;
    letter-spacing: 0.5px;
    background: var(--sidebar-logo);
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 2px 4px rgba(139, 92, 246, 0.1));
}

.nav-links {
    flex: 1;
    list-style: none;
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 20px;
    border-radius: var(--radius-md);
    cursor: pointer;
    color: var(--sidebar-text);
    font-weight: 500;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
    margin-bottom: 2px;
}

.nav-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%) scaleY(0);
    height: 70%;
    width: 4px;
    background: var(--accent-primary);
    border-radius: 0 4px 4px 0;
    transition: transform 0.3s ease;
}

.nav-item:hover {
    background-color: rgba(139, 92, 246, 0.08);
    color: var(--sidebar-text-active);
    transform: translateX(4px);
}

.nav-item:hover::before {
    transform: translateY(-50%) scaleY(1);
}

.nav-item.active {
    background: linear-gradient(90deg, rgba(139, 92, 246, 0.15) 0%, rgba(139, 92, 246, 0) 100%);
    color: var(--sidebar-text-active);
    border-left: 4px solid var(--accent-primary);
}

.nav-item.active::before {
    display: none;
}

.nav-item.active i {
    color: var(--accent-primary);
    filter: drop-shadow(0 0 8px rgba(139, 92, 246, 0.8));
}

.nav-item i {
    font-size: 1.25rem;
    width: 24px;
    text-align: center;
    color: var(--text-muted);
    transition: color 0.3s ease;
}

.nav-item:hover i {
    color: var(--accent-primary);
}

.sidebar-footer {
    padding: 20px 24px;
    border-top: 1px solid var(--border-color);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
}

.details {
    display: flex;
    flex-direction: column;
}

.details .name {
    font-weight: 600;
    font-size: 0.9rem;
}

.details .role {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.btn-logout {
    margin-left: auto;
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-muted);
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.btn-logout:hover {
    background: rgba(244, 63, 94, 0.12);
    border-color: rgba(244, 63, 94, 0.3);
    color: var(--danger);
    transform: scale(1.1);
}

/* Main Content */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

/* App Background Blur (Glassmorphism bg) */
.main-content::before {
    content: '';
    position: absolute;
    top: -20%;
    right: -10%;
    width: 500px;
    height: 500px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(139, 92, 246, 0.15) 0%, rgba(0, 0, 0, 0) 70%);
    filter: blur(60px);
    z-index: -1;
    pointer-events: none;
}

.top-header {
    height: var(--header-height);
    background-color: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: var(--glass-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    z-index: 50;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.mobile-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 1.5rem;
    cursor: pointer;
}

.header-left h1 {
    font-size: 1.25rem;
    margin: 0;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.date-display {
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
}

.theme-toggle,
.notifications {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    transition: var(--transition-fast);
    position: relative;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
}

.theme-toggle:hover,
.notifications:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.1);
}

.badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: var(--danger);
    color: white;
    font-size: 0.7rem;
    font-weight: bold;
    border-radius: 10px;
    padding: 2px 6px;
    border: 2px solid var(--bg-secondary);
}

.content-wrapper {
    flex: 1;
    overflow-y: auto;
    padding: 32px;
    scroll-behavior: smooth;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Mobile Responsiveness */
@media (max-width: 1024px) {
    .content-wrapper {
        padding: 24px;
    }
}

@media (max-width: 768px) {
    :root {
        --sidebar-width: 280px;
    }

    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        bottom: 0;
        box-shadow: var(--shadow-xl);
    }

    .sidebar.open {
        left: 0;
    }

    .mobile-toggle {
        display: block;
    }

    .top-header {
        padding: 0 20px;
    }

    .content-wrapper {
        padding: 16px;
    }

    .date-display {
        display: none;
    }
}

/* Utility Components */

/* Cards */
.card {
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 32px;
    /* Increased from 24px */
    box-shadow: var(--shadow-sm);
    transition: var(--transition-normal);
}

.card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--border-light);
}

.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: var(--glass-border);
    border-radius: var(--radius-lg);
    padding: 32px;
    /* Increased from 24px */
    box-shadow: var(--shadow-md);
}

/* Common Spacing Utilities */
.mb-4 {
    margin-bottom: 32px !important;
}

.mb-lg {
    margin-bottom: 48px !important;
}

.mt-4 {
    margin-top: 32px !important;
}

.mt-lg {
    margin-top: 48px !important;
}

.p-lg {
    padding: 32px !important;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-transform: capitalize;
    letter-spacing: 0.3px;
    position: relative;
    overflow: hidden;
}

.btn::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.1);
    border-radius: inherit;
    transform: translate(-50%, -50%) scale(0);
    opacity: 0;
    transition: transform 0.4s ease, opacity 0.4s ease;
}

.btn:active::after {
    transform: translate(-50%, -50%) scale(2);
    opacity: 1;
    transition: 0s;
}

.btn-primary {
    background: var(--accent-gradient);
    color: white;
    box-shadow: 0 4px 15px rgba(139, 92, 246, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-primary:hover {
    box-shadow: 0 6px 20px rgba(139, 92, 246, 0.4);
    transform: translateY(-2px);
    filter: brightness(1.1);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-light);
    backdrop-filter: blur(4px);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.3);
    transform: translateY(-1px);
}

.btn-success {
    background: rgba(16, 185, 129, 0.1) !important;
    color: var(--success) !important;
    border: 1px solid rgba(16, 185, 129, 0.2) !important;
    box-shadow: none !important;
}

.btn-success:hover {
    background: var(--success) !important;
    color: #fff !important;
    transform: translateY(-2px);
}

.btn-danger {
    background: rgba(244, 63, 94, 0.1) !important;
    color: var(--danger) !important;
    border: 1px solid rgba(244, 63, 94, 0.2) !important;
    box-shadow: none !important;
}

.btn-danger:hover {
    background: var(--danger) !important;
    color: #fff !important;
    transform: translateY(-2px);
}

/* Forms */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.form-control {
    width: 100%;
    padding: 12px 16px;
    background-color: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 1rem;
    transition: var(--transition-fast);
}

.form-control:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px rgba(139, 92, 246, 0.2);
}

/* Tables */
.table-container {
    overflow-x: auto;
    width: 100%;
}

.table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.table th {
    padding: 20px 24px;
    color: var(--text-primary);
    opacity: 0.8;
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    border-bottom: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.05);
}

.table td {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 0.95rem;
    vertical-align: middle;
}

.table tbody tr {
    transition: var(--transition-fast);
}

.table tbody tr:hover {
    background-color: var(--bg-tertiary);
    transform: scale(1.002);
}

.table td strong {
    color: var(--text-primary);
    font-weight: 600;
}

/* Badges - Minimalist SaaS style */
.status-badge {
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.75rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.status-paid,
.status-received {
    background: var(--success-soft);
    color: var(--success);
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.status-pending {
    background: var(--warning-soft);
    color: var(--warning);
    border: 1px solid rgba(245, 158, 11, 0.2);
}

.status-overdue {
    background: var(--danger-soft);
    color: var(--danger);
    border: 1px solid rgba(244, 63, 94, 0.2);
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition-normal);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 500px;
    box-shadow: var(--shadow-lg);
    transform: translateY(20px);
    transition: var(--transition-normal);
}

.modal-overlay.active .modal-content {
    transform: translateY(0);
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-title {
    font-size: 1.25rem;
    font-weight: 600;
}

.btn-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.25rem;
    cursor: pointer;
    transition: var(--transition-fast);
}

.btn-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 24px;
}

.modal-footer {
    padding: 20px 24px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* Toasts */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.toast {
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    border: var(--glass-border);
    border-left: 4px solid var(--accent-primary);
    color: var(--text-primary);
    padding: 16px 20px;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 300px;
    transform: translateX(120%);
    transition: transform 0.3s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.toast.show {
    transform: translateX(0);
}

.toast.success {
    border-left-color: var(--success);
}

.toast.success i {
    color: var(--success);
}

.toast.error {
    border-left-color: var(--danger);
}

.toast.error i {
    color: var(--danger);
}

/* Flex Utilities */
.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.search-box {
    position: relative;
    display: flex;
    align-items: center;
}

.search-box i {
    position: absolute;
    left: 14px;
    color: var(--text-muted);
}

/* ========================================
   MOBILE BOTTOM NAV & PWA STYLES
   ======================================== */

/* Hide bottom nav on desktop */
.mobile-bottom-nav {
    display: none;
}

@media (max-width: 768px) {

    /* --- Layout --- */
    .app-container {
        flex-direction: column;
    }

    /* Hide sidebar on mobile */
    .sidebar {
        display: none !important;
    }

    /* Full width main */
    .main-content {
        width: 100%;
        padding-bottom: 80px;
        /* Space for bottom nav */
    }

    /* Top header mobile */
    .top-header {
        padding: 12px 16px;
        height: auto;
    }

    .top-header h1 {
        font-size: 1.1rem;
    }

    /* Hide period selector on very small screens */
    .period-selector select {
        font-size: 0.78rem;
        padding: 6px 8px;
    }

    /* Content wrapper */
    .content-wrapper {
        padding: 16px;
    }

    /* Cards */
    .card {
        padding: 16px !important;
    }

    /* Stats grid - single column on mobile */
    .stats-cards {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px;
    }

    .stat-card {
        padding: 16px !important;
        gap: 12px;
    }

    .stat-value {
        font-size: 1.2rem;
    }

    /* Tables - horizontal scroll */
    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Modals - full screen on mobile */
    .modal-content {
        margin: 0;
        width: 100%;
        max-width: 100%;
        min-height: 50vh;
        max-height: 90vh;
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        position: fixed;
        bottom: 0;
        left: 0;
    }

    /* Toast position - above bottom nav */
    .toast-container {
        bottom: 90px;
        right: 16px;
        left: 16px;
    }

    .toast {
        min-width: unset;
        width: 100%;
    }

    /* Login page */
    .login-card {
        padding: 28px !important;
    }

    /* Grid layouts */
    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr !important;
    }

    /* --- Mobile Bottom Navigation Bar --- */
    .mobile-bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 1000;
        background: var(--bg-secondary);
        border-top: 1px solid var(--border-color);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        padding: 8px 0;
        padding-bottom: calc(8px + env(safe-area-inset-bottom));
        justify-content: space-around;
        align-items: center;
    }

    .mob-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 4px;
        cursor: pointer;
        padding: 6px 12px;
        border-radius: var(--radius-md);
        color: var(--text-muted);
        text-decoration: none;
        transition: all var(--transition-fast);
        flex: 1;
    }

    .mob-nav-item i {
        font-size: 1.1rem;
        transition: all var(--transition-fast);
    }

    .mob-nav-item span {
        font-size: 0.65rem;
        font-weight: 500;
        letter-spacing: 0.02em;
    }

    .mob-nav-item.active {
        color: var(--accent-primary);
    }

    .mob-nav-item.active i {
        filter: drop-shadow(0 0 6px rgba(139, 92, 246, 0.6));
        transform: translateY(-2px);
    }

    .mob-nav-item:hover {
        color: var(--accent-primary);
        background: rgba(139, 92, 246, 0.08);
    }

    /* Hide mobile toggle button on mobile (we use bottom nav instead) */
    .mobile-toggle {
        display: none;
    }
}