:root {
  --bg: #F6F7FB; --surface: #FFFFFF; --surface-2: #EEF1F8; --ink: #0E1726; --muted: #5B6578; --line: #E1E6EF;
  --brand: #3B5BFD; --brand-fill: #3B5BFD; --ok: #067647; --bad: #D92D20; --warn: #B54708; --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0A0F1C; --surface: #111A2C; --surface-2: #17223A; --ink: #E8ECF5; --muted: #9AA6BD; --line: #22304A;
    --brand: #6D86FF; --brand-fill: #3B5BFD; --ok: #34D399; --bad: #F97066; --warn: #FDB022;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0A0F1C; --surface: #111A2C; --surface-2: #17223A; --ink: #E8ECF5; --muted: #9AA6BD; --line: #22304A;
  --brand: #6D86FF; --brand-fill: #3B5BFD; --ok: #34D399; --bad: #F97066; --warn: #FDB022;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink); font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; }
.muted { color: var(--muted); font-size: .9rem; }
.error { color: var(--bad); font-weight: 600; }
[hidden] { display: none !important; }

.bar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: .6rem;
  padding: .6rem 16px; padding-top: calc(.6rem + env(safe-area-inset-top));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.bar img { border-radius: 8px; flex: none; }
.who { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.who strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill {
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink); border-radius: 999px;
  padding: .25rem .7rem; font-size: .8rem; font-weight: 600; white-space: nowrap;
}
.pill.off { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); border-color: transparent; }
.pill.on { color: var(--ok); }
.pill.pending { cursor: pointer; background: var(--brand-fill); color: #fff; border-color: transparent; font: inherit;
  font-size: .8rem; font-weight: 700; }

main { padding: 16px; max-width: 1200px; margin: 0 auto; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.setup { max-width: 560px; margin: 8vh auto 0; }
.setup ol { padding-left: 1.2rem; }

.button {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 44px;
  padding: .55rem 1rem; border-radius: 12px; border: 1px solid var(--line); background: var(--surface);
  color: var(--ink); font: inherit; font-weight: 600; cursor: pointer; text-align: center;
}
.button.primary { background: var(--brand-fill); border-color: var(--brand-fill); color: #fff; }
.button.danger { color: var(--bad); width: 100%; margin-top: .5rem; }
.button.big { width: 100%; min-height: 56px; font-size: 1.15rem; }
.button.small { min-height: 40px; font-size: .9rem; }
.button:disabled { opacity: .45; cursor: not-allowed; }
.button:focus-visible, .chip:focus-visible, .product:focus-visible { outline: 3px solid var(--brand); outline-offset: 2px; }
.file input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file { position: relative; }

#till { display: grid; grid-template-columns: 1fr 360px; gap: 16px; align-items: start; }
#search {
  width: 100%; min-height: 44px; padding: .5rem .8rem; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit;
}
.chips { display: flex; flex-wrap: wrap; gap: .4rem; margin: .7rem 0; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 999px;
  padding: .4rem .85rem; min-height: 40px; font: inherit; font-size: .9rem; cursor: pointer;
}
.chip[aria-pressed="true"], .chip[aria-checked="true"] { background: var(--brand-fill); border-color: var(--brand-fill); color: #fff; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .6rem; }
.product {
  display: flex; flex-direction: column; justify-content: space-between; gap: .4rem; min-height: 88px;
  padding: .7rem; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: inherit; text-align: left; cursor: pointer;
}
.product:active { transform: scale(.98); }
.product .price { font-weight: 700; color: var(--brand); }

.cart { position: sticky; top: 76px; }
.lines { list-style: none; margin: 0; padding: 0; max-height: 40vh; overflow: auto; }
.lines li { display: grid; grid-template-columns: 1fr auto; gap: .2rem .5rem; padding: .5rem 0; border-bottom: 1px solid var(--line); }
.lines .qty { display: flex; align-items: center; gap: .3rem; }
.lines .qty button {
  width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2);
  color: var(--ink); font: inherit; font-weight: 700; cursor: pointer;
}
.total { display: flex; justify-content: space-between; align-items: baseline; margin: .8rem 0; font-size: 1.1rem; }
.total strong { font-size: 1.6rem; }
.methods { margin: .3rem 0 .6rem; }
.cash { display: flex; align-items: center; gap: .5rem; margin-bottom: .7rem; flex-wrap: wrap; }
.cash input {
  width: 110px; min-height: 40px; padding: .3rem .5rem; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font: inherit;
}

dialog {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink);
  width: min(460px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 18px;
}
dialog::backdrop { background: rgba(10, 15, 28, .55); }
.row { display: flex; gap: .5rem; margin-top: .8rem; flex-wrap: wrap; }
.row .button { flex: 1; }
.steps { padding-left: 1.2rem; font-size: .92rem; }
.pending-list { list-style: none; padding: 0; margin: .4rem 0; max-height: 30vh; overflow: auto; font-size: .9rem; }
.pending-list li { display: flex; justify-content: space-between; padding: .35rem 0; border-bottom: 1px solid var(--line); }
hr { border: 0; border-top: 1px solid var(--line); margin: 1rem 0; }
#close-pending { width: 100%; margin-top: .6rem; }

.ticket { font: 14px/1.4 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; background: var(--surface-2);
  border-radius: 12px; padding: 12px; }
.ticket .center { text-align: center; }
.ticket table { width: 100%; border-collapse: collapse; }
.ticket td { padding: 2px 0; vertical-align: top; }
.ticket td:last-child { text-align: right; white-space: nowrap; }
.ticket .grand td { font-weight: 700; font-size: 1.05em; border-top: 1px dashed currentColor; padding-top: 4px; }

#print-area { display: none; }
@media print {
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block; color: #000; }
  #print-area .ticket { background: none; padding: 0; width: 72mm; }
}

.to-cart { display: none; }
@media (max-width: 760px) {
  #till { grid-template-columns: 1fr; padding-bottom: 72px; }
  .to-cart:not([hidden]) {
    display: flex; position: fixed; left: 16px; right: 16px; bottom: calc(12px + env(safe-area-inset-bottom));
    z-index: 6; min-height: 52px; font-size: 1.05rem; box-shadow: 0 10px 30px -10px rgba(14, 23, 38, .5);
  }
  .cart { position: static; }
  .grid { grid-template-columns: repeat(2, 1fr); }
}
