/* ============================================
   ADVANCED MOBILE CSS FOR LEDGER MANAGEMENT
   Add this inside <style> tags or as separate CSS file
   ============================================ */

/* Mobile-Only Media Query - Applies to screens 768px and below */
@media only screen and (max-width: 768px) {
    
    /* ========== CSS VARIABLES ========== */
    :root {
        --primary-color: #667eea;
        --secondary-color: #764ba2;
        --success-color: #2ecc71;
        --danger-color: #e74c3c;
        --sidebar-width: 280px;
        --header-height: 60px;
        --transition-speed: 0.3s;
    }

    /* ========== BODY & BASE ========== */
    body {
        padding: 0 !important;
        overflow-x: hidden;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important;
    }

    .container {
        padding: 0 !important;
        max-width: 100% !important;
        margin: 0 !important;
    }

    /* ========== HAMBURGER SIDEBAR NAVIGATION ========== */
    
    /* Hide default navbar */
    .navbar {
        display: none !important;
    }

    /* Mobile Header with Hamburger */
    body::before {
        content: '';
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        height: var(--header-height);
        background: rgba(255, 255, 255, 0.98);
        backdrop-filter: blur(20px);
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
        z-index: 1000;
    }

    /* Create Mobile Header */
    .main-card::before {
        content: 'Client Ledgers';
        position: fixed;
        top: 0;
        left: 60px;
        right: 0;
        height: var(--header-height);
        display: flex;
        align-items: center;
        font-size: 18px;
        font-weight: 700;
        color: #333;
        z-index: 1001;
        padding-left: 15px;
    }

    /* Hamburger Menu Button */
    body::after {
        content: '\f0c9';
        font-family: 'Font Awesome 6 Free';
        font-weight: 900;
        position: fixed;
        top: 0;
        left: 0;
        width: 60px;
        height: var(--header-height);
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 22px;
        color: var(--primary-color);
        cursor: pointer;
        z-index: 1002;
        transition: all var(--transition-speed) ease;
    }

    /* Sidebar Container */
    #mobileSidebar {
        position: fixed;
        top: 0;
        left: -100%;
        width: var(--sidebar-width);
        height: 100vh;
        background: white;
        box-shadow: 4px 0 30px rgba(0, 0, 0, 0.2);
        z-index: 2000;
        transition: left var(--transition-speed) cubic-bezier(0.4, 0, 0.2, 1);
        overflow-y: auto;
        display: flex;
        flex-direction: column;
    }

    /* Sidebar Active State */
    body.sidebar-open #mobileSidebar {
        left: 0;
    }

    /* Sidebar Overlay */
    #sidebarOverlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(4px);
        z-index: 1999;
        opacity: 0;
        visibility: hidden;
        transition: all var(--transition-speed) ease;
    }

    body.sidebar-open #sidebarOverlay {
        opacity: 1;
        visibility: visible;
    }

    /* Sidebar Header */
    .sidebar-header {
        padding: 20px;
        background: var(--primary-gradient);
        color: white;
        display: flex;
        align-items: center;
        gap: 15px;
        border-bottom: 2px solid rgba(255, 255, 255, 0.2);
    }

    .sidebar-logo {
        width: 50px;
        height: 50px;
        background: rgba(255, 255, 255, 0.2);
        border-radius: 12px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 24px;
    }

    .sidebar-title {
        font-size: 20px;
        font-weight: 700;
    }

    /* Sidebar Menu */
    .sidebar-menu {
        flex: 1;
        padding: 20px 0;
    }

    .sidebar-menu-item {
        display: flex;
        align-items: center;
        gap: 15px;
        padding: 16px 25px;
        color: #333;
        font-size: 16px;
        font-weight: 500;
        cursor: pointer;
        transition: all 0.2s ease;
        border-left: 4px solid transparent;
    }

    .sidebar-menu-item:active {
        background: rgba(102, 126, 234, 0.1);
        border-left-color: var(--primary-color);
        transform: translateX(5px);
    }

    .sidebar-menu-item i {
        width: 24px;
        font-size: 20px;
        color: var(--primary-color);
    }

    .sidebar-divider {
        height: 1px;
        background: #e1e5e9;
        margin: 15px 20px;
    }

    /* Sidebar Logout */
    .sidebar-logout {
        padding: 20px;
        border-top: 2px solid #f0f0f0;
    }

    .sidebar-logout-btn {
        width: 100%;
        padding: 14px;
        background: var(--danger-gradient);
        color: white;
        border: none;
        border-radius: 12px;
        font-size: 16px;
        font-weight: 600;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 10px;
        cursor: pointer;
        box-shadow: 0 4px 15px rgba(231, 76, 60, 0.3);
    }

    .sidebar-logout-btn:active {
        transform: scale(0.98);
    }

    /* ========== MAIN CONTENT ADJUSTMENTS ========== */
    
    .main-card {
        border-radius: 0 !important;
        padding: 15px !important;
        margin: 0 !important;
        margin-top: var(--header-height) !important;
        box-shadow: none !important;
        min-height: calc(100vh - var(--header-height));
    }

    .page-header {
        text-align: center;
        margin-bottom: 20px !important;
        padding: 15px 10px !important;
        border-bottom: 2px solid #f0f0f0;
    }

    .page-header h1 {
        font-size: 22px !important;
        margin-bottom: 8px !important;
        color: #333;
    }

    .page-header p {
        font-size: 13px !important;
        color: #666;
    }

    /* ========== TOGGLE BUTTONS (Client/Supplier) ========== */
    
    .main-card > div:first-of-type {
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
        margin-bottom: 20px !important;
        padding: 0 5px !important;
    }

    .main-card > div:first-of-type button {
        width: 100% !important;
        padding: 14px 20px !important;
        border-radius: 12px !important;
        font-size: 15px !important;
        font-weight: 600 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 10px !important;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1) !important;
        transition: all 0.2s ease !important;
    }

    .main-card > div:first-of-type button:active {
        transform: scale(0.98) !important;
    }

    /* ========== SUMMARY SECTION ========== */
    
    #summarySection {
        margin: 0 -15px 20px -15px !important;
        padding: 20px 15px !important;
        border-radius: 0 !important;
    }

    #summarySection h3 {
        font-size: 18px !important;
        margin-bottom: 15px !important;
    }

    #summarySection > div:last-child {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    #summarySection > div:last-child > div {
        padding: 18px !important;
        border-radius: 12px !important;
    }

    #summarySection h4 {
        font-size: 12px !important;
        margin-bottom: 8px !important;
    }

    #summarySection .value,
    #totalCount,
    #totalClosingBalance {
        font-size: 24px !important;
        font-weight: 800 !important;
    }

    /* ========== SEARCH SECTION ========== */
    
    .search-section {
        margin: 0 -15px 20px -15px !important;
        padding: 15px !important;
        border-radius: 0 !important;
        background: #ffffff !important;
    }

    .search-grid {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    .form-group label {
        font-size: 12px !important;
        margin-bottom: 6px !important;
        color: #555;
        font-weight: 600;
    }

    .form-group input,
    .form-group select {
        padding: 12px 15px !important;
        border: 2px solid #e1e5e9 !important;
        border-radius: 10px !important;
        font-size: 15px !important;
        width: 100%;
    }

    .form-group input:focus,
    .form-group select:focus {
        border-color: var(--primary-color) !important;
        box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1) !important;
    }

    .search-btn {
        width: 100% !important;
        padding: 14px !important;
        margin-top: 8px !important;
        border-radius: 10px !important;
        font-size: 16px !important;
        font-weight: 600 !important;
    }

    /* ========== CLIENT/SUPPLIER CARDS ========== */
    
    .clients-grid {
        grid-template-columns: 1fr !important;
        gap: 15px !important;
        margin-top: 0 !important;
        padding: 0 5px !important;
    }

    .client-card {
        padding: 18px !important;
        border-radius: 16px !important;
        background: white !important;
        border: 2px solid #e1e5e9 !important;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06) !important;
        transition: all 0.3s ease !important;
    }

    .client-card:active {
        transform: scale(0.98) !important;
        box-shadow: 0 6px 25px rgba(102, 126, 234, 0.2) !important;
        border-color: var(--primary-color) !important;
    }

    .client-card h3 {
        font-size: 17px !important;
        margin-bottom: 12px !important;
        color: #333;
    }

    .client-card p {
        font-size: 13px !important;
        margin-bottom: 6px !important;
        color: #666;
        line-height: 1.6;
    }

    .client-card .balance {
        margin-top: 15px !important;
        padding-top: 15px !important;
        font-size: 16px !important;
        font-weight: 700 !important;
        color: var(--primary-color) !important;
    }

    /* ========== EMPTY STATE ========== */
    
    .empty-state {
        padding: 60px 20px !important;
        text-align: center;
    }

    .empty-state i {
        font-size: 48px !important;
        color: #667eea;
        margin-bottom: 15px !important;
    }

    .empty-state h3 {
        font-size: 20px !important;
        margin-bottom: 10px !important;
        color: #333;
    }

    .empty-state p {
        font-size: 14px !important;
        color: #999;
    }

    /* ========== MODAL ADJUSTMENTS ========== */
    
    .modal {
        padding: 0 !important;
        align-items: flex-end !important;
    }

    .modal-content {
        border-radius: 24px 24px 0 0 !important;
        padding: 20px 15px !important;
        max-height: 90vh !important;
        width: 100% !important;
        animation: slideUp 0.3s ease !important;
    }

    @keyframes slideUp {
        from {
            transform: translateY(100%);
        }
        to {
            transform: translateY(0);
        }
    }

    .modal-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 15px !important;
        padding-bottom: 15px !important;
    }

    .modal-header > div:first-child {
        width: 100%;
    }

    .modal-header h2 {
        font-size: 20px !important;
        margin-bottom: 8px !important;
        color: #333;
    }

    .modal-header p {
        font-size: 13px !important;
        color: #666;
    }

    .modal-header button {
        width: 100% !important;
        padding: 12px !important;
        justify-content: center !important;
    }

    /* Modal Actions */
    .modal-actions {
        display: flex !important;
        flex-direction: column !important;
        gap: 10px !important;
        margin-bottom: 20px !important;
    }

    .modal-actions button {
        width: 100% !important;
        padding: 14px !important;
        border-radius: 10px !important;
        font-size: 15px !important;
    }

    /* Payment Section */
    .payment-section {
        padding: 15px !important;
        border-radius: 12px !important;
        margin-bottom: 20px !important;
    }

    .payment-section h3 {
        font-size: 16px !important;
        margin-bottom: 15px !important;
    }

    .payment-grid {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    /* ========== TABLE IMPROVEMENTS ========== */
    
    #ledgerTableContainer {
        overflow-x: auto !important;
        margin: 0 -15px !important;
        padding: 0 15px !important;
    }

    table {
        font-size: 12px !important;
        min-width: 600px !important;
    }

    th {
        padding: 10px 8px !important;
        font-size: 11px !important;
        position: sticky !important;
        top: 0 !important;
        z-index: 10 !important;
    }

    td {
        padding: 10px 8px !important;
        font-size: 12px !important;
    }

    tfoot td {
        padding: 10px 8px !important;
        font-size: 13px !important;
        font-weight: 700 !important;
    }

    /* ========== SUMMARY BOX ========== */
    
    .summary-box {
        padding: 20px 15px !important;
        border-radius: 16px !important;
        margin: 20px -15px 0 -15px !important;
    }

    .summary-box h3 {
        font-size: 18px !important;
        margin-bottom: 15px !important;
    }

    .summary-grid {
        grid-template-columns: 1fr !important;
        gap: 15px !important;
    }

    .summary-item h4 {
        font-size: 13px !important;
        margin-bottom: 8px !important;
    }

    .summary-item .value {
        font-size: 24px !important;
        font-weight: 800 !important;
    }

    /* ========== ALERT/NOTIFICATION ========== */
    
    .alert {
        top: 70px !important;
        right: 10px !important;
        left: 10px !important;
        padding: 15px 20px !important;
        font-size: 14px !important;
        border-radius: 12px !important;
        box-shadow: 0 6px 25px rgba(0, 0, 0, 0.2) !important;
    }

    /* ========== FLOATING ACTION STYLES ========== */
    
    .nav-btn.primary {
        background: var(--primary-gradient) !important;
        box-shadow: 0 4px 15px rgba(102, 126, 234, 0.3) !important;
    }

    .nav-btn.secondary {
        background: #f0f0f0 !important;
        color: #333 !important;
    }

    .nav-btn.warning {
        background: linear-gradient(135deg, #f39c12, #e67e22) !important;
    }

    /* ========== SMOOTH SCROLLING ========== */
    
    html {
        scroll-behavior: smooth;
    }

    .modal-content {
        scroll-behavior: smooth;
    }

    /* ========== TRANSFER MODAL ========== */
    
    #transferModal .modal-content {
        max-width: 100% !important;
        padding: 20px 15px !important;
    }

    #transferModal .modal-header {
        flex-direction: column !important;
        gap: 12px !important;
    }

    #transferModal .modal-header > div:first-child {
        width: 100%;
    }

    #transferModal h2 {
        font-size: 18px !important;
    }

    #transferModal h3 {
        font-size: 16px !important;
    }

    #transferModal h4 {
        font-size: 14px !important;
    }

    #transferModal > div > div {
        padding: 15px !important;
        border-radius: 12px !important;
        margin-bottom: 15px !important;
    }

    #transferModal ul {
        font-size: 13px !important;
        line-height: 1.8 !important;
    }

    #transferModal .modal-content > div:last-child {
        flex-direction: column !important;
        gap: 10px !important;
    }

    #transferModal .modal-content > div:last-child button {
        width: 100% !important;
        padding: 14px !important;
    }

    /* ========== UTILITY CLASSES ========== */
    
    .mobile-hide {
        display: none !important;
    }

    .mobile-show {
        display: block !important;
    }

    /* ========== TOUCH FEEDBACK ========== */
    
    button:active,
    .client-card:active,
    .sidebar-menu-item:active {
        opacity: 0.8;
    }

    /* ========== ACCESSIBILITY ========== */
    
    *:focus {
        outline: 2px solid var(--primary-color);
        outline-offset: 2px;
    }

    /* ========== LOADING STATES ========== */
    
    .loading {
        pointer-events: none;
        opacity: 0.6;
    }

    /* ========== RESPONSIVE TYPOGRAPHY ========== */
    
    body {
        font-size: 14px;
        line-height: 1.6;
    }

    h1 { font-size: 24px; }
    h2 { font-size: 20px; }
    h3 { font-size: 18px; }
    h4 { font-size: 16px; }
    h5 { font-size: 14px; }
    h6 { font-size: 12px; }

    /* ========== PRINT STYLES OVERRIDE ========== */
    
    @media print {
        body {
            padding: 20px !important;
        }
        
        .mobile-header,
        #mobileSidebar,
        #sidebarOverlay {
            display: none !important;
        }
    }
}

/* ============================================
   VERY SMALL SCREENS (320px and below)
   ============================================ */
@media only screen and (max-width: 360px) {
    :root {
        --sidebar-width: 260px;
        --header-height: 56px;
    }

    .page-header h1 {
        font-size: 20px !important;
    }

    .client-card h3 {
        font-size: 16px !important;
    }

    table {
        font-size: 11px !important;
    }

    th, td {
        padding: 8px 6px !important;
    }
}