:root {
    color-scheme: light;
    --bg: #f5f7fb;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --line: #dbe3ef;
    --line-strong: #bfd0e4;
    --text: #132238;
    --muted: #59708b;
    --accent: #0f6d5f;
    --accent-strong: #0b5a4e;
    --danger: #b42318;
    --danger-soft: #fff1f0;
    --warning: #a15c00;
    --warning-soft: #fff7e8;
    --success-soft: #edf9f5;
    --shadow: 0 12px 30px rgba(15, 23, 42, 0.08);
    --radius-xl: 24px;
    --radius-lg: 18px;
    --radius-md: 14px;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    margin: 0;
    min-height: 100%;
    overscroll-behavior: none;
    touch-action: manipulation;
}

body {
    font-family: "Inter", "Avenir Next", "Segoe UI", sans-serif;
    background:
        radial-gradient(circle at top left, rgba(15, 109, 95, 0.08), transparent 26%),
        linear-gradient(180deg, #f8fbff 0%, var(--bg) 100%);
    color: var(--text);
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
}

button,
a,
.product-card,
.filter-chip,
.order-item {
    touch-action: manipulation;
    user-select: none;
}

.shell {
    padding: 0.85rem;
}

.products-panel,
.order-panel,
.modal-card {
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid rgba(219, 227, 239, 0.92);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
}

.stat-pill,
.sync-pill,
.admin-link,
.compact-action {
    min-height: 54px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.65rem 0.9rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--line);
    background: var(--surface-muted);
    text-decoration: none;
    color: var(--text);
    font-weight: 700;
}

.stat-pill,
.sync-pill {
    flex-direction: column;
    align-items: flex-start;
}

.stat-pill span,
.sync-pill span {
    font-size: 0.78rem;
    color: var(--muted);
    line-height: 1.1;
}

.stat-pill strong,
.sync-pill strong {
    font-size: 1.02rem;
    line-height: 1.1;
}

.sync-pill.online {
    border-color: rgba(15, 109, 95, 0.2);
    background: var(--success-soft);
}

.sync-pill.offline {
    border-color: rgba(180, 35, 24, 0.2);
    background: var(--danger-soft);
}

.sync-pill.syncing {
    border-color: rgba(161, 92, 0, 0.2);
    background: var(--warning-soft);
}

.admin-link {
    background: var(--surface);
    font-size: 0.95rem;
}

.compact-action {
    width: 100%;
    min-height: 54px;
    padding: 0.8rem 0.9rem;
}

.filters {
    display: flex;
    gap: 0.65rem;
    margin: 0.85rem 0;
    overflow-x: auto;
    padding-bottom: 0.15rem;
}

.filter-chip {
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.92);
    color: var(--text);
    border-radius: 999px;
    padding: 0.8rem 1rem;
    font-size: 0.98rem;
    font-weight: 800;
    min-height: 52px;
    white-space: nowrap;
}

.filter-chip.active {
    background: var(--accent);
    color: #fff;
    border-color: transparent;
}

.layout {
    display: grid;
    grid-template-columns: minmax(0, 1.9fr) minmax(320px, 0.95fr);
    gap: 0.85rem;
    align-items: start;
}

.products-panel,
.order-panel {
    padding: 0.95rem;
}

.products-panel {
    padding: 0;
    background: transparent;
    border: none;
    box-shadow: none;
    backdrop-filter: none;
}

.products-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(158px, 1fr));
    gap: 0.72rem;
}

.mobile-products-list,
.mobile-checkout-bar {
    display: none;
}

.product-card {
    border: 1px solid var(--line);
    background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
    border-radius: 22px;
    padding: 0.7rem;
    display: grid;
    gap: 0.55rem;
    min-height: 224px;
    position: relative;
    overflow: hidden;
    transition: transform 70ms ease, box-shadow 70ms ease, border-color 70ms ease;
    cursor: pointer;
    -webkit-touch-callout: none;
}

.product-card:active,
.product-card.is-pressed {
    transform: scale(0.985);
    border-color: var(--accent);
    box-shadow: inset 0 0 0 1px rgba(15, 109, 95, 0.18);
}

.product-card.disabled {
    opacity: 0.5;
    filter: grayscale(0.08);
    cursor: default;
}

.product-card img {
    width: 100%;
    height: 110px;
    object-fit: cover;
    border-radius: 16px;
    background: #edf2f7;
    pointer-events: none;
    user-select: none;
    -webkit-user-drag: none;
}

.product-card h3 {
    margin: 0;
    font-size: 1.06rem;
    line-height: 1.12;
    text-align: left;
}

.price-row,
.stock-row {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    font-size: 0.92rem;
    font-weight: 700;
    text-align: left;
}

.price-row span:last-child {
    color: var(--accent-strong);
    font-weight: 900;
}

.badge {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    min-width: 42px;
    min-height: 42px;
    padding: 0.5rem 0.65rem;
    border-radius: 999px;
    background: var(--accent);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: 0.98rem;
}

.order-panel {
    position: sticky;
    top: 0.85rem;
}

.order-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.8rem;
    margin-bottom: 0.9rem;
}

.order-head h2,
.modal-head h3 {
    margin: 0;
    font-size: 1.18rem;
    letter-spacing: -0.02em;
}

.order-head p,
.order-empty,
.order-line small,
.payment-check {
    color: var(--muted);
}

.order-total-box {
    background: var(--surface-muted);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 0.72rem 0.9rem;
    text-align: right;
    min-width: 126px;
}

.order-total-box span {
    display: block;
    font-size: 0.8rem;
    color: var(--muted);
}

.order-total-box strong {
    display: block;
    margin-top: 0.18rem;
    font-size: 1.75rem;
    line-height: 1.05;
}

.order-items {
    display: grid;
    gap: 0.68rem;
    margin: 0.9rem 0;
    max-height: calc(100vh - 290px);
    overflow: auto;
}

.order-empty {
    border: 1px dashed var(--line-strong);
    border-radius: 20px;
    padding: 1rem;
    text-align: center;
    background: rgba(248, 250, 252, 0.88);
}

.order-item {
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 0.82rem;
    display: grid;
    gap: 0.52rem;
    background: #fff;
}

.order-line {
    display: flex;
    justify-content: space-between;
    gap: 0.8rem;
    align-items: center;
}

.order-line strong {
    font-size: 1rem;
}

.order-item-actions {
    display: flex;
    gap: 0.45rem;
}

.pill-btn,
.action,
.payment-type,
.money-field,
.icon-btn {
    border: none;
    border-radius: 16px;
    font-weight: 800;
    cursor: pointer;
    min-height: 52px;
}

.pill-btn {
    padding: 0.75rem 0.9rem;
    background: var(--surface-muted);
    border: 1px solid var(--line);
}

.action {
    width: 100%;
    padding: 0.9rem 1rem;
    font-size: 1rem;
}

.action.primary {
    background: linear-gradient(180deg, var(--accent) 0%, var(--accent-strong) 100%);
    color: #fff;
}

.action.secondary {
    background: #eef4fb;
    color: var(--text);
    border: 1px solid var(--line);
}

.action.tertiary {
    background: #fff5f5;
    border: 1px solid #f4d0cf;
    color: var(--danger);
}

.order-actions {
    display: grid;
    gap: 0.65rem;
}

.status-card {
    margin-top: 0.85rem;
    display: grid;
    gap: 0.65rem;
    padding-top: 0.85rem;
    border-top: 1px solid var(--line);
}

.action:disabled,
.pill-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.modal.hidden,
.toast.hidden {
    display: none;
}

.modal {
    position: fixed;
    inset: 0;
    padding: 1rem;
    background: rgba(15, 23, 42, 0.4);
    display: grid;
    place-items: center;
    -webkit-touch-callout: none;
}

#payment-modal {
    z-index: 40;
}

#numeric-modal {
    z-index: 60;
}

.modal-card {
    width: min(680px, 100%);
    padding: 0.95rem;
}

.modal-card.compact {
    width: min(430px, 100%);
}

.modal-head,
.modal-actions {
    display: flex;
    justify-content: space-between;
    gap: 0.7rem;
    align-items: center;
}

.modal-head {
    margin-bottom: 0.2rem;
}

.modal-label {
    margin: 0;
    color: var(--muted);
    font-size: 0.86rem;
    font-weight: 700;
}

.big-display {
    border-radius: 20px;
    border: 1px solid var(--line);
    background: #fff;
    padding: 0.9rem 1rem;
    font-size: clamp(1.9rem, 5vw, 3rem);
    font-weight: 900;
    text-align: right;
    margin: 0.9rem 0;
}

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

.keypad-grid button {
    min-height: 76px;
    border-radius: 18px;
    border: 1px solid var(--line);
    background: #fff;
    font-size: 1.45rem;
    font-weight: 900;
}

.payment-summary {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: center;
    background: var(--surface-muted);
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 0.9rem 1rem;
    margin: 0.8rem 0 0.95rem;
}

.payment-summary strong {
    font-size: 1.85rem;
    line-height: 1;
}

.payment-types,
.payment-fields {
    display: grid;
    gap: 0.65rem;
    grid-template-columns: repeat(3, 1fr);
}

.payment-fields {
    grid-template-columns: repeat(2, 1fr);
    margin-top: 0.8rem;
}

.payment-type {
    background: #fff;
    border: 1px solid var(--line);
}

.payment-type.active {
    background: var(--accent);
    color: #fff;
    border-color: transparent;
}

.money-field {
    background: var(--surface-muted);
    border: 1px solid var(--line);
    padding: 0.9rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.money-field strong {
    font-size: 1.35rem;
}

.payment-check {
    min-height: 1.5rem;
    padding: 0.65rem 0 0;
    font-weight: 700;
}

.payment-check.is-valid {
    color: var(--accent-strong);
}

.payment-check.is-error {
    color: var(--danger);
}

.icon-btn {
    padding: 0.72rem 0.92rem;
    background: #eef4fb;
    border: 1px solid var(--line);
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 1rem;
    transform: translateX(-50%);
    background: rgba(19, 34, 56, 0.96);
    color: #fff;
    border-radius: 999px;
    padding: 0.9rem 1.15rem;
    z-index: 80;
    box-shadow: var(--shadow);
    font-weight: 800;
    max-width: min(92vw, 560px);
    text-align: center;
}

@media (max-width: 980px) {
    .layout {
        grid-template-columns: 1fr;
    }

    .order-panel {
        position: static;
    }

    .order-items {
        max-height: none;
    }
}

@media (max-width: 760px) {
    body {
        background: linear-gradient(180deg, #f8fbff 0%, var(--bg) 100%);
        padding-bottom: calc(86px + env(safe-area-inset-bottom));
    }

    .shell {
        padding: 0 0.5rem 0.5rem;
    }

    .topbar,
    .products-panel,
    .order-panel,
    .modal-card {
        border-radius: 18px;
    }

    .filters {
        position: sticky;
        top: 0;
        z-index: 10;
        margin: 0;
        padding: calc(0.35rem + env(safe-area-inset-top)) 0 0.55rem;
        background: linear-gradient(180deg, rgba(248, 251, 255, 0.98) 74%, rgba(248, 251, 255, 0));
    }

    .filter-chip {
        min-height: 42px;
        padding: 0.58rem 0.78rem;
        font-size: 0.9rem;
    }

    .products-grid {
        display: none;
    }

    .mobile-products-list {
        display: grid;
        gap: 0.42rem;
    }

    .mobile-product-row {
        min-height: 64px;
        border: 1px solid var(--line);
        border-radius: 14px;
        background: #fff;
        display: grid;
        grid-template-columns: 54px minmax(0, 1fr) minmax(42px, auto);
        align-items: center;
        gap: 0.58rem;
        padding: 0.42rem 0.5rem;
        text-align: left;
        transition: transform 70ms ease, border-color 70ms ease, box-shadow 70ms ease;
        -webkit-touch-callout: none;
    }

    .mobile-product-row:active,
    .mobile-product-row.is-pressed {
        transform: scale(0.99);
        border-color: var(--accent);
        box-shadow: inset 0 0 0 1px rgba(15, 109, 95, 0.16);
    }

    .mobile-product-row.disabled {
        opacity: 0.5;
        filter: grayscale(0.08);
    }

    .mobile-product-row img {
        width: 54px;
        height: 48px;
        object-fit: cover;
        border-radius: 10px;
        background: #edf2f7;
        pointer-events: none;
        user-select: none;
        -webkit-user-drag: none;
    }

    .mobile-product-main {
        min-width: 0;
        display: grid;
        gap: 0.16rem;
    }

    .mobile-product-main strong,
    .mobile-product-main small {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .mobile-product-main strong {
        font-size: 0.98rem;
        line-height: 1.1;
    }

    .mobile-product-main small {
        color: var(--muted);
        font-size: 0.78rem;
        font-weight: 800;
    }

    .mobile-product-qty {
        min-width: 40px;
        min-height: 40px;
        border-radius: 999px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        background: var(--accent);
        color: #fff;
        font-weight: 900;
        font-size: 0.95rem;
    }

    .layout {
        gap: 0.62rem;
    }

    .products-panel,
    .order-panel {
        padding: 0;
    }

    .order-panel {
        margin-top: 0.3rem;
        padding: 0.72rem;
    }

    .order-head {
        margin-bottom: 0.55rem;
    }

    .order-head p {
        display: none;
    }

    .order-total-box {
        display: none;
    }

    .order-items {
        margin: 0.55rem 0;
        gap: 0.45rem;
    }

    .order-item {
        border-radius: 14px;
        padding: 0.62rem;
        gap: 0.42rem;
    }

    .order-line {
        gap: 0.5rem;
    }

    .order-line strong {
        font-size: 0.94rem;
    }

    .order-item-actions {
        gap: 0.35rem;
    }

    .pill-btn {
        min-height: 40px;
        padding: 0.58rem 0.7rem;
    }

    .order-actions {
        grid-template-columns: 1fr;
    }

    #complete-sale-btn {
        display: none;
    }

    .status-card {
        grid-template-columns: 1fr 1fr;
        gap: 0.45rem;
        margin-top: 0.65rem;
        padding-top: 0.65rem;
    }

    .sync-pill,
    .stat-pill,
    .compact-action,
    .admin-link {
        min-height: 46px;
        border-radius: 14px;
        padding: 0.58rem 0.62rem;
        font-size: 0.82rem;
    }

    .sync-pill {
        grid-column: 1 / -1;
    }

    .mobile-checkout-bar {
        position: fixed;
        left: 0.55rem;
        right: 0.55rem;
        bottom: calc(0.55rem + env(safe-area-inset-bottom));
        z-index: 35;
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(128px, 0.82fr);
        gap: 0.6rem;
        align-items: center;
        padding: 0.58rem;
        border: 1px solid rgba(191, 208, 228, 0.95);
        border-radius: 18px;
        background: rgba(255, 255, 255, 0.96);
        box-shadow: 0 14px 34px rgba(15, 23, 42, 0.18);
        backdrop-filter: blur(14px);
    }

    .mobile-checkout-bar div {
        min-width: 0;
        display: grid;
        gap: 0.1rem;
    }

    .mobile-checkout-bar span {
        color: var(--muted);
        font-size: 0.78rem;
        font-weight: 800;
    }

    .mobile-checkout-bar strong {
        font-size: 1.35rem;
        line-height: 1.05;
        white-space: nowrap;
    }

    .mobile-checkout-bar .action {
        min-height: 52px;
        border-radius: 14px;
        padding: 0.75rem 0.85rem;
        font-size: 0.98rem;
    }

    .payment-types,
    .payment-fields {
        grid-template-columns: 1fr;
    }
}
