/* =========================================================================
   GLOBAL TYPOGRAPHY ENFORCEMENT
   ========================================================================= */
:root {
    --font-num: 'Times New Roman', 'Arial', 'Arial Narrow', 'Inter', 'Poppins', 'Noto Sans Thai Looped', sans-serif;
    --font-body: 'Inter', 'Arial', 'Noto Sans Thai Looped', 'Arial Narrow', 'Times New Roman', 'Poppins', sans-serif;
    --font-lao: 'Phetsarath_OT', 'Phetsarath OT', 'Saysettha OT', 'Saysettha', 'Noto Sans Lao Looped', sans-serif;
}

/* Force specific font for Numbers */
body,
html {
    font-family: var(--font-body), var(--font-lao);
}

/* Specific elements that are primarily numbers */
input[type="number"],
.item-price,
.item-amount,
.item-qty,
#totalAmount,
#totalQty,
.num-font,
td[align="right"],
th[align="right"],
.text-right {
    font-family: var(--font-num) !important;
}

/* Overrides for Lao text specifically if needed (handled by cascade mostly) */
/* The user asked for English+Thai to use one stack, and Lao another. 
   Since we can't detect language easily in CSS, we stack them. 
   The Body stack above handles this: Inter handles Eng, falls back to Noto Sans Thai, then Phetsarath/Lao (via Cascade or Font Fallback).
*/

/* =========================================
   1. Select2 Override...
   ========================================= */
.select2-container--default .select2-selection--single {
    height: 44px !important;
    border: 1px solid #e2e8f0 !important;
    /* var(--border) */
    border-radius: 0.5rem !important;
    /* var(--radius-md) */
    display: flex !important;
    align-items: center !important;
    background-color: #fff !important;
    transition: all 0.2s ease-in-out;
}

.select2-container--default .select2-selection--single:hover {
    border-color: #cbd5e1 !important;
}

.select2-container--default.select2-container--open .select2-selection--single {
    border-color: #4F46E5 !important;
    /* var(--primary) */
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1) !important;
}

.select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 44px !important;
    padding-left: 1rem !important;
    color: #1e293b !important;
    /* var(--text-main) */
    font-family: 'Inter', 'Noto Sans Lao Looped', sans-serif !important;
    font-size: 0.95rem;
}

.select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 42px !important;
    right: 8px !important;
}

/* Dropdown Panel */
.select2-dropdown {
    border: 1px solid #e2e8f0 !important;
    border-radius: 0.5rem !important;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05) !important;
    padding: 0.5rem 0 !important;
    z-index: 9999 !important;
}

/* Search Box */
.select2-search--dropdown {
    padding: 0.5rem 1rem !important;
}

.select2-search__field {
    border: 1px solid #e2e8f0 !important;
    border-radius: 0.375rem !important;
    padding: 0.5rem !important;
    font-family: 'Inter', 'Noto Sans Lao Looped', sans-serif !important;
    outline: none !important;
}

.select2-search__field:focus {
    border-color: #4F46E5 !important;
    box-shadow: 0 0 0 1px #4F46E5 !important;
}

/* Results List */
.select2-results__option {
    padding: 0.5rem 1rem !important;
    font-family: 'Inter', 'Noto Sans Lao Looped', sans-serif !important;
    font-size: 0.9rem !important;
    color: #475569 !important;
}

.select2-results__option--highlighted[aria-selected] {
    background-color: #EEF2FF !important;
    /* var(--primary-light) */
    color: #4F46E5 !important;
    /* var(--primary) */
    font-weight: 500;
}

.select2-results__option[aria-selected="true"] {
    background-color: #E0E7FF !important;
    color: #4338CA !important;
}

/* Placeholder */
.select2-container--default .select2-selection--single .select2-selection__placeholder {
    color: #94a3b8 !important;
    /* var(--text-muted) */
}

/* =========================================
   2. Global Layout & Components
   ========================================= */

/* Branch Switcher Styles */
.branch-switch-select {
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #EEF2FF;
    color: var(--primary);
    font-weight: 600;
    font-size: 0.8rem;
    cursor: pointer;
    min-width: 120px;
    font-family: 'Inter', 'Noto Sans Lao Looped', 'Phetsarath', sans-serif !important;
}

.branch-switch-select option {
    font-family: 'Inter', 'Noto Sans Lao Looped', 'Phetsarath', sans-serif !important;
}

/* Button Fonts */
.btn-primary,
.btn {
    font-family: 'Inter', 'Noto Sans Lao Looped', 'Phetsarath', sans-serif !important;
}

/* =========================================
   3. Navigation (Sidebar)
   ========================================= */
.nav-group {
    margin: 0.25rem 0;
}

.nav-group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 8px;
    margin: 0 0.5rem;
    transition: all 0.2s ease;
}

.nav-group-header:hover {
    background: rgba(79, 70, 229, 0.08);
    /* var(--primary-light) with opacity */
    color: var(--primary);
}

.nav-group-header span {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-group-header span i {
    font-size: 0.9rem;
    width: 20px;
}

.nav-group-header .nav-arrow {
    font-size: 0.65rem;
    transition: transform 0.3s ease;
}

.nav-group.open .nav-group-header .nav-arrow {
    transform: rotate(180deg);
}

.nav-group.open .nav-group-header {
    color: var(--primary);
}

.nav-group-items {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    padding-left: 0.5rem;
}

.nav-group.open .nav-group-items {
    max-height: 500px;
}

.nav-group-items .nav-item {
    padding-left: 1.5rem;
    font-size: 0.85rem;
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
}

/* Sidebar Scrollbar */
.nav-links::-webkit-scrollbar {
    width: 4px;
}

.nav-links::-webkit-scrollbar-track {
    background: transparent;
}

.nav-links::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.nav-links::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* =========================================
   4. Dashboard Elements
   ========================================= */

/* Hero Header Section */
.hero-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    padding: 1.5rem 2rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #6B8DD6 100%);
    border-radius: 20px;
    box-shadow: 0 15px 35px rgba(102, 126, 234, 0.35);
    color: #fff;
}

.hero-title {
    font-size: 1.875rem;
    font-weight: 700;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    margin-bottom: 0.25rem;
}

.hero-subtitle {
    color: rgba(255, 255, 255, 0.85);
    margin: 0;
}

.hero-date-badge {
    font-size: 1rem;
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.3);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

/* Expense Cards Grid */
.expense-cards-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

/* Stats/Monthly Grid */
.monthly-stats-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

/* Common Card Styles & Hovers */
.card-hover {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
}

.card-hover:hover {
    transform: translateY(-6px) scale(1.02);
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.15) !important;
}

/* Text Colors */
.text-blue {
    color: #2563eb;
}

.text-green {
    color: #16a34a;
}

.text-orange {
    color: #ea580c;
}

.text-purple {
    color: #9333ea;
}

/* Responsive Table Wrapper */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* =========================================
   5. Responsive Media Queries
   ========================================= */

/* Large Desktop and up */
@media (min-width: 1024px) {
    .brand-mobile-only {
        display: none !important;
    }

    .branch-switcher-mobile {
        display: none !important;
    }

    .hamburger-btn {
        display: none;
    }
}

/* Hide PC branch switcher on mobile */
@media (max-width: 1023px) {
    .pc-only-branch {
        display: none !important;
    }
}

/* Tablet & Mobile (Max 1200px) - Adjust Monthly Grid */
@media (max-width: 1200px) {
    .monthly-stats-grid {
        display: grid !important;
        /* Keep grid but change columns */
        grid-template-columns: repeat(3, 1fr) !important;
        /* 3 columns on tablet */
    }

    .top-nav-links {
        display: none !important;
        /* Hide top nav links on smaller screens */
    }
}

/* Tablet (Max 1024px) */
@media (max-width: 1024px) {
    .expense-cards-grid {
        grid-template-columns: repeat(3, 1fr);
        /* Keep 3 for tablet landscape */
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Mobile (Max 768px) */
@media (max-width: 768px) {

    /* Layout */
    .top-menu {
        padding: 0.5rem 1rem;
    }

    .main-content {
        padding: 1rem;
    }

    /* Navigation */
    .sidebar {
        transform: translateX(-100%);
        z-index: 1000;
    }

    .sidebar.active {
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: none;
    }

    .sidebar-overlay.active {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 900;
    }

    /* Headers */
    .hero-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
        padding: 1.25rem;
    }

    .hero-header>div {
        width: 100%;
    }

    .hero-header div:last-child {
        text-align: left !important;
    }

    .hero-title {
        font-size: 1.5rem;
    }

    /* Branch Switcher Mobile */
    .branch-switcher-mobile {
        display: flex !important;
        align-items: center;
    }

    /* Grids to Single Column */
    .expense-cards-grid {
        grid-template-columns: 1fr;
    }

    .monthly-stats-grid {
        grid-template-columns: 1fr !important;
        gap: 0.75rem !important;
    }

    .stats-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    /* Cards in List Vew (Monthly stats) */
    .monthly-stats-grid .monthly-card {
        width: 100% !important;
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 1rem !important;
    }

    .monthly-card .stat-label {
        margin-bottom: 0 !important;
        font-size: 0.9rem !important;
    }

    .monthly-card .stat-value {
        font-size: 1.1rem !important;
        text-align: right;
    }

    .monthly-card .stat-trend {
        display: none;
        /* Hide extra details on mobile list view to save space, or style differently */
    }

    /* Tables */
    .table-responsive {
        border: 0;
    }

    /* User Profile */
    .user-menu .dropdown-menu {
        position: fixed;
        top: 60px;
        right: 10px;
        width: calc(100% - 20px);
        max-width: 300px;
    }
}

/* =========================================
   6. Responsive Form Helpers
   ========================================= */

.responsive-filter-form {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-end;
}

.responsive-filter-form .form-group {
    flex: 1;
    min-width: 200px;
}

@media (max-width: 768px) {
    .responsive-filter-form {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    /* Hide labels on mobile as requested */
    .responsive-filter-form .form-group label {
        display: none;
    }

    .responsive-filter-form .form-group {
        width: 100%;
        min-width: 100%;
    }

    /* Action buttons container */
    .filter-actions {
        display: flex;
        gap: 0.75rem;
        width: 100%;
        margin-top: 0.5rem;
    }

    .filter-actions .btn {
        flex: 1;
        justify-content: center;
        width: auto !important;
        /* Override the previous width: 100% rule if it exists */
    }
}

/* =========================================
   3. Form Layout Stability (Locking)
   ========================================= */

/* The Container ensures scrollability if table is wider than screen, 
   but 'table-layout: fixed' treats width strictly. */
.table-container {
    overflow-x: auto;
    width: 100%;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #fff;
}

.smart-table {
    width: 100%;
    table-layout: fixed;
    /* CRITICAL: Locks column widths */
    border-collapse: separate;
    border-spacing: 0;
}

.smart-table th {
    background: #f8fafc;
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 0.5rem;
    font-weight: 600;
    color: #64748b;
    font-size: 0.85rem;
    border-bottom: 1px solid #e2e8f0;
    white-space: nowrap;
    /* Prevent Wrapping */
    overflow: hidden;
    text-overflow: ellipsis;
}

.smart-table td {
    padding: 0;
    /* Remove padding for cell-like inputs */
    border-bottom: 1px solid #e2e8f0;
    height: 40px;
    /* Force Fixed Height */
    vertical-align: middle;
    background: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Ensure inputs fill the cell perfectly and don't push dimensions */
.smart-table input.form-input {
    width: 100%;
    height: 100%;
    border: none !important;
    /* No border by default */
    border-radius: 0;
    background: transparent;
    padding: 0 0.5rem;
    margin: 0;
    box-shadow: none !important;
    font-size: 0.95rem;
}

.smart-table input.form-input:focus {
    background: #fff;
    box-shadow: inset 0 0 0 2px #4F46E5 !important;
    /* Inner focus ring */
    z-index: 5;
    position: relative;
}

/* Select2 inside table */
.smart-table .select2-container--default .select2-selection--single {
    border: none !important;
    background: transparent !important;
    height: 38px !important;
    border-radius: 0 !important;
}

.smart-table .select2-container--default .select2-selection--single .select2-selection__rendered {
    line-height: 38px !important;
    padding-left: 0.5rem !important;
}

/* =========================================
   4. Sidebar Font Override
   ========================================= */
/* Apply font to common text containers, not * wildcard which overrides icons */
.sidebar,
.sidebar a,
.sidebar span,
.sidebar div {
    font-family: "Inter", 'Times New Roman', 'Arial', 'Arial Narrow', "Roboto", "Poppins", "Noto Sans Thai Looped", "Noto Sans Lao Looped", 'Phetsarath', 'Phetsarath_OT', 'Phetsarath OT', 'Saysettha OT', 'Saysettha', sans-serif !important;
}

/* Explicitly protect Font Awesome icons */
.sidebar i,
.sidebar .fa,
.sidebar .fas,
.sidebar .far,
.sidebar .fab,
.sidebar .fa-solid,
.sidebar .fa-regular {
    font-family: "Font Awesome 6 Free", "Font Awesome 6 Brands", "FontAwesome" !important;
    font-weight: 900;
    /* fa-solid needs 900 */
}

/* =========================================
   5. Top Menu Dropdowns (PC Only)
   ========================================= */
/* Laptop / Small Desktop Optimization (850px - 1440px) */
@media (min-width: 850px) and (max-width: 1440px) {
    .top-menu-nav {
        gap: 0.1rem !important;
    }

    /* Balance the Brand Logo with the Menu */
    .brand-mobile-only {
        font-size: 1.1rem !important;
        /* Reduced from 1.5rem */
    }

    .top-menu-btn {
        font-size: 0.82rem !important;
        /* Slightly increased for readability */
        padding: 0.35rem 0.35rem !important;
        white-space: nowrap;
    }

    .top-menu-btn i:first-child {
        font-size: 0.75rem !important;
    }

    .top-menu-btn i.fa-caret-down {
        font-size: 0.6rem !important;
    }

    /* Hide decorative arrows in text if getting too tight */
    .top-menu-dropdown-content {
        min-width: 240px;
    }
}

.top-menu-nav {
    display: none;
    /* Hidden by default (mobile) */
    align-items: center;
    gap: 0.25rem;
    flex: 1;
    justify-content: center;
}

/* Show on PC/Tablet Landscape (min-width: 850px) */
@media (min-width: 850px) {
    .top-menu-nav {
        display: flex;
    }

    /* Hide hamburger when top menu is visible */
    .hamburger-btn {
        display: none !important;
    }
}

.top-menu-dropdown {
    position: relative;
}

.top-menu-btn {
    background: transparent;
    border: none;
    padding: 0.5rem 0.75rem;
    font-size: 1.0rem;
    font-weight: 500;
    color: #475569;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    border-radius: 6px;
    transition: all 0.2s ease;
    font-family: "Inter", 'Times New Roman', 'Arial', 'Arial Narrow', "Roboto", "Poppins", "Noto Sans Thai Looped", "Noto Sans Lao Looped", 'Phetsarath', 'Phetsarath_OT', 'Phetsarath OT', 'Saysettha OT', 'Saysettha', sans-serif !important;
}

.top-menu-btn:hover {
    background: #EEF2FF;
    color: #4F46E5;
}

.top-menu-btn i:first-child {
    font-size: 0.9rem;
}

.top-menu-btn i.fa-caret-down {
    font-size: 0.7rem;
    opacity: 0.6;
}

.top-menu-dropdown-content {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 280px;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1), 0 4px 10px rgba(0, 0, 0, 0.05);
    z-index: 1000;
    padding: 0.5rem 0;
    animation: dropdownFadeIn 0.15s ease-out;
}

@keyframes dropdownFadeIn {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.top-menu-dropdown:hover .top-menu-dropdown-content {
    display: block;
}

.top-menu-dropdown-content a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 1rem;
    font-size: 1.0rem;
    color: #475569;
    text-decoration: none;
    transition: all 0.15s ease;
    font-family: "Inter", 'Times New Roman', 'Arial', 'Arial Narrow', "Roboto", "Poppins", "Noto Sans Thai Looped", "Noto Sans Lao Looped", 'Phetsarath', 'Phetsarath_OT', 'Phetsarath OT', 'Saysettha OT', 'Saysettha', sans-serif !important;
}

.top-menu-dropdown-content a:hover {
    background: #EEF2FF;
    color: #4F46E5;
}

.top-menu-dropdown-content a i {
    width: 16px;
    text-align: center;
    color: #94a3b8;
}

.top-menu-dropdown-content a:hover i {
    color: #4F46E5;
}

.top-menu-divider {
    height: 1px;
    background: #e2e8f0;
    margin: 0.35rem 0;
}

/* Right side container */
.top-nav-right {
    margin-left: auto;
}