:root {
    --ink: #29271f;
    --muted: #716d62;
    --paper: #fffdf8;
    --cream: #fff8ed;
    --peach: #ff795c;
    --peach-dark: #e9553b;
    --sun: #ffd557;
    --mint: #62c9a6;
    --blue: #6c9ff8;
    --line: #e9e2d6;
    --shadow: 0 18px 55px rgba(74, 55, 30, .12);
    --background-base: #fff8ed;
    --background-glow-a: rgba(255, 213, 87, .34);
    --background-glow-b: rgba(98, 201, 166, .24);
    --background-dots: rgba(233, 85, 59, .09);
    font-family: "Avenir Next", Avenir, "Segoe UI", system-ui, sans-serif;
    color: var(--ink);
    background: var(--background-base);
}

* { box-sizing: border-box; }
html, body, form { min-height: 100%; margin: 0; }
body {
    position: relative;
    min-width: 320px;
    background:
        radial-gradient(circle at 4% 12%, var(--background-glow-a) 0 8%, transparent 8.2%),
        radial-gradient(circle at 93% 91%, var(--background-glow-b) 0 11%, transparent 11.2%),
        var(--background-base);
    transition: background-color .28s ease;
    -webkit-tap-highlight-color: transparent;
}
body::before {
    position: fixed;
    z-index: 0;
    inset: 0;
    background-image: radial-gradient(circle, var(--background-dots) 0 2px, transparent 2.5px);
    background-size: 28px 28px;
    content: "";
    mask-image: linear-gradient(115deg, black, transparent 42%, transparent 68%, black);
    pointer-events: none;
}
body[data-theme="sky"] {
    --background-base: #eef8ff;
    --background-glow-a: rgba(108, 159, 248, .31);
    --background-glow-b: rgba(255, 213, 87, .28);
    --background-dots: rgba(62, 130, 211, .09);
}
body[data-theme="berry"] {
    --background-base: #fff1f6;
    --background-glow-a: rgba(255, 121, 154, .30);
    --background-glow-b: rgba(180, 134, 231, .24);
    --background-dots: rgba(189, 73, 119, .09);
}
body[data-theme="mint"] {
    --background-base: #effbf5;
    --background-glow-a: rgba(98, 201, 166, .30);
    --background-glow-b: rgba(126, 188, 238, .23);
    --background-dots: rgba(36, 138, 103, .09);
}
button, input { font: inherit; }
button { touch-action: manipulation; }
button:focus-visible, input:focus-visible { outline: 4px solid rgba(108, 159, 248, .42); outline-offset: 2px; }

.app-shell { position: relative; z-index: 1; min-height: 100vh; padding: max(18px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left)); }
.topbar { max-width: 1440px; margin: 0 auto 18px; display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.brand { display: flex; align-items: center; gap: 13px; }
.brand-mark { display: grid; place-items: center; width: 54px; height: 54px; border-radius: 18px; background: var(--peach); color: white; font: 800 31px/1 Georgia, serif; transform: rotate(-4deg); box-shadow: 0 8px 18px rgba(233, 85, 59, .25); }
.eyebrow { margin: 0 0 3px; color: var(--peach-dark); font-size: .74rem; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
.brand h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(1.45rem, 3vw, 2.15rem); line-height: 1; }
.top-actions { display: flex; align-items: center; gap: 12px; }
.theme-picker { min-height: 46px; display: flex; align-items: center; gap: 7px; border: 1px solid var(--line); border-radius: 15px; padding: 0 11px; background: rgba(255, 253, 248, .82); box-shadow: 0 5px 16px rgba(60, 50, 36, .06); backdrop-filter: blur(12px); }
.theme-picker-label { margin-right: 2px; color: var(--muted); font-size: .75rem; font-weight: 800; }
.theme-button { width: 25px; height: 25px; border: 3px solid white; border-radius: 50%; padding: 0; box-shadow: 0 0 0 1px rgba(41, 39, 31, .16); transition: transform .12s ease, box-shadow .12s ease; }
.theme-button:active { transform: scale(.9); }
.theme-button[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--ink); transform: scale(1.08); }
.theme-cream { background: linear-gradient(135deg, #ffd557 0 48%, #ff795c 50%); }
.theme-sky { background: linear-gradient(135deg, #82c8ff 0 48%, #f9dc72 50%); }
.theme-berry { background: linear-gradient(135deg, #ff7eac 0 48%, #b98be7 50%); }
.theme-mint { background: linear-gradient(135deg, #62c9a6 0 48%, #80bff0 50%); }
.clock { color: var(--muted); font-weight: 700; text-transform: capitalize; }
.icon-button { min-height: 46px; display: flex; align-items: center; gap: 7px; border: 1px solid var(--line); border-radius: 14px; padding: 0 14px; background: var(--paper); color: var(--ink); font-weight: 750; box-shadow: 0 5px 16px rgba(60, 50, 36, .06); }
.icon-button:disabled { opacity: .42; }
.compact-icon-button { flex: 0 0 46px; width: 46px; justify-content: center; padding: 0; font-size: 1.2rem; }
.new-product-button { background: #35a97e; color: white; border-color: #35a97e; }
.catalog-button { background: var(--ink); color: white; }
.fullscreen-button { color: #477fcf; }
.fullscreen-button[aria-pressed="true"] { border-color: #477fcf; background: #477fcf; color: white; }

.workspace { max-width: 1440px; height: calc(100vh - 102px); min-height: 650px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1.56fr) minmax(370px, .74fr); gap: 18px; }
.catalog-panel, .cart-panel { min-height: 0; border: 1px solid rgba(233, 226, 214, .8); border-radius: 27px; background: rgba(255, 253, 248, .88); box-shadow: var(--shadow); backdrop-filter: blur(16px); }
.catalog-panel { overflow: auto; padding: 20px; }
.cart-panel { display: flex; flex-direction: column; overflow: hidden; padding: 22px; background: var(--paper); }

.scan-card { display: grid; grid-template-columns: auto 1fr minmax(255px, .75fr); gap: 14px; align-items: center; padding: 16px 18px; border: 2px solid rgba(98, 201, 166, .52); border-radius: 21px; background: linear-gradient(135deg, rgba(98, 201, 166, .15), rgba(255, 255, 255, .82)); }
.scan-icon { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 15px; background: var(--mint); color: white; font-size: 28px; font-weight: 900; }
.scan-card label { display: flex; flex-direction: column; gap: 3px; }
.scan-card label strong { font-size: 1.02rem; }
.scan-card label span { color: var(--muted); font-size: .82rem; }
.scan-entry { display: flex; gap: 7px; }
.scan-entry input { min-width: 0; width: 100%; height: 48px; border: 1px solid var(--line); border-radius: 13px; padding: 0 13px; background: white; color: var(--ink); }
.scan-entry button { min-height: 48px; border: 0; border-radius: 13px; padding: 0 15px; background: var(--ink); color: white; font-weight: 800; }
.scan-status { grid-column: 2 / -1; min-height: 18px; margin: -7px 0 0; color: var(--muted); font-size: .8rem; font-weight: 700; }
.scan-status.success { color: #238667; }
.scan-status.error { color: #b63e2e; }

.section-heading, .cart-heading { display: flex; align-items: end; justify-content: space-between; gap: 14px; }
.section-heading { margin: 23px 3px 14px; }
.section-heading h2, .cart-heading h2 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 1.65rem; }
.count-pill, .cart-badge { display: grid; place-items: center; min-width: 38px; height: 34px; padding: 0 12px; border-radius: 999px; background: #fff0cb; color: #775815; font-size: .82rem; font-weight: 800; }
.product-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 11px; padding-bottom: 3px; }
.product-card { position: relative; min-height: 151px; overflow: hidden; border: 1px solid var(--line); border-radius: 19px; background: white; color: var(--ink); box-shadow: 0 7px 20px rgba(64, 50, 31, .055); transition: transform .12s ease, border-color .12s ease, box-shadow .12s ease; }
.product-card-main { width: 100%; min-height: 149px; display: flex; flex-direction: column; align-items: flex-start; border: 0; padding: 14px; background: transparent; color: var(--ink); text-align: left; }
.product-card-main:active { transform: scale(.97); }
.product-card:hover { border-color: rgba(255, 121, 92, .58); box-shadow: 0 10px 25px rgba(64, 50, 31, .09); }
.product-emoji { display: grid; place-items: center; width: 50px; height: 50px; margin-bottom: 8px; border-radius: 16px; background: var(--cream); font-size: 27px; }
.product-category { color: var(--muted); font-size: .66rem; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.product-card strong { max-width: 100%; margin: 3px 0 8px; overflow: hidden; font-size: .89rem; line-height: 1.1; text-overflow: ellipsis; white-space: nowrap; }
.product-price { margin-top: auto; color: var(--peach-dark); font-size: 1.05rem; font-weight: 900; }
.product-edit-button { position: absolute; z-index: 2; top: 10px; right: 10px; width: 34px; height: 34px; border: 1px solid rgba(41, 39, 31, .12); border-radius: 11px; padding: 0; background: rgba(255, 253, 248, .95); color: var(--ink); box-shadow: 0 4px 12px rgba(41, 39, 31, .1); font-size: 1.05rem; font-weight: 900; }
.product-edit-button:active { transform: scale(.92); }
.custom-product::after { position: absolute; right: 13px; bottom: 11px; width: 7px; height: 7px; border-radius: 50%; background: var(--mint); content: ""; box-shadow: 0 0 0 3px white; pointer-events: none; }

.cart-heading { padding-bottom: 17px; border-bottom: 1px solid var(--line); }
.cart-badge { min-width: 42px; height: 42px; background: var(--peach); color: white; font-size: 1rem; }
.empty-cart { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); text-align: center; }
.empty-cart[hidden] { display: none; }
.basket { margin-bottom: 12px; filter: grayscale(.25); font-size: 60px; }
.empty-cart strong { color: var(--ink); font-family: Georgia, "Times New Roman", serif; font-size: 1.25rem; }
.empty-cart span { margin-top: 5px; font-size: .9rem; }
.cart-items { flex: 1; min-height: 0; overflow: auto; margin: 3px -7px 0; padding: 3px 7px; }
.cart-item { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; grid-template-areas: "emoji info price" "emoji controls price"; align-items: center; gap: 3px 9px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.cart-item-emoji { grid-area: emoji; display: grid; place-items: center; width: 38px; height: 38px; border-radius: 12px; background: var(--cream); font-size: 20px; }
.cart-item-info { grid-area: info; min-width: 0; display: flex; flex-direction: column; }
.cart-item-info strong { overflow: hidden; font-size: .87rem; text-overflow: ellipsis; white-space: nowrap; }
.cart-item-info span { color: var(--muted); font-size: .7rem; }
.quantity-control { grid-area: controls; display: flex; align-items: center; gap: 7px; margin-top: 4px; }
.quantity-control button { width: 29px; height: 29px; border: 0; border-radius: 9px; background: #f2eee6; color: var(--ink); font-size: 1.12rem; font-weight: 900; }
.quantity-control span { min-width: 17px; text-align: center; font-size: .81rem; font-weight: 900; }
.line-price { grid-area: price; font-size: .9rem; }
.cart-summary { padding-top: 14px; border-top: 1px solid var(--line); }
.summary-row { display: flex; align-items: baseline; justify-content: space-between; }
.summary-row.muted { color: var(--muted); font-size: .85rem; }
.summary-row.total { margin: 7px 0 14px; font-family: Georgia, "Times New Roman", serif; font-size: 1.5rem; }
.summary-row.total strong { font-size: 1.75rem; }
.checkout-button, .complete-button { width: 100%; min-height: 55px; display: flex; align-items: center; justify-content: space-between; border: 0; border-radius: 17px; padding: 0 20px; background: var(--peach); color: white; font-weight: 900; box-shadow: 0 9px 20px rgba(233, 85, 59, .23); }
.checkout-button:disabled { background: #c8c2b8; box-shadow: none; }
.clear-button { width: 100%; min-height: 42px; border: 0; background: transparent; color: var(--muted); font-size: .8rem; font-weight: 750; }
.clear-button:disabled { opacity: .35; }

.modal[hidden], .toast[hidden] { display: none; }
.modal { position: fixed; z-index: 20; inset: 0; display: grid; place-items: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(35, 31, 25, .48); backdrop-filter: blur(5px); }
.payment-card { position: relative; width: min(480px, 100%); border-radius: 27px; padding: 28px; background: var(--paper); box-shadow: 0 30px 90px rgba(20, 16, 10, .28); }
.payment-card h2 { margin-bottom: 18px; font-family: Georgia, "Times New Roman", serif; font-size: 1.8rem; }
.modal-close { position: absolute; top: 15px; right: 15px; width: 42px; height: 42px; border: 0; border-radius: 50%; background: #f2eee6; color: var(--ink); font-size: 1.5rem; }
.pin-card { width: min(380px, 100%); text-align: center; }
.pin-card .form-field { text-align: left; }
.parent-lock { display: grid; place-items: center; width: 64px; height: 64px; margin: 0 auto 15px; border-radius: 20px; background: #e9f8f2; font-size: 2rem; }
.pin-input { font-size: 1.45rem; font-weight: 900; letter-spacing: .28em; text-align: center; }
.pin-card .complete-button { margin-top: 4px; }
.parent-area-card { width: min(540px, 100%); max-height: calc(100vh - 30px); overflow-y: auto; }
.parent-tools { display: grid; gap: 10px; }
.parent-tool { width: 100%; min-height: 76px; display: flex; align-items: center; gap: 13px; border: 1px solid var(--line); border-radius: 17px; padding: 11px 14px; background: white; color: var(--ink); text-align: left; }
.parent-tool:active { transform: scale(.985); }
.parent-tool-icon { flex: 0 0 auto; display: grid; place-items: center; width: 45px; height: 45px; border-radius: 14px; font-size: 1.65rem; font-weight: 500; }
.parent-tool-icon.green { background: #e7f7f1; color: #258565; }
.parent-tool-icon.blue { background: #eaf2ff; color: #477fcf; }
.parent-tool-icon.yellow { background: #fff4cf; color: #9a7310; }
.parent-tool > span:last-child { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.parent-tool strong { font-size: .94rem; }
.parent-tool small { color: var(--muted); font-size: .75rem; }
.lock-area-button { width: 100%; min-height: 48px; display: flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line); border-radius: 15px; background: #f5f1e9; color: var(--muted); font-size: .82rem; font-weight: 850; }
.payment-total { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 17px; padding: 15px 17px; border-radius: 16px; background: var(--cream); }
.payment-total strong { font: 800 1.6rem Georgia, serif; }
.payment-methods { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.payment-method { min-height: 88px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; border: 2px solid var(--line); border-radius: 17px; background: white; color: var(--ink); font-size: 1.45rem; }
.payment-method strong { font-size: .9rem; }
.payment-method.selected { border-color: var(--peach); background: rgba(255, 121, 92, .08); }
.cash-section { margin: 17px 0 8px; }
.cash-section[hidden] { display: none; }
.cash-section label { display: block; margin-bottom: 6px; color: var(--muted); font-size: .8rem; font-weight: 750; }
.money-input { display: flex; align-items: center; gap: 7px; height: 52px; border: 1px solid var(--line); border-radius: 14px; padding: 0 14px; background: white; }
.money-input span { color: var(--muted); font-weight: 900; }
.money-input input { min-width: 0; width: 100%; border: 0; outline: 0; background: transparent; font-size: 1.15rem; font-weight: 850; }
.change-row { display: flex; justify-content: space-between; margin-top: 9px; font-size: .9rem; }
.payment-error { min-height: 20px; margin: 6px 0; color: #b63e2e; font-size: .82rem; font-weight: 750; }
.complete-button { justify-content: center; }
.editor-note { margin: -9px 0 18px; color: var(--muted); font-size: .86rem; line-height: 1.4; }
.product-editor { width: min(540px, 100%); max-height: calc(100vh - 30px); overflow-y: auto; }
.product-form { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.form-field { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.form-field-wide { grid-column: 1 / -1; }
.form-field > span { color: var(--muted); font-size: .78rem; font-weight: 800; }
.form-field > input { width: 100%; height: 50px; border: 1px solid var(--line); border-radius: 14px; padding: 0 14px; background: white; color: var(--ink); }
.form-field .money-input { height: 50px; }
.emoji-field { min-width: 0; margin: 0; border: 0; padding: 0; }
.emoji-field legend { margin-bottom: 7px; padding: 0; color: var(--muted); font-size: .78rem; font-weight: 800; }
.emoji-picker { max-height: 156px; display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 7px; overflow-y: auto; border: 1px solid var(--line); border-radius: 15px; padding: 9px; background: #faf7f1; overscroll-behavior: contain; }
.emoji-choice { min-width: 0; height: 42px; display: grid; place-items: center; border: 1px solid transparent; border-radius: 11px; padding: 0; background: white; font-size: 1.35rem; box-shadow: 0 2px 7px rgba(41, 39, 31, .055); }
.emoji-choice:active { transform: scale(.91); }
.emoji-choice[aria-pressed="true"] { border-color: #35a97e; background: #e9f8f2; box-shadow: 0 0 0 2px rgba(53, 169, 126, .24); }
.editor-actions { display: flex; align-items: center; gap: 10px; }
.editor-actions .complete-button { flex: 1; }
.save-product-button { justify-content: center; gap: 9px; background: #35a97e; box-shadow: 0 9px 20px rgba(35, 134, 99, .24); }
.save-product-button:active { background: #288966; }
.delete-product-button { min-height: 55px; display: flex; align-items: center; justify-content: center; gap: 7px; border: 1px solid #efb4aa; border-radius: 17px; padding: 0 15px; background: #fff5f2; color: #a53d2c; font-size: .8rem; font-weight: 850; }
.trash-icon { font-size: 1.15rem; line-height: 1; }
.delete-product-button[hidden] { display: none; }
.toast { position: fixed; z-index: 30; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: calc(100% - 32px); border-radius: 14px; padding: 12px 18px; background: var(--ink); color: white; box-shadow: var(--shadow); font-size: .87rem; font-weight: 750; text-align: center; }
.print-receipt { display: none; }

@media (max-width: 1020px) {
    .workspace { grid-template-columns: minmax(0, 1.3fr) minmax(340px, .8fr); }
    .product-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .scan-card { grid-template-columns: auto 1fr; }
    .scan-entry, .scan-status { grid-column: 2; }
}

@media (max-width: 1180px) {
    .clock, .theme-picker-label { display: none; }
}

@media (max-width: 760px), (orientation: portrait) and (max-width: 900px) {
    .app-shell { padding: 12px; }
    .topbar { margin-bottom: 12px; }
    .clock { display: none; }
    .theme-picker-label { display: none; }
    .icon-button:not(.catalog-button):not(.compact-icon-button) span:last-child { display: none; }
    .workspace { height: auto; min-height: 0; grid-template-columns: 1fr; }
    .catalog-panel, .cart-panel { border-radius: 22px; }
    .catalog-panel { max-height: none; }
    .cart-panel { min-height: 560px; }
    .product-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 520px) {
    .brand-mark { width: 46px; height: 46px; border-radius: 14px; }
    .brand h1 { font-size: 1.25rem; }
    .theme-picker { gap: 5px; padding: 0 8px; }
    .theme-button { width: 22px; height: 22px; }
    .product-form { grid-template-columns: 1fr; }
    .form-field-wide { grid-column: auto; }
    .emoji-picker { grid-template-columns: repeat(6, minmax(0, 1fr)); }
    .editor-actions { align-items: stretch; flex-direction: column-reverse; }
    .scan-card { grid-template-columns: 1fr; }
    .scan-icon { display: none; }
    .scan-entry, .scan-status { grid-column: 1; }
    .product-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media print {
    @page { size: 58mm auto; margin: 3mm; }
    html, body, form { width: 52mm !important; min-width: 0 !important; margin: 0 !important; padding: 0 !important; background: white !important; }
    body * { visibility: hidden !important; }
    #printReceipt, #printReceipt * { visibility: visible !important; }
    #printReceipt {
        position: absolute;
        display: block !important;
        left: 0;
        top: 0;
        width: 52mm;
        padding: 0;
        color: black;
        font-family: "Courier New", monospace;
        font-size: 9pt;
    }
    .receipt-logo { margin-bottom: 1mm; font-size: 16pt; text-align: center; }
    .print-receipt h1 { margin: 0 0 1mm; font: 800 13pt/1.05 "Courier New", monospace; text-align: center; }
    .receipt-subtitle, .receipt-footer { margin: 1mm 0; text-align: center; }
    .receipt-rule { margin: 2mm 0; border-top: 1px dashed black; }
    #receiptMeta p { margin: .5mm 0; }
    .receipt-line { display: flex; align-items: baseline; justify-content: space-between; gap: 2mm; margin: 1mm 0; }
    .receipt-line span { min-width: 0; overflow-wrap: anywhere; }
    .receipt-line strong { flex: 0 0 auto; }
    .receipt-grand-total { margin: 2mm 0; font-size: 11pt; }
}
