/* css/responsive.css (Final New Version - Focus on Small Screens) */

/* === 1. Medium Screens (Tablets, Small Laptops) ~1024px === */
@media (max-width: 1024px) {
    #sidebar {
        position: fixed; left: 0; top: 0; height: 100vh; height: 100dvh; z-index: 1000;
        width: 250px;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        transform: translateX(-100%); /* Start hidden */
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 5px 0 15px rgba(0,0,0,0.15);
        background-color: var(--bg-sidebar);
        color: var(--text-color-secondary);
        border-right: 1px solid var(--border-color);
    }
    body.dark-theme #sidebar { box-shadow: 5px 0 20px rgba(0,0,0,0.5); }
    #sidebar.sidebar-visible { transform: translateX(0); }

    #main-content { padding: 1.5rem; padding-top: 75px; width: 100%; }
    #app-container { flex-direction: column; width: 100%; }

    #mobile-header {
        display: flex; align-items: center; padding: 0 1.5rem;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
        position: fixed; top: 0; left: 0; right: 0; z-index: 900; height: 60px;
        background-color: var(--bg-card); border-bottom: 1px solid var(--border-color);
        transition: background-color var(--transition-speed);
    }
    body.dark-theme #mobile-header { box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3); }
    #mobile-page-title { font-size: 1.25rem; margin: 0; color: var(--text-color-primary); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex-grow: 1; text-align: left; margin-left: 10px; }

    #menu-toggle-btn {
        background: none;
        border: none;
        padding: 0; /* Remove padding */
        margin: 0; /* Remove margin */
        margin-right: 15px; /* Add margin back for spacing */
        cursor: pointer;
        width: 24px; /* Fixed width */
        height: 18px; /* Fixed height based on lines */
        display: flex; /* Use flexbox to space lines */
        flex-direction: column;
        justify-content: space-between; /* Creates space between lines */
        flex-shrink: 0;
        outline: none; /* Remove focus outline */
    }

    #menu-toggle-btn span {
        display: block;
        height: 2px; /* Line thickness */
        width: 100%; /* Full width of button */
        border-radius: 1px; /* Slightly rounded ends */
        background-color: var(--text-color-primary); /* Use primary text color (White in dark theme) */
        transition: background-color var(--transition-speed);
        /* Remove margins from spans, rely on justify-content */
        margin-top: 0 !important;
    }

    #menu-close-btn { display: block; position: absolute; top: 8px; right: 12px; background: none; border: none; font-size: 2.2rem; cursor: pointer; padding: 0; width: auto; line-height: 1; color: var(--text-color-muted); }
    #menu-close-btn:hover { color: var(--text-color-primary); }

    /* Adjust grids */
    #dashboard-main-grid { grid-template-areas: "stats stats" "chart1 chart2" "lowstock activity"; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
    .settings-grid, .invoice-grid-container, .sales-grid-container { grid-template-columns: 1fr; } /* Stack earlier */
    .date-filter-grid { grid-template-columns: 1fr 1fr; }
    .date-filter-grid .form-group:last-child { grid-column: 1 / -1; }
    .date-filter-grid button { width: 100%; margin-top: 1rem; }

    .chart-wrapper { height: 35vh; }
}


/* === 2. Small Tablets / Large Phones (~768px and below) === */
@media (max-width: 768px) {
    body { font-size: 15px; }
    #main-content { padding: 1.2rem; padding-top: 70px; }
    .page h1, .page-header h1 { font-size: 1.5rem; }
    .page-header { flex-direction: column; align-items: stretch; gap: 12px; margin-bottom: 1.5rem; }
    .date-filter-container { width: 100%; }
    .date-filter-container select { width: 100%; }
    .form-card, .table-container { padding: 1.5rem; }
    .form-card h3, .table-container h3 { font-size: 1.25rem; }
    .form-grid { grid-template-columns: 1fr; }
    .date-filter-grid { grid-template-columns: 1fr; }

    /* Dashboard */
    #dashboard-main-grid { grid-template-areas: "stats" "chart1" "chart2" "lowstock" "activity"; grid-template-columns: 1fr; gap: 1.5rem; }
    #dashboard-stats-row { grid-template-columns: 1fr 1fr; gap: 1rem; } /* Keep stats 2-col */
    .stat-card p { font-size: 1.8rem; }
    .chart-wrapper { height: 40vh; overflow: hidden; }

    /* Tables */
    .table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    table { table-layout: auto; width: auto; min-width: 550px; /* Reduced min-width slightly */ border-spacing: 0; }
    th, td { padding: 10px 12px; font-size: 0.9rem; white-space: nowrap; }

    /* Hide specific columns (adjust as needed) */
    #products-table th:nth-child(2), #products-table td:nth-child(2), /* Cat */
    #products-table th:nth-child(5), #products-table td:nth-child(5) { display: none; } /* Buy */
    #expenses-table th:nth-child(3), #expenses-table td:nth-child(3) { display: none; } /* Cat */
    #contacts-table th:nth-child(3), #contacts-table td:nth-child(3) { display: none; } /* Email */
    #report-ledger-table th:nth-child(3), #report-ledger-table td:nth-child(3) { display: none; } /* Type */
    #invoice-history-table th:nth-child(5), #invoice-history-table td:nth-child(5) { display: none; } /* Status */
    #po-table th:nth-child(3), #po-table td:nth-child(3), /* Supplier */
    #po-table th:nth-child(4), #po-table td:nth-child(4) { display: none; } /* Items */
    #staff-table th:nth-child(3), #staff-table td:nth-child(3) { display: none; } /* Status */
    #modal-po-items-table th:nth-child(3), #modal-po-items-table td:nth-child(3) { display: none; } /* Received */

    /* Action Buttons */
    .sales-actions, .invoice-actions { flex-direction: column; gap: 10px; }
    .sales-actions button, .invoice-actions button { width: 100%; margin: 0 !important; }

    /* Modals */
    .modal-content { width: 95%; max-height: 90vh; padding: 1.8rem; }
    .modal-content h2 { font-size: 1.5rem; }
}

/* === 3. Smaller Mobile Phones (~480px and below) === */
@media (max-width: 480px) {
     body { font-size: 14px; }
     #main-content { padding: 1rem; padding-top: 65px; } /* Less padding */
     .page h1, .page-header h1 { font-size: 1.4rem; }
     .form-card, .table-container { padding: 1rem; } /* Less padding */
     .form-card h3, .table-container h3 { font-size: 1.15rem; }

     #dashboard-stats-row { grid-template-columns: 1fr; } /* Stack all stats */
     .stat-card { padding: 1rem 1.2rem; }
     .stat-card p { font-size: 1.6rem; }
     .chart-wrapper { height: 45vh; }

     th, td { padding: 9px 10px; font-size: 0.85rem; } /* Smaller table text */
     table { min-width: 400px; } /* Further reduce min-width */
     .table-wrapper { margin-left: -1rem; margin-right: -1rem; padding-left: 1rem; padding-right: 1rem; } /* Allow wrapper scroll to edge */

    /* Consider hiding more columns on very small screens if needed */
    #products-table th:nth-child(4), #products-table td:nth-child(4) { display: none; } /* Hide Reorder Pt. */
    #expenses-table th:nth-child(2), #expenses-table td:nth-child(2) { display: none; } /* Hide Title */
    #contacts-table th:nth-child(2), #contacts-table td:nth-child(2) { display: none; } /* Hide Type */
    #invoice-history-table th:nth-child(2), #invoice-history-table td:nth-child(2) { display: none; } /* Hide Inv # */
    #po-table th:nth-child(2), #po-table td:nth-child(2) { display: none; } /* Hide PO # */
    #report-ledger-table th:nth-child(2), #report-ledger-table td:nth-child(2) { display: none; } /* Hide Description */


     button { padding: 10px 15px; font-size: 0.95rem; }
     .btn-delete, .btn-edit, .btn-view { padding: 5px 8px; font-size: 0.8rem; }
     .modal-content { padding: 1.5rem; }
     #mobile-header { padding: 0 1rem; height: 55px; }
     #mobile-page-title { font-size: 1.15rem; }
}

/* === 4. iPhone SE Specific (375px width and below) === */
@media (max-width: 375px) {
    body { font-size: 13px; } /* Even smaller base font */
    #main-content { padding: 0.8rem; padding-top: 60px; }
    .page h1, .page-header h1 { font-size: 1.3rem; }
    .form-card, .table-container { padding: 0.8rem; }
    .form-card h3, .table-container h3 { font-size: 1.1rem; }
    .stat-card { padding: 0.8rem 1rem; }
    .stat-card p { font-size: 1.5rem; }
    th, td { padding: 8px 8px; font-size: 0.8rem; }
    table { min-width: 350px; }
    .table-wrapper { margin-left: -0.8rem; margin-right: -0.8rem; padding-left: 0.8rem; padding-right: 0.8rem; }
    button { padding: 8px 12px; font-size: 0.9rem; }
    .btn-delete, .btn-edit, .btn-view { padding: 4px 6px; }
    #mobile-header { height: 50px; }
    #mobile-page-title { font-size: 1.1rem; }
    #menu-toggle-btn {
        background: none;
        border: none;
        padding: 0; /* Remove padding */
        margin: 0; /* Remove margin */
        margin-right: 15px; /* Add margin back for spacing */
        cursor: pointer;
        width: 24px; /* Fixed width */
        height: 18px; /* Fixed height based on lines */
        display: flex; /* Use flexbox to space lines */
        flex-direction: column;
        justify-content: space-between; /* Creates space between lines */
        flex-shrink: 0;
        outline: none; /* Remove focus outline */
    }

    #menu-toggle-btn span {
        display: block;
        height: 2px; /* Line thickness */
        width: 100%; /* Full width of button */
        border-radius: 1px; /* Slightly rounded ends */
        background-color: var(--text-color-primary); /* Use primary text color (White in dark theme) */
        transition: background-color var(--transition-speed);
        /* Remove margins from spans, rely on justify-content */
        margin-top: 0 !important;
    }
    .modal-content { padding: 1rem; }
}