/* ═══════════════════════════════════════════════════════════════════════════
   ALZAR POS MODULE – iPad / Tablet-First Point-of-Sale UI
   Dark Glassmorphism · Touch Optimised (48px min targets) · Responsive
   Uses design tokens from base/variables.css
   File: css/modules/pos.css
   ═══════════════════════════════════════════════════════════════════════════ */

/* ─── MASTER LAYOUT: 65 / 35 Split ─────────────────────────────────────── */
.pos-shell {
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 0;
    height: calc(100vh - 56px);      /* minus view-header */
    overflow: hidden;
}

.pos-products {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 16px 20px;
    gap: 14px;
}

.pos-ticket {
    display: flex;
    flex-direction: column;
    background: rgba(15, 23, 42, 0.70);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-left: 1px solid var(--color-border);
    overflow: hidden;
}

/* ─── SEARCH / SCAN BAR ────────────────────────────────────────────────── */
.pos-search-bar {
    display: flex;
    gap: 10px;
    align-items: center;
}

.pos-search-bar .pos-search-input {
    flex: 1;
    position: relative;
}

.pos-search-bar .pos-search-input input {
    width: 100%;
    padding: 12px 14px 12px 40px;
    min-height: 48px;
    background: rgba(0,0,0,0.25);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    color: var(--color-text-main);
    font-size: 0.95rem;
    font-family: var(--font-base);
    transition: border-color 0.2s;
}

.pos-search-bar .pos-search-input input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.15);
}

.pos-search-bar .pos-search-input .search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--color-text-muted);
    pointer-events: none;
    font-size: 1.1rem;
}

/* ─── CATEGORY TABS ────────────────────────────────────────────────────── */
.pos-category-tabs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

@media not all and (min-resolution:.001dpcm) {
    @supports (-webkit-appearance:none) {
        .pos-category-tabs::-webkit-scrollbar { display: none; }
    }
}

.pos-cat-tab {
    min-height: 48px;
    padding: 10px 18px;
    border: 1px solid var(--color-border);
    border-radius: 10px;
    background: var(--color-bg-surface);
    color: var(--color-text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

.pos-cat-tab:hover {
    border-color: var(--color-primary);
    color: var(--color-text-main);
}

.pos-cat-tab.active {
    background: var(--color-primary);
    color: var(--color-bg-base);
    border-color: var(--color-primary);
}

/* ─── PRODUCT GRID ─────────────────────────────────────────────────────── */
.pos-grid {
    flex: 1;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
    align-content: start;
    padding: 4px 2px 16px;
}

/* ─── PRODUCT CARD (.pos-card) ─────────────────────────────────────────── */
.pos-card {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 130px;
    padding: 14px;
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border);
    border-radius: 10px;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.pos-card:hover {
    transform: translateY(-2px);
    border-color: var(--color-primary);
    box-shadow: 0 6px 20px rgba(34, 197, 94, 0.12);
}

.pos-card:active {
    transform: scale(0.97);
}

.pos-card .pos-card-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--color-text-main);
    line-height: 1.3;
    margin-bottom: 6px;
    /* Clamp to 2 lines */
    display: -webkit-box;           /* Required */
    -webkit-line-clamp: 2;          /* Limit to 2 lines */
    -webkit-box-orient: vertical;   /* Required */
    overflow: hidden;               /* Hide the rest */
}

.pos-card .pos-card-sku {
    font-size: 0.72rem;
    color: var(--color-text-muted);
    margin-bottom: auto;
}

.pos-card .pos-card-footer {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-top: 10px;
}

.pos-card .pos-card-price {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--color-primary);
}

.pos-card .pos-card-stock {
    font-size: 0.72rem;
    padding: 2px 8px;
    border-radius: 20px;
    font-weight: 600;
}

.pos-card .pos-card-stock.in-stock     { background: rgba(34,197,94,0.12); color: #22c55e; }
.pos-card .pos-card-stock.low-stock    { background: rgba(234,179,8,0.12); color: #eab308; }
.pos-card .pos-card-stock.out-of-stock { background: rgba(239,68,68,0.12); color: #ef4444; }

/* ─── EMPTY GRID STATE ─────────────────────────────────────────────────── */
.pos-grid-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 48px 16px;
    color: var(--color-text-muted);
}

.pos-grid-empty i {
    font-size: 3rem;
    display: block;
    margin-bottom: 12px;
    opacity: 0.4;
}

/* =======================================================================
   THE TICKET  (Right sidebar — Cart + Totals)
   ======================================================================= */

.pos-ticket-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}

.pos-ticket-header h3 {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--color-text-main);
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
}

.pos-ticket-header .badge-counter {
    position: relative;
    top: auto;
    right: auto;
    background: var(--color-primary);
    color: var(--color-bg-base);
    font-size: 0.75rem;
    font-weight: 700;
    min-width: 24px;
    height: 24px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 7px;
    margin-left: 8px;
}

/* ─── Customer Bar (inside ticket) ─────────────────────────────────────── */
.pos-ticket-customer {
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.pos-ticket-customer input {
    flex: 1;
    min-height: 40px;
    padding: 8px 10px;
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    color: var(--color-text-main);
    font-size: 0.82rem;
    font-family: var(--font-base);
}

.pos-ticket-customer input:focus {
    outline: none;
    border-color: var(--color-primary);
}

/* ─── TICKET ITEM (.pos-ticket-item) ───────────────────────────────────── */
.pos-ticket-items {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
}

.pos-ticket-item {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    border-bottom: 1px solid rgba(51, 65, 85, 0.5);
    transition: background 0.15s;
}

.pos-ticket-item:hover {
    background: rgba(255,255,255,0.02);
}

.pos-ticket-item .item-info {
    min-width: 0;
}

.pos-ticket-item .item-name {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--color-text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pos-ticket-item .item-meta {
    font-size: 0.72rem;
    color: var(--color-text-muted);
    display: flex;
    gap: 8px;
    margin-top: 2px;
}

.pos-ticket-item .item-meta .badge {
    font-size: 0.65rem;
    padding: 1px 6px;
    border-radius: 4px;
    font-weight: 600;
    text-transform: uppercase;
}

.pos-ticket-item .item-line-total {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--color-text-main);
    white-space: nowrap;
    text-align: right;
    min-width: 65px;
}

/* ─── QTY STEPPER ──────────────────────────────────────────────────────── */
.pos-qty-stepper {
    display: inline-flex;
    align-items: center;
    gap: 0;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    overflow: hidden;
    flex-shrink: 0;
}

.pos-qty-stepper button {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-bg-hover);
    border: none;
    color: var(--color-text-main);
    font-size: 1rem;
    cursor: pointer;
    transition: background 0.15s;
    touch-action: manipulation;
}

.pos-qty-stepper button:hover {
    background: var(--color-primary);
    color: var(--color-bg-base);
}

.pos-qty-stepper .qty-display {
    width: 36px;
    text-align: center;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--color-text-main);
    background: transparent;
}

/* ─── TICKET EMPTY STATE ───────────────────────────────────────────────── */
.pos-ticket-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--color-text-muted);
    gap: 8px;
    padding: 32px 16px;
}

.pos-ticket-empty i { font-size: 2.5rem; opacity: 0.3; }
.pos-ticket-empty p { font-size: 0.85rem; }

/* =======================================================================
   TOTALS + ACTION BAR (bottom of ticket)
   ======================================================================= */

.pos-totals {
    padding: 14px 16px;
    border-top: 1px solid var(--color-border);
    background: rgba(0,0,0,0.15);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.pos-total-line {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    color: var(--color-text-muted);
}

.pos-total-line span:last-child {
    color: var(--color-text-main);
    font-weight: 500;
}

.pos-total-display {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--color-text-main);
    padding: 6px 0 4px;
    letter-spacing: -0.5px;
}

.pos-total-display .total-amount {
    color: var(--color-primary);
}

/* ─── TIP CONTROLS ─────────────────────────────────────────────────────── */
.pos-tips-row {
    display: flex;
    gap: 6px;
    align-items: center;
}

.pos-tips-row .btn-chip {
    min-height: 34px;
    padding: 6px 12px;
    border: 1px solid var(--color-border);
    border-radius: 20px;
    background: transparent;
    color: var(--color-text-muted);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    touch-action: manipulation;
}

.pos-tips-row .btn-chip:hover,
.pos-tips-row .btn-chip.active {
    background: var(--color-primary);
    color: var(--color-bg-base);
    border-color: var(--color-primary);
}

.pos-tips-row input {
    width: 68px;
    min-height: 34px;
    padding: 4px 8px;
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--color-border);
    border-radius: 6px;
    color: var(--color-text-main);
    font-size: 0.82rem;
    text-align: center;
    font-family: var(--font-base);
}

/* ─── ACTION BUTTONS (bottom) ──────────────────────────────────────────── */
.pos-actions {
    margin: 0 2px 16px 0;
    padding: 12px;
    border: 2px solid var(--color-border);
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-shrink: 0;
}

.pos-actions .pos-checkout-btn {
    min-height: 56px;
    width: 100%;
    border: none;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 700;
    font-family: var(--font-base);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.2s;
    touch-action: manipulation;
}

.pos-checkout-btn.pay-card {
    background: var(--color-primary);
    color: var(--color-bg-base);
}

.pos-checkout-btn.pay-card:hover:not(:disabled) {
    background: #16a34a;
    box-shadow: 0 4px 20px rgba(34, 197, 94, 0.3);
}

.pos-checkout-btn.pay-card:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.pos-checkout-btn.pay-card:active:not(:disabled) {
    transform: scale(0.98);
}

.pos-actions-row {
    display: flex;
    gap: 8px;
}

.pos-actions-row .btn {
    flex: 1;
    min-height: 48px;
    justify-content: center;
}

/* ─── STRIPE CARD MOUNT ────────────────────────────────────────────────── */
.pos-stripe-mount {
    margin: 8px 16px 0;
    padding: 12px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    min-height: 48px;
    background: rgba(0,0,0,0.15);
}

.pos-stripe-mount .StripeElement--focus {
    border-color: var(--color-primary);
}

/* ─── BADGES ───────────────────────────────────────────────────────────── */
.badge           { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 0.7rem; font-weight: 600; text-transform: uppercase; }
.badge-success   { background: rgba(34,197,94,0.15); color: #22c55e; }
.badge-warning   { background: rgba(234,179,8,0.15); color: #eab308; }
.badge-danger    { background: rgba(239,68,68,0.15); color: #ef4444; }
.badge-info      { background: rgba(59,130,246,0.15); color: #3b82f6; }

/* ─── SEARCH DROPDOWN (autocomplete) ───────────────────────────────────── */
.pos-search-dropdown {
    position: absolute;
    left: 0; right: 0;
    top: 100%;
    z-index: 200;
    background: var(--color-bg-surface);
    border: 1px solid var(--color-border);
    border-top: none;
    border-radius: 0 0 10px 10px;
    max-height: 260px;
    overflow-y: auto;
    box-shadow: 0 12px 32px rgba(0,0,0,0.5);
}

.pos-search-item {
    padding: 12px 14px;
    cursor: pointer;
    border-bottom: 1px solid rgba(51,65,85,0.4);
    font-size: 0.85rem;
    transition: background 0.12s;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 48px;
}

.pos-search-item:hover {
    background: var(--color-bg-hover);
}

.pos-search-item:last-child { border-bottom: none; }

/* ─── TODAY TOTAL PILL ─────────────────────────────────────────────────── */
.pos-today-total {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--color-primary);
    background: rgba(34, 197, 94, 0.10);
    padding: 6px 14px;
    border-radius: 8px;
}

/* ─── KEYPAD MODAL ─────────────────────────────────────────────────────── */
.pos-keypad {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    max-width: 280px;
    margin: 0 auto;
}

.pos-keypad button {
    min-height: 56px;
    border: 1px solid var(--color-border);
    border-radius: 10px;
    background: var(--color-bg-surface);
    color: var(--color-text-main);
    font-size: 1.3rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.12s;
    touch-action: manipulation;
}

.pos-keypad button:hover { background: var(--color-bg-hover); }
.pos-keypad button:active { transform: scale(0.95); }
.pos-keypad button.key-action { background: var(--color-primary); color: var(--color-bg-base); }
.pos-keypad button.key-clear  { background: rgba(239,68,68,0.15); color: #ef4444; }

.pos-keypad-display {
    text-align: center;
    font-size: 2.2rem;
    font-weight: 700;
    color: var(--color-text-main);
    padding: 16px;
    margin-bottom: 12px;
    background: rgba(0,0,0,0.2);
    border-radius: 10px;
    border: 1px solid var(--color-border);
    letter-spacing: 1px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace, var(--font-base);
}

/* ─── UTILITY ──────────────────────────────────────────────────────────── */
.w-full  { width: 100%; }
.mt-3    { margin-top: 12px; }
.mt-4    { margin-top: 16px; }
.p-0     { padding: 0; }
.btn-lg  { padding: 12px 24px !important; font-size: 1rem !important; min-height: 48px; }
.btn-sm  { padding: 4px 10px !important; font-size: 0.8rem !important; }

/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE: Tablet Portrait + Mobile
   ═══════════════════════════════════════════════════════════════════════════ */

@media (max-width: 1024px) {
    .pos-shell {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr auto;
        height: auto;
        min-height: calc(100vh - 56px);
    }

    .pos-ticket {
        border-left: none;
        border-top: 1px solid var(--color-border);
        max-height: 50vh;
    }

    .pos-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    }
}

/* Mobile: stacked with collapsible ticket */
@media (max-width: 640px) {
    .pos-products { padding: 10px 12px; gap: 10px; }

    .pos-grid {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
        gap: 8px;
    }

    .pos-card { min-height: 110px; padding: 10px; }
    .pos-card .pos-card-name { font-size: 0.82rem; }
    .pos-card .pos-card-price { font-size: 0.95rem; }

    .pos-ticket {
        position: fixed;
        bottom: 0; left: 0; right: 0;
        max-height: 70vh;
        border-radius: 16px 16px 0 0;
        z-index: 500;
        transform: translateY(calc(100% - 64px));
        transition: transform 0.3s ease;
        box-shadow: 0 -8px 40px rgba(0,0,0,0.5);
    }

    .pos-ticket.drawer-open {
        transform: translateY(0);
    }

    /* Drawer handle */
    .pos-ticket-header::before {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 36px;
        height: 4px;
        border-radius: 4px;
        background: var(--color-text-muted);
        opacity: 0.4;
    }

    .pos-ticket-header {
        position: relative;
        padding-top: 20px;
        cursor: pointer;
    }

    /* Give main area bottom padding so cart drawer doesn't cover products */
    .pos-products {
        padding-bottom: 72px;
    }
}

.w-full { width: 100%; }

.tip-controls {
    display: flex;
    gap: 6px;
    align-items: center;
}

.tip-input {
    width: 70px;
}

.job-list {
    max-height: 400px;
    overflow-y: auto;
}
