/* Modern CSS Custom Properties for Design System */
:root {
    /* Modern Color Palette */
    --primary-50: #f0f9ff;
    --primary-100: #e0f2fe;
    --primary-200: #bae6fd;
    --primary-300: #7dd3fc;
    --primary-400: #38bdf8;
    --primary-500: #0ea5e9;
    --primary-600: #0284c7;
    --primary-700: #0369a1;
    --primary-800: #075985;
    --primary-900: #0c4a6e;
    
    /* Neutral Colors */
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;
    
    /* Semantic Colors */
    --success-500: #10b981;
    --success-600: #059669;
    --warning-500: #f59e0b;
    --warning-600: #d97706;
    --error-500: #ef4444;
    --error-600: #dc2626;
    
    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    --font-mono: 'JetBrains Mono', 'Monaco', 'Cascadia Code', 'Roboto Mono', monospace;
    
    /* Spacing Scale */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    
    /* Border Radius */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
}

/* Base Styles with Modern Typography */
* {
    box-sizing: border-box;
}

body {
    font-family: var(--font-sans);
    background: var(--gray-50);
    color: var(--gray-800);
    line-height: 1.6;
    font-feature-settings: 'kern' 1, 'liga' 1, 'calt' 1;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

html, body {
    overscroll-behavior-y: none;
}

/* Modern Navigation */
.navbar {
    background: var(--primary-700) !important;
    box-shadow: var(--shadow-md);
    border: none;
}

.navbar-brand {
    font-weight: 600;
    font-size: 1.25rem;
    color: white !important;
    letter-spacing: -0.025em;
}

/* Desktop nav active state */
.navbar-nav .nav-link {
    border-radius: var(--radius-md);
    transition: background-color 0.15s ease;
}

.navbar-nav .nav-link:hover {
    background-color: rgb(255 255 255 / 0.12);
}

.navbar-nav .nav-link.is-active {
    background-color: rgb(255 255 255 / 0.2);
    font-weight: 600;
}

/* Mobile bottom navigation (native-app pattern) */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1030;
    display: flex;
    align-items: center;
    justify-content: space-around;
    background: white;
    border-top: 1px solid var(--gray-200);
    box-shadow: 0 -2px 12px -4px rgb(0 0 0 / 0.12);
    padding: 0.375rem 0.5rem;
    padding-bottom: calc(0.375rem + env(safe-area-inset-bottom, 0px));
}

.bottom-nav__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.125rem;
    flex: 1 1 0;
    min-height: 48px;
    text-decoration: none;
    color: var(--gray-500);
    font-size: 0.6875rem;
    font-weight: 500;
    transition: color 0.15s ease;
}

.bottom-nav__item .bi {
    font-size: 1.25rem;
    line-height: 1;
}

.bottom-nav__item.is-active {
    color: var(--primary-600);
}

.bottom-nav__label {
    letter-spacing: 0.01em;
}

@media (prefers-reduced-motion: reduce) {
    .bottom-nav__item,
    .navbar-nav .nav-link {
        transition: none;
    }
}

/* Chart.js responsive containers */
.chart-wrapper {
    position: relative;
    width: 100%;
    height: 300px;
}

.chart-wrapper--tall {
    height: 320px;
}

.chart-wrapper canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
}

/* Pagination - prevent horizontal overflow on small screens */
.pagination {
    flex-wrap: wrap;
    gap: 0.25rem;
}

/* Modern Typography Scale */
h1 {
    font-size: 2.25rem;
    font-weight: 700;
    color: var(--gray-900);
    letter-spacing: -0.05em;
    line-height: 1.2;
    margin-bottom: var(--space-lg);
}

h2 { font-size: 1.875rem; font-weight: 600; color: var(--gray-800); letter-spacing: -0.025em; }
h3 { font-size: 1.5rem; font-weight: 600; color: var(--gray-800); }
h4 { font-size: 1.25rem; font-weight: 600; color: var(--gray-700); }
h5 { font-size: 1.125rem; font-weight: 600; color: var(--gray-700); }
h6 { font-size: 1rem; font-weight: 600; color: var(--gray-600); }

/* Modern Cards */
.card {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: var(--space-lg);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
}

.card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--gray-300);
}

.card-header {
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
    padding: var(--space-lg);
    font-weight: 600;
    color: var(--gray-800);
}

.card-body {
    padding: var(--space-lg);
}

/* KPI / stat cards - vertically center content within equal-height cards */
.stat-card .card-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
}

.stat-card .card-title,
.stat-card .card-text {
    margin-bottom: 0;
}

/* Modern Buttons */
.btn {
    font-family: var(--font-sans);
    font-weight: 500;
    border-radius: var(--radius-md);
    padding: 0.625rem 1.25rem;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    border: none;
    font-size: 0.875rem;
    line-height: 1.5;
    letter-spacing: -0.01em;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

/* Universal Button States */
.btn:focus, .btn:focus-visible {
    outline: 2px solid transparent;
    outline-offset: 2px;
    box-shadow: 0 0 0 3px rgb(14 165 233 / 0.2);
}

.btn:active {
    box-shadow: var(--shadow-sm) !important;
}

.btn:disabled, .btn.disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
    box-shadow: none !important;
}

.btn:disabled:hover, .btn.disabled:hover {
    transform: none !important;
    box-shadow: none !important;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-500) 0%, var(--primary-600) 100%);
    color: white;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--primary-500);
}

.btn-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, var(--primary-600) 0%, var(--primary-700) 100%);
    box-shadow: var(--shadow-md);
    color: white;
    border-color: var(--primary-600);
}

.btn-primary:focus {
    box-shadow: 0 0 0 3px rgb(14 165 233 / 0.2), var(--shadow-sm);
}

.btn-success {
    background: var(--success-500);
    color: white;
    border: 1px solid var(--success-500);
    box-shadow: var(--shadow-sm);
}

.btn-success:hover:not(:disabled) {
    background: var(--success-600);
    color: white;
    border-color: var(--success-600);
    box-shadow: var(--shadow-md);
}

.btn-success:focus {
    box-shadow: 0 0 0 3px rgb(16 185 129 / 0.2), var(--shadow-sm);
}

.btn-outline-primary {
    border: 1px solid var(--primary-500);
    color: var(--primary-600);
    background: transparent;
}

.btn-outline-primary:hover:not(:disabled) {
    background: var(--primary-500);
    border-color: var(--primary-500);
    color: white;
    box-shadow: var(--shadow-sm);
}

.btn-outline-primary:focus {
    box-shadow: 0 0 0 3px rgb(14 165 233 / 0.2);
    border-color: var(--primary-400);
}

.btn-outline-secondary {
    border: 1px solid var(--gray-400);
    color: var(--gray-600);
    background: transparent;
}

.btn-outline-secondary:hover:not(:disabled) {
    background: var(--gray-500);
    border-color: var(--gray-500);
    color: white;
    box-shadow: var(--shadow-sm);
}

.btn-outline-secondary:focus {
    box-shadow: 0 0 0 3px rgb(148 163 184 / 0.2);
    border-color: var(--gray-300);
}

.btn-outline-success {
    border: 1px solid var(--success-500);
    color: var(--success-600);
    background: transparent;
}

.btn-outline-success:hover:not(:disabled) {
    background: var(--success-500);
    border-color: var(--success-500);
    color: white;
    box-shadow: var(--shadow-sm);
}

.btn-outline-success:focus {
    box-shadow: 0 0 0 3px rgb(16 185 129 / 0.2);
    border-color: var(--success-400);
}

.btn-outline-danger {
    border: 1px solid var(--error-500);
    color: var(--error-600);
    background: transparent;
}

.btn-outline-danger:hover:not(:disabled) {
    background: var(--error-500);
    border-color: var(--error-500);
    color: white;
    box-shadow: var(--shadow-sm);
}

.btn-outline-danger:focus {
    box-shadow: 0 0 0 3px rgb(239 68 68 / 0.2);
    border-color: var(--error-400);
}

.btn-outline-info {
    border: 1px solid var(--primary-500);
    color: var(--primary-600);
    background: transparent;
}

.btn-outline-info:hover:not(:disabled) {
    background: var(--primary-500);
    border-color: var(--primary-500);
    color: white;
    box-shadow: var(--shadow-sm);
}

.btn-outline-info:focus {
    box-shadow: 0 0 0 3px rgb(14 165 233 / 0.2);
    border-color: var(--primary-400);
}


/* Button Size Variants */
.btn-sm {
    padding: 0.5rem 0.875rem;
    font-size: 0.8125rem;
    border-radius: var(--radius-sm);
}

.btn-lg {
    padding: 0.875rem 1.5rem;
    font-size: 1rem;
    border-radius: var(--radius-lg);
}

/* Modern Form Controls */
.form-control, .form-select {
    font-family: var(--font-sans);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    background: white;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary-400);
    box-shadow: 0 0 0 3px rgb(14 165 233 / 0.1);
    outline: none;
}

.form-label {
    font-weight: 500;
    color: var(--gray-700);
    font-size: 0.875rem;
    margin-bottom: var(--space-sm);
}

/* Invoice Cards with Modern Design */
.invoice-card {
    position: relative;
    cursor: pointer;
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    overflow: hidden;
    height: 100%;
}

.invoice-card .card-body {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.invoice-card .card-content {
    flex: 1 1 auto;
}

.invoice-card .card-actions {
    margin-top: auto;
    flex-shrink: 0;
    padding-top: 0.5rem;
    position: relative;
    z-index: 2;
}

.invoice-card:hover {
    border-color: var(--gray-300);
    box-shadow: var(--shadow-md);
}

.invoice-card .card-title {
    font-family: var(--font-mono);
    font-weight: 500;
    font-size: 0.95rem;
    color: var(--primary-700);
    letter-spacing: -0.01em;
}

/* Invoice list cells (grid + list views) */
.inv-cell--meta {
    font-size: 0.8125rem;
}

#invoicesListRoot.view-grid .card-content {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
        "id status"
        "customer customer"
        "date date"
        "amounts amounts"
        "meta meta";
    gap: 0.5rem;
}

#invoicesListRoot.view-grid .inv-cell--id { grid-area: id; }
#invoicesListRoot.view-grid .inv-cell--status { grid-area: status; justify-self: end; align-self: start; }
#invoicesListRoot.view-grid .inv-cell--customer { grid-area: customer; }
#invoicesListRoot.view-grid .inv-cell--date { grid-area: date; }
#invoicesListRoot.view-grid .inv-cell--amounts { grid-area: amounts; }
#invoicesListRoot.view-grid .inv-cell--meta { grid-area: meta; }

#invoicesListRoot.view-grid .inv-cell--amounts .inv-amounts-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

#invoicesListRoot.view-list .card-actions .d-flex {
    flex-direction: row !important;
}

@media (min-width: 576px) {
    #invoicesListRoot.view-list .invoice-card .card-body {
        flex-direction: row !important;
        align-items: center !important;
        height: auto !important;
    }

    #invoicesListRoot.view-list .card-content {
        display: flex !important;
        flex-direction: row !important;
        flex-wrap: wrap !important;
    }
}

/* List view — tablet/desktop */
#invoicesListRoot.view-list #invoicesContainer {
    --bs-gutter-x: 0;
    --bs-gutter-y: 0.5rem;
}

#invoicesListRoot.view-list .invoice-item {
    flex: 0 0 100%;
    max-width: 100%;
    margin-bottom: 0 !important;
}

#invoicesListRoot.view-list .invoice-card {
    height: auto;
}

#invoicesListRoot.view-list .invoice-card .card-body {
    flex-direction: row;
    align-items: center;
    gap: 1rem;
    padding-top: 0.875rem;
    padding-bottom: 0.875rem;
}

#invoicesListRoot.view-list .card-content {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    flex: 1 1 auto;
    gap: 0.75rem 1.25rem;
    min-width: 0;
}

#invoicesListRoot.view-list .inv-cell--id {
    flex: 1 1 10rem;
    min-width: 8rem;
}

#invoicesListRoot.view-list .inv-cell--customer {
    flex: 1 1 12rem;
    min-width: 8rem;
}

#invoicesListRoot.view-list .inv-cell--date {
    flex: 0 1 11rem;
    font-size: 0.875rem;
}

#invoicesListRoot.view-list .inv-cell--amounts {
    flex: 0 0 auto;
    text-align: right;
}

#invoicesListRoot.view-list .inv-cell--amounts .inv-amounts-grid {
    display: flex;
    gap: 1.25rem;
    justify-content: flex-end;
}

#invoicesListRoot.view-list .inv-cell--amounts .inv-amount-item {
    white-space: nowrap;
}

#invoicesListRoot.view-list .inv-cell--status {
    flex: 0 0 auto;
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    justify-content: flex-end;
}

#invoicesListRoot.view-list .inv-cell--meta {
    display: none;
}

#invoicesListRoot.view-list .card-actions {
    margin-top: 0;
    padding-top: 0;
    flex-shrink: 0;
    margin-left: auto;
}

#invoicesListRoot.view-list .card-actions .d-flex {
    flex-direction: row !important;
}

/* List view — mobile compact rows */
@media (max-width: 575.98px) {
    #invoicesListRoot.view-list .invoice-card .card-body {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    #invoicesListRoot.view-list .card-content {
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-areas:
            "id status"
            "customer balance"
            "date date";
        gap: 0.375rem 0.75rem;
    }

    #invoicesListRoot.view-list .inv-cell--id { grid-area: id; }
    #invoicesListRoot.view-list .inv-cell--status { grid-area: status; justify-self: end; }
    #invoicesListRoot.view-list .inv-cell--customer { grid-area: customer; }
    #invoicesListRoot.view-list .inv-cell--date { grid-area: date; font-size: 0.8125rem; }
    #invoicesListRoot.view-list .inv-cell--amounts {
        grid-area: balance;
        justify-self: end;
        align-self: center;
        text-align: right;
    }

    #invoicesListRoot.view-list .inv-cell--amounts .inv-amounts-grid {
        flex-direction: column;
        gap: 0;
    }

    #invoicesListRoot.view-list .inv-cell--amounts .inv-amount-item:first-child {
        display: none;
    }

    #invoicesListRoot.view-list .card-actions {
        margin-left: 0;
        width: 100%;
    }
}

/* View mode toggle active state */
#viewGridBtn.active,
#viewListBtn.active {
    background-color: var(--primary-600);
    border-color: var(--primary-600);
    color: white;
}

/* Modern Status Badges */
.badge {
    font-family: var(--font-sans);
    font-weight: 500;
    font-size: 0.75rem;
    border-radius: var(--radius-sm);
    padding: 0.25rem 0.5rem;
    letter-spacing: 0.025em;
}

.bg-success { background: var(--success-500) !important; }
.bg-warning { background: var(--warning-500) !important; color: var(--gray-900) !important; }
.bg-danger { background: var(--error-500) !important; }

.badge.bg-warning {
    color: var(--gray-900) !important;
}

/* Tabular figures for monetary values */
.text-end,
.invoice-number,
.stat-card .card-title,
.invoice-masthead__balance-amount,
.card-body .d-flex.justify-content-between span:last-child,
.card-body .d-flex.justify-content-between strong:last-child {
    font-variant-numeric: tabular-nums;
}

/* Invoice detail masthead */
.invoice-masthead {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: var(--space-lg) var(--space-xl);
    box-shadow: var(--shadow-sm);
}

.invoice-masthead__eyebrow {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--gray-500);
}

.invoice-masthead__number {
    font-family: var(--font-mono);
    font-size: 1.75rem;
    font-weight: 600;
    color: var(--primary-800);
    letter-spacing: -0.02em;
    margin-bottom: 0;
}

.invoice-masthead__balance-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--gray-500);
    margin-bottom: 0.25rem;
}

.invoice-masthead__balance-amount {
    font-family: var(--font-mono);
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.2;
}

/* Modern Balance Colors */
.balance-zero, .text-success { color: var(--success-600) !important; }
.balance-positive, .text-danger { color: var(--error-600) !important; }

/* Modern Image Gallery */
.invoice-images {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: var(--space-md);
    margin-top: var(--space-md);
}

.invoice-image {
    position: relative;
    border-radius: var(--radius-md);
    overflow: hidden;
    aspect-ratio: 1;
}

.invoice-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.invoice-image:hover img {
    transform: scale(1.05);
}

.delete-image-btn {
    position: absolute;
    top: var(--space-sm);
    right: var(--space-sm);
    background: rgba(239, 68, 68, 0.9);
    backdrop-filter: blur(4px);
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 12px;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: pointer;
}

.delete-image-btn:hover {
    background: var(--error-600);
    transform: scale(1.1);
}

/* Modern Links - Consistent across all devices */
a {
    color: var(--primary-600);
    text-decoration: none;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

a:hover {
    color: var(--primary-700);
    text-decoration: none;
}

a:focus {
    outline: 2px solid transparent;
    outline-offset: 2px;
    box-shadow: 0 0 0 2px rgb(14 165 233 / 0.2);
    border-radius: var(--radius-sm);
}

a:active {
    color: var(--primary-800);
}

.text-primary {
    color: var(--primary-600) !important;
}

.text-primary:hover {
    color: var(--primary-700) !important;
}

/* Modern Input Groups */
.input-group-text {
    background: var(--gray-100);
    border: 1px solid var(--gray-300);
    color: var(--gray-600);
}

/* Modern Alerts */
.alert {
    border: none;
    border-radius: var(--radius-md);
    font-weight: 500;
}

.alert-info {
    background: var(--primary-50);
    color: var(--primary-800);
    border-left: 4px solid var(--primary-500);
}

/* Monospace for Invoice Numbers and Codes */
.invoice-number, .form-control[readonly], .card-title h6 {
    font-family: var(--font-mono);
}

/* Add subtle background to readonly fields */
.form-control[readonly] {
    background-color: var(--gray-100) !important;
    border-color: var(--gray-300);
    color: var(--gray-700);
}

/* Enhanced visual hierarchy for invoice titles */
.invoice-card .card-title h6 {
    font-family: var(--font-mono);
    color: var(--primary-700);
    font-weight: 600;
    margin-bottom: 0;
}

/* RESPONSIVE DESIGN IMPROVEMENTS */

/* Mobile First - Base styles for small screens */
@media (max-width: 767.98px) {
    /* Fix navbar brand styling for mobile */
    .navbar-brand {
        font-size: 1.1rem !important;
        font-weight: 600 !important;
        letter-spacing: -0.01em !important;
    }
    
    /* Typography adjustments for mobile */
    h1 {
        font-size: 1.8rem !important;
        margin-bottom: 1rem !important;
        line-height: 1.3 !important;
    }
    
    h2, h3, h4, h5, h6 {
        font-size: calc(1rem + 0.5vw) !important;
    }
    
    /* Container padding adjustments */
    .container {
        padding-left: 15px !important;
        padding-right: 15px !important;
    }
    
    /* Card spacing for mobile */
    .card {
        margin-bottom: 1rem !important;
        border-radius: var(--radius-md) !important;
    }
    
    .card-body {
        padding: 1rem !important;
    }
    
    /* Form improvements for mobile */
    .form-control, .form-select {
        font-size: 16px !important; /* Prevents zoom on iOS */
        padding: 0.75rem !important;
    }
    
    /* Button improvements for mobile - preserve animations */
    .btn {
        padding: 0.75rem 1rem !important;
        font-size: 0.95rem !important;
        margin-bottom: 0.5rem !important;
        border-radius: var(--radius-md) !important;
        min-height: 44px !important; /* Touch target size */
    }
    
    .btn-sm {
        padding: 0.5rem 0.75rem !important;
        font-size: 0.85rem !important;
        border-radius: var(--radius-sm) !important;
        min-height: 38px !important;
    }
    
    .btn-lg {
        padding: 1rem 1.5rem !important;
        font-size: 1rem !important;
        min-height: 48px !important;
    }
    
    /* Enhanced touch targets and visual consistency */
    .btn, .form-control, .form-select, a {
        min-height: 44px !important;
    }
    
    .btn-sm {
        min-height: 38px !important;
    }
    
    /* Maintain outline button consistency */
        .btn-outline-primary, .btn-outline-secondary, .btn-outline-success, .btn-outline-danger, .btn-outline-info {
        border-width: 1px !important;
        border-style: solid !important;
        background: transparent !important;
    }
    
    /* Stack buttons vertically on mobile */
    .d-flex.gap-1, .d-flex.gap-2 {
        flex-direction: column !important;
        gap: 0.5rem !important;
    }
    
    /* Invoice card improvements for mobile */
    .invoice-card {
        margin-bottom: 1rem !important;
        border: 1px solid var(--gray-200) !important;
        border-radius: var(--radius-lg) !important;
        background: white !important;
        box-shadow: var(--shadow-sm) !important;
        overflow: hidden !important;
    }
    
    .invoice-card .card-body {
        padding: 1rem !important;
        display: flex !important;
        flex-direction: column !important;
        height: 100% !important;
    }
    
    .invoice-card .card-content {
        flex: 1 1 auto !important;
    }
    
    .invoice-card .card-actions {
        margin-top: auto !important;
        flex-shrink: 0 !important;
        padding-top: 0.5rem !important;
    }
    
    .invoice-card .card-title {
        font-size: 0.9rem !important;
        margin-bottom: 0.5rem !important;
        color: var(--primary-700) !important;
        font-weight: 500 !important;
        font-family: var(--font-mono) !important;
    }
    
    .invoice-card .card-text {
        font-size: 0.85rem !important;
        line-height: 1.4 !important;
        margin-bottom: 0.5rem !important;
    }
    
    .invoice-card .d-flex {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.5rem !important;
    }
    
    /* Fix button group in invoice cards - keep horizontal on mobile */
    .invoice-card .card-actions .d-flex.gap-1 {
        flex-direction: row !important;
        gap: 0.25rem !important;
        width: 100% !important;
    }
    
    .invoice-card .btn-sm {
        flex: 1 !important;
        font-size: 0.75rem !important;
        padding: 0.4rem 0.5rem !important;
        border-width: 1px !important;
    }
    
    /* Status badge improvements */
    .invoice-card .badge {
        font-size: 0.7rem !important;
        padding: 0.25rem 0.5rem !important;
    }
    
    /* Search and filter improvements */
    .input-group {
        margin-bottom: 1rem !important;
    }
    
    /* Statistics cards stack on mobile */
    .row > [class*="col-"] {
        margin-bottom: 1rem !important;
    }

    /* Dashboard chart sizing on mobile */
    .chart-wrapper {
        height: 240px !important;
    }

    .chart-wrapper--tall {
        height: 260px !important;
    }

    /* Reserve space for the fixed bottom navigation */
    body {
        padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px)) !important;
    }
    
    /* Action buttons in invoice detail */
    .d-grid.gap-2 > * {
        margin-bottom: 0.5rem !important;
    }
    
    /* Form row adjustments */
    .row.mb-3 > [class*="col-"] {
        margin-bottom: 1rem !important;
    }
    
    /* Image preview improvements */
    .invoice-images {
        display: flex !important;
        flex-direction: column !important;
        gap: 1rem !important;
    }
    
    .invoice-image {
        width: 100% !important;
        max-width: none !important;
    }
    
    .invoice-image img {
        width: 100% !important;
        height: auto !important;
        max-height: 300px !important;
        object-fit: contain !important;
    }
    
    /* Image preview grid for upload */
    #imagePreviews .col-md-4 {
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }
    
    /* Banking information improvements */
    .card-body h6 {
        margin-top: 1.5rem !important;
        margin-bottom: 1rem !important;
        font-size: 1.1rem !important;
        color: var(--gray-600) !important;
    }
    
    .card-body h6:first-child {
        margin-top: 0 !important;
    }
    
    /* Payment details improvements */
    .card-body p {
        margin-bottom: 0.75rem !important;
        line-height: 1.5 !important;
    }
    
    .card-body p strong {
        display: inline-block !important;
        min-width: 100px !important;
        margin-bottom: 0.25rem !important;
    }
    
    /* Table responsiveness */
    .table-responsive {
        border: none !important;
        margin-bottom: 1rem !important;
    }
    
    /* Items section improvements */
    .item-row {
        border: 1px solid var(--gray-200) !important;
        border-radius: var(--radius-md) !important;
        padding: 1rem !important;
        margin-bottom: 1rem !important;
        background-color: var(--gray-50) !important;
    }
    
    .item-row .row > [class*="col-"] {
        margin-bottom: 0.75rem !important;
    }
    
    .item-row .btn {
        width: 100% !important;
        margin-top: 0.5rem !important;
    }
    
    /* Totals section improvements */
    .text-end {
        text-align: center !important;
    }
    
    /* Status badges */
    .badge {
        font-size: 0.8rem !important;
        padding: 0.5rem 0.75rem !important;
    }
    
    /* Modal improvements for mobile */
    .modal-dialog {
        margin: 1rem !important;
    }
    
    .modal-body {
        padding: 1rem !important;
    }
    
    /* Enhanced touch targets for mobile */
    .btn, .form-control, .form-select, a {
        min-height: 44px !important; /* Apple's recommended touch target size */
    }
    
    .btn-sm {
        min-height: 38px !important;
    }
    
    /* Maintain consistent link and button interactions on mobile */
    /* Links inherit from base styles for consistency */
    
    /* Larger click areas for icons and improved accessibility */
    .bi {
        padding: 2px !important;
    }
}

/* Tablet styles */
@media (min-width: 768px) and (max-width: 991.98px) {
    .container {
        max-width: 720px !important;
    }
    
    /* Adjust invoice cards for tablet */
    .col-md-6 {
        flex: 0 0 50% !important;
        max-width: 50% !important;
    }
    
    .col-lg-4 {
        flex: 0 0 50% !important;
        max-width: 50% !important;
    }
    
    /* Form adjustments for tablet */
    .col-md-8 {
        flex: 0 0 100% !important;
        max-width: 100% !important;
        margin-bottom: 2rem !important;
    }
    
    .col-md-4 {
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }
    
    /* Button consistency for tablet */
    .btn {
        min-height: 42px !important;
        padding: 0.625rem 1.25rem !important;
    }
    
    .btn-sm {
        min-height: 36px !important;
        padding: 0.5rem 0.875rem !important;
    }
    
    .btn-lg {
        min-height: 46px !important;
        padding: 0.875rem 1.5rem !important;
    }
}

/* LOADING INDICATORS AND ANIMATIONS */

/* Keyframe Animations */
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.spin {
    animation: spin 1s linear infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

@keyframes shimmer {
    0% { background-position: -200px 0; }
    100% { background-position: calc(200px + 100%) 0; }
}

@keyframes slideDown {
    0% { transform: translateY(-10px); opacity: 0; }
    100% { transform: translateY(0); opacity: 1; }
}

/* Loading Spinner */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--gray-300);
    border-top: 2px solid var(--primary-500);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.spinner-sm {
    width: 16px;
    height: 16px;
    border-width: 1.5px;
}

.spinner-lg {
    width: 32px;
    height: 32px;
    border-width: 3px;
}

.spinner-white {
    border-color: rgba(255, 255, 255, 0.3);
    border-top-color: white;
}

/* Button Loading States */
.btn-loading {
    position: relative;
    pointer-events: none;
    color: transparent !important;
}

.btn-loading::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 16px;
    height: 16px;
    margin: -8px 0 0 -8px;
    border: 2px solid transparent;
    border-top: 2px solid currentColor;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.btn-loading.btn-primary::after,
.btn-loading.btn-success::after {
    border-top-color: white;
    border-right-color: rgba(255, 255, 255, 0.3);
    border-bottom-color: rgba(255, 255, 255, 0.3);
    border-left-color: rgba(255, 255, 255, 0.3);
}

.btn-loading.btn-outline-primary::after {
    border-top-color: var(--primary-600);
    border-right-color: rgba(14, 165, 233, 0.3);
    border-bottom-color: rgba(14, 165, 233, 0.3);
    border-left-color: rgba(14, 165, 233, 0.3);
}

.btn-loading.btn-outline-success::after {
    border-top-color: var(--success-600);
    border-right-color: rgba(16, 185, 129, 0.3);
    border-bottom-color: rgba(16, 185, 129, 0.3);
    border-left-color: rgba(16, 185, 129, 0.3);
}

.btn-loading.btn-outline-secondary::after {
    border-top-color: var(--gray-600);
    border-right-color: rgba(71, 85, 105, 0.3);
    border-bottom-color: rgba(71, 85, 105, 0.3);
    border-left-color: rgba(71, 85, 105, 0.3);
}

.btn-loading.btn-outline-danger::after {
    border-top-color: var(--error-600);
    border-right-color: rgba(239, 68, 68, 0.3);
    border-bottom-color: rgba(239, 68, 68, 0.3);
    border-left-color: rgba(239, 68, 68, 0.3);
}

.btn-loading.btn-outline-info::after {
    border-top-color: var(--primary-600);
    border-right-color: rgba(14, 165, 233, 0.3);
    border-bottom-color: rgba(14, 165, 233, 0.3);
    border-left-color: rgba(14, 165, 233, 0.3);
}


/* Page Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: slideDown 0.3s ease-out;
}

.loading-overlay.hidden {
    display: none;
}

.loading-content {
    text-align: center;
    color: var(--gray-700);
}

.loading-content .spinner {
    margin-bottom: 1rem;
}

.loading-text {
    font-size: 1rem;
    font-weight: 500;
    color: var(--gray-600);
}

/* Form Loading Overlay */
.form-loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(1px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    border-radius: var(--radius-lg);
}

.form-loading-overlay.hidden {
    display: none;
}

/* Upload Progress Bar */
.upload-progress-container {
    margin-top: 1rem;
    padding: 1rem;
    background: var(--gray-50);
    border-radius: var(--radius-md);
    border: 1px solid var(--gray-200);
}

.upload-progress-container.hidden {
    display: none;
}

.upload-progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.upload-progress-text {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-700);
}

.upload-progress-percentage {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--primary-600);
}

.upload-progress-bar {
    width: 100%;
    height: 8px;
    background: var(--gray-200);
    border-radius: 4px;
    overflow: hidden;
}

.upload-progress-fill {
    height: 100%;
    background: linear-gradient(135deg, var(--primary-500) 0%, var(--primary-600) 100%);
    border-radius: 4px;
    transition: width 0.3s ease;
    width: 0%;
}

.upload-progress-success .upload-progress-fill {
    background: linear-gradient(135deg, var(--success-500) 0%, var(--success-600) 100%);
}

.upload-progress-error .upload-progress-fill {
    background: linear-gradient(135deg, var(--error-500) 0%, var(--error-600) 100%);
}

/* Skeleton Loading */
.skeleton {
    background: linear-gradient(90deg, var(--gray-200) 25%, var(--gray-100) 50%, var(--gray-200) 75%);
    background-size: 200px 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-md);
}

.skeleton-text {
    height: 1rem;
    margin-bottom: 0.5rem;
    border-radius: var(--radius-sm);
}

.skeleton-text.w-75 { width: 75%; }
.skeleton-text.w-50 { width: 50%; }
.skeleton-text.w-25 { width: 25%; }

.skeleton-card {
    height: 200px;
    margin-bottom: 1rem;
}

.skeleton-button {
    height: 38px;
    width: 120px;
    border-radius: var(--radius-md);
}

/* Loading Card Placeholder */
.invoice-card.loading {
    pointer-events: none;
    opacity: 0.7;
}

.invoice-card.loading .card-body > * {
    visibility: hidden;
}

.invoice-card.loading .card-body::after {
    content: "";
    position: absolute;
    top: 1rem;
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
    background: linear-gradient(90deg, var(--gray-200) 25%, var(--gray-100) 50%, var(--gray-200) 75%);
    background-size: 200px 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
}

/* Search Loading */
.search-loading {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--gray-600);
    font-size: 0.875rem;
}

.search-loading .spinner {
    width: 14px;
    height: 14px;
    border-width: 1.5px;
}

/* Ensure search spinner is hidden by default */
#searchSpinner {
    display: none !important;
}

#searchSpinner.hidden {
    display: none !important;
}

/* Ensure search icon is visible by default */
#searchIcon {
    display: inline !important;
}

/* Accessibility Loading States */
.loading-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Responsive Loading Adjustments */
@media (max-width: 767.98px) {
    .loading-overlay .spinner-lg {
        width: 24px;
        height: 24px;
        border-width: 2px;
    }
    
    .loading-text {
        font-size: 0.9rem;
    }
    
    .upload-progress-container {
        padding: 0.75rem;
    }
    
    .btn-loading::after {
        width: 14px;
        height: 14px;
        margin: -7px 0 0 -7px;
    }
}

/* Print styles */
@media print {
    .navbar, .bottom-nav, .btn, .d-grid, .card-header {
        display: none !important;
    }
    
    .card {
        border: none !important;
        box-shadow: none !important;
    }
    
    .container {
        max-width: none !important;
        padding: 0 !important;
    }
    
    .loading-overlay, .form-loading-overlay, .upload-progress-container {
        display: none !important;
    }
}
