/* =========================================
   BUILDFRAME RESPONSIVE FIXES
   Safe global layout balancing layer
========================================= */

/* Universal safety */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html,
body {
    max-width: 100%;
    overflow-x: hidden;
}

img,
video,
canvas,
iframe {
    max-width: 100%;
}

/* Prevent long text from breaking layouts */
p,
span,
td,
th,
label,
strong,
h1,
h2,
h3,
h4,
h5,
h6,
button,
a {
    overflow-wrap: break-word;
    word-break: normal;
}

/* Forms */
input,
select,
textarea,
button {
    max-width: 100%;
}

.form-grid,
.order-grid,
.admin-form-grid,
.dashboard-grid,
.stats-grid,
.cards-grid,
.module-grid {
    min-width: 0;
}

.form-group,
.module-card,
.dashboard-card,
.stat-card,
.order-card,
.table-card,
.admin-card {
    min-width: 0;
}

/* Tables */
.table-wrap,
.table-card,
.admin-table-wrap {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
}

table,
.admin-table,
.orders-table {
    width: 100%;
    min-width: 720px;
    border-collapse: collapse;
}

/* Buttons */
button,
.btn,
.primary-btn,
.save-btn,
.clear-btn,
.back-link {
    white-space: normal;
}

/* Modals */
.invoice-modal,
.modal,
.popup {
    max-width: 100vw;
    overflow-y: auto;
}

.invoice-modal-content,
.modal-content,
.popup-content {
    max-width: calc(100vw - 32px);
}

/* Dashboard/sidebar safety */
.admin-layout,
.dashboard-layout {
    max-width: 100%;
    overflow-x: hidden;
}

.admin-main,
.dashboard-main,
.admin-content {
    min-width: 0;
    max-width: 100%;
}

/* Tablet */
@media (max-width: 1024px) {

    .form-grid,
    .order-grid,
    .admin-form-grid,
    .dashboard-grid,
    .stats-grid,
    .cards-grid,
    .module-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    .wide-field,
    .signature-section,
    .order-actions {
        grid-column: 1 / -1 !important;
    }
}

/* Mobile */
@media (max-width: 768px) {
    body {
        font-size: 15px;
    }

    .form-grid,
    .order-grid,
    .admin-form-grid,
    .dashboard-grid,
    .stats-grid,
    .cards-grid,
    .module-grid {
        grid-template-columns: 1fr !important;
    }

    .wide-field,
    .signature-section,
    .order-actions {
        grid-column: 1 / -1 !important;
    }

    .top-bar,
    .page-top,
    .admin-header,
    .order-actions,
    .form-actions,
    .invoice-actions {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 12px !important;
    }

    .brand {
        align-items: flex-start !important;
    }

    .brand img {
        width: 56px !important;
        height: 56px !important;
    }

    h1 {
        font-size: 26px !important;
    }

    h2 {
        font-size: 22px !important;
    }

    .order-page,
    .admin-content,
    .dashboard-main {
        padding-left: 14px !important;
        padding-right: 14px !important;
    }

    .order-card,
    .form-card,
    .table-card,
    .module-card,
    .dashboard-card {
        padding: 18px !important;
        border-radius: 18px !important;
    }

    input,
    select,
    textarea {
        font-size: 16px !important;
    }

    button,
    .btn,
    .primary-btn,
    .save-btn,
    .clear-btn,
    .back-link {
        width: 100%;
        text-align: center;
    }

    table,
    .admin-table,
    .orders-table {
        min-width: 680px;
    }

    .invoice-modal {
        align-items: flex-start !important;
        padding: 14px !important;
    }

    .invoice-modal-content {
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 18px !important;
    }

    .invoice-header,
    .invoice-body,
    .invoice-actions {
        padding: 20px !important;
    }

    .invoice-grid {
        grid-template-columns: 1fr !important;
    }

    .invoice-total-box h1 {
        font-size: 32px !important;
    }

    #signatureCanvas {
        height: 130px !important;
    }
}

/* Small phones */
@media (max-width: 480px) {

    .order-page,
    .admin-content,
    .dashboard-main {
        padding-left: 10px !important;
        padding-right: 10px !important;
    }

    .order-card,
    .form-card,
    .table-card,
    .module-card,
    .dashboard-card {
        padding: 14px !important;
    }

    h1 {
        font-size: 23px !important;
    }

    h2 {
        font-size: 20px !important;
    }

    table,
    .admin-table,
    .orders-table {
        min-width: 620px;
    }
}

/* POS receipt print safety */
@media print {
    body {
        overflow: visible !important;
    }

    .invoice-modal {
        overflow: visible !important;
    }

    .invoice-modal-content {
        overflow: visible !important;
    }
}

/* =========================================
   FLEXIBLE PRINT FORMAT
   Browser/printer controls final paper size
========================================= */

@media print {

    @page {
        margin: 4mm;
    }

    body {
        background: white !important;
        color: black !important;
        overflow: visible !important;
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
    }

    body * {
        visibility: hidden !important;
    }

    #invoiceModal,
    #invoiceModal * {
        visibility: visible !important;
    }

    #invoiceModal {
        display: block !important;
        position: absolute !important;
        inset: 0 !important;
        background: white !important;
        padding: 0 !important;
        margin: 0 !important;
        overflow: visible !important;
    }

    .invoice-modal-content {
        width: 100% !important;
        max-width: 100% !important;
        max-height: none !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        overflow: visible !important;
    }

    .invoice-header {
        padding: 8px 0 !important;
        text-align: center !important;
        display: block !important;
    }

    .invoice-body {
        padding: 8px 0 !important;
    }

    .invoice-actions,
    .close-invoice-btn {
        display: none !important;
    }

    .invoice-grid {
        display: block !important;
    }

    .invoice-grid div {
        page-break-inside: avoid;
        break-inside: avoid;
    }

    .invoice-total-box {
        page-break-inside: avoid;
        break-inside: avoid;
    }

    .invoice-signature img {
        max-width: 100% !important;
        height: auto !important;
    }
}

/* =========================================
   GLOBAL SECTION SPACING
========================================= */

.store-section,
.wholesale-section,
.promos-section,
.products-section {
    padding: 40px 24px;
}

/* =========================================
   WHOLESALE PRODUCTS HEADER
========================================= */

.wholesale-products-header,
.products-header-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 20px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.wholesale-products-header h2,
.products-header-row h2 {
    margin-bottom: 8px;
}

.wholesale-products-header p,
.products-header-row p {
    margin: 0;
    color: #64748b;
}

.request-bulk-link {
    white-space: nowrap;
    font-weight: 700;
    color: #005f2f;
    text-decoration: none;
    font-size: 18px;
}

.request-bulk-link:hover {
    opacity: 0.8;
}

/* =========================================
   HERO BALANCING
========================================= */

.wholesale-hero,
.promos-hero,
.store-hero {
    padding: 40px;
    border-radius: 30px;
    margin-bottom: 40px;
}

.hero-grid {
    display: grid;
    grid-template-columns: 1.5fr 0.8fr;
    gap: 30px;
    align-items: stretch;
}

.hero-left,
.hero-right {
    width: 100%;
}

/* =========================================
   FEATURE CARDS
========================================= */

.hero-features {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 18px;
    margin-top: 30px;
}

.hero-feature-card {
    padding: 24px;
    border-radius: 20px;
    min-height: 120px;
}

/* =========================================
   SEARCH + FILTER
========================================= */

.search-filter-row {
    display: flex;
    gap: 20px;
    align-items: center;
    margin: 35px 0;
    flex-wrap: wrap;
}

.search-filter-row input,
.search-filter-row select {
    min-height: 58px;
    border-radius: 16px;
}

/* =========================================
   PRODUCT GRID
========================================= */

.products-grid,
.wholesale-grid,
.promos-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 24px;
}

/* =========================================
   PRODUCT CARD
========================================= */

.product-card {
    padding: 22px;
    border-radius: 24px;
    overflow: hidden;
}

/* =========================================
   LOAD MORE BUTTON
========================================= */

.load-more-wrapper {
    text-align: center;
    margin-top: 40px;
}

/* =========================================
   MOBILE RESPONSIVE
========================================= */

@media (max-width: 991px) {

    .hero-grid {
        grid-template-columns: 1fr;
    }

    .hero-features {
        grid-template-columns: 1fr;
    }

    .wholesale-products-header,
    .products-header-row {
        flex-direction: column;
        align-items: flex-start;
    }

    .request-bulk-link {
        margin-top: 10px;
    }

}

/* =========================================
   MOBILE PHONE
========================================= */

@media (max-width: 768px) {

    .store-section,
    .wholesale-section,
    .promos-section,
    .products-section {
        padding: 25px 16px;
    }

    .wholesale-hero,
    .promos-hero,
    .store-hero {
        padding: 24px;
        border-radius: 24px;
    }

    .search-filter-row {
        flex-direction: column;
        align-items: stretch;
    }

    .search-filter-row input,
    .search-filter-row select {
        width: 100%;
    }

}

/* =========================================
   ADMIN ORDERS FORM CART TABLE FIX
   Safe CSS only
========================================= */

.admin-content .order-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
}

.admin-content #addToCartBtn {
    width: 100%;
    min-height: 52px;
}

.admin-content #cartTableBody,
.admin-content #cartTableBody tr,
.admin-content #cartTableBody td {
    max-width: 100%;
}

.admin-content .order-grid .table-wrap {
    grid-column: 1 / -1 !important;
    width: 100%;
    overflow-x: auto;
}

.admin-content .order-grid table,
.admin-content .order-grid .orders-table {
    min-width: 650px;
}

@media (max-width: 1100px) {
    .admin-content .order-grid {
        grid-template-columns: 1fr !important;
    }
}

/* =========================================
   PUBLIC STORE PRODUCT HEADER ALIGNMENT
========================================= */

.store-section-header,
.products-header,
.retail-products-header,
.wholesale-products-header,
.promo-products-header {
    max-width: 1300px;
    margin: 0 auto 24px;
    padding: 0 24px;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
}

.store-section-header h2,
.products-header h2,
.retail-products-header h2,
.wholesale-products-header h2,
.promo-products-header h2 {
    margin: 0;
}

.store-section-header p,
.products-header p,
.retail-products-header p,
.wholesale-products-header p,
.promo-products-header p {
    margin: 6px 0 0;
}

.store-section-header a,
.products-header a,
.retail-products-header a,
.wholesale-products-header a,
.promo-products-header a {
    white-space: nowrap;
    font-weight: 800;
    color: #005f2f;
    text-decoration: none;
}

@media (max-width: 768px) {

    .store-section-header,
    .products-header,
    .retail-products-header,
    .wholesale-products-header,
    .promo-products-header {
        flex-direction: column;
        align-items: flex-start;
    }
}

/* =========================================
   FINAL WHOLESALE PRODUCT CARD FIX
   Store App / Wholesale Page
========================================= */

#productGrid {
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)) !important;
    gap: 16px !important;
}

#productGrid .product-card {
    padding: 0 !important;
    border-radius: 16px !important;
    min-height: auto !important;
}

#productGrid .product-image {
    height: 150px !important;
}

#productGrid .product-image img {
    width: 100% !important;
    height: 100% !important;
    object-fit: contain !important;
    padding: 8px !important;
}

#productGrid .product-info {
    padding: 12px !important;
}

#productGrid .product-info h3 {
    font-size: 15px !important;
    line-height: 1.35 !important;
}

#productGrid .product-info p {
    font-size: 12px !important;
    line-height: 1.4 !important;
    min-height: auto !important;
}

@media (max-width: 768px) {
    #productGrid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
}