:root {
    --primary: #0d9488;
    --primary-light: #14b8a6;
    --accent: #065f5b;
    --bg: #f0fdfa;
    --bg-light: #f8fafc;
    --keypad: #ccfbf1;
    --keypad-action: #99f6e4;
    --keypad-text: #ffffff;
    --text: #0f172a;
}

body {
    margin: 0;
    padding: 0;
    font-family: Arial, sans-serif;
    background: var(--bg);
    overflow-x: hidden;
    touch-action: manipulation;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

h1 {
    text-align: center;
    color: var(--primary);
    margin: 10px 0;
    font-size: 2.5em;
}

.screen {
    display: none;
    flex-direction: column;
    height: 100vh;
    width: 100vw;
    max-width: none;
    overflow-x: hidden;
    padding: 10px;
    box-sizing: border-box;
}

.screen.active {
    display: flex;
}

.grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    row-gap: 12px;
    flex-grow: 1;
    padding: 10px 5px;
    overflow-y: auto;
    touch-action: manipulation;
    max-width: none;
    width: 100%;
    max-width: none;
    margin: 0 auto;
    box-sizing: border-box;
    align-content: start;
    /* Prevents excessive vertical stretching */
}

.grid button {
    background: var(--primary-light);
    color: white;
    border: none;
    border-radius: 15px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    word-wrap: break-word;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: clamp(14px, 4vw, 24px) clamp(8px, 2vw, 12px);
    gap: 8px;
    min-height: 110px;
    font-size: clamp(1.6rem, 5vw, 2.2rem);
    /* Larger base */
    line-height: 1.3;
    width: 100%;
    box-sizing: border-box;
}

.grid button strong {
    font-size: clamp(1.6rem, 4.8vw, 2.1rem);
    font-weight: bold;
}

.nav-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px 8px;
    position: relative;
    width: 100%;
    box-sizing: border-box;
    flex-shrink: 0;
}

.nav-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.back-btn,
.cart-btn {
    font-size: 2.5em;
    background: none;
    border: none;
    color: var(--primary);
    padding: 0;
    margin: 0;
    z-index: 10;
}

.back-btn {
    /* Flex-based navigation */
    cursor: pointer;
}

.nav-right {
    display: flex;
    align-items: center;
    gap: 15px;
}

.cart-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    position: relative;
}

.logout-btn {
    font-size: 2.2em;
    background: none;
    border: none;
    color: var(--primary);
    cursor: pointer;
    padding: 0;
    margin: 0;
    transition: transform 0.2s;
    display: flex;
}

#staff-name {
    font-size: 1.4em;
    color: var(--primary);
    font-weight: 500;
    white-space: nowrap;
    opacity: 0.8;
    margin-left: 10px;
}

.logout-btn:hover {
    transform: scale(1.1);
}

/* Cart item count badge */
.cart-btn::after {
    content: attr(data-count);
    font-size: 0.5em;
    background: var(--accent);
    color: white;
    border-radius: 50%;
    padding: 4px 8px;

    /* Receipt interactive items */
    .receipt-item-row {
        display: flex;
        justify-content: space-between;
        padding: 8px 12px;
        border-radius: 8px;
        transition: background 0.2s, transform 0.1s;
        user-select: none;
    }

    .receipt-item-row:hover {
        background: rgba(var(--primary-rgb, 216, 27, 96), 0.05);
        transform: scale(1.01);
    }

    .receipt-item-row:active {
        background: rgba(var(--primary-rgb, 216, 27, 96), 0.1);
        transform: scale(0.99);
    }

    .receipt-item-row .desc {
        flex: 1;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    min-width: 20px;
    position: absolute;
    top: -8px;
    right: -12px;
    display: none;
}

.cart-btn[data-count]:not([data-count=""])::after {
    display: block;
}

/* Badge Styles */
.badge {
    display: inline-block;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.85em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    white-space: nowrap;
}

.badge.retail {
    background: rgba(var(--primary-rgb, 26, 35, 126), 0.1);
    color: var(--primary);
    border: 1px solid rgba(var(--primary-rgb), 0.2);
}

.badge.wholesale {
    background: #e3f2fd;
    color: #1976d2;
    border: 1px solid #bbdefb;
}

/* Sync Badge States */
.badge.sync-online {
    background: #e8f5e9;
    color: #2e7d32;
    border: 1px solid #a5d6a7;
}

.badge.sync-offline {
    background: #fff3e0;
    color: #ef6c00;
    border: 1px solid #ffe0b2;
}

.badge.sync-pending {
    background: #e3f2fd;
    color: #1976d2;
    border: 1px solid #bbdefb;
}

.badge.sync-error {
    background: #ffebee;
    color: #c62828;
    border: 1px solid #ef9a9a;
}

/* Keypad */
.keypad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin: 20px 0;
    flex-shrink: 0;
    padding: 0 10px;
}

.keypad button {
    font-size: clamp(2.5rem, 8vw, 3.5rem);
    padding: clamp(20px, 6vw, 30px);
    background: var(--keypad);
    color: var(--keypad-text);
    border: none;
    border-radius: 15px;
}

.keypad button.backspace {
    background: var(--keypad-action);
}

.keypad button.add {
    background: #4caf50;
}

.keypad button.equals {
    background: var(--accent) !important;
    grid-column: span 3;
}

#current-qty {
    font-size: 4em;
    text-align: center;
    margin: 20px 0;
    color: var(--accent);
    font-weight: bold;
    flex-shrink: 0;
}

#cart-items {
    flex-grow: 1;
    overflow-y: auto;
    font-size: 1.8em;
    margin-bottom: 10px;
}

#cart-items div {
    padding: 15px;
    background: var(--bg-light);
    margin: 8px 0;
    border-radius: 10px;
    display: flex;
    justify-content: space-between;
    cursor: pointer;
}

#total {
    font-size: 2.5em;
    text-align: center;
    color: var(--accent);
    margin: 10px 0;
}

.big-btn {
    font-size: 2.2em;
    padding: 20px;
    margin: 10px 0;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 15px;
}

#receipt-content {
    flex-grow: 1;
    overflow-y: auto;
    padding: 10px;
    background: white;
    margin: 10px 0;
    border-radius: 15px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    font-size: 1.6em;
    line-height: 1.6;
}

#receipt-content h1 {
    text-align: center;
    color: var(--primary);
    font-size: 2.8em;
    margin: 10px 0 20px;
}

#receipt-content .date {
    text-align: center;
    font-size: 1.8em;
    margin: 10px 0;
    color: #555;
}

#receipt-content .customer {
    text-align: center;
    font-size: 1.6em;
    margin: 15px 0;
}

#receipt-content hr {
    border: none;
    border-top: 2px dashed var(--primary);
    margin: 20px 0;
}

#receipt-content .items div {
    display: flex;
    justify-content: space-between;
    margin: 10px 0;
    font-size: 1.7em;
}

#receipt-content .total {
    text-align: center;
    font-size: 2.6em;
    color: var(--accent);
    font-weight: bold;
    margin: 20px 0;
}

#receipt-content .thanks {
    text-align: center;
    font-size: 1.8em;
    margin: 30px 0 10px;
    color: var(--primary);
}

.receipt-actions .full-width {
    width: 100%;
    margin: 0;
    font-size: 2.2em;
    padding: 25px;
    background: var(--primary);
}

.receipt-actions {
    padding: 20px;
}

#receipt-content h1 {
    font-size: 2.8em;
    text-align: center;
    color: var(--primary);
    margin: 0 0 15px 0;
    font-weight: bold;
}

#receipt-content .date {
    text-align: center;
    font-size: 1.6em;
    color: #777;
    margin: 10px 0 20px 0;
}

#receipt-content .customer {
    background: var(--bg-light);
    padding: 15px;
    border-radius: 12px;
    margin: 20px 0;
    text-align: center;
    font-size: 1.4em;
}

#receipt-content .customer strong {
    color: var(--accent);
}

#receipt-content hr {
    border: none;
    border-top: 3px dashed var(--primary);
    margin: 30px 0;
}

#receipt-content .category {
    font-size: 1.6em;
    font-weight: bold;
    color: var(--primary);
    margin: 15px 0 5px 0;
    text-align: left;
    padding-bottom: 4px;
    border-bottom: 2px solid var(--primary-light);
}

#receipt-content .items div {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 1.5em;
    border-bottom: 1px dotted #eee;
}

#receipt-content .items .desc {
    flex: 1;
    padding-right: 20px;
    word-wrap: break-word;
}

#receipt-content .items .amount {
    font-weight: bold;
    color: var(--accent);
    min-width: 120px;
    text-align: right;
}

#receipt-content .total {
    font-size: 2.2em !important;
    font-weight: bold;
    color: var(--accent);
    text-align: right !important;
    margin: 10px 0 5px 0;
    padding: 10px;
    background: var(--bg-light);
    border-radius: 10px;
}

#receipt-content .thanks {
    text-align: center;
    font-size: 1.4em;
    color: var(--primary);
    margin: 10px 0;
    font-style: italic;
}



/* Ensure full content in PDF generation */
#receipt-content * {
    max-width: 100%;
    word-wrap: break-word;
    page-break-inside: avoid;
}

@media print {
    @page {
        size: a4 portrait;
        margin: 0.5in;
    }

    body,
    html {
        margin: 0;
        padding: 0;
        background: white;
    }

    #receipt-content {
        width: 100%;
        font-size: 0.9em !important;
        line-height: 1.2 !important;
        padding: 0.5in !important;
        margin: 0 auto;
    }

    #receipt-content h1 {
        font-size: 2.2em;
    }

    #receipt-content .date {
        font-size: 1.4em;
    }

    #receipt-content .category {
        font-size: 1.6em;
        margin: 15px 0 5px 0;
    }

    #receipt-content .items div {
        padding: 6px 0;
        font-size: 1.5em;
    }

    #receipt-content .total {
        font-size: 2.5em !important;
        margin: 20px 0 10px 0;
        padding: 10px;
    }

    #receipt-content .thanks {
        font-size: 1.5em;
        margin: 20px 0 0 0;
    }

    /* Ensure no page breaks inside groups */
    .category,
    .items div {
        page-break-inside: avoid;
    }
}

/* Custom POS Modal - Mobile-Friendly */
/* Custom POS Modal - Mobile-Friendly with Full Scrolling */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: flex-end;
    /* Bottom-aligned on mobile */
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    border-radius: 20px 20px 0 0;
    width: 100%;
    max-width: 500px;
    height: 90vh;
    /* Fixed height for consistent scrolling */
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.3);
}

.modal-content h2 {
    background: var(--primary);
    color: white;
    margin: 0;
    padding: 18px;
    text-align: center;
    font-size: 2em;
    flex-shrink: 0;
}

.modal-body {
    padding: 20px;
    flex: 1;
    /* Takes available space */
    overflow-y: auto;
    /* Always scrollable */
    -webkit-overflow-scrolling: touch;
}

.modal-body label {
    display: block;
    margin: 15px 0 6px 0;
    font-size: 1.5em;
    color: var(--accent);
    font-weight: bold;
}

.modal-body input {
    width: 100%;
    padding: 14px;
    font-size: 1.6em;
    border: 2px solid var(--primary-light);
    border-radius: 12px;
    box-sizing: border-box;
}

#existing-customer-info {
    background: rgba(var(--primary-rgb), 0.1);
    padding: 15px;
    border-radius: 12px;
    margin: 15px 0;
    font-size: 1.4em;
}

.modal-actions {
    display: flex;
    gap: 12px;
    padding: 20px;
    background: var(--bg);
    flex-shrink: 0;
    /* Buttons always visible */
    border-radius: 0 0 20px 20px;
}

.modal-actions button {
    flex: 1;
    font-size: 1.8em;
    padding: 16px;
}

/* On larger screens (tablets+), center the modal */
@media (min-width: 600px) {
    .modal {
        align-items: center;
    }

    .modal-content {
        border-radius: 20px;
        height: auto;
        max-height: 85vh;
    }

    .modal-actions {
        border-radius: 0 0 20px 20px;
    }
}


/* Custom POS Modal */
/* .modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    border-radius: 20px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    overflow: hidden;
}

.modal-content h2 {
    background: #d81b60;
    color: white;
    margin: 0;
    padding: 20px;
    text-align: center;
    font-size: 2.2em;
}

.modal-body {
    padding: 20px;
}

.modal-body label {
    display: block;
    margin: 15px 0 8px 0;
    font-size: 1.6em;
    color: #c51162;
    font-weight: bold;
}

.modal-body input {
    width: 100%;
    padding: 15px;
    font-size: 1.8em;
    border: 2px solid #f06292;
    border-radius: 12px;
    box-sizing: border-box;
}

.modal-actions {
    display: flex;
    gap: 15px;
    padding: 20px;
    background: #f8bbd0;
}

.modal-actions button {
    flex: 1;
    font-size: 1.8em;
    padding: 18px;
} */


/* Phones (small screens) - 2 columns */
@media (max-width: 600px) {
    .grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        row-gap: 10px;
    }

    .cart-btn {
        font-size: 2.2em;
        top: 8px;
        right: 8px;
        gap: 6px;
    }

    .grid button {
        min-height: 100px;
        padding: 12px 8px;
        font-size: clamp(1.3rem, 4.5vw, 1.6rem);
    }

    .grid button strong {
        font-size: clamp(1.4rem, 5vw, 1.7rem);
    }

    .keypad {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 10px;
        padding: 0 16px;
    }

    .keypad button {
        font-size: 2.8rem !important;
        padding: 18px !important;
        min-height: 70px;
        line-height: 1.1;
        width: 100%;
        box-sizing: border-box;
    }

    .keypad button.backspace {
        font-size: 2.5rem !important;
    }

    .keypad button.equals {
        padding: 20px !important;
    }

    #current-qty {
        font-size: 3.0rem !important;
        margin: 10px 0;
    }

    #product-title {
        font-size: 2rem !important;
        line-height: 1.3;
    }

    #product-title strong {
        font-size: 2.2rem !important;
    }

    #screen-quantity {
        padding: 10px;
    }

    .back-btn,
    .cart-btn {
        font-size: 2.2em !important;
    }

    .modal {
        align-items: center;
        justify-content: center;
    }

    .modal-content {
        height: 90vh;
        max-height: 90vh;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        /* prevents growth */
    }

    .modal-body {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .modal-actions {
        flex-shrink: 0;
    }
}

/* Large desktops only (iMac etc.) - Still 3 columns but centered */
@media (min-width: 1200px) {
    .grid {
        grid-template-columns: repeat(3, 1fr);
        max-width: 1200px;
        margin: 0 auto;
    }
}

/* Extra large text on tablets/old iPads */
/* @media (min-width: 481px) and (max-width: 1024px) {
    .grid button {
        font-size: clamp(2rem, 7vw, 3rem) !important;
        padding: clamp(20px, 6vw, 40px) clamp(12px, 4vw, 20px) !important;
        min-height: 140px !important;
    }
    .grid button strong {
        font-size: clamp(2.4rem, 8vw, 3.6rem) !important;
    }
} */

/* Old iPads – PORTRAIT (768 × 1024) */
@media (orientation: portrait) and (max-width: 820px) and (min-width: 700px) {

    .grid {
        grid-template-columns: repeat(3, 1fr);
        padding: 16px;
        gap: 16px;
    }

    .grid button {
        min-height: 150px !important;
        padding: 24px 20px !important;
        font-size: 1.8rem !important;
        line-height: 1.25;
    }

    .grid button strong {
        font-size: 1.8rem !important;
    }

    .keypad {
        gap: 15px;
        margin: 25px 0;
        padding: 0 20px;
    }

    .keypad button {
        font-size: 3.5rem !important;
        padding: 30px !important;
        min-height: 90px;
    }

    .keypad button.backspace {
        font-size: 3rem !important;
    }

    #current-qty {
        font-size: 3.0rem !important;
        margin: 10px 0;
    }

    #product-title {
        font-size: 2rem !important;
        line-height: 1.3;
    }

    #product-title strong {
        font-size: 2.2rem !important;
    }

    #screen-quantity {
        padding: 10px;
    }

    .back-btn,
    .cart-btn {
        font-size: 2.2em !important;
    }
}

/* Old iPads – LANDSCAPE font lock */
@media (orientation: landscape) and (max-width: 1025px) {

    .grid {
        grid-template-columns: repeat(3, 1fr);
        padding: 16px;
        gap: 16px;
    }

    .grid button {
        min-height: 150px !important;
        padding: 24px 20px !important;
        font-size: 1.8rem !important;
        line-height: 1.25;
    }

    .grid button strong {
        font-size: 1.8rem !important;
    }

    .keypad {
        gap: 10px;
        margin: 15px 0;
        padding: 0 16px;
    }

    .keypad button {
        font-size: 2.8rem !important;
        padding: 18px !important;
        min-height: 70px;
        line-height: 1.1;
    }

    .keypad button.backspace {
        font-size: 2.5rem !important;
    }

    .keypad button.equals {
        padding: 20px !important;
    }

    #current-qty {
        font-size: 3.0rem !important;
        margin: 6px 0 !important;
    }

    #product-title {
        font-size: 2rem !important;
        line-height: 1.3;
    }

    #product-title strong {
        font-size: 2.2rem !important;
    }

    #screen-quantity {
        padding: 10px;
    }

    /* Aggressive Space Saving for Receipt Screen */
    #screen-receipt.active {
        padding: 0 10px !important;
        /* Minimal vertical padding */
        overflow: hidden !important;
        /* Ensure height is strictly 100vh */
        display: flex;
        flex-direction: column;
    }

    #screen-receipt>h1 {
        display: none !important;
        /* Redundant header - save vertical space */
    }

    #screen-receipt .nav-bar {
        padding: 5px 10px !important;
        /* Tighter nav */
        flex-shrink: 0 !important;
    }

    #receipt-content {
        padding: 8px !important;
        margin: 2px 0 5px 0 !important;
        /* Minimal vertical margins */
        font-size: 1.25em !important;
        flex: 1 1 0% !important;
        /* Strict flex growth to fill available height */
        min-height: 0 !important;
        /* REQUIRED for content to shrink and scroll within flex */
        overflow-y: auto !important;
    }

    #receipt-content h1 {
        display: block !important;
        /* Store name inside receipt */
        font-size: 1.6em !important;
        margin: 2px 0 5px 0 !important;
    }

    #receipt-content .date {
        font-size: 1.1em !important;
        margin: 0 0 10px 0 !important;
    }

    #receipt-content hr {
        margin: 10px 0 !important;
    }

    #receipt-content .category {
        font-size: 1.3em !important;
        margin: 8px 0 2px 0 !important;
    }

    #receipt-content .items div {
        font-size: 1.25em !important;
        padding: 2px 0 !important;
    }

    #receipt-content .total {
        font-size: 1.8em !important;
        margin: 10px 0 !important;
        padding: 8px !important;
    }

    #receipt-content .thanks {
        font-size: 1.1em !important;
        margin: 2px 0 !important;
    }

    .receipt-actions {
        padding: 5px 20px !important;
        gap: 8px !important;
        flex-shrink: 0 !important;
        /* Never let buttons be hidden */
        display: flex;
        flex-direction: column;
    }

    .receipt-actions .big-btn {
        padding: 12px 15px !important;
        font-size: 1.6em !important;
        margin: 0 !important;
        height: auto !important;
    }

    .back-btn,
    .cart-btn {
        font-size: 2.0em !important;
    }
}