:root {
    /* Color Palette */
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --border-color: #e2e8f0;
    --border-color-input: #cbd5e0;
    --text-primary: #2d3748;
    --text-muted: #4a5568;
    --accent-color: #319795;
    --accent-bg: #e6fffa;
    --accent-badge-bg: #b2f5ea;
    
    /* Layout Spacing */
    --panel-padding: 1.25rem;
    --panel-padding-mobile: 0.75rem;
    --panel-margin-bottom: 1.5rem;
    --panel-gap: 1.25rem;
    --panel-gap-mobile: 0.75rem;
    
    --table-header-bg: #f8fafc;
    --table-border-color: #e2e8f0;
    --table-padding-desktop: 0.75rem 0.5rem;
    --table-padding-mobile: 0.5rem 0.4rem;
    --font-size-mobile: 0.8rem;
}

/* Base Styles for Reusable Components */
.filter-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: var(--panel-padding);
    margin-top: 1rem;
    margin-bottom: var(--panel-margin-bottom);
    display: flex;
    flex-wrap: wrap;
    gap: var(--panel-gap);
    align-items: flex-end;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.row-expander {
    margin: 0 auto;
    padding: 0.2rem 0.4rem;
    background: var(--border-color);
    border: none;
    border-radius: 4px;
    font-weight: bold;
    cursor: pointer;
    color: var(--text-muted);
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
}

.row-expander:hover {
    background: #cbd5e0;
    color: var(--text-primary);
}

.sort-badge-bar {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    padding: 0.5rem;
    border-radius: 6px;
    margin-bottom: 1rem;
}

.sort-badge-bar-inner {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.sort-badge-bar-label {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.75rem;
}

.sort-badge-bar-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
}

.nav-link {
    color: #ffffff;
    text-decoration: none;
    margin-right: 10px;
}

.nav-link:hover {
    color: #ffffff;
    text-decoration: underline;
}

.nav-link-special {
    color: #ffffff;
    font-weight: bold;
}

.dashboard-link {
    text-decoration: none;
    color: #2c3e50;
    padding: 0.75rem;
    border-radius: 6px;
    transition: all 0.2s;
    font-weight: 500;
    font-size: 1.1rem;
    border: 1px solid transparent;
}

.dashboard-link:hover {
    background: #e9ecef;
    border-color: #dee2e6;
    transform: translateX(5px);
}

.nav-link-login {
    font-weight: bold;
}

.nav-link-register {
    font-weight: bold;
    background: #3498db;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    color: white !important;
}

.nav-link-register:hover {
    background: #2980b9;
}

.auth-link {
    color: #3498db;
    text-decoration: none;
    font-weight: bold;
}

.auth-link:hover {
    text-decoration: underline;
}

.auth-link-button {
    background: #3498db;
    color: white !important;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    text-decoration: none;
    font-weight: bold;
}

.auth-link-button:hover {
    background: #2980b9;
}

.text-right {
    text-align: right;
}

/* Dropdown Navigation Menu */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-content {
    display: none;
    position: absolute;
    background-color: #2c3e50;
    min-width: 180px;
    box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.25);
    z-index: 1000;
    border-radius: 4px;
    border: 1px solid #34495e;
    overflow: hidden;
    left: 0;
}

/* Align rightmost dropdown to the right so it doesn't clip */
.dropdown-right .dropdown-content {
    left: auto;
    right: 0;
}

.dropdown-content .nav-link,
.dropdown-content a {
    color: #ecf0f1 !important;
    padding: 10px 16px;
    text-decoration: none;
    display: block;
    margin-right: 0;
    font-size: 0.95rem;
    transition: background 0.2s, color 0.2s;
    font-weight: 500;
}

.dropdown-content .nav-link:hover,
.dropdown-content a:hover {
    background-color: #34495e;
    color: #ffffff !important;
    text-decoration: none;
}

.dropdown:hover .dropdown-content {
    display: block;
}

.dropdown-trigger {
    cursor: pointer;
    font-weight: 500;
    padding: 0.5rem 0.75rem;
    color: #ecf0f1;
    display: flex;
    align-items: center;
    gap: 4px;
    transition: color 0.2s;
}

.dropdown:hover .dropdown-trigger,
.dropdown-trigger:hover {
    color: #ffffff;
}

.dropdown-trigger::after {
    content: ' ▾';
    font-size: 0.8rem;
}

/* ==========================================================================
   Table Container with Fixed Headers & Scrollbars
   ========================================================================== */
.table-container {
    max-height: calc(100vh - 420px);
    min-height: 200px;
    overflow-y: auto;
    overflow-x: auto;
    position: relative;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    box-shadow: inset 0 2px 4px 0 rgba(0, 0, 0, 0.06);
    margin-top: 1rem;
    background: #ffffff;
}

.table-container table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
}

.table-container thead th {
    position: sticky;
    top: 0;
    background-color: #f8fafc !important;
    z-index: 10;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
    padding: 0.75rem 1rem;
    font-weight: 600;
    color: #4a5568;
    border-bottom: 2px solid #cbd5e0;
}

.table-container tbody td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #edf2f7;
    color: #2d3748;
}

/* Hover and selection transitions for table rows */
.table-container tbody tr {
    transition: background-color 0.2s ease, border-left-color 0.2s ease;
}

.table-container tbody tr:hover {
    background-color: #f7fafc;
}

.table-container tbody tr.selected-row {
    background-color: #e6fffa !important;
}

/* ==========================================================================
   Responsive Sticky Menu Bar
   ========================================================================== */
.nav-menu-btn {
    display: none;
    background: none;
    border: none;
    color: #ecf0f1;
    font-size: 1.75rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    line-height: 1;
    transition: color 0.2s;
    outline: none;
}

.nav-menu-btn:hover {
    color: #ffffff;
}

.nav-links-container {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-grow: 1;
}

.user-dropdown {
    margin-left: auto;
}

@media (max-width: 768px) {
    .nav-menu-btn {
        display: block;
        margin-left: auto;
    }

    .nav-links-container {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background-color: #2c3e50;
        flex-direction: column;
        align-items: stretch;
        padding: 1rem 1.5rem;
        box-shadow: 0 8px 16px rgba(0,0,0,0.15);
        border-top: 1px solid #34495e;
        gap: 0.5rem;
        z-index: 999;
    }

    .nav-links-container.open {
        display: flex;
    }

    .user-dropdown {
        margin-left: 0;
        border-top: 1px solid #34495e;
        padding-top: 0.5rem;
    }

    .dropdown {
        width: 100%;
    }

    .dropdown-trigger {
        width: 100%;
        justify-content: space-between;
        padding: 0.75rem 0;
    }

    .dropdown-content {
        position: static;
        display: none;
        box-shadow: none;
        border: none;
        background-color: #34495e;
        width: 100%;
        padding-left: 1rem;
        border-radius: 4px;
        margin-top: 0.25rem;
    }

    .dropdown:hover .dropdown-content {
        display: block;
    }

    .dropdown-content .nav-link,
    .dropdown-content a {
        padding: 8px 16px;
    }
}

/* ==========================================================================
   Mobile-responsiveness Utility Styles (Phase 2)
   ========================================================================== */
.main-content {
    padding: 0 2rem;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(600px, 1fr));
    gap: 2rem;
    margin-bottom: 2rem;
}

/* Inline Form layout for Countries - highly specific to override global mobile form stacking */
.crud-form form.country-inline-form {
    display: flex !important;
    flex-direction: row !important;
    flex-wrap: wrap !important;
    align-items: center !important;
    gap: 0.75rem !important;
    margin-bottom: 1rem;
}
.crud-form form.country-inline-form > div {
    display: flex !important;
    flex-direction: row !important;
    align-items: center !important;
    gap: 0.5rem !important;
    width: auto !important;
    margin: 0 !important;
}
.crud-form form.country-inline-form label {
    width: auto !important;
    flex-shrink: 0 !important;
}
.crud-form form.country-inline-form input {
    width: 70px !important;
    flex-grow: 0 !important;
}
.crud-form form.country-inline-form #name {
    width: 120px !important;
    flex-grow: 0 !important;
}

/* Mobile Toggle Button */
.filter-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background: var(--accent-color);
    color: white;
    border: none;
    padding: 0.6rem 1.2rem;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 1rem;
    margin-bottom: 1rem;
    width: 100%;
    transition: background 0.2s;
}
.filter-toggle-btn:hover {
    background: #257977;
}

/* Backdrop Overlay */
.filter-drawer-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.4);
    z-index: 998;
}

.form-group {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.75rem;
}
.form-label {
    width: 110px;
    flex-shrink: 0;
    font-weight: 600;
    color: var(--text-muted);
}
.form-input {
    flex-grow: 1;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border-color-input);
    border-radius: 4px;
    font-size: 0.95rem;
    box-sizing: border-box;
}
.form-input:disabled {
    background: #edf2f7;
    color: var(--text-muted);
    cursor: not-allowed;
}
.form-select-el {
    background: white;
    height: 34px;
}

@media (max-width: 768px) {
    .main-content {
        padding: 0 0.5rem;
    }
    
    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .mobile-hide {
        display: none !important;
    }
    .mobile-only {
        display: block !important;
    }
    tr.mobile-only {
        display: table-row !important;
    }
    th.mobile-only, td.mobile-only {
        display: table-cell !important;
    }
    
    /* Responsive Form Spacing */
    .crud-form form > div {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.5rem !important;
    }

    /* ID and button alignment inline on mobile */
    .crud-form form > div:has(input[disabled]),
    .crud-form form > div:has(span) {
        flex-direction: row !important;
        align-items: center !important;
        gap: 1rem !important;
    }
    .crud-form form > div:has(input[disabled]) input,
    .crud-form form > div:has(span) span {
        width: 80px !important;
        flex-grow: 0 !important;
        text-align: center;
    }
    .crud-form form > div:has(button) {
        flex-direction: row !important;
        align-items: center !important;
        gap: 1rem !important;
    }

    /* Account fields inline on mobile */
    .crud-form form > div:has(#acc_code),
    .crud-form form > div:has(#starting_balance),
    .crud-form form > div:has(#balance),
    .crud-form form > div:has(#active) {
        flex-direction: row !important;
        align-items: center !important;
        gap: 1rem !important;
    }
    .crud-form form > div:has(#acc_code) input,
    .crud-form form > div:has(#starting_balance) input,
    .crud-form form > div:has(#balance) input {
        width: 140px !important;
        flex-grow: 0 !important;
    }
    .crud-form form > div:has(#active) input {
        width: 20px !important;
        flex-grow: 0 !important;
    }
    
    .crud-form label {
        width: auto !important;
        font-size: 0.9rem !important;
    }
    
    .crud-form input,
    .crud-form select {
        width: 100% !important;
        font-size: 0.95rem !important;
        height: 38px !important;
        padding: 0.5rem !important;
        box-sizing: border-box !important;
    }
    
    .crud-container {
        padding: 1rem !important;
        margin-bottom: 1rem !important;
    }
    
    .table-container {
        max-height: calc(100vh - 250px) !important;
    }

    .filter-group {
        flex-direction: row !important;
        align-items: center !important;
        justify-content: space-between !important;
        width: 100% !important;
        gap: 1rem !important;
    }
    .filter-group label {
        flex-shrink: 0 !important;
        min-width: 110px !important;
        margin-bottom: 0 !important;
        font-size: 0.9rem !important;
        text-align: left;
    }
    .filter-group input {
        flex-grow: 1 !important;
        width: auto !important;
        margin-top: 0 !important;
    }
    .filter-group select {
        flex-grow: 1 !important;
        width: auto !important;
        margin-top: 0 !important;
        max-width: 150px !important;
        min-width: 0 !important;
        text-overflow: ellipsis;
    }

    .search-group label {
        min-width: 70px !important;
    }
    .search-group input {
        max-width: 140px !important;
    }

    .table-container thead th,
    .table-container tbody td {
        padding: 0.5rem 0.4rem !important;
        font-size: 0.8rem !important;
    }

    .filter-panel {
        position: fixed;
        top: 0;
        right: 0;
        height: 100vh;
        width: 320px;
        background: white !important;
        z-index: 999;
        margin: 0 !important;
        box-shadow: -4px 0 10px rgba(0,0,0,0.1) !important;
        flex-direction: column !important;
        align-items: stretch !important;
        padding: 1.5rem !important;
        transform: translateX(100%);
        transition: transform 0.3s ease-in-out !important;
        display: flex !important;
        gap: 1rem !important;
        overflow-y: auto;
    }
    
    .filter-panel.open {
        transform: translateX(0);
    }

    .filter-panel > * {
        flex: none !important;
        flex-grow: 0 !important;
    }

    .filter-drawer-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        border-bottom: 1px solid var(--border-color);
        padding-bottom: 0.75rem;
        margin-bottom: 0.5rem;
    }
    .filter-drawer-header h3 {
        margin: 0;
        font-size: 1.15rem;
        color: var(--text-primary);
    }
    .filter-drawer-close-btn {
        background: transparent;
        border: none;
        font-size: 1.25rem;
        cursor: pointer;
        color: var(--text-muted);
    }
    
    .sort-arrows, .sort-pos {
        display: none !important;
    }

    .refresh-btn-container {
        width: 100% !important;
        display: flex !important;
        justify-content: flex-end !important;
        margin-top: 0.25rem !important;
    }

    .date-group label {
        min-width: 80px !important;
    }

    .form-group {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        gap: 0.75rem !important;
    }
    .form-label {
        width: 110px !important;
        flex-shrink: 0 !important;
        margin-bottom: 0 !important;
    }
    
    .transaction-header-grid {
        flex-direction: column !important;
        gap: 0.35rem !important;
        margin-bottom: 1rem !important;
    }
    .transaction-header-grid .transaction-header-field {
        flex: none !important;
        width: 100% !important;
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        gap: 0.4rem !important;
    }
    .transaction-header-grid .transaction-header-label {
        width: 85px !important;
        margin-bottom: 0 !important;
        font-size: 0.8rem !important;
        flex-shrink: 0 !important;
        text-align: left !important;
    }
    .transaction-header-grid input {
        flex-grow: 1 !important;
        min-width: 0 !important;
        width: auto !important;
        box-sizing: border-box !important;
        font-size: 0.8rem !important;
        padding: 0.3rem 0.5rem !important;
        height: 30px !important;
    }
    
    /* Mobile Detail Carousel Styles */
    .detail-card {
        background: white;
        border: 1px solid var(--border-color);
        border-radius: 8px;
        padding: 0.75rem !important;
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
        margin-bottom: 0.75rem !important;
        display: flex;
        flex-direction: column;
        gap: 0.35rem !important;
        box-sizing: border-box !important;
    }
    .detail-card .form-group {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        gap: 0.4rem !important;
        margin-bottom: 0 !important;
    }
    .detail-card .form-label {
        width: 85px !important;
        font-size: 0.8rem !important;
        flex-shrink: 0 !important;
        margin-bottom: 0 !important;
    }
    .detail-card .form-input,
    .detail-card .form-select-el {
        font-size: 0.8rem !important;
        padding: 0.2rem 0.4rem !important;
        height: 28px !important;
        flex-grow: 1 !important;
        min-width: 0 !important;
        width: auto !important;
        box-sizing: border-box !important;
    }
    
    .carousel-nav-bar {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 0.5rem !important;
        background: var(--bg-secondary);
        padding: 0.3rem 0.6rem !important;
        border-radius: 6px;
        border: 1px solid var(--border-color);
        font-size: 0.8rem !important;
    }
    
    .carousel-nav-btn {
        background: var(--accent-color);
        color: white;
        border: none;
        padding: 0.25rem 0.5rem !important;
        border-radius: 4px;
        font-weight: bold;
        cursor: pointer;
        font-size: 0.8rem !important;
    }
    
    .carousel-nav-btn:disabled {
        background: var(--border-color);
        cursor: not-allowed;
    }

    /* Product Price Form Mobile Styles */
    .crud-form form.product-price-form > div {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        gap: 0.4rem !important;
        justify-content: flex-start !important;
    }
    .crud-form form.product-price-form label {
        width: 85px !important;
        font-size: 0.8rem !important;
        flex-shrink: 0 !important;
        margin-bottom: 0 !important;
    }
    .crud-form form.product-price-form input,
    .crud-form form.product-price-form select {
        font-size: 0.8rem !important;
        padding: 0.2rem 0.4rem !important;
        height: 28px !important;
        flex-grow: 1 !important;
        min-width: 120px !important;
        width: auto !important;
        box-sizing: border-box !important;
    }
    .crud-form form.product-price-form button {
        padding: 0.1rem !important;
        flex-shrink: 0 !important;
        margin-left: 0.1rem !important;
    }
}

@media (min-width: 769px) {
    .mobile-only {
        display: none !important;
    }
}