/* KindStock POS / till surface.
   Moved verbatim from styles.css (selectors frozen: these flows are e2e-pinned),
   then tokenized. Loaded on every shell so the offline till precache stays simple. */

/* ==========================================================================
   Point of Sale (POS)
   ========================================================================== */
.pos-container {
    display: flex;
    gap: 1rem;
    height: calc(100vh - 2rem);
    padding: 1rem;
    /* Within the till, Bootstrap's "dark" is the brand's deepest forest:
       the header bar and TOTAL row (bg-dark in frozen markup) pick this up. */
    --bs-dark-rgb: 16, 37, 31;
}

.cart-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.keypad-panel {
    width: 440px;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

/* The cart is the receipt-in-progress: paper surface, hairline rules,
   and the Gift Aid marker in gold (gold = HMRC money, nowhere else). */
.cart-items {
    flex: 1;
    overflow-y: auto;
    background: var(--ks-paper);
}

.cart-item {
    padding: 0.75rem;
    border-bottom: 1px solid var(--ks-rule);
    cursor: pointer;
}

.cart-item:hover,
.cart-item.selected {
    background: var(--ks-accent-tint);
}

.cart-item.gift-aid {
    border-left: 3px solid var(--ks-gift-aid-strong);
}

/* Money voice on the totals block; the Gift Aid line reads gold. */
.cart-panel .card-footer td.text-end {
    font-family: var(--ks-font-money);
    font-variant-numeric: tabular-nums lining-nums;
}

.pos-ga-row {
    color: var(--ks-gift-aid);
}

/* Secondary action tiles — 2-up grid; Refund spans the full width. */
.pos-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}

.pos-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-height: 58px;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 12px;
}

.pos-action-wide {
    grid-column: 1 / -1;
}

/* Quick buttons — only rendered when configured; flow as an auto-fit row. */
.pos-quick {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(72px, 1fr));
    gap: 0.5rem;
}

.quick-btn {
    min-height: 56px;
    font-size: 0.9rem;
    font-weight: 600;
    border-radius: 12px;
}

/* Number pad — 3 columns of gently-proportioned keys. aspect-ratio keeps them
   from stretching into tall slabs on a big landscape display (the old 4x1fr
   fill made them elongated). The pad sits in a flex-grow wrapper so it centres
   in the leftover height, with PAY anchored to the bottom edge. */
.keypad-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    min-height: 0;
}

.keypad-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.6rem;
    width: 100%;
}

.keypad-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 3 / 2;
    min-height: 56px;
    font-size: clamp(1.6rem, 4vh, 2.4rem);
    font-weight: 700;
    border-radius: 16px;
    box-shadow: 0 2px 4px rgba(16, 37, 31, 0.2);
    font-family: var(--ks-font-money);
}

/* Digit keys go deepest forest (markup keeps btn-dark; these vars win by
   source order). Clear keeps its distinct grey via btn-secondary. */
.keypad-btn:not(.keypad-btn-clear) {
    --bs-btn-bg: var(--ks-ink-deep);
    --bs-btn-border-color: var(--ks-ink-deep);
    --bs-btn-hover-bg: var(--ks-forest-mid);
    --bs-btn-hover-border-color: var(--ks-forest-mid);
    --bs-btn-active-bg: var(--ks-forest);
    --bs-btn-active-border-color: var(--ks-forest);
}

.keypad-btn-clear {
    font-size: clamp(1rem, 2.4vh, 1.4rem);
    font-weight: 600;
}

.pay-btn {
    width: 100%;
    min-height: 92px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    font-size: clamp(1.6rem, 3.6vh, 2.2rem);
    font-weight: 800;
    border-radius: 18px;
    box-shadow: 0 4px 12px rgba(25, 135, 84, 0.4);
}

.pay-btn .bi {
    font-size: 1.3em;
}

.pin-display {
    font-size: 2.4rem;
    letter-spacing: 1rem;
    font-family: monospace;
}

.pin-keypad-container {
    max-width: 320px;
    margin: 0 auto;
}

.pin-keypad-container .btn {
    min-height: 56px;
    font-size: 1.4rem;
    font-weight: 600;
    border-radius: 12px;
}

/* ==========================================================================
   Enhanced POS Touch Targets (WCAG 2.1 - minimum 44x44px)
   ========================================================================== */

/* POS action buttons row - Item, Basket%, Misc, Remove, Refund */
.pos-container .keypad-panel > .row.g-2.mb-2:first-of-type .btn {
    min-height: 48px;
    padding: 0.5rem 0.25rem;
    font-size: 0.85rem;
}

@media (min-width: 768px) {
    .pos-container .keypad-panel > .row.g-2.mb-2:first-of-type .btn {
        min-height: 56px;
        padding: 0.75rem 0.5rem;
        font-size: 0.95rem;
    }
}

/* Payment modal buttons - larger touch targets */
#payModal .btn-lg {
    min-height: 64px;
    font-size: 1.25rem;
}

@media (min-width: 768px) {
    #payModal .btn-lg {
        min-height: 72px;
        font-size: 1.4rem;
    }
}

/* Modal close buttons - ensure tappable */
.modal-header .btn-close {
    width: 44px;
    height: 44px;
    padding: 1rem;
}

/* Success/refund modal action buttons */
#successModal .btn-lg,
#refundSuccessModal .btn-lg {
    min-height: 56px;
    padding: 0.75rem 1.5rem;
}

/* Refund lookup/confirm buttons */
#refundLookupModal .modal-footer .btn,
#refundConfirmModal .modal-footer .btn {
    min-height: 48px;
    padding: 0.75rem 1.25rem;
}

@media (min-width: 768px) {
    #refundLookupModal .modal-footer .btn,
    #refundConfirmModal .modal-footer .btn {
        min-height: 56px;
        padding: 0.75rem 1.5rem;
        font-size: 1.05rem;
    }
}

/* Discount modal - slider-friendly input and buttons */
#discountModal .form-control-lg {
    min-height: 56px;
    font-size: 1.5rem;
}

#discountModal .modal-footer .btn {
    min-height: 48px;
}

/* Till close/sign out modal buttons */
#closeTillModal .modal-footer .btn,
#signOutModal .modal-footer .btn {
    min-height: 48px;
}

@media (min-width: 768px) {
    #closeTillModal .modal-footer .btn,
    #signOutModal .modal-footer .btn {
        min-height: 56px;
        font-size: 1.05rem;
    }
}

/* Till closed summary modal */
#tillClosedModal .modal-footer .btn {
    min-height: 56px;
    padding: 0.75rem 2rem;
}

/* Cart header buttons (Sign Out, Close Till) */
.cart-panel .card-header .btn-sm {
    min-height: 36px;
    padding: 0.375rem 0.75rem;
}

@media (min-width: 768px) {
    .cart-panel .card-header .btn-sm {
        min-height: 44px;
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
    }
}

/* Barcode input clear button */
.keypad-panel .input-group .btn-outline-danger {
    min-width: 48px;
    padding: 0.5rem 0.75rem;
}

@media (min-width: 768px) {
    .keypad-panel .input-group .btn-outline-danger {
        min-width: 56px;
        padding: 0.75rem 1rem;
    }
}

/* Select elements in modals (refund reason dropdown) */
.modal .form-select-lg {
    min-height: 56px;
}

/* Touch-friendly spacing for cart item content */
@media (min-width: 768px) and (max-width: 1199.98px) {
    .cart-item strong {
        font-size: 1.1rem;
    }

    .cart-item small {
        font-size: 0.9rem;
    }
}

/* Improved visual feedback for touch */
.btn:active,
.cart-item:active,
.keypad-btn:active {
    transform: scale(0.97);
    opacity: 0.9;
}

/* Focus visible for accessibility */
.btn:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible {
    outline: 3px solid rgba(26, 60, 52, 0.5);
    outline-offset: 2px;
}

/* Larger touch area for cart item selection */
@media (pointer: coarse) {
    .cart-item {
        padding: 1rem 0.75rem;
        min-height: 70px;
    }

    .keypad-btn {
        min-height: 65px;
    }

    .quick-btn {
        min-height: 55px;
    }
}

/* ==========================================================================
   Barcode Scanner
   ========================================================================== */

/* Scanner viewport container */
.scanner-viewport {
    position: relative;
    min-height: 300px;
    overflow: hidden;
    background: #000;
}

.scanner-viewport video {
    width: 100%;
    height: auto;
    display: block;
}

.scanner-viewport canvas.drawingBuffer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* Scanner overlay with scan region guide */
.scanner-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Scan region box - visual guide for user */
.scanner-region {
    width: 70%;
    max-width: 300px;
    height: 100px;
    border: 3px solid rgba(26, 60, 52, 0.8);
    border-radius: 8px;
    box-shadow: 0 0 0 4000px rgba(0, 0, 0, 0.4);
    animation: scanner-pulse 2s ease-in-out infinite;
}

@keyframes scanner-pulse {
    0%, 100% {
        border-color: rgba(26, 60, 52, 0.6);
    }
    50% {
        border-color: rgba(26, 60, 52, 1);
    }
}

/* Scan success flash effect */
.scanner-viewport.scan-success .scanner-region {
    border-color: #10b981;
    animation: scanner-success 0.3s ease-out;
}

@keyframes scanner-success {
    0% {
        transform: scale(1);
        border-color: #10b981;
    }
    50% {
        transform: scale(1.05);
        border-color: #10b981;
    }
    100% {
        transform: scale(1);
        border-color: #10b981;
    }
}

/* Scanner modal responsive adjustments */
@media (max-width: 767.98px) {
    .scanner-viewport {
        min-height: 250px;
    }

    .scanner-region {
        width: 80%;
        height: 80px;
    }
}

@media (min-width: 768px) {
    .scanner-viewport {
        min-height: 350px;
    }
}

/* The receipt's accountant's mark: a double rule above the TOTAL row.
   (The row's bg-dark never rendered - Bootstrap td backgrounds paint over
   row utilities - and the paper total reads better anyway.) */
.cart-panel .card-footer tr:last-child td {
    border-top: 3px double var(--ks-ink);
}
