/* Admin pages — tables, DataTables pagination, forms on mobile */

.main-content .card-body {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.main-content .table {
    margin-bottom: 0;
}

.main-content .dataTables_wrapper {
    width: 100%;
    overflow-x: visible;
}

.main-content .dataTables_wrapper .row {
    margin-left: 0;
    margin-right: 0;
}

.main-content .dataTables_wrapper .dataTables_length,
.main-content .dataTables_wrapper .dataTables_filter {
    margin-bottom: 0.75rem;
}

.main-content .dataTables_wrapper .dataTables_filter input {
    max-width: 100%;
}

/* Pagination: show all page numbers (2, 3, 4…) — scroll if needed */
.main-content .dataTables_wrapper .dataTables_paginate {
    width: 100%;
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    padding: 4px 0 8px;
    text-align: center;
}

.main-content .dataTables_wrapper .dataTables_paginate .pagination {
    flex-wrap: wrap;
    justify-content: center;
    gap: 4px;
    margin: 0;
    padding: 0;
}

.main-content .dataTables_wrapper .dataTables_paginate .page-link {
    min-width: 2.25rem;
    text-align: center;
    padding: 0.35rem 0.5rem;
}

.main-content .dataTables_wrapper .dataTables_info {
    padding-top: 0.5rem;
    font-size: 0.85rem;
    text-align: center;
}

@media (max-width: 992px) {
    .main-content {
        padding-bottom: calc(72px + env(safe-area-inset-bottom)) !important;
    }

    .top-bar {
        flex-direction: column;
        align-items: stretch !important;
        gap: 0.5rem;
    }

    .top-bar h4 {
        font-size: 1.1rem;
    }

    .top-bar .d-flex,
    .top-bar .btn {
        width: 100%;
    }

    .top-bar .d-flex.gap-2 {
        flex-wrap: wrap;
    }

    .workflow-steps .workflow-step {
        padding: 0.5rem;
    }

    .workflow-steps .step-num {
        width: 28px;
        height: 28px;
        font-size: 0.85rem;
    }

    .row.g-4 > [class*="col-"] {
        margin-bottom: 0.5rem;
    }

    .main-content .dataTables_wrapper > .row:last-child {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    .main-content .dataTables_wrapper .dataTables_paginate {
        order: 2;
    }

    .main-content .dataTables_wrapper .dataTables_info {
        order: 1;
    }

    .table .btn-sm {
        padding: 0.2rem 0.4rem;
        font-size: 0.75rem;
    }

    .table td,
    .table th {
        font-size: 0.8rem;
        vertical-align: middle;
    }
}

@media (max-width: 576px) {
    .main-content .dataTables_wrapper .dataTables_length select {
        max-width: 100%;
    }
}

/* Stock audit — category flow + mobile cards */
.page-audit .audit-table-wrap {
    max-height: min(60vh, 520px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.page-audit .audit-history-wrap {
    max-height: min(50vh, 420px);
    overflow-y: auto;
}

.page-audit .pur-inline-cat-grid {
    max-height: 240px;
    overflow-y: auto;
}

@media (max-width: 576px) {
    .page-audit .audit-stock-table thead {
        display: none;
    }

    .page-audit .audit-stock-table tbody tr {
        display: block;
        border-bottom: 1px solid var(--border, #e2e8f0);
        padding: 10px 12px;
    }

    .page-audit .audit-stock-table tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        border: none;
        padding: 4px 0;
    }

    .page-audit .audit-stock-table tbody td::before {
        content: attr(data-label);
        font-weight: 700;
        font-size: 11px;
        color: var(--text-muted, #64748b);
        margin-right: 8px;
    }

    .page-audit .audit-stock-table tbody td:last-child {
        justify-content: flex-end;
    }

    #auditSearch {
        font-size: 16px;
    }
}

/* Purchase page */
.page-purchase .purchase-qty-row > [class*="col-"] {
    margin-bottom: 0.5rem;
}

.page-purchase .qty-stepper {
    width: 100%;
}

.page-purchase .qty-stepper .btn {
    min-width: 44px;
    font-size: 1.25rem;
}

.page-purchase .qty-stepper .form-control {
    min-width: 3rem;
}

.page-purchase .purchase-recent-wrap {
    max-height: none;
    overflow: visible;
}

@media (max-width: 992px) {
    .page-purchase .purchase-layout > [class*="col-"] {
        flex: 0 0 100%;
        max-width: 100%;
    }
}

/* ——— Products page + Add/Edit modal ——— */
.page-products .workflow-step-row .workflow-step {
    padding: 0.65rem 0.5rem;
}

/* Modal: body scrolls, footer always visible */
#productModal .product-modal-dialog {
    max-width: 720px;
    width: calc(100% - 1.5rem);
    margin: 0.75rem auto;
    max-height: calc(100dvh - 1.5rem);
    display: flex;
    align-items: center;
}

#productModal .modal-content {
    max-height: calc(100dvh - 1.5rem);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    width: 100%;
}

#productModal .product-modal-form {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    max-height: calc(100dvh - 1.5rem);
    overflow: hidden;
}

#productModal .product-modal-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    padding: 1rem 1.25rem;
}

#productModal .product-modal-body .alert {
    font-size: 0.85rem;
    line-height: 1.45;
}

#productModal .product-modal-footer {
    display: flex !important;
    flex-wrap: wrap;
    flex-shrink: 0 !important;
    align-items: center;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.75rem 1rem !important;
    margin: 0 !important;
    border-top: 1px solid var(--border, #e2e8f0);
    background: var(--bg-surface, #fff);
    position: relative;
    z-index: 5;
    box-shadow: 0 -4px 14px rgba(15, 23, 42, 0.08);
}

#productModal .product-modal-footer .btn {
    flex: 0 0 auto;
    min-width: 0;
    white-space: nowrap;
}

#productModal .btn-modal-save {
    min-width: 130px;
}

@media (max-width: 575px) {
    #productModal .product-modal-dialog {
        width: calc(100% - 0.5rem);
        max-height: calc(100dvh - 0.5rem);
        margin: 0.25rem auto;
    }

    #productModal .modal-content,
    #productModal .product-modal-form {
        max-height: calc(100dvh - 0.5rem);
    }

    #productModal .product-modal-footer {
        flex-direction: column;
        align-items: stretch;
    }

    #productModal .product-modal-footer .btn {
        width: 100%;
        white-space: normal;
    }

    #productModal .btn-modal-cancel {
        order: 3;
    }

    .page-products .workflow-steps .small code {
        word-break: break-all;
    }
}

/* Do not shrink product modal footer buttons */
#productModal .modal-footer .btn {
    flex: 0 0 auto !important;
}

body.dark-mode #productModal .product-modal-footer {
    background: var(--bg-surface, #1e293b);
    border-top-color: #334155;
}

/* ——— Inventory: variant column on small screens ——— */
.page-inventory .inv-variant-cell {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    min-width: 0;
    max-width: 280px;
}

.page-inventory .inv-swatch {
    display: inline-block;
    width: 18px;
    height: 18px;
    min-width: 18px;
    border-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.15);
    margin-top: 2px;
}

.page-inventory .inv-variant-text {
    font-size: 0.85rem;
    line-height: 1.35;
    word-break: break-word;
    white-space: normal;
}

@media (max-width: 768px) {
    .page-inventory .inventory-table thead {
        display: none;
    }

    .page-inventory .inventory-table tbody tr {
        display: block;
        margin-bottom: 10px;
        border: 1px solid var(--border, #e2e8f0);
        border-radius: 10px;
        padding: 10px 12px;
        background: var(--bg-surface, #fff);
    }

    .page-inventory .inventory-table tbody tr.table-warning {
        background: #fffbeb;
    }

    .page-inventory .inventory-table tbody td {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 10px;
        padding: 6px 0;
        border: none;
        text-align: right;
    }

    .page-inventory .inventory-table tbody td::before {
        content: attr(data-label);
        font-weight: 700;
        font-size: 0.75rem;
        color: var(--text-muted, #64748b);
        text-align: left;
        flex-shrink: 0;
    }

    .page-inventory .inv-col-variant {
        flex-direction: column;
        align-items: stretch !important;
        text-align: left !important;
    }

    .page-inventory .inv-col-variant::before {
        margin-bottom: 4px;
    }

    .page-inventory .inv-variant-cell {
        max-width: none;
        justify-content: flex-start;
    }

    .page-inventory .inv-col-sku,
    .page-inventory .inv-col-alert {
        display: none !important;
    }
}

/* Hide less important columns on very small screens */
@media (max-width: 480px) {
    .page-products table.data-table thead th:nth-child(1),
    .page-products table.data-table tbody td:nth-child(1),
    .page-products table.data-table thead th:nth-child(3),
    .page-products table.data-table tbody td:nth-child(3) {
        display: none;
    }
}

/* Other modals — mobile friendly (exclude #productModal — fixed above) */
@media (max-width: 575px) {
    .modal-dialog:not(.modal-sm):not(.product-modal-dialog) {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }

    .modal:not(#productModal) .modal-footer {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .modal:not(#productModal) .modal-footer .btn {
        flex: 1 1 auto;
        min-width: 100px;
    }
}
