:root {
  --bg: #f5efe1;
  --surface: #fffaf0;
  --surface-2: #ece3cf;
  --ink: #1d2a20;
  --ink-soft: #5b5a45;
  --line: #d9cdb2;
  --accent: #1f4d34;
  --accent-strong: #163a27;
  --accent-ink: #fdf6e3;
  --accent-soft: #dde6d3;
  --marigold: #b47d2a;
  --marigold-soft: #f3e2b5;
  --marigold-ink: #1a1408;
  --danger: #a8321f;
  --danger-soft: #f6dcd2;
  --ok: #2f6b3f;
  --shadow: 0 1px 2px rgb(45 35 15 / 0.1), 0 6px 18px rgb(45 35 15 / 0.07);
  --radius: 14px;
  --radius-small: 9px;
  --font-display: 'Oswald', 'Avenir Next Condensed', 'Arial Narrow', system-ui, sans-serif;
  --font-body: 'Atkinson Hyperlegible', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --tabbar-height: 68px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f2219;
    --surface: #152e22;
    --surface-2: #1c3a2b;
    --ink: #f3ead2;
    --ink-soft: #bfb391;
    --line: #2e4a39;
    --accent: #d9b25c;
    --accent-strong: #e8c77a;
    --accent-ink: #10241a;
    --accent-soft: #2a3a26;
    --marigold: #e8a948;
    --marigold-soft: #3d3219;
    --marigold-ink: #1a1408;
    --danger: #f0907c;
    --danger-soft: #3f211b;
    --ok: #93c08e;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.4), 0 6px 18px rgb(0 0 0 / 0.25);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { font-family: var(--font-display); line-height: 1.15; margin: 0; letter-spacing: 0.01em; text-wrap: balance; }
h2 { font-size: 1.3rem; font-weight: 700; }
h3 { font-size: 1.05rem; font-weight: 700; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--marigold); outline-offset: 2px; }
.num, .tabular { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-soft); }

.icon { display: inline-flex; width: 1.25em; height: 1.25em; flex: none; }
.icon svg { width: 100%; height: 100%; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45em;
  min-height: 48px; padding: 0 1.1rem; border-radius: var(--radius-small);
  border: 1px solid transparent; font-weight: 700; cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease;
  white-space: nowrap;
}
.btn:active:not(:disabled) { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-primary:hover:not(:disabled) { background: var(--accent-strong); }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: var(--surface); }
.btn-small { min-height: 38px; padding: 0 0.8rem; font-size: 0.92rem; }
.btn-block { width: 100%; }

.link-button { background: none; border: 0; padding: 0.35rem 0.2rem; color: var(--accent); font-weight: 700; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.link-button.danger { color: var(--danger); }

.icon-button {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer;
}
.icon-button:disabled { opacity: 0.4; cursor: not-allowed; }

input[type='text'], input[type='search'], input[type='tel'], input[type='number'], input[type='date'], input[type='datetime-local'], input[type='url'], input[type='password'], select, textarea {
  width: 100%; min-height: 48px; padding: 0.6rem 0.8rem;
  border: 1px solid var(--line); border-radius: var(--radius-small);
  background: var(--surface); color: var(--ink);
}
textarea { resize: vertical; line-height: 1.4; }
input::placeholder, textarea::placeholder { color: var(--ink-soft); opacity: 0.8; }
input[type='checkbox'] { width: 24px; height: 24px; accent-color: var(--accent); flex: none; }

.field { display: grid; gap: 0.35rem; min-width: 0; }
.field > label, .field-label { font-weight: 700; font-size: 0.95rem; }
.field-hint { font-size: 0.85rem; color: var(--ink-soft); }
.field-error { font-size: 0.88rem; color: var(--danger); font-weight: 700; }
.field-row { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.field-row > label { font-weight: 700; min-width: 5.5rem; }
.field-row > input { flex: 1 1 8rem; width: auto; min-width: 0; }
.check-row { display: flex; align-items: center; gap: 0.6rem; min-height: 44px; cursor: pointer; font-weight: 700; }
.form-grid { display: grid; gap: 0.9rem; }
.form-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); }
.section-title { font-family: var(--font-display); font-size: 1.1rem; font-weight: 700; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 0.8rem; flex-wrap: wrap; }

.chip { display: inline-flex; align-items: center; gap: 0.3em; padding: 0.15rem 0.6rem; border-radius: 999px; background: var(--surface-2); font-size: 0.82rem; font-weight: 700; color: var(--ink-soft); white-space: nowrap; }
.chip-warn { background: var(--marigold-soft); color: var(--ink); }
.chip-ok { background: var(--accent-soft); color: var(--accent-strong); }
.chip-danger { background: var(--danger-soft); color: var(--danger); }

.segmented { display: inline-flex; padding: 4px; gap: 4px; background: var(--surface-2); border-radius: 12px; }
.segmented button { min-height: 40px; padding: 0 1rem; border: 0; border-radius: 9px; background: transparent; font-weight: 700; color: var(--ink-soft); cursor: pointer; }
.segmented button[aria-pressed='true'] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }

.list { list-style: none; margin: 0; padding: 0; display: grid; }
.list-row { display: flex; align-items: center; gap: 0.75rem; padding: 0.8rem 0.2rem; border-bottom: 1px solid var(--line); min-width: 0; }
.list-row:last-child { border-bottom: 0; }
.list-row-main { flex: 1; min-width: 0; display: grid; gap: 0.1rem; }
.list-row-title { font-weight: 700; overflow-wrap: anywhere; }
.list-row-sub { font-size: 0.88rem; color: var(--ink-soft); overflow-wrap: anywhere; }
button.list-row { width: 100%; background: none; border: 0; border-bottom: 1px solid var(--line); text-align: left; cursor: pointer; }
button.list-row:hover { background: var(--surface-2); }

.empty-state { display: grid; gap: 0.8rem; justify-items: start; padding: 1.4rem; border: 2px dashed var(--line); border-radius: var(--radius); grid-column: 1 / -1; }
.empty-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }

.table-wrap { overflow-x: auto; }

.topbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 0.8rem;
  padding: 0.7rem 16px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 0.55rem; min-width: 0; }
.brand-mark { width: 32px; height: 32px; flex: none; }
.brand h1 { font-size: 1.35rem; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sync-pill { display: inline-flex; align-items: center; gap: 0.4rem; min-height: 36px; padding: 0 0.8rem; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 0.85rem; font-weight: 700; cursor: pointer; white-space: nowrap; }
.sync-pill::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: var(--ink-soft); }
.sync-pill[data-tone='ok']::before { background: var(--ok); }
.sync-pill[data-tone='warn']::before { background: var(--marigold); }
.sync-pill[data-tone='danger']::before { background: var(--danger); }

.app-main { padding: 1rem 16px calc(var(--tabbar-height) + 1.5rem + env(safe-area-inset-bottom, 0px)); max-width: 1280px; margin: 0 auto; }
.view { display: grid; gap: 1rem; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  padding: 0.3rem 0.3rem calc(0.3rem + env(safe-area-inset-bottom, 0px));
  background: var(--surface); border-top: 1px solid var(--line);
}
.tab { display: grid; justify-items: center; gap: 0.15rem; padding: 0.4rem 0.2rem; border: 0; border-radius: 10px; background: none; color: var(--ink-soft); font-size: 0.78rem; font-weight: 700; cursor: pointer; }
.tab .icon { width: 24px; height: 24px; }
.tab.is-active { color: var(--accent); background: var(--accent-soft); }

@media (min-width: 1024px) {
  body.app-shell { display: grid; grid-template-columns: 220px 1fr; grid-template-rows: auto 1fr; min-height: 100vh; }
  .topbar { grid-column: 1 / -1; }
  .tabbar { position: sticky; top: 64px; align-self: start; grid-template-columns: 1fr; gap: 0.3rem; height: calc(100vh - 64px); padding: 1rem 0.8rem; border-top: 0; border-right: 1px solid var(--line); background: var(--bg); align-content: start; }
  .tab { display: flex; justify-content: flex-start; gap: 0.7rem; padding: 0.75rem 0.9rem; font-size: 1rem; }
  .app-main { padding: 1.5rem 24px 2rem; width: 100%; }
}

.toast {
  position: fixed; left: 50%; top: calc(4.2rem + env(safe-area-inset-top, 0px)); z-index: 60;
  display: flex; align-items: center; gap: 0.8rem; max-width: min(92vw, 520px);
  padding: 0.8rem 1rem; border-radius: 12px; background: var(--ink); color: var(--bg);
  font-weight: 700; box-shadow: var(--shadow);
  transform: translate(-50%, -0.6rem); opacity: 0; pointer-events: none; transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.is-visible { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast[data-tone='ok'] { background: var(--accent); color: var(--accent-ink); }
.toast[data-tone='danger'] { background: var(--danger); color: var(--surface); }
.toast-action { background: none; border: 2px solid currentColor; border-radius: 8px; padding: 0.3rem 0.6rem; font-weight: 700; cursor: pointer; color: inherit; }
@media (max-width: 759px) {
  .toast { left: 16px; right: 16px; max-width: none; justify-content: space-between; transform: translateY(-0.6rem); }
  .toast.is-visible { transform: translateY(0); }
}
.toast > span:first-child { flex: 1; min-width: 0; }
.toast-action { flex: none; }
@media (min-width: 1024px) { .toast { top: 1rem; } }

dialog#confirm-dialog { width: min(92vw, 460px); border: 0; border-radius: var(--radius); padding: 0; background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgb(0 0 0 / 0.35); }
dialog#confirm-dialog::backdrop { background: rgb(12 26 18 / 0.55); }
.dialog-body { display: grid; gap: 0.9rem; padding: 1.3rem; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.6rem; flex-wrap: wrap; }

.scanner { position: fixed; inset: 0; z-index: 70; display: grid; place-items: center; padding: 16px; background: rgb(6 12 9 / 0.88); }
.scanner-card { width: min(100%, 520px); display: grid; gap: 0.8rem; padding: 1rem; border-radius: var(--radius); background: var(--surface); }
.scanner-head { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; }
.scanner-head p { font-family: var(--font-display); font-weight: 700; font-size: 1.15rem; }
.scanner-video { width: 100%; aspect-ratio: 4 / 3; max-width: 100%; overflow: hidden; border-radius: var(--radius-small); background: #000; }
.scanner-video video { width: 100% !important; height: 100% !important; object-fit: cover; }
.scanner-message { font-weight: 700; min-height: 1.5em; }

.customer-display { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 24px 16px; background: var(--accent); color: var(--accent-ink); }
.cd-inner { display: grid; gap: 1rem; justify-items: center; width: min(100%, 640px); text-align: center; }
.cd-label { font-size: 1.3rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; opacity: 0.85; }
.cd-total { font-family: var(--font-display); font-size: clamp(3.5rem, 18vw, 8rem); font-weight: 800; line-height: 1; font-variant-numeric: tabular-nums; }
.cd-lines { list-style: none; margin: 0; padding: 0; width: 100%; display: grid; gap: 0.3rem; font-size: 1.15rem; }
.cd-lines li { display: flex; justify-content: space-between; gap: 1rem; border-bottom: 1px solid color-mix(in srgb, var(--accent-ink) 25%, transparent); padding: 0.35rem 0; }
.cd-discount { font-weight: 700; }
.cd-close { margin-top: 0.5rem; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

dialog.sync-dialog { width: min(94vw, 520px); max-height: 86vh; border: 0; border-radius: var(--radius); padding: 0; background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgb(0 0 0 / 0.35); }
dialog.sync-dialog::backdrop { background: rgb(10 20 14 / 0.55); }
.sync-dialog-section { display: grid; gap: 0.4rem; }

.tab-signout { display: none; }
@media (min-width: 1024px) {
  .tab-signout { display: flex; margin-top: auto; color: var(--danger); }
  .tabbar { align-content: stretch; grid-auto-rows: min-content; }
  .signout-top { display: none; }
}
