/*
 * Till layout layer (POS redesign, 2026-09).
 *
 * Loaded after pos.css, design-system.css, viewport-compact.css and
 * workspace.css, so the cashier screen has one place that decides its
 * composition, menu density, type hierarchy and surface treatment instead of
 * the result of four sheets overriding one another. Everything is scoped to
 * the counter screen (.pos-counter-screen) or the POS page body.
 *
 * Measured before this layer (headless Chrome, Beanery catalog):
 *   - product grid started 244px down at 1520x730 (a third of the height)
 *   - product names rendered at 13px/600, prices in monospace accent colour
 *   - four favourites took a full row of the grid, the rest of it empty
 *   - portrait 768x1024 showed ~1.5 cart lines in a permanent half-screen split
 * See docs/POS-REDESIGN-2026-09.md for the decisions and the after numbers.
 */

/* ---- Tokens ------------------------------------------------------------ */

.pos-counter-screen {
    /* Deliberate card width: grows with the screen instead of adding columns
       until each card is ~105px wide on a large monitor. */
    --till-card-min: clamp(132px, 11vw, 220px);
    --till-card-gap: 10px;
    --till-name-size: 0.9375rem;   /* 15px at the 16px root */
    --till-price-size: 0.875rem;   /* 14px */
    --till-meta-size: 0.75rem;     /* 12px - stock and badges */
}

.pos-counter-screen .pos-products-panel[data-density="compact"] {
    --till-card-min: clamp(124px, 8.5vw, 168px);
}

/* ---- Global search is not a sale-time control -------------------------- */

/* design-system.css already meant to hide this on the till, but its rule
   (body[data-page] .top-bar-search) loses to #topBar .top-bar-search. Ctrl+K
   still opens the command palette. */
body[data-page="pos"] #topBar .top-bar-search {
    display: none;
}

/* ---- One bar: order controls + product search + categories ------------- */

.pos-counter-screen .pos-products-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 10px;
    padding: 8px 12px 4px;
    background: var(--bg-void);
    flex-shrink: 0;
}

/* When there is room the search and the category rail share one row; on a
   narrow products column the categories wrap to a second row by themselves. */
/* No max-width: sharing a row, flex 1 vs 999 keeps it near its basis; alone
   on its row (narrow till) it takes the width instead of leaving a gap. */
.pos-counter-screen .pos-products-bar > .pos-products-toolbar {
    flex: 1 1 380px;
    padding: 0;
    background: transparent;
    gap: 4px;
}

/* The icon buttons beside it must not squeeze the search to a stub. */
.pos-counter-screen .pos-products-toolbar .search-bar {
    min-width: 160px;
}

/* 300px basis: with the labelled Photos | Compact switch in the toolbar, a
   380px basis pushed the categories onto a second row at 1280 and 1366. */
.pos-counter-screen .pos-products-bar > .pos-categories {
    flex: 999 1 300px;
    min-width: 0;
    padding: 0;
    height: 44px;
    min-height: 44px;
    max-height: 44px;
    background: transparent;
}

.pos-counter-screen .pos-products-toolbar .search-bar .input {
    height: 44px;
    font-size: var(--ds-text-sm);
}

.pos-counter-screen .pos-toolbar-btn {
    width: 44px;
    height: 44px;
    border-color: transparent;
    background: transparent;
    color: var(--ds-text-secondary);
}

.pos-counter-screen .pos-toolbar-btn:hover {
    background: var(--ds-surface-alt);
    border-color: transparent;
    color: var(--ds-text-primary);
}

.pos-counter-screen .pos-toolbar-btn[aria-pressed="true"] {
    background: var(--ds-primary-tint);
    color: var(--ds-primary);
}

/* Photos | Compact: a labelled two-way switch, 44px tall. */
.pos-density-switch {
    display: inline-flex;
    flex-shrink: 0;
    padding: 2px;
    border-radius: var(--ds-radius-md);
    background: var(--ds-surface-alt);
}

.pos-density-opt {
    min-height: 40px;
    padding: 0 12px;
    border: 0;
    border-radius: calc(var(--ds-radius-md) - 2px);
    background: transparent;
    color: var(--ds-text-secondary);
    font: inherit;
    font-size: var(--ds-text-sm);
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
}

.pos-density-opt[aria-pressed="true"] {
    background: var(--ds-surface);
    color: var(--ds-text-primary);
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
}

.pos-density-opt:focus-visible {
    outline: 3px solid var(--ds-primary);
    outline-offset: 1px;
}

.pos-counter-screen .pos-products-toolbar .pos-screen-back,
.pos-counter-screen .pos-products-toolbar .pos-counter-chip {
    min-height: 44px;
    flex-shrink: 0;
}

.pos-counter-screen .pos-products-toolbar .pos-screen-overflow-wrap {
    position: relative;
    flex-shrink: 0;
}

.pos-counter-screen .pos-products-toolbar .pos-screen-overflow-btn {
    width: 44px;
    height: 44px;
}

/* ---- Open-order tabs: identity and amount, without a pill on each ------- */

.pos-counter-screen .pos-order-tab {
    box-shadow: none;
}

.pos-counter-screen .pos-order-tab .tab-amount {
    font-family: var(--ds-font-sans, inherit);
    font-variant-numeric: tabular-nums;
    font-weight: 500;
    color: var(--ds-text-secondary);
    background: transparent;
    padding: 0;
}

.pos-counter-screen .pos-order-tab .tab-badge {
    font-family: var(--ds-font-sans, inherit);
    background: var(--ds-surface-alt);
    color: var(--ds-text-secondary);
    font-weight: 600;
}

/* ---- Categories: flat until selected ----------------------------------- */

.pos-counter-screen .pos-cat-btn {
    border-color: transparent;
    background: transparent;
    font-weight: 500;
    color: var(--ds-text-secondary);
}

.pos-counter-screen .pos-cat-btn:hover {
    background: var(--ds-surface-alt);
    border-color: transparent;
    color: var(--ds-text-primary);
}

.pos-counter-screen .pos-cat-btn.active {
    background: var(--ds-primary-tint);
    border-color: transparent;
    color: var(--ds-primary);
    font-weight: 600;
}

.pos-counter-screen .pos-cat-rail-btn {
    border-color: transparent;
    background: var(--ds-surface-alt);
}

/* ---- Grid and cards ---------------------------------------------------- */

.pos-counter-screen .pos-product-grid {
    padding: 6px 12px 16px;
    gap: 10px;
}

.pos-counter-screen .pos-menu-section-grid,
.pos-counter-screen .pos-product-grid:not(:has(.pos-menu-section)) {
    grid-template-columns: repeat(auto-fill, minmax(var(--till-card-min), 1fr));
    gap: var(--till-card-gap);
}

.pos-counter-screen .pos-product-card {
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius-md, 12px);
    box-shadow: none;
    background: var(--ds-surface);
}

.pos-counter-screen .pos-product-card:hover {
    transform: none;
    box-shadow: none;
    border-color: var(--ds-border-strong);
}

.pos-counter-screen .pos-product-card:hover .product-img {
    transform: none;
}

/* One frame for every photo: contained on a neutral well, so an isolated cup
   and a tightly cropped glass sit at a similar scale instead of one filling
   the tile and the next floating in it. */
/* 16:10, not 4:3: at 1520x730 the taller frame left two full rows on screen.
   On a wide-but-short till (the 1520x730 class) it goes to 2:1. */
.pos-counter-screen .pos-product-card .product-img-well {
    aspect-ratio: 16 / 10;
    background: var(--ds-surface-alt);
    border-radius: 0;
}

@media (min-width: 1280px) and (max-height: 820px) {
    .pos-counter-screen .pos-product-card .product-img-well {
        aspect-ratio: 2 / 1;
    }
}

.pos-counter-screen .pos-product-card .product-img-well .product-img {
    object-fit: contain;
    padding: 6%;
    box-sizing: border-box;
    border-radius: 0;
}

.pos-counter-screen .pos-product-card .product-name {
    font-size: var(--till-name-size);
    font-weight: 500;
    line-height: 1.3;
    color: var(--ds-text-primary);
    padding: 8px 10px 0;
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    /* Two lines reserved so a one-line name does not make its row uneven. */
    min-height: calc(2.6em + 8px);
}

.pos-counter-screen .pos-product-card .product-price {
    font-family: var(--ds-font-sans, inherit);
    font-size: var(--till-price-size);
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    color: var(--ds-text-secondary);
    padding: 4px 10px 10px;
    margin-top: auto;
}

.pos-counter-screen .pos-product-card .product-price .ds-tabular {
    font-family: inherit;
}

/* Text-first tiles (compact density, or a catalog with few photos). */
.pos-counter-screen .pos-product-card.is-text-only {
    min-height: 76px;
    justify-content: space-between;
}

.pos-counter-screen .pos-product-card.is-text-only .product-name {
    padding-top: 10px;
}

/* Stock is metadata: small and quiet, amber when low, red only below zero. */
.pos-counter-screen .pos-product-card .product-stock {
    font-size: var(--till-meta-size);
    font-weight: 500;
    background: var(--ds-surface);
    color: var(--ds-text-secondary);
    border: 1px solid var(--ds-border);
}

.pos-counter-screen .pos-product-card .product-stock.low-stock {
    background: var(--ds-warning-tint);
    color: var(--ds-warning-text, var(--ds-text-primary));
    border-color: transparent;
}

.pos-counter-screen .pos-product-card .product-stock.negative-stock {
    background: var(--ds-danger-tint);
    color: var(--ds-danger);
    border-color: transparent;
}

/* Text-only tiles carry the badge in the price row (see renderProductCard),
   in flow, so it can never cover the name. */
.pos-counter-screen .pos-product-card .product-price .product-stock {
    position: static;
    margin-inline-start: auto;
    padding: 1px 6px;
    border-radius: 4px;
    line-height: 1.3;
}

/* ---- Favourites: a quick-pick strip, not a grid row --------------------- */

/* One row. More favourites than fit scroll sideways; the trailing fade and a
   visibly cut-off pill say there is more, which a hidden-scrollbar row did not
   (the reason the category strip had moved away from that pattern). */
.pos-quick-picks {
    display: flex;
    /* A flex item with overflow != visible gets min-height 0 and the grid's
       column squeezed it to its padding; it must keep its own height. */
    flex-shrink: 0;
    flex-wrap: nowrap;
    align-items: center;
    gap: 8px;
    padding: 2px 32px 6px 0;
    overflow-x: auto;
    scrollbar-width: thin;
    -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent);
    mask-image: linear-gradient(to right, #000 calc(100% - 32px), transparent);
}

body[dir="rtl"] .pos-quick-picks {
    padding: 2px 0 6px 32px;
    -webkit-mask-image: linear-gradient(to left, #000 calc(100% - 32px), transparent);
    mask-image: linear-gradient(to left, #000 calc(100% - 32px), transparent);
}

.pos-quick-picks-icon {
    width: 18px;
    height: 18px;
    color: var(--ds-warning);
    flex-shrink: 0;
    margin-inline-end: 2px;
}

.pos-quick-pick {
    display: inline-flex;
    flex-shrink: 0;
    align-items: center;
    gap: 6px;
    min-height: 44px;
    max-width: 210px;
    padding: 3px 12px 3px 3px;
    border: 1px solid var(--ds-border);
    border-radius: var(--ds-radius-pill, 999px);
    background: var(--ds-surface);
    color: var(--ds-text-primary);
    font: inherit;
    font-size: var(--ds-text-sm);
    font-weight: 500;
    cursor: pointer;
    text-align: start;
}

.pos-quick-pick:hover {
    border-color: var(--ds-border-strong);
}

.pos-quick-pick:focus-visible {
    outline: 3px solid var(--ds-primary);
    outline-offset: 2px;
}

.pos-quick-pick.added {
    border-color: var(--ds-primary);
}

.pos-quick-pick.is-sold-out {
    opacity: 0.55;
}

.pos-quick-pick-thumb {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--ds-surface-alt);
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    font-size: var(--till-meta-size);
    font-weight: 600;
    color: var(--ds-text-secondary);
}

.pos-quick-pick-thumb img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 3px;
    box-sizing: border-box;
}

.pos-quick-pick-name {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pos-quick-pick-price {
    color: var(--ds-text-secondary);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    font-size: var(--ds-text-xs);
}

/* Narrow menu column (a 1024 till): name only, so ~3-4 picks fit instead
   of two and a clipped third. The price is on the tile in the grid below. */
.pos-counter-screen .pos-products-panel {
    container-type: inline-size;
    container-name: till-products;
}

@container till-products (max-width: 760px) {
    .pos-quick-pick-price {
        display: none;
    }

    .pos-quick-pick {
        max-width: 170px;
    }
}

/* ---- Cart: a list, not a stack of cards --------------------------------- */

.pos-counter-screen .pos-order-item {
    border: 0;
    border-bottom: 1px solid var(--ds-border);
    border-radius: 0;
    margin: 0;
    padding: 10px 14px;
    background: transparent;
}

.pos-counter-screen .pos-order-item.is-addon {
    margin-inline-start: 26px;
    margin-top: 0;
}

.pos-counter-screen .pos-order-item:hover {
    background: var(--ds-surface-alt);
}

.pos-counter-screen .pos-order-item.selected {
    background: var(--ds-primary-tint);
}

.pos-counter-screen .pos-order-item .item-name {
    font-weight: 500;
}

.pos-counter-screen .pos-order-item .item-total {
    font-family: var(--ds-font-sans, inherit);
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    color: var(--ds-text-primary);
}

.pos-counter-screen .pos-order-item .qty-btn {
    background: transparent;
    border-color: var(--ds-border);
}

.pos-counter-screen .pos-order-panel-title {
    font-weight: 600;
}

/* Secondary actions stay quiet so Charge is the one strong control. */
.pos-counter-screen .pos-utility-tile {
    background: transparent;
    color: var(--ds-text-secondary);
    border-color: var(--ds-border);
    min-height: 52px;
}

.pos-counter-screen .pos-utility-tile:hover:not(:disabled) {
    background: var(--ds-surface-alt);
    color: var(--ds-text-primary);
}

/* ---- Portrait: menu first, cart as a tray -------------------------------- */

/*
 * The tray is the terminal's second grid row, not a position:fixed layer: the
 * page already ends above the phone bottom nav, and a fixed layer measured
 * from the wrong containing block floated 64px above it. Collapsed it is the
 * total and Charge; open, the screen splits menu / order so the cashier can
 * keep adding while reading the lines.
 */
.pos-cart-handle {
    display: none;
}

@media (orientation: portrait) and (max-width: 1100px) {
    .pos-counter-screen .pos-terminal {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: minmax(0, 1fr) auto;
    }

    .pos-counter-screen .pos-terminal:has(.pos-order-panel.is-tray-open) {
        grid-template-rows: minmax(0, 2fr) minmax(0, 3fr);
    }

    .pos-counter-screen .pos-products-panel {
        border: 0;
        min-height: 0;
    }

    .pos-counter-screen .pos-order-panel {
        position: static;
        min-height: 0;
        max-height: none;
        width: auto;
        padding: 0;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        background: var(--ds-surface);
        border-top: 1px solid var(--ds-border);
        box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.08);
    }

    .pos-counter-screen .pos-order-panel > #orderPanel {
        border-radius: 0;
        box-shadow: none;
        border: 0;
        min-height: 0;
    }

    .pos-counter-screen .pos-cart-handle {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        min-height: 36px;
        width: 100%;
        border: 0;
        background: transparent;
        color: var(--ds-text-secondary);
        font: inherit;
        font-size: var(--ds-text-sm);
        font-weight: 500;
        cursor: pointer;
    }

    .pos-cart-handle-grip {
        width: 36px;
        height: 4px;
        border-radius: 2px;
        background: var(--ds-border-strong);
    }

    .pos-cart-handle svg {
        width: 16px;
        height: 16px;
        transition: transform var(--ds-duration-fast, 120ms) var(--ds-ease-standard);
    }

    .pos-order-panel.is-tray-open .pos-cart-handle svg {
        transform: rotate(180deg);
    }

    /* Collapsed: total and Charge only. */
    .pos-counter-screen .pos-order-panel:not(.is-tray-open) .pos-order-header,
    .pos-counter-screen .pos-order-panel:not(.is-tray-open) .pos-edit-banner,
    .pos-counter-screen .pos-order-panel:not(.is-tray-open) .pos-view-banner,
    .pos-counter-screen .pos-order-panel:not(.is-tray-open) #orderItems,
    .pos-counter-screen .pos-order-panel:not(.is-tray-open) .ds-seam,
    .pos-counter-screen .pos-order-panel:not(.is-tray-open) .pos-utility-grid,
    .pos-counter-screen .pos-order-panel:not(.is-tray-open) .pos-order-notes,
    .pos-counter-screen .pos-order-panel:not(.is-tray-open) .pos-summary-row:not(.total-row) {
        display: none;
    }

    .pos-counter-screen .pos-order-panel:not(.is-tray-open) .pos-order-footer {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: 12px;
        padding: 0 16px 12px;
    }

    .pos-counter-screen .pos-order-panel:not(.is-tray-open) .pos-order-summary {
        padding: 0;
        margin: 0;
    }

    .pos-counter-screen .pos-order-panel:not(.is-tray-open) .pos-charge-btn {
        margin: 0;
        min-width: 220px;
    }

    /* Open: the order takes the lower three fifths. */
    .pos-counter-screen .pos-order-panel.is-tray-open > #orderPanel {
        flex: 1;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .pos-counter-screen .pos-order-panel.is-tray-open #orderItems {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
    }
}
