/* Global Styles */
:root {
    --primary-color: #4f46e5;
    --primary-hover: #4338ca;
    --secondary-color: #64748b;
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.4);
    --glass-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
    --text-main: #1e293b;
    --text-muted: #64748b;
}

body {
    background: radial-gradient(circle at top left, #a78bfa, transparent 40%),
                radial-gradient(circle at bottom right, #38bdf8, transparent 40%),
                #f1f5f9;
    background-attachment: fixed;
    min-height: 100vh;
    font-family: 'Poppins', sans-serif;
    color: var(--text-main);
    overflow-x: hidden; /* Global overflow fix */
    width: 100%;
    position: relative;
    box-sizing: border-box;
}

*, *::before, *::after {
    box-sizing: border-box;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    letter-spacing: -0.025em;
    color: #0f172a;
}

/* Glassmorphism Utilities */
/* Glassmorphism Utilities */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    box-shadow: var(--glass-shadow);
    border-radius: 1.5rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
}

.glass-panel:hover {
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.12);
}

.backdrop-blur-md {
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

/* Text Utilities */
.ls-wide {
    letter-spacing: 0.1em;
}

.tracking-wider {
    letter-spacing: 0.05em;
}

/* Hover Utilities */
.hover-bg-white-10:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Main Content Area */
main {
    transition: all 0.3s ease;
    display: block; /* Revert to block to prevent flex-clipping */
    width: auto; /* Allow flex-grow to handle sizing */
    min-width: 0; /* Standard fix for flex children overflow */
    /* margin: 0 auto is handled by container class logic */
}

.container-xxl-custom {
    max-width: 1600px;
    margin: 0 auto;
    width: 100%;
    /* Remove generic flex centering that breaks grids */
}

/* Sidebar Specifics */
.sidebar-glass {
    background: rgba(15, 23, 42, 0.8) !important;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    color: white;
    box-shadow: 4px 0 24px rgba(0,0,0,0.1);
}

.sidebar-link {
    color: rgba(255, 255, 255, 0.7);
    transition: all 0.2s ease;
    border-radius: 0.75rem;
    font-weight: 500;
}

.sidebar-link:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    transform: translateX(4px);
}

/* Open state for mobile sidebar */
#sidebar.show {
    transform: translateX(0) !important;
}

/* Large Screen Constraint */
@media (min-width: 1400px) {
    .container-xxl-custom {
        max-width: 1440px;
        margin-left: auto;
        margin-right: auto;
        padding-left: 2rem;
        padding-right: 2rem;
    }
}

/* Card Improvements */
.hover-translate-y-1:hover {
    transform: translateY(-5px);
}

.stat-card {
    border: none;
    border-radius: 1.5rem;
    padding: 1.5rem;
    position: relative;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(12px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 6px;
    height: 100%;
    background: currentColor;
}

.stat-card.variant-primary { color: var(--primary-color); }
.stat-card.variant-primary .icon-box { background: rgba(79, 70, 229, 0.1); color: var(--primary-color); }

.stat-card.variant-success { color: #10b981; }
.stat-card.variant-success .icon-box { background: rgba(16, 185, 129, 0.1); color: #10b981; }

.stat-card.variant-purple { color: #8b5cf6; }
.stat-card.variant-purple .icon-box { background: rgba(139, 92, 246, 0.1); color: #8b5cf6; }

.stat-card.variant-danger { color: #ef4444; }
.stat-card.variant-danger .icon-box { background: rgba(239, 68, 68, 0.1); color: #ef4444; }

.stat-card .h3 {
    font-size: 1.5rem; /* Slightly smaller on all devices for safety */
    word-break: break-word; /* Prevent long numbers clipping */
}

@media (max-width: 768px) {
    .stat-card {
        padding: 0.75rem !important; /* Aggressive reduction for max space */
    }
    .glass-panel {
        padding: 0.75rem !important; /* Compacting all panels */
    }
    .stat-card .h3 {
        font-size: 1.15rem; /* Dynamic scaling for long numbers */
    }
    .stat-card .icon-box {
        width: 40px; /* Smaller icon to save width */
        height: 40px;
        font-size: 1.25rem;
    }
}

.stat-card .icon-box {
    width: 56px;
    height: 56px;
    border-radius: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.75rem;
    transition: transform 0.3s ease;
    flex-shrink: 0; /* Prevent icon squishing */
}

.stat-card:hover .icon-box {
    transform: rotate(10deg) scale(1.1);
}

/* Table overrides for transparent look */
.table-glass {
    --bs-table-bg: transparent;
    --bs-table-hover-bg: rgba(255, 255, 255, 0.5);
    border-collapse: separate;
    border-spacing: 0 0.5rem;
}

.table-glass thead th {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid rgba(0,0,0,0.05);
    padding-bottom: 1rem;
}

.table-glass tbody tr {
    background: rgba(255, 255, 255, 0.4);
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
    transition: transform 0.2s;
    border-radius: 0.5rem;
}

.table-glass tbody tr:hover {
    transform: scale(1.01);
    background: rgba(255, 255, 255, 0.6);
}

.table-glass td {
    border: none;
    padding: 1rem 1.5rem;
    vertical-align: middle;
}

.table-glass td:first-child {
    border-top-left-radius: 0.75rem;
    border-bottom-left-radius: 0.75rem;
}

.table-glass td:last-child {
    border-top-right-radius: 0.75rem;
    border-bottom-right-radius: 0.75rem;
}

/* Responsive Table (Card View on Mobile) */
@media (max-width: 768px) {
    /* Layout Wrapper */
    .layout-wrapper {
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
        flex-direction: column;
        align-items: center; /* Center the main container */
    }

    /* Main Content Adjustments */
    main {
        width: 100%;
        max-width: 100%;
        padding-left: 15px !important; 
        padding-right: 15px !important;
        overflow-x: hidden;
    }
    
    /* Ensure all direct children of main take full width */
    main > * {
        width: 100%;
        max-width: 100%;
    }

    .container-xxl-custom {
        padding-left: 0;
        padding-right: 0;
        width: 100%;
    }

    /* Standard Bootstrap Row Behavior (Reverted forced 0 margins) */
    /* SMART RESET: Remove negative margins on mobile to strictly prevent overflow */
    .row {
        margin-left: 0 !important;
        margin-right: 0 !important;
        width: 100% !important;
    }
    
    /* Adjust column padding to look good with 0 margin row */
    .row > * {
        padding-left: 0.5rem !important;
        padding-right: 0.5rem !important;
    }
    
    .col-md-6, .col-12 {
        /* Revert forced padding */
    }

    .glass-panel {
        width: 100%;
        max-width: 100%;
    }

    /* Standardize Header Stacking on Mobile */
    .d-flex.justify-content-between.align-items-center.mb-4 {
        flex-direction: column;
        align-items: center !important;
        text-align: center;
        gap: 15px;
    }
    
    .header-actions { width: 100%; flex-direction: column; gap: 10px; align-items: center; }
    .header-actions form { width: 100%; display: flex; justify-content: center; }
    .header-actions .btn { width: 100%; }

    /* Button Groups in Cards */
    .btn-group { display: flex; gap: 5px; }
    .btn-group .btn { border-radius: 4px !important; padding: 5px 10px; }

    .responsive-table thead { display: none; }
    .responsive-table tr { 
        display: block; 
        background: rgba(255, 255, 255, 0.8); 
        margin-bottom: 1rem; 
        border: 1px solid rgba(255, 255, 255, 0.6); 
        border-radius: 1rem; 
        padding: 1.25rem; 
        backdrop-filter: blur(8px);
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05); 
    }
    .responsive-table td { 
        display: flex; 
        justify-content: space-between; 
        align-items: center;
        border: none; 
        padding: 0.75rem 0; 
        border-bottom: 1px solid rgba(0, 0, 0, 0.05); 
    }
    .responsive-table td:last-child { 
        border-bottom: none; 
        padding-bottom: 0; 
        display: flex; 
        justify-content: flex-end; 
        gap: 10px; 
    }
    .responsive-table td::before { 
        content: attr(data-label); 
        font-weight: 600; 
        color: var(--text-muted);
        font-size: 0.875rem;
        padding-right: 1rem; 
    }
}

/* Form Controls */
.form-control, .form-select {
    background-color: rgba(255, 255, 255, 0.6);
    border: 1px solid rgba(203, 213, 225, 0.6);
    backdrop-filter: blur(8px);
    border-radius: 0.75rem;
    padding: 0.6rem 1rem;
    font-size: 0.95rem;
    transition: all 0.2s ease;
}

.form-control:focus, .form-select:focus {
    background-color: rgba(255, 255, 255, 0.95);
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.1);
    border-color: var(--primary-color);
}

/* Buttons */
.btn {
    border-radius: 0.75rem;
    padding: 0.6rem 1.2rem;
    font-weight: 500;
    letter-spacing: 0.02em;
    transition: all 0.2s ease;
}

.btn-primary {
    background: linear-gradient(135deg, #4f46e5 0%, #4338ca 100%);
    border: none;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(79, 70, 229, 0.4);
}

/* Text Gradients & Badges */
.text-gradient {
    background: linear-gradient(135deg, #4f46e5, #ec4899);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.badge {
    padding: 0.5em 0.8em;
    font-weight: 600;
    letter-spacing: 0.05em;
}

/* Responsive Print/Invoice Container */
@media (max-width: 768px) {
    .print-container {
        width: 100%;
        min-height: auto;
        height: auto;
        padding: 15px;
        margin: 0 auto; /* Center alignment */
        border: none;
    }
    
    .invoice-box {
        border: 1px solid #000;
        width: 100%;
    }

    .info-grid {
        grid-template-columns: 100%;
    }
    
    .info-left {
        border-right: none;
        border-bottom: 1px solid #000;
    }
    
    .bottom-grid {
        grid-template-columns: 100%;
    }
    
    .bottom-left {
        border-right: none;
        border-bottom: 1px solid #000;
    }
    
    /* Allow scrolling inside the table if it bursts */
    .items-table {
        display: block;
        width: 100%;
        overflow-x: auto;
        white-space: nowrap;
    }
    
    .items-table th, .items-table td {
        min-width: 60px; /* Prevent squishing */
    }
}
