/* ===================================
   Additional Mobile Responsive Styles
   =================================== */

/* Responsive Tables - Horizontal Scroll */
@media (max-width: 768px) {

    .table-container,
    .data-table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
        max-width: 100%;
    }

    .data-table {
        min-width: 600px;
        /* Prevent table from being too narrow */
        width: 100%;
    }

    /* Ensure list containers don't overflow */
    .list-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
        max-width: 100%;
    }
}

/* Very Small Screens - Card Layout for Tables */
@media (max-width: 480px) {

    .table-container,
    .data-table-container {
        overflow-x: visible;
        width: 100%;
    }

    .data-table {
        min-width: 100%;
        width: 100%;
    }

    .data-table thead {
        display: none;
    }

    .data-table,
    .data-table tbody,
    .data-table tr,
    .data-table td {
        display: block;
        width: 100%;
        box-sizing: border-box;
        /* Force box sizing */
    }

    .data-table tr {
        margin-bottom: 0.75rem;
        border: 1px solid var(--gray-200);
        border-radius: var(--radius-md);
        padding: 0.75rem;
        background: var(--bg-primary);
        box-shadow: var(--shadow-sm);
    }

    .data-table td {
        padding: 0.5rem 0;
        border-bottom: 1px solid var(--gray-100);
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        /* Better for multiline */
        text-align: right;
        word-break: break-word;
        /* Prevent overflow */
    }

    .data-table td:last-child {
        border-bottom: none;
        padding-bottom: 0;
    }

    .data-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-secondary);
        margin-right: 1rem;
        text-align: left;
        flex-shrink: 0;
        /* Keep label intact */
        max-width: 40%;
        /* Limit label width */
    }

    /* Button groups in table cells */
    .data-table td .btn {
        margin: 0.125rem;
    }
}

/* Mobile Stats Grid */
@media (max-width: 640px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .stat-card {
        padding: var(--space-lg);
    }
}

/* Mobile Invoice Cards */
@media (max-width: 768px) {

    .invoice-card,
    .date-group {
        margin-bottom: 1rem;
    }

    .invoice-card {
        padding: 1rem !important;
    }
}

/* Mobile Stock Items */
@media (max-width: 768px) {
    .stock-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .stock-actions {
        width: 100%;
        display: flex;
        justify-content: space-between;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .stock-actions .btn {
        flex: 1;
        min-width: 100px;
    }
}

/* Mobile Cart Items (Sell Section) */
@media (max-width: 640px) {
    .cart-item {
        flex-direction: column;
        align-items: flex-start;
        padding: 1rem;
    }

    .cart-item-details {
        width: 100%;
        margin-bottom: 0.5rem;
    }

    .cart-item-actions {
        width: 100%;
        display: flex;
        justify-content: space-between;
    }

    /* Quantity presets in 2 columns */
    #quantity-presets {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    /* Payment buttons stack on very small screens */
    .payment-buttons {
        grid-template-columns: 1fr !important;
    }
}

/* Mobile Modal Optimizations */
@media (max-width: 640px) {
    .modal {
        border-radius: var(--radius-md);
    }

    .modal-body {
        max-height: calc(90vh - 120px);
        overflow-y: auto;
    }

    /* Full-screen invoice builder on mobile */
    .modal.invoice-modal {
        max-width: 100vw;
        max-height: 100vh;
        margin: 0;
        border-radius: 0;
    }
}

/* Tablet Optimizations */
@media (min-width: 641px) and (max-width: 1023px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .module-actions {
        flex-wrap: wrap;
    }

    .module-actions .btn {
        flex: 1;
        min-width: 150px;
    }
}

/* Sell Section Mobile Fixes */
@media (max-width: 768px) {

    #sell-section-welcome,
    #invoice-builder-container {
        width: 100%;
        max-width: 100%;
        margin: 0 auto;
        box-sizing: border-box;
    }

    .invoice-builder-container .card {
        width: 100%;
        max-width: 100%;
        margin: 0;
        box-sizing: border-box;
    }

    /* Ensure cart and invoice elements don't overflow */
    .cart-items,
    .invoice-summary,
    .payment-buttons {
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }
}

/* Landscape Mode - Sell Section */
@media (max-height: 600px) and (orientation: landscape) {

    #sell-section-welcome,
    #invoice-builder-container {
        width: 100%;
        max-width: 100vw;
        overflow-x: hidden;
    }

    .card {
        width: 100%;
        max-width: 100%;
        margin-left: 0;
        margin-right: 0;
    }
}