/* =================================================================
   MOBILE-FIRST RESPONSIVE DESIGN FOR PENSION LOAN SYSTEM
   ================================================================= */

/* ===== MOBILE-FIRST BREAKPOINTS ===== */
:root {
    --mobile-xs: 320px;  /* Small phones */
    --mobile-sm: 375px;  /* Standard phones */
    --mobile-md: 425px;  /* Large phones */
    --tablet: 768px;     /* Tablets */
    --desktop: 1024px;   /* Small desktop */
    --desktop-lg: 1440px; /* Large desktop */
    
    /* Mobile-optimized spacing */
    --mobile-padding: 16px;
    --mobile-margin: 12px;
    --mobile-gap: 8px;
    
    /* Touch-friendly sizes */
    --touch-target: 44px;
    --touch-target-lg: 56px;
}

/* ===== BASE MOBILE STYLES (DEFAULT) ===== */

/* Mobile-first body adjustments */
body {
    font-size: 16px; /* Prevents zoom on iOS */
    -webkit-text-size-adjust: 100%;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    touch-action: manipulation;
    overflow-x: hidden;
}

/* Mobile-first container */
.container {
    padding: var(--mobile-padding);
    margin: 0;
    margin-top: 60px; /* Space for fixed header - very compact */
    width: 100%;
    max-width: 100vw;
    box-sizing: border-box;
}

/* ===== MOBILE HEADER IMPROVEMENTS ===== */
.top-header {
    position: fixed !important;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    z-index: 1002;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

/* OPTIMIZED: Compact header on mobile */
@media (max-width: 768px) {
    .top-header {
        min-height: 56px !important;
    }

    .header-container {
        padding: 8px 12px !important;
        flex-wrap: nowrap !important; /* Prevent wrapping to save vertical space */
        gap: 6px !important;
        align-items: center !important;
    }

    .header-center {
        display: none !important; /* Hide breadcrumb */
    }

    .header-stats {
        display: none !important; /* Hide stats */
    }

    .brand-tagline {
        display: none !important; /* Hide tagline */
    }
}

/* This media query is now handled in the main hamburger toggle section below at line 307 */

.header-logo-icon {
    font-size: 24px;
    padding: 6px;
    min-width: var(--touch-target);
    min-height: var(--touch-target);
    display: flex;
    align-items: center;
    justify-content: center;
}

.brand-name {
    font-size: 16px !important;
    line-height: 1.2;
}

.brand-tagline {
    font-size: 11px !important;
    opacity: 0.9;
}

/* ===== MOBILE NAVIGATION ===== */
/* Mobile-first: sidebar hidden by default on small screens */
.modern-sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1); /* Smooth easing */
    position: fixed;
    top: 0; /* START FROM TOP - cover entire screen including header */
    left: 0;
    height: 100vh; /* FULL VIEWPORT HEIGHT */
    width: 280px; /* Default desktop width */
    max-width: 280px; /* Default desktop max-width */
    z-index: 1001; /* Default z-index for desktop, overridden on mobile */
    background: var(--sidebar-bg, #FFFFFF);
    box-shadow: 2px 0 20px rgba(0, 0, 0, 0.3);
    /* CRITICAL: Don't add overflow-y: auto here - it breaks flexbox layout */
    /* The sidebar uses flexbox, and only .sidebar-nav should scroll */
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Sidebar container doesn't scroll, only .sidebar-nav does */
}

.modern-sidebar.mobile-open {
    transform: translateX(0);
}

/* Sidebar mobile header - shown at top of sidebar on mobile */
.sidebar-mobile-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    flex-shrink: 0; /* Don't shrink */
}

.sidebar-mobile-title {
    display: flex;
    align-items: center;
    gap: 12px;
    color: white;
}

.sidebar-logo-icon {
    font-size: 28px;
}

.sidebar-title-text {
    font-size: 18px;
    font-weight: 700;
    color: white;
}

.sidebar-close-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 24px;
    cursor: pointer;
    transition: all 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.sidebar-close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: scale(1.05);
}

.sidebar-close-btn:active {
    transform: scale(0.95);
}

/* ========================================
   GLOBAL MOBILE SIDEBAR FIX
   APPLIES TO ALL PAGES
   ======================================== */
@media (max-width: 768px) {
    /* Prevent horizontal overflow */
    html,
    body {
        overflow-x: hidden !important;
        max-width: 100vw !important;
    }

    body {
        position: relative !important;
    }

    /* CRITICAL: All containers must NOT constrain sidebar */
    .container,
    .app-layout,
    .main-content,
    .page-container,
    .content-wrapper {
        position: static !important;
        overflow: visible !important;
        padding-left: 0 !important;
        padding-right: 0 !important;
        margin: 0 !important;
        margin-top: 60px !important; /* Space for fixed header - very compact */
        width: 100% !important;
        max-width: 100vw !important;
    }

    /* ========================================
       MOBILE SIDEBAR - ZERO DESKTOP INHERITANCE
       ATTACHED TO VIEWPORT EDGES
       ======================================== */
    .modern-sidebar,
    aside.modern-sidebar,
    .modern-sidebar[class*="sidebar"] {
        /* Reset ALL possible desktop properties */
        all: unset !important;

        /* VIEWPORT ATTACHMENT - No gaps, no spacing */
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        bottom: 0 !important;
        right: auto !important;

        /* FULL VIEWPORT DIMENSIONS */
        width: 280px !important;
        max-width: 75vw !important;
        min-width: 0 !important;
        height: 100vh !important;
        min-height: 100vh !important;
        max-height: 100vh !important;

        /* ZERO SPACING - Edge to edge */
        margin: 0 !important;
        padding: 0 !important;
        border: none !important;
        border-width: 0 !important;
        border-radius: 0 !important;
        outline: none !important;

        /* NO VISUAL EFFECTS */
        box-shadow: none !important;
        filter: none !important;
        backdrop-filter: none !important;

        /* BOX MODEL */
        box-sizing: border-box !important;

        /* HIDE BY DEFAULT - Completely off-screen */
        transform: translateX(-100%) !important;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;

        /* STACKING */
        z-index: 9999 !important;

        /* APPEARANCE */
        background: #ffffff !important;
        background-color: #ffffff !important;
        color: #000000 !important;

        /* SCROLLING */
        overflow-x: hidden !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        overscroll-behavior: contain !important;

        /* LAYOUT */
        display: flex !important;
        flex-direction: column !important;
        flex-wrap: nowrap !important;
        align-items: stretch !important;

        /* FONT RESET */
        font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
        font-size: 16px !important;
        line-height: 1.5 !important;

        /* INTERACTION */
        pointer-events: auto !important;
        user-select: auto !important;
    }

    /* SIDEBAR OPEN STATE */
    .modern-sidebar.mobile-open,
    aside.modern-sidebar.mobile-open {
        transform: translateX(0) !important;
    }

    /* Sidebar navigation scrollable */
    .sidebar-nav {
        flex: 1 1 auto !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        padding: 8px 0 !important;
        width: 100% !important;
    }

    /* MOBILE-ONLY Z-INDEX OVERRIDES */
    .top-header,
    .app-header,
    header.top-header,
    header.app-header {
        z-index: 100 !important;
    }

    .sidebar-mobile-overlay,
    .sidebar-overlay {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100vw !important;
        height: 100vh !important;
        background: rgba(0, 0, 0, 0.5) !important;
        z-index: 1000 !important;
        display: none !important;
        pointer-events: auto !important;
    }

    .sidebar-mobile-overlay.active,
    .sidebar-overlay.active {
        display: block !important;
    }

    .mobile-sidebar-toggle {
        display: flex !important;
        position: fixed !important;
        top: 15px !important;
        left: 15px !important;
        z-index: 1002 !important;
        width: 48px !important;
        height: 48px !important;
        pointer-events: auto !important;
    }

    /* Hide sidebar footer on mobile */
    .sidebar-footer {
        display: none !important;
    }

    .main-content {
        width: 100% !important;
        max-width: 100vw !important;
        margin-left: 0 !important;
        padding: var(--mobile-padding);
        box-sizing: border-box;
    }

    .container {
        display: block !important;
        flex-direction: column !important;
        width: 100% !important;
        max-width: 100vw !important;
        overflow-x: hidden !important;
        padding-left: 15px !important; /* Prevent sidebar offset */
    }

    /* Ensure sidebar doesn't affect layout when hidden */
    .modern-sidebar:not(.mobile-open) {
        pointer-events: none;
    }

    .modern-sidebar.mobile-open {
        pointer-events: auto;
    }

    /* Prevent body scroll when sidebar is open */
    body.sidebar-open {
        overflow: hidden !important;
    }
}

/* Desktop: always show sidebar, position static */
@media (min-width: 768px) {
    .modern-sidebar {
        transform: translateX(0) !important;
        position: static !important;
        width: 280px !important;
        max-width: 280px !important;
        height: auto !important;
        box-shadow: none !important;
    }

    .container {
        display: flex !important;
    }

    .main-content {
        flex: 1;
    }

    /* Hide hamburger button on desktop */
    .mobile-sidebar-toggle {
        display: none !important;
    }

    /* Hide overlay on desktop */
    .sidebar-mobile-overlay,
    .sidebar-overlay {
        display: none !important;
    }
}

/* Mobile menu toggle button */
.mobile-menu-toggle {
    display: flex !important;
    flex-direction: column;
    justify-content: space-around;
    width: var(--touch-target);
    height: var(--touch-target);
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 8px;
    cursor: pointer;
    padding: 8px;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.mobile-menu-toggle span {
    display: block;
    height: 2px;
    width: 100%;
    background: white;
    border-radius: 1px;
    transition: all 0.3s ease;
    transform-origin: center;
}

.mobile-menu-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translate(6px, 6px);
}

.mobile-menu-toggle.active span:nth-child(2) {
    opacity: 0;
}

.mobile-menu-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translate(6px, -6px);
}

/* Sidebar overlay for mobile - COVERS ENTIRE SCREEN INCLUDING HEADER */
.sidebar-overlay,
.sidebar-mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5); /* Semi-transparent black backdrop */
    z-index: 1000; /* BELOW sidebar (1001) but ABOVE main content */
    pointer-events: auto;
    transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    -webkit-tap-highlight-color: transparent;
}

.sidebar-overlay.active,
.sidebar-mobile-overlay.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Mobile sidebar toggle button (hamburger) */
.mobile-sidebar-toggle {
    display: none; /* Hidden by default, show only on mobile */
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 1002; /* Above sidebar (1001) and overlay (1000) */
    width: 48px;
    height: 48px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); /* Gradient for better visibility */
    border: none;
    border-radius: 12px; /* rounded-xl from design system */
    cursor: pointer;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 5px;
    padding: 10px;
    box-shadow: 0 4px 16px rgba(102, 126, 234, 0.4);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    -webkit-tap-highlight-color: transparent;
}

.mobile-sidebar-toggle:hover {
    background: linear-gradient(135deg, #764ba2 0%, #667eea 100%); /* Reverse gradient on hover */
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.5);
}

.mobile-sidebar-toggle:active {
    transform: scale(0.95);
}

.mobile-sidebar-toggle span {
    display: block;
    width: 22px;
    height: 2.5px;
    background: white;
    border-radius: 2px;
    transition: all 0.3s ease;
    transform-origin: center;
}

/* Hamburger animation when active */
.mobile-sidebar-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translateY(9px);
}

.mobile-sidebar-toggle.active span:nth-child(2) {
    opacity: 0;
    transform: translateX(-20px);
}

.mobile-sidebar-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translateY(-9px);
}

/* Show hamburger only on mobile and tablet (767px and below) */
@media (max-width: 767px) {
    .mobile-sidebar-toggle {
        display: flex !important;
    }

    /* Adjust header padding to accommodate hamburger button */
    .header-container {
        padding-left: 68px !important; /* Space for hamburger button (48px + 20px margin) */
    }
}

/* Mobile sidebar links */
.sidebar-link {
    min-height: var(--touch-target-lg);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 16px;
    border-radius: 0;
    margin: 0 8px;
    transition: all 0.2s ease;
}

.sidebar-link:hover,
.sidebar-link:active {
    background: rgba(102, 126, 234, 0.1);
    transform: translateX(4px);
}

/* Mobile-specific sidebar improvements */
@media (max-width: 767px) {
    /* CRITICAL: Sidebar nav must be scrollable */
    .sidebar-nav {
        flex: 1 1 auto !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain !important;
        min-height: 0 !important; /* Critical for flexbox scrolling */
        padding: 8px 0 !important;
    }

    .sidebar-mobile-header {
        flex: 0 0 auto !important;
        flex-shrink: 0 !important;
    }

    .sidebar-footer {
        flex: 0 0 auto !important;
        flex-shrink: 0 !important;
        display: none !important; /* HIDE user profile on mobile to save space */
    }

    /* Ensure all sidebar navigation items are touch-friendly */
    .sidebar-nav .sidebar-link,
    .sidebar-nav .dropdown-toggle {
        min-height: 56px;
        padding: 16px 20px;
        font-size: 16px; /* Prevent iOS zoom */
        -webkit-tap-highlight-color: transparent;
    }

    .nav-icon {
        font-size: 20px; /* Larger icons for mobile */
        min-width: 24px;
    }

    .nav-text {
        font-size: 16px;
        font-weight: 500;
    }

    /* Sidebar footer adjustments for mobile */
    .sidebar-footer {
        padding: 16px;
        border-top: 1px solid rgba(0, 0, 0, 0.1);
    }

    .user-info {
        padding: 12px;
    }

    .user-name {
        font-size: 16px;
        font-weight: 600;
    }

    .user-role {
        font-size: 14px;
    }
}

/* ===== MOBILE-FIRST FORMS ===== */
.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
}

.form-control,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
    width: 100%;
    padding: 16px;
    border: 2px solid var(--input-border);
    border-radius: 8px;
    font-size: 16px; /* Prevents zoom on iOS */
    background: var(--input-bg);
    transition: all 0.2s ease;
    box-sizing: border-box;
    min-height: var(--touch-target);
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.form-control:focus,
input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
    transform: translateY(-1px);
}

/* Touch-friendly buttons */
button,
.btn {
    min-height: var(--touch-target);
    padding: 16px 24px;
    border-radius: 8px;
    font-size: 16px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.btn-primary:hover,
.btn-primary:active {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 2px solid var(--border-color);
}

/* ===== MOBILE TABLE OPTIMIZATION ===== */
.table-container {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
    box-shadow: var(--shadow);
    margin: var(--mobile-margin) 0;
}

/* Hide table on mobile, show cards instead */
.records-table {
    display: none;
}

/* Mobile card layout for data */
.mobile-records-container {
    display: block;
    padding: 0;
}

.mobile-record-card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    border: 1px solid var(--border-color);
    position: relative;
    transition: all 0.2s ease;
}

.mobile-record-card:active {
    transform: translateY(1px);
    box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

.mobile-record-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
    flex-wrap: wrap;
    gap: 8px;
}

.mobile-record-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
    margin: 0;
}

.mobile-record-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    margin: 4px 0 0 0;
}

.mobile-record-status {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

.mobile-record-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 16px;
}

.mobile-record-detail {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.mobile-record-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.mobile-record-value {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-primary);
}

/* Mobile actions */
.mobile-record-actions {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 12px;
}

.mobile-action-btn {
    flex: 1;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    text-align: center;
    text-decoration: none;
    transition: all 0.2s ease;
    min-height: var(--touch-target);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ===== MOBILE SEARCH & FILTERS ===== */
.search-container {
    position: sticky;
    top: 80px;
    z-index: 100;
    background: var(--bg-primary);
    padding: var(--mobile-padding);
    margin: 0 -16px 16px -16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.search-box {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.search-input {
    width: 100%;
    padding: 16px;
    border: 2px solid var(--input-border);
    border-radius: 25px;
    font-size: 16px;
    background: var(--input-bg);
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.05);
}

.search-input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1), inset 0 2px 4px rgba(0,0,0,0.05);
}

.filter-chips {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 4px 0;
    -webkit-overflow-scrolling: touch;
}

.filter-chip {
    padding: 8px 16px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    font-size: 14px;
    white-space: nowrap;
    cursor: pointer;
    transition: all 0.2s ease;
    user-select: none;
    -webkit-user-select: none;
}

.filter-chip.active {
    background: #667eea;
    color: white;
    border-color: #667eea;
}

/* ===== MOBILE MODALS & DIALOGS ===== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2000;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    background: rgba(0,0,0,0.5);
    padding: 0;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.modal-content {
    width: 100%;
    max-width: 100vw;
    max-height: 85vh;
    background: var(--bg-secondary);
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.2);
    overflow: hidden;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modal.active .modal-content {
    transform: translateY(0);
}

.modal-header {
    padding: 20px var(--mobile-padding) 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: relative;
}

.modal-header::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 40px;
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
}

.modal-body {
    padding: 20px var(--mobile-padding);
    overflow-y: auto;
    max-height: 60vh;
}

/* ===== MOBILE NOTIFICATIONS ===== */
.notification {
    position: fixed;
    top: 90px;
    left: var(--mobile-padding);
    right: var(--mobile-padding);
    z-index: 3000;
    padding: 16px 20px;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    transform: translateY(-100px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.notification.show {
    transform: translateY(0);
}

.notification-success {
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.95), rgba(21, 128, 61, 0.95));
    color: white;
    border: 1px solid rgba(255,255,255,0.2);
}

.notification-error {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.95), rgba(153, 27, 27, 0.95));
    color: white;
    border: 1px solid rgba(255,255,255,0.2);
}

.notification-warning {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.95), rgba(180, 83, 9, 0.95));
    color: white;
    border: 1px solid rgba(255,255,255,0.2);
}

/* ===== MOBILE LOADING STATES ===== */
.mobile-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px var(--mobile-padding);
    gap: 16px;
}

.mobile-loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top: 3px solid #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.mobile-loading-text {
    font-size: 16px;
    color: var(--text-secondary);
    text-align: center;
}

/* ===== MOBILE EMPTY STATES ===== */
.mobile-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px var(--mobile-padding) 40px;
    text-align: center;
    gap: 16px;
}

.mobile-empty-icon {
    font-size: 48px;
    opacity: 0.5;
}

.mobile-empty-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.mobile-empty-description {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
    margin: 0;
}

/* ===== RESPONSIVE BREAKPOINTS ===== */

/* Small phones (320px and up) */
@media (min-width: 320px) {
    .container {
        padding: 12px;
    }
    
    .mobile-record-details {
        grid-template-columns: 1fr;
        gap: 16px;
    }
}

/* Standard phones (375px and up) */
@media (min-width: 375px) {
    .container {
        padding: 16px;
    }
    
    .mobile-record-details {
        grid-template-columns: 1fr 1fr;
    }
    
    .brand-name {
        font-size: 18px !important;
    }
}

/* Large phones (425px and up) */
@media (min-width: 425px) {
    .modal {
        align-items: center;
        padding: 20px;
    }
    
    .modal-content {
        width: 90%;
        max-height: 80vh;
        border-radius: 16px;
        transform: scale(0.9);
    }
    
    .modal.active .modal-content {
        transform: scale(1);
    }
    
    .mobile-record-actions {
        flex-direction: row;
    }
}

/* Mobile specific (below 768px) - Additional responsive rules */
@media (max-width: 767px) {
    /* Sidebar rules are defined above at line 332 - don't duplicate them here */
    /* This section is for other mobile-specific layout rules only */

    .main-content {
        width: 100% !important;
        margin-left: 0 !important;
        padding: var(--mobile-padding) !important;
    }

    .app-layout {
        display: block !important;
        flex-direction: column !important;
    }

    .container {
        width: 100% !important;
        max-width: 100vw !important;
        padding: var(--mobile-padding) !important;
        margin: 0 !important;
        margin-top: 60px !important; /* Space for fixed header - very compact */
    }
}

/* Tablets (768px and up) */
@media (min-width: 768px) {
    .modern-sidebar {
        position: relative !important;
        transform: translateX(0) !important;
        width: 250px;
        height: auto;
        box-shadow: none;
    }
    
    .mobile-menu-toggle {
        display: none !important;
    }
    
    .sidebar-overlay {
        display: none !important;
    }
    
    .records-table {
        display: table;
    }
    
    .mobile-records-container {
        display: none;
    }
    
    .container {
        display: flex;
        padding: 20px;
        gap: 20px;
    }
    
    .main-content {
        flex: 1;
    }
    
    .search-container {
        position: relative;
        top: auto;
        margin: 0 0 20px 0;
        box-shadow: var(--shadow);
    }
    
    .search-box {
        flex-direction: row;
        align-items: center;
    }
    
    .notification {
        top: 20px;
        left: auto;
        right: 20px;
        width: 400px;
    }
}

/* Small desktop (1024px and up) */
@media (min-width: 1024px) {
    .modern-sidebar {
        width: 280px;
    }
    
    .container {
        max-width: 1200px;
        margin: 0 auto;
        margin-top: 70px; /* Space for fixed header - balanced spacing */
        padding: 30px;
    }
    
    .mobile-record-details {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Large desktop (1440px and up) */
@media (min-width: 1440px) {
    .container {
        max-width: 1400px;
        margin-top: 70px; /* Space for fixed header - balanced spacing */
        padding: 40px;
    }
    
    .mobile-record-details {
        grid-template-columns: repeat(4, 1fr);
    }
}

/* ===== PRINT STYLES ===== */
@media print {
    .top-header,
    .modern-sidebar,
    .mobile-menu-toggle,
    .search-container,
    .mobile-record-actions,
    .sidebar-overlay {
        display: none !important;
    }
    
    .container {
        padding: 0;
        max-width: 100%;
    }
    
    .main-content {
        margin: 0;
        padding: 0;
    }
    
    .mobile-record-card {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ccc;
    }
}

/* ===== ACCESSIBILITY IMPROVEMENTS ===== */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Dark mode removed - system will always use light theme */

/* High contrast mode support */
@media (prefers-contrast: high) {
    .form-control:focus,
    input:focus,
    select:focus,
    textarea:focus {
        border-width: 3px;
        box-shadow: 0 0 0 2px currentColor;
    }
    
    .btn-primary {
        background: #000;
        border: 2px solid #fff;
    }
}

/* ===== iOS SPECIFIC FIXES ===== */
@supports (-webkit-touch-callout: none) {
    /* iOS Safari specific styles */
    .form-control,
    input,
    select,
    textarea {
        border-radius: 0;
    }
    
    .notification {
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        background: rgba(0,0,0,0.95);
    }
}

/* ===== ANDROID SPECIFIC FIXES ===== */
@media (max-width: 768px) and (orientation: landscape) {
    .modal-content {
        max-height: 70vh;
    }
    
    .mobile-empty-state {
        padding: 20px var(--mobile-padding);
    }
}/* ===== MOBILE & TABLET UX ENHANCEMENTS ===== */
/* Based on Playwright analysis - October 2025 */

/* Fix horizontal scrolling globally */
@media (max-width: 1024px) {
    html, body {
        overflow-x: hidden !important;
        max-width: 100vw;
    }

    .container, .main-content, .app-container {
        max-width: 100% !important;
        overflow-x: hidden;
    }

    /* Fix tables that cause horizontal scroll */
    table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }

    /* Responsive images */
    img {
        max-width: 100%;
        height: auto;
    }
}

/* ===== TOUCH TARGET IMPROVEMENTS ===== */
/* WCAG recommends minimum 44x44px touch targets */

@media (max-width: 768px) {
    /* Global button improvements */
    button, .btn, .action-btn, input[type="submit"], input[type="button"] {
        min-height: 48px !important;
        min-width: 48px !important;
        padding: 14px 20px !important;
        font-size: 16px !important;
        touch-action: manipulation; /* Disable double-tap zoom */
    }

    /* Primary buttons */
    .btn-primary, .primary-btn {
        min-height: 52px !important;
        padding: 16px 24px !important;
        font-size: 17px !important;
        font-weight: 600;
    }

    /* Table action buttons */
    .action-btn, td button, .data-grid button {
        width: 48px !important;
        height: 48px !important;
        padding: 12px !important;
        margin: 4px !important;
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }

    /* Links and navigation */
    a, .nav-link, .sidebar-link, .dropdown-item {
        min-height: 44px !important;
        padding: 12px 16px !important;
        display: flex;
        align-items: center;
    }

    /* Form inputs */
    input, select, textarea {
        min-height: 48px !important;
        font-size: 16px !important; /* Prevents zoom on iOS */
        padding: 12px 16px !important;
    }

    /* Increase spacing between tappable elements */
    button + button,
    .btn + .btn,
    .action-btn + .action-btn {
        margin-left: 12px !important;
    }
}

/* ===== TABLET-SPECIFIC OPTIMIZATIONS ===== */

@media (min-width: 769px) and (max-width: 1024px) {
    /* Tablet touch targets - slightly smaller than mobile but still accessible */
    button, .btn, .action-btn {
        min-height: 44px !important;
        min-width: 44px !important;
        padding: 12px 18px !important;
        font-size: 15px !important;
    }

    /* Tablet forms */
    input, select, textarea {
        min-height: 44px !important;
        font-size: 15px !important;
        padding: 10px 14px !important;
    }
}

/* ===== MOBILE SIDEBAR OVERLAY ===== */

/* Mobile sidebar behavior for sm breakpoint and below */
@media (max-width: 640px) {
    .sidebar-mobile-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1000;
        display: none;
        opacity: 0;
        transition: opacity 0.3s ease; /* duration-300 from design system */
        pointer-events: auto;
    }

    .sidebar-mobile-overlay.active {
        display: block;
        opacity: 1;
    }

    /* Hide sidebar by default on mobile */
    .modern-sidebar {
        transform: translateX(-100%) !important;
        transition: transform 0.3s ease; /* duration-300 from design system */
        z-index: 1001 !important; /* Above overlay (1000) */
        /* CRITICAL: Don't set overflow-y: auto on sidebar container */
        /* Only .sidebar-nav should scroll (see rules at line 334) */
        overflow: hidden !important;
        display: flex !important;
        flex-direction: column !important;
        pointer-events: auto !important;
    }

    .modern-sidebar.mobile-open {
        transform: translateX(0) !important;
        z-index: 1001 !important; /* Ensure sidebar stays above overlay (1000) */
    }
}

/* ===== MOBILE TYPOGRAPHY ===== */

@media (max-width: 768px) {
    /* Ensure readable text on mobile */
    body, p, span, div, td, th, label {
        font-size: 16px !important;
        line-height: 1.5 !important;
    }

    /* Headings */
    h1 {
        font-size: 28px !important;
        line-height: 1.3 !important;
    }

    h2 {
        font-size: 24px !important;
        line-height: 1.3 !important;
    }

    h3 {
        font-size: 20px !important;
        line-height: 1.4 !important;
    }

    h4, h5, h6 {
        font-size: 18px !important;
        line-height: 1.4 !important;
    }

    /* Small text should still be readable */
    small, .small-text {
        font-size: 14px !important;
    }
}

/* ===== MOBILE-FRIENDLY TABLES ===== */

@media (max-width: 768px) {
    /* Responsive table wrapper */
    .table-responsive, .data-grid-wrapper {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin-bottom: 1rem;
    }

    /* Table improvements */
    table {
        min-width: 600px; /* Prevent tables from being too narrow */
        font-size: 14px;
    }

    table th,
    table td {
        padding: 12px 8px !important;
        white-space: nowrap;
    }

    /* Make action columns sticky on mobile tables */
    table td:last-child,
    table th:last-child {
        position: sticky;
        right: 0;
        background: white;
        box-shadow: -2px 0 4px rgba(0,0,0,0.1);
    }
}

/* ===== MOBILE FORMS ===== */

@media (max-width: 768px) {
    /* Stack form fields */
    .form-row {
        flex-direction: column !important;
    }

    .form-group {
        width: 100% !important;
        margin-bottom: 16px !important;
    }

    /* Full-width inputs */
    .form-input, .form-control {
        width: 100% !important;
    }

    /* Larger labels for touch */
    label {
        font-size: 16px !important;
        font-weight: 600 !important;
        margin-bottom: 8px !important;
        display: block;
    }

    /* Radio buttons and checkboxes */
    input[type="radio"],
    input[type="checkbox"] {
        width: 24px !important;
        height: 24px !important;
        margin-right: 12px !important;
    }
}

/* ===== MOBILE MODALS ===== */

@media (max-width: 768px) {
    .modal, .modal-overlay {
        padding: 20px !important;
    }

    .modal-content {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        max-height: 90vh;
        overflow-y: auto;
    }

    .modal-header {
        padding: 20px !important;
    }

    .modal-body {
        padding: 20px !important;
    }

    .modal-footer {
        padding: 20px !important;
        flex-direction: column;
    }

    .modal-footer button {
        width: 100% !important;
        margin: 8px 0 !important;
    }
}

/* ===== MOBILE CARDS ===== */

@media (max-width: 768px) {
    .card {
        margin-bottom: 16px !important;
        border-radius: 12px !important;
    }

    .card-header {
        padding: 16px !important;
    }

    .card-body {
        padding: 16px !important;
    }
}

/* ===== FIX REPORTS.HTML HORIZONTAL SCROLL ===== */
/* Specific fix for reports page */

@media (max-width: 1024px) {
    /* Reports page containers */
    .reports-container,
    .report-grid,
    .report-list {
        max-width: 100% !important;
        overflow-x: hidden !important;
    }

    /* Report cards should stack on mobile */
    .report-card {
        width: 100% !important;
        margin-bottom: 16px !important;
    }
}

/* ===== MOBILE UTILITY CLASSES ===== */

@media (max-width: 768px) {
    /* Hide on mobile */
    .hide-mobile {
        display: none !important;
    }

    /* Show only on mobile */
    .show-mobile {
        display: block !important;
    }

    /* Full width on mobile */
    .mobile-full-width {
        width: 100% !important;
    }

    /* Stack on mobile */
    .mobile-stack {
        flex-direction: column !important;
    }

    /* Center on mobile */
    .mobile-center {
        text-align: center !important;
        justify-content: center !important;
    }
}

/* ===== PERFORMANCE OPTIMIZATIONS ===== */

/* Reduce animations on mobile for better performance */
@media (max-width: 768px) {
    *, *::before, *::after {
        animation-duration: 0.2s !important;
        transition-duration: 0.2s !important;
    }
}

/* ===== ACCESSIBILITY IMPROVEMENTS ===== */

/* Focus states for keyboard/screen reader users */
@media (max-width: 1024px) {
    *:focus {
        outline: 3px solid #667eea !important;
        outline-offset: 2px !important;
    }

    button:focus,
    a:focus,
    input:focus,
    select:focus,
    textarea:focus {
        box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.3) !important;
    }
}

/* END OF MOBILE & TABLET UX ENHANCEMENTS */
