:root {
  --bg: #f6f3ee; --card: #ffffff; --text: #1c1a17; --muted: #6f6a62; --line: #e6e0d6;
  --brand: #7a4b12; --brand-ink: #ffffff; --brand-soft: #f3e8d6;
  --danger: #b42318; --ok: #157f3b; --warn: #b54708; --warn-bg: #fff5e6;
  --field: #fbf9f6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12100d; --card: #1c1915; --text: #ece7df; --muted: #a59d90; --line: #332d25;
    --brand: #d9a35b; --brand-ink: #1b1206; --brand-soft: #2c2318;
    --danger: #f97066; --ok: #47cd89; --warn: #fdb022; --warn-bg: #2b2112;
    --field: #15130f;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text);
       -webkit-tap-highlight-color: transparent; }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 6px;
          background: var(--brand); color: var(--brand-ink); padding: 10px 12px; padding-top: calc(10px + env(safe-area-inset-top)); }
.titles { flex: 1; min-width: 0; padding: 0 4px; }
.title { font-weight: 700; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.subtitle { font-size: 12px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.subtitle:empty { display: none; }
.icon-btn { background: transparent; border: 0; color: inherit; font-size: 26px; width: 40px; height: 40px; border-radius: 10px; cursor: pointer; line-height: 1; }
.icon-btn:active { background: rgba(255,255,255,.15); }

.menu { position: fixed; right: 10px; top: calc(60px + env(safe-area-inset-top)); z-index: 30; background: var(--card); border: 1px solid var(--line);
        border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.18); min-width: 200px; overflow: hidden; }
.menu button { display: block; width: 100%; text-align: left; background: none; border: 0; color: var(--text); font: inherit; padding: 13px 16px; cursor: pointer; }
.menu button + button { border-top: 1px solid var(--line); }
.menu .who { padding: 12px 16px; font-size: 13px; color: var(--muted); border-bottom: 1px solid var(--line); }

main { max-width: 720px; margin: 0 auto; padding: 14px 16px 140px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 0 0 6px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); font-size: 14px; }
.small { font-size: 13px; }
.center { text-align: center; }
.hidden { display: none !important; }
.spacer { height: 10px; }

label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 4px; }
input, select, textarea { width: 100%; font: inherit; color: var(--text); background: var(--field); border: 1px solid var(--line);
                          border-radius: 10px; padding: 11px 12px; min-height: 44px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
input[type=checkbox] { width: 22px; height: 22px; min-height: 0; accent-color: var(--brand); }
.field { margin-bottom: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 380px) { .grid3 { grid-template-columns: 1fr 1fr; } }

.row { display: flex; gap: 8px; align-items: center; }
.row > * { min-width: 0; }
.grow { flex: 1; }
.wrap { flex-wrap: wrap; }

.btn { font: inherit; font-weight: 600; border: 1px solid transparent; border-radius: 11px; padding: 11px 14px; min-height: 44px;
       background: var(--brand); color: var(--brand-ink); cursor: pointer; white-space: nowrap; }
.btn.secondary { background: transparent; color: var(--text); border-color: var(--line); }
.btn.soft { background: var(--brand-soft); color: var(--text); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.wa { background: #1fa855; color: #fff; }
.btn.block { width: 100%; }
.btn.sm { padding: 7px 10px; min-height: 36px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: default; }

.tabs { display: flex; gap: 6px; margin-bottom: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 4px; }
.tabs button { flex: 1; border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 600; padding: 9px 6px; border-radius: 9px; cursor: pointer; }
.tabs button.on { background: var(--brand); color: var(--brand-ink); }

.list-row { display: flex; gap: 10px; align-items: center; padding: 11px 0; border-top: 1px solid var(--line); cursor: pointer; }
.list-row:first-child { border-top: 0; }
.list-row .main { flex: 1; min-width: 0; }
.list-row .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.list-row .s { font-size: 13px; color: var(--muted); }
.list-row .r { text-align: right; font-size: 14px; white-space: nowrap; }

.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 99px; background: var(--brand-soft); color: var(--text); vertical-align: middle; }
.badge.off { background: transparent; border: 1px solid var(--line); color: var(--muted); }
.badge.admin { background: var(--brand); color: var(--brand-ink); }

#reader { display: none; width: 100%; min-height: 220px; border-radius: 12px; overflow: hidden; background: #000; margin-top: 10px; }
#reader.on { display: block; }
#reader:has(video) { min-height: 0; }
#reader video { display: block; width: 100%; border-radius: 12px; }
.cam { position: relative; }
.cam video { max-height: 55vh; object-fit: cover; }
.cam-box { position: absolute; left: 7%; right: 7%; top: 30%; bottom: 30%; border: 2px solid rgba(255,255,255,.9);
           border-radius: 10px; box-shadow: 0 0 0 999px rgba(0,0,0,.28); pointer-events: none; }
.cam-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 8px; }
.cam-tools:empty { display: none; }
.cam-tools .zoom { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 160px; margin: 0; font-size: 13px; color: var(--muted); }
.cam-tools .zoom input { flex: 1; min-height: 0; padding: 0; accent-color: var(--brand); }

.scan-line { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 10px 0; border-top: 1px solid var(--line); }
.scan-line:first-child { border-top: 0; }
.scan-line .name { font-weight: 700; }
.scan-line .meta { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; font-size: 13px; }
.scan-line .meta div span { display: block; color: var(--muted); font-size: 11px; }
.x-btn { width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line); background: var(--field); color: var(--danger); font-size: 18px; cursor: pointer; }
.sr { color: var(--muted); font-weight: 600; margin-right: 4px; }

.sum-bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 9; background: var(--card); border-top: 1px solid var(--line);
           padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); box-shadow: 0 -6px 20px rgba(0,0,0,.06); }
.sum-bar .inner { max-width: 720px; margin: 0 auto; }
.sum-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 8px; }
.sum-grid div { font-size: 12px; color: var(--muted); }
.sum-grid b { display: block; color: var(--text); font-size: 15px; }

table.sheet { width: 100%; border-collapse: collapse; font-size: 13px; }
table.sheet th, table.sheet td { padding: 7px 5px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.sheet th:nth-child(-n+3), table.sheet td:nth-child(-n+3) { text-align: left; }
table.sheet th { color: var(--muted); font-weight: 600; font-size: 12px; }
table.sheet tfoot td { font-weight: 700; border-bottom: 0; }
.table-wrap { overflow-x: auto; margin: 0 -4px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14px; }
.kv div:nth-child(odd) { color: var(--muted); }
.totals { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; font-size: 15px; margin-top: 10px; }
.totals .big { font-weight: 800; font-size: 17px; }

.modal-wrap { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--card); width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; border-radius: 18px 18px 0 0;
         padding: 18px 16px calc(16px + env(safe-area-inset-bottom)); }
@media (min-width: 600px) { .modal-wrap { align-items: center; } .modal { border-radius: 18px; } }

.toast { position: fixed; left: 50%; top: calc(70px + env(safe-area-inset-top)); transform: translateX(-50%); z-index: 50; background: var(--text); color: var(--bg);
         padding: 11px 16px; border-radius: 12px; font-size: 15px; font-weight: 600; opacity: 0; transition: opacity .15s; pointer-events: none; max-width: 92vw; text-align: center; }
.toast.show { opacity: 1; }
.toast.err { background: var(--danger); color: #fff; }
.toast.warn { background: var(--warn); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }

.steps { display: flex; gap: 6px; margin-bottom: 12px; }
.steps button { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-size: 14px; font-weight: 600;
                padding: 9px 4px; border-radius: 11px; border: 1px solid var(--line); background: var(--card); color: var(--muted); cursor: pointer; }
.steps button span { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; font-size: 12px;
                     background: var(--field); border: 1px solid var(--line); }
.steps button.done span { background: var(--ok); border-color: var(--ok); color: #fff; }
.steps button.on { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.steps button.on span { background: var(--brand-ink); border-color: var(--brand-ink); color: var(--brand); }
.step { display: none; }
.step.on { display: block; }
.party-strip { display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 0 10px; background: var(--brand-soft);
               border-radius: 12px; padding: 10px 12px; margin-bottom: 12px; }
.party-strip .btn { grid-row: 1 / span 2; grid-column: 2; }
textarea { font: inherit; }

.sel-bar { display: flex; align-items: center; gap: 8px; margin-top: 8px; padding: 8px 10px; border-radius: 10px;
           background: var(--brand-soft); font-size: 14px; font-weight: 600; }
.list-row > input[type=checkbox] { flex: none; pointer-events: none; }

.suggest { margin-top: 6px; border-radius: 10px; overflow: hidden; }
.suggest:empty { display: none; }
.suggest { border: 1px solid var(--line); }
.sug { display: block; width: 100%; text-align: left; background: var(--field); color: var(--text); border: 0; border-top: 1px solid var(--line);
       font: inherit; padding: 10px 12px; cursor: pointer; }
.sug:first-child { border-top: 0; }
.sug:active { background: var(--brand-soft); }
.sug:disabled { opacity: .55; cursor: default; }
.sug-main { display: block; }
.sug-sub { display: block; font-size: 12px; color: var(--muted); }
.sug-more { padding: 8px 12px; background: var(--field); }

.empty { text-align: center; color: var(--muted); padding: 24px 8px; }
.warnbox { background: var(--warn-bg); border: 1px solid var(--warn); border-radius: 12px; padding: 12px; font-size: 14px; }
.remarks { white-space: pre-wrap; }
