:root {
  --forest: #10241F; --forest-2: #16302A; --line-dark: #2E4B44; --pine: #1D5C4D;
  --gold: #C98A2B; --gold-soft: #E8C27A; --gold-text: #8A5A12;
  --ivory: #F6F1E6; --sand: #EFE8D6; --sand-2: #E9DFC8; --card: #FFFFFF;
  --ink: #16302A; --muted: #5C6B66; --mist: #A9BDB6;
  --ok-bg: #E3EFEA; --ok: #0F5132; --warn-bg: #F8EBD3; --bad-bg: #FBEFE6; --bad: #9A3412;
  --shadow: 0 1px 2px rgba(16,36,31,.05), 0 10px 24px rgba(16,36,31,.07);
  --serif: Fraunces, Georgia, serif; --sans: Inter, system-ui, -apple-system, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--ivory); color: var(--ink); font-family: var(--sans); -webkit-tap-highlight-color: transparent; }
body { min-height: 100vh; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--pine); }
#app { max-width: 560px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; padding-bottom: env(safe-area-inset-bottom); }
.boot { flex: 1; display: flex; align-items: center; justify-content: center; background: var(--forest); min-height: 100vh; }
.mark { width: 64px; height: 64px; border-radius: 32px; background: var(--pine); color: var(--gold-soft); display: flex; align-items: center; justify-content: center; font-family: var(--serif); font-size: 30px; border: 1px solid var(--gold); }

/* Dark screens (setup, login) */
.dark { background: var(--forest); color: var(--ivory); min-height: 100vh; padding: calc(48px + env(safe-area-inset-top)) 28px 32px; display: flex; flex-direction: column; }
.brand { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.brand h1 { font-family: var(--serif); font-weight: 500; font-size: 34px; margin: 0; letter-spacing: -.01em; }
.eyebrow { font-size: 11px; font-weight: 600; letter-spacing: .16em; text-transform: uppercase; color: var(--gold-text); }
.dark .eyebrow { color: var(--gold-soft); }
.rule { display: flex; align-items: center; gap: 10px; }
.rule::before, .rule::after { content: ""; width: 24px; height: 1px; background: var(--gold); }
.dark label.field { color: var(--mist); }
.dark .input { background: var(--forest-2); border-color: var(--line-dark); color: var(--ivory); }
.dots { display: flex; gap: 16px; justify-content: center; margin: 8px 0; }
.dot { width: 12px; height: 12px; border-radius: 6px; border: 1px solid #5E7A72; }
.dot.on { background: var(--gold-soft); border-color: var(--gold-soft); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 22px; padding: 0 18px; margin-top: 20px; }
.key { height: 64px; border-radius: 32px; border: 1px solid var(--line-dark); background: transparent; color: var(--ivory); font-family: var(--serif); font-size: 26px; }
.key:active { background: var(--forest-2); }
.key.ghost { border: none; font-family: var(--sans); font-size: 15px; color: var(--mist); }
.err { color: #F3B4A0; text-align: center; min-height: 20px; font-size: 14px; margin-top: 8px; }
.light .err { color: var(--bad); }

/* Light app */
.light { background: var(--ivory); min-height: 100vh; display: flex; flex-direction: column; }
.top { padding: calc(20px + env(safe-area-inset-top)) 20px 10px; display: flex; align-items: center; gap: 12px; }
.top .title { flex: 1; display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.top h2 { font-family: var(--serif); font-weight: 500; font-size: 24px; margin: 0; }
.iconbtn { width: 44px; height: 44px; border-radius: 22px; border: none; background: var(--card); box-shadow: 0 1px 2px rgba(16,36,31,.08); display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.content { padding: 8px 20px 120px; display: flex; flex-direction: column; gap: 12px; flex: 1; }
.card { background: var(--card); border-radius: 20px; padding: 16px; box-shadow: var(--shadow); }
.card.flat { box-shadow: 0 1px 2px rgba(16,36,31,.05); }
.row { display: flex; align-items: center; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); font-size: 13px; }
.small { font-size: 12px; }
.serif { font-family: var(--serif); font-weight: 500; }
.big { font-family: var(--serif); font-size: 34px; font-weight: 500; }
.price { font-family: var(--serif); font-size: 30px; font-weight: 500; color: var(--pine); }
.strike { text-decoration: line-through; color: var(--muted); }
.chip { display: inline-block; font-size: 12px; font-weight: 600; padding: 5px 10px; border-radius: 10px; background: var(--sand); color: var(--ink); }
.chip.ok { background: var(--ok-bg); color: var(--ok); }
.chip.warn { background: var(--warn-bg); color: var(--gold-text); }
.chip.bad { background: var(--bad-bg); color: var(--bad); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--card); border-radius: 20px; padding: 14px 4px; box-shadow: 0 1px 2px rgba(16,36,31,.05); }
.stats > div { display: flex; flex-direction: column; align-items: center; gap: 2px; border-right: 1px solid var(--sand); }
.stats > div:last-child { border-right: none; }
.stats b { font-family: var(--serif); font-weight: 500; font-size: 22px; }
.stats span { font-size: 12px; color: var(--muted); }

/* Hero (home) */
.hero { background: var(--forest); color: var(--ivory); padding: calc(28px + env(safe-area-inset-top)) 22px 34px; border-radius: 0 0 28px 28px; display: flex; flex-direction: column; gap: 16px; }
.hero h2 { font-family: var(--serif); font-weight: 500; font-size: 28px; margin: 4px 0 0; }
.hero .iconbtn { background: transparent; border: 1px solid var(--line-dark); box-shadow: none; color: var(--ivory); }
.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.tile { text-decoration: none; background: var(--card); border: none; border-radius: 20px; padding: 16px; display: flex; flex-direction: column; gap: 14px; color: var(--ink); box-shadow: 0 1px 2px rgba(16,36,31,.05); text-align: left; position: relative; }
.tile .ic { width: 40px; height: 40px; border-radius: 12px; background: var(--ok-bg); display: flex; align-items: center; justify-content: center; }
.tile.goldic .ic { background: var(--warn-bg); }
.tile b { font-size: 15px; }
.badge { position: absolute; top: 12px; right: 12px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px; background: var(--gold); color: var(--forest); font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center; }
.section { margin-top: 8px; }

/* Forms */
label.field { display: flex; flex-direction: column; gap: 6px; font-size: 11px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.input { height: 50px; border-radius: 14px; border: 1px solid var(--sand-2); background: var(--card); padding: 0 14px; font-size: 16px; letter-spacing: normal; text-transform: none; width: 100%; }
textarea.input { height: 88px; padding: 12px 14px; }
select.input { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 20px) 22px, calc(100% - 15px) 22px; background-size: 5px 5px; background-repeat: no-repeat; }
.input:focus { outline: 2px solid var(--gold); outline-offset: 1px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.search { display: flex; gap: 8px; }
.search .input { flex: 1; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: 14px; }
.check input { width: 20px; height: 20px; accent-color: var(--gold); margin: 0; }
.stepper { display: flex; align-items: center; justify-content: space-between; height: 50px; border-radius: 14px; background: var(--ivory); padding: 0 4px; }
.stepper button { width: 42px; height: 42px; border-radius: 12px; border: none; background: var(--card); font-size: 20px; }
.stepper input { width: 70px; text-align: center; border: none; background: transparent; font-family: var(--serif); font-size: 22px; }

/* Buttons */
.btn { height: 54px; border-radius: 18px; border: none; padding: 0 18px; font-weight: 600; font-size: 15px; background: var(--pine); color: var(--ivory); display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn.block { width: 100%; }
.btn.dark { background: var(--forest-2); }
.btn.gold { background: var(--gold); color: var(--forest); }
.btn.line { background: var(--card); color: var(--ink); border: 1px solid #D8CDB4; }
.btn.danger { background: var(--card); color: var(--bad); border: 1px solid #E8B9A3; }
.btn.small { height: 40px; border-radius: 12px; font-size: 13px; padding: 0 12px; }
.btn:disabled { opacity: .5; }
.dark .btn.line { background: transparent; color: var(--ivory); border-color: var(--line-dark); }
.actions { position: fixed; left: 0; right: 0; bottom: 0; padding: 12px 20px calc(16px + env(safe-area-inset-bottom)); background: linear-gradient(to top, var(--ivory) 70%, rgba(246,241,230,0)); display: flex; gap: 10px; max-width: 560px; margin: 0 auto; }
.actions .btn { flex: 1; }

/* Lists */
.list { display: flex; flex-direction: column; gap: 10px; }
.item { background: var(--card); border-radius: 18px; padding: 14px 16px; display: flex; align-items: center; gap: 12px; box-shadow: 0 1px 2px rgba(16,36,31,.05); border: none; text-align: left; width: 100%; color: var(--ink); }
.thumb { width: 44px; height: 44px; border-radius: 12px; background: var(--sand-2); flex-shrink: 0; overflow: hidden; display: flex; align-items: center; justify-content: center; font-family: var(--serif); color: var(--gold-text); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.item .name { font-size: 15px; font-weight: 600; }
.item .qty { font-family: var(--serif); font-size: 20px; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; font-size: 14px; }
.divider { height: 1px; background: var(--sand); margin: 4px 0; }

/* Sheet (modal) */
.backdrop { position: fixed; inset: 0; background: rgba(16,36,31,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 50; }
.sheet { background: var(--ivory); width: 100%; max-width: 560px; border-radius: 26px 26px 0 0; padding: 18px 20px calc(20px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; max-height: 92vh; overflow: auto; }
.sheet h3 { font-family: var(--serif); font-weight: 500; font-size: 22px; margin: 0; }
.grab { width: 40px; height: 4px; border-radius: 2px; background: var(--sand-2); align-self: center; }
.scanner { position: relative; border-radius: 20px; overflow: hidden; background: #000; aspect-ratio: 4 / 3; }
.scanner video { width: 100%; height: 100%; object-fit: cover; }
.scanner .frame { position: absolute; left: 15%; right: 15%; top: 30%; bottom: 30%; border: 2px solid var(--gold-soft); border-radius: 12px; }

/* Toast */
#toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); background: var(--forest); color: var(--ivory); padding: 12px 18px; border-radius: 14px; font-size: 14px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 60; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.bad { background: var(--bad); }

.lock { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.spin { width: 22px; height: 22px; border-radius: 11px; border: 2px solid var(--sand-2); border-top-color: var(--gold); animation: sp .8s linear infinite; margin: 20px auto; }
@keyframes sp { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spin { animation: none; } #toast { transition: none; } }
