:root {
  --bg: #f6f1e9;
  --card: #fffdf9;
  --ink: #1f1a15;
  --muted: #7a7166;
  --line: #e6ddcf;
  --accent: #9a5b2e;
  --accent-ink: #fff;
  --soft: #efe6d8;
  --ok: #3f7a4a;
  --warn: #b5562f;
  --c1: #9a5b2e; --c2: #c99a4b; --c3: #3d3a4f; --c4: #7f9a8a;
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15120f; --card: #201c18; --ink: #f2ebe1; --muted: #a59a8c; --line: #352e27;
    --accent: #d08a52; --accent-ink: #1a120b; --soft: #2a241e; --ok: #7fbf8a; --warn: #e48a62;
    --c1: #d08a52; --c2: #e2bd6f; --c3: #9a95c2; --c4: #9cc0aa;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 16px/1.4 Inter, system-ui, -apple-system, sans-serif; -webkit-font-smoothing: antialiased; padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
h1, h2, h3 { font-family: Fraunces, Georgia, serif; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
button, input, select, textarea { font: inherit; color: inherit; }
.wrap { max-width: 640px; margin: 0 auto; padding: calc(16px + env(safe-area-inset-top)) 16px 24px; }

header.top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
header.top .brand { font-family: Fraunces, serif; font-weight: 700; font-size: 13px; letter-spacing: 0.14em; text-transform: uppercase; color: var(--accent); }
header.top h1 { font-size: 28px; }
.link { background: none; border: 0; color: var(--muted); padding: 8px; cursor: pointer; font-size: 14px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card h2 { font-size: 19px; margin-bottom: 4px; }
.card .sub { color: var(--muted); font-size: 13px; margin-bottom: 12px; }
.row { display: flex; gap: 10px; align-items: center; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
label.f { display: block; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
label.f > input, label.f > select, label.f > textarea { margin-top: 5px; }
input, select, textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; min-height: 46px; font-size: 16px;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.timefield { position: relative; }
.timefield button { position: absolute; right: 6px; bottom: 7px; font-size: 12px; padding: 6px 8px; border-radius: 8px; border: 0; background: var(--soft); color: var(--muted); cursor: pointer; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 0; border-radius: 12px; padding: 12px 16px; min-height: 46px; font-weight: 600; cursor: pointer; background: var(--soft); color: var(--ink); text-decoration: none; }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.block { width: 100%; }
.btn.small { min-height: 36px; padding: 7px 12px; font-size: 14px; border-radius: 10px; }
.btn.danger { color: var(--warn); }
.btn:disabled { opacity: 0.5; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px dashed var(--line); background: transparent; border-radius: 999px; padding: 8px 12px; font-size: 14px; cursor: pointer; color: var(--ink); }
.chip.on { background: var(--ink); color: var(--bg); border-style: solid; border-color: var(--ink); }

.line { border-top: 1px solid var(--line); padding: 12px 0; }
.line:first-of-type { border-top: 0; }
.line .name { font-weight: 600; flex: 1; }
.x { border: 0; background: none; color: var(--muted); font-size: 22px; width: 36px; height: 36px; cursor: pointer; }
.stepper { display: inline-flex; align-items: center; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.stepper button { border: 0; background: var(--soft); width: 42px; height: 42px; font-size: 20px; cursor: pointer; }
.stepper input { width: 54px; border: 0; border-radius: 0; text-align: center; min-height: 42px; padding: 0; background: var(--card); }
.sizes { margin-top: 10px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.seg { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 7px 11px; font-size: 14px; cursor: pointer; }
.seg.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.custom { display: flex; gap: 6px; align-items: center; }
.custom input { width: 84px; min-height: 36px; padding: 6px 8px; }
.custom select { width: 70px; min-height: 36px; padding: 6px; }
.lbs { color: var(--muted); font-size: 13px; white-space: nowrap; }
.total { display: flex; justify-content: space-between; font-weight: 600; padding-top: 10px; border-top: 1px solid var(--line); margin-top: 4px; }

.sticky-save { position: sticky; bottom: calc(76px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, var(--bg) 30%); padding-top: 18px; }

nav.tabs { position: fixed; left: 0; right: 0; bottom: 0; background: var(--card); border-top: 1px solid var(--line); display: flex; justify-content: center; padding-bottom: env(safe-area-inset-bottom); z-index: 5; }
nav.tabs a { flex: 1; max-width: 140px; text-align: center; padding: 10px 4px 12px; color: var(--muted); text-decoration: none; font-size: 12px; font-weight: 600; }
nav.tabs a .i { display: flex; justify-content: center; margin-bottom: 2px; }
nav.tabs a.on { color: var(--accent); }

.hist { cursor: pointer; }
.hist .d { font-family: Fraunces, serif; font-weight: 700; font-size: 18px; }
.hist .meta { color: var(--muted); font-size: 13px; }
.pill { display: inline-block; font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 999px; background: var(--soft); color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.pill.sent { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.pill.failed { background: color-mix(in srgb, var(--warn) 15%, transparent); color: var(--warn); }
.kv { display: flex; justify-content: space-between; font-size: 14px; padding: 2px 0; }
.kv span:first-child { color: var(--muted); }

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stat .n { font-family: Fraunces, serif; font-size: 26px; font-weight: 700; }
.stat .l { font-size: 12px; color: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
svg.chart text { fill: var(--muted); font-size: 10px; font-family: Inter, sans-serif; }

.login { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; padding-bottom: 60px; }
.login .brand { font-family: Fraunces, serif; letter-spacing: 0.16em; text-transform: uppercase; color: var(--accent); font-weight: 700; font-size: 13px; }
.login h1 { font-size: 34px; margin: 6px 0 24px; }
.who { display: flex; gap: 10px; margin-bottom: 20px; }
.dots { display: flex; gap: 12px; margin: 8px 0 18px; height: 16px; }
.dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--muted); }
.dots i.on { background: var(--ink); border-color: var(--ink); }
.pad { display: grid; grid-template-columns: repeat(3, 76px); gap: 12px; }
.pad button { height: 64px; border-radius: 50%; border: 0; background: var(--card); font-size: 24px; font-weight: 500; cursor: pointer; box-shadow: 0 1px 0 var(--line); }
.pad button.ghost { background: transparent; box-shadow: none; font-size: 15px; color: var(--muted); }
.err { color: var(--warn); font-size: 14px; min-height: 20px; }

#toast { position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg); padding: 11px 16px; border-radius: 12px; font-size: 14px; opacity: 0; transition: 0.2s; pointer-events: none; max-width: calc(100% - 32px); z-index: 10; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.bad { background: var(--warn); color: #fff; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.notice { background: var(--soft); border-radius: 12px; padding: 12px; font-size: 14px; margin-bottom: 14px; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th { text-align: left; color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; padding: 6px 4px; border-bottom: 1px solid var(--line); }
table.t td { padding: 8px 4px; border-bottom: 1px solid var(--line); }
table.t td.r, table.t th.r { text-align: right; font-variant-numeric: tabular-nums; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.switch input { width: 48px; min-height: 28px; height: 28px; accent-color: var(--accent); }

.perf { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.perf span { background: var(--soft); border-radius: 8px; padding: 4px 8px; font-size: 12px; color: var(--muted); }
.perf b { color: var(--ink); font-weight: 600; }
.seg-row { display: flex; gap: 6px; flex-wrap: wrap; }

/* ---------- v2: simpler log + layout fixes ---------- */
input, select, textarea { min-width: 0; max-width: 100%; display: block; }
input[type="date"], input[type="time"] { -webkit-appearance: none; appearance: none; }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.card { overflow: hidden; }
header.top { gap: 12px; }
header.top h1 { font-size: 26px; }

.datebar { position: relative; display: flex; align-items: center; justify-content: space-between; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 14px; font-weight: 600; }
.datebar b { color: var(--accent); font-size: 14px; }
.datebar input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; min-height: 0; border: 0; padding: 0; }

.card h2 { margin-bottom: 8px; }
.sublabel { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 14px 0 2px; }
.trow, .srow { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 56px; border-top: 1px solid var(--line); }
.trow:first-of-type { border-top: 0; }
.trow > span, .srow .bn { font-size: 17px; }
.srow.has .bn { font-weight: 600; }
.trow input { width: 132px; min-height: 44px; text-align: center; font-size: 17px; font-weight: 600; padding: 8px; background: var(--soft); border-color: transparent; }
.now { min-width: 132px; min-height: 44px; border: 1px dashed var(--muted); background: transparent; border-radius: 10px; font-size: 16px; font-weight: 600; color: var(--accent); cursor: pointer; }
.stepper { flex: none; border-radius: 12px; }
.stepper button { width: 48px; height: 48px; font-size: 24px; color: var(--ink); }
.stepper input { width: 52px; min-height: 48px; font-size: 18px; font-weight: 600; }
.srow.has .stepper input { color: var(--accent); }
.stepper.sm button { width: 40px; height: 40px; font-size: 20px; }
.stepper.sm input { width: 44px; min-height: 40px; }
.sum { color: var(--muted); font-size: 14px; padding-top: 8px; min-height: 8px; }
.sum:empty { display: none; }
.xrow { border-top: 1px solid var(--line); padding: 12px 0; }
.xrow .row { justify-content: space-between; }
.xrow select { flex: 1; }
.xrow .note { margin-top: 8px; }
.segs { display: flex; gap: 6px; flex-wrap: wrap; }
.seg { display: inline-flex; align-items: center; gap: 4px; min-height: 40px; }
.seg input { width: 54px; min-height: 28px; padding: 2px 6px; display: inline-block; background: var(--card); color: var(--ink); }
.link.add { color: var(--accent); font-weight: 600; padding: 12px 0 2px; }
.extras { display: flex; gap: 18px; padding: 0 4px 6px; }
.extras .link { color: var(--accent); font-weight: 600; font-size: 15px; padding: 8px 0; }
.savebar { position: sticky; bottom: calc(68px + env(safe-area-inset-bottom)); background: var(--bg); padding: 10px 0 12px; margin: 0 -16px; padding-left: 16px; padding-right: 16px; border-top: 1px solid var(--line); z-index: 4; }
.savebar .sum { text-align: center; padding: 0 0 8px; color: var(--ink); font-weight: 600; }
.savebar .btn.primary { min-height: 54px; font-size: 17px; }
nav.tabs a { padding: 8px 2px 10px; }

/* Bigger PIN pad */
.login h1 { margin: 6px 0 10px; }
.login .brand { margin-bottom: 4px; }
.who { margin: 10px 0 6px; }
.who .chip { font-size: 17px; padding: 10px 18px; }
.dots { gap: 16px; margin: 18px 0 10px; height: 20px; }
.dots i { width: 18px; height: 18px; }
.err { min-height: 22px; margin-bottom: 14px; color: var(--muted); }
.pad { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; width: min(330px, 100%); }
.pad button { height: auto; aspect-ratio: 1; font-size: 34px; font-weight: 500; background: var(--soft); box-shadow: none; }
.pad button:active { background: var(--line); }
.pad button.ghost { font-size: 17px; aspect-ratio: auto; }
.err.bad { color: var(--warn); }

/* ---------- v3: required date, extra lb, promo grid ---------- */
.datecard h2 { font-size: 20px; margin-bottom: 12px; }
.datecard.need { border: 2px solid var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--card)); }
.datecard.need h2 { color: var(--accent); }
.datechips { display: flex; gap: 8px; }
.datechips .chip { position: relative; flex: 1; text-align: center; padding: 12px 6px; font-size: 16px; font-weight: 600; border-style: solid; overflow: hidden; }
.datechips .chip input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; min-height: 0; padding: 0; border: 0; }
.xpill { display: flex; align-items: center; gap: 10px; width: 100%; margin-top: 12px; padding: 12px 14px; border-radius: 12px; border: 1px dashed var(--line); background: transparent; font-size: 16px; font-weight: 600; color: var(--ink); cursor: pointer; text-align: left; }
.card > .xpill:first-child { margin-top: 0; }
.xpill span { flex: 1; }
.xpill b { color: var(--accent); font-size: 14px; }
.xpill i { font-style: normal; font-size: 22px; color: var(--accent); width: 20px; text-align: center; }
.xpill.open { border-style: solid; background: var(--soft); }
.grid-head, .grow { display: grid; grid-template-columns: minmax(0, 1fr) 84px; gap: 8px; align-items: center; }
.grid-head.three, .grow.three { grid-template-columns: minmax(0, 1fr) repeat(3, 62px); }
.grid-head { margin-top: 10px; font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; text-align: center; }
.grow { min-height: 54px; border-top: 1px solid var(--line); }
.grow .bn { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell { text-align: center; min-height: 42px; padding: 6px 4px; font-size: 17px; font-weight: 600; }
.cell.has { color: var(--accent); border-color: var(--accent); }
.note { margin-top: 12px; }
.xpill, .xpill span { text-transform: none; letter-spacing: normal; }
.grid-head.three, .grow.three { grid-template-columns: minmax(0, 1fr) repeat(3, 54px); gap: 6px; }
.grow.three .bn { font-size: 15px; }
.grow.three .cell { font-size: 16px; padding: 6px 2px; }
#toast { top: calc(14px + env(safe-area-inset-top)); bottom: auto; transform: translateX(-50%) translateY(-20px); }
#toast.show { transform: translateX(-50%) translateY(0); }

/* ---------- v4: typed times, no double-tap zoom, report read-out ---------- */
html, body, button, input, select, textarea, a, label { touch-action: manipulation; }
button { -webkit-tap-highlight-color: transparent; user-select: none; -webkit-user-select: none; }
input, select, textarea { font-size: 16px; }
.tbox { display: flex; align-items: center; gap: 6px; }
.tin { width: 92px; min-height: 46px; text-align: center; font-size: 20px; font-weight: 600; letter-spacing: 0.02em; background: var(--soft); border-color: transparent; padding: 6px; }
.tin::placeholder { color: var(--muted); opacity: 0.6; }
.ampm { width: 52px; min-height: 46px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-size: 16px; font-weight: 600; color: var(--accent); cursor: pointer; }
.ampm.dim { color: var(--muted); opacity: 0.5; }
.report { font-size: 18px; line-height: 1.55; padding: 20px 18px; }
.report p { margin: 0 0 16px; }
.report .rp-h { font-weight: 700; font-size: 19px; letter-spacing: 0.02em; margin-bottom: 16px; }
.report .rp-h2 { font-weight: 600; margin: 4px 0 6px; padding-top: 14px; border-top: 1px solid var(--line); }
.report .rp-k { color: var(--muted); font-size: 15px; }
.report .rp-total { display: flex; flex-direction: column; gap: 2px; border-top: 1px solid var(--line); padding-top: 12px; font-size: 15px; color: var(--muted); }
.report .rp-total b { font-size: 20px; color: var(--ink); }

/* ---------- v5: built-in keypad ---------- */
.tin { width: 96px; border: 1px solid transparent; border-radius: 10px; cursor: pointer; color: var(--ink); }
.tin.empty { color: var(--muted); font-weight: 500; }
.stepper .sv { width: 56px; min-height: 48px; border: 0; background: var(--card); font-size: 18px; font-weight: 600; color: var(--ink); cursor: pointer; }
.srow.has .stepper .sv { color: var(--accent); }
button.cell { width: 100%; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--muted); cursor: pointer; }
button.cell.has { color: var(--accent); border-color: var(--accent); }
.padding-on { outline: 2px solid var(--accent) !important; outline-offset: 1px; position: relative; z-index: 1; }
body.pad-open { padding-bottom: 360px; }
.kpad { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--card); border-top: 1px solid var(--line); border-radius: 18px 18px 0 0; box-shadow: 0 -8px 30px rgba(0,0,0,.25); padding: 10px 12px calc(12px + env(safe-area-inset-bottom)); transform: translateY(105%); transition: transform .18s ease-out; touch-action: none; user-select: none; -webkit-user-select: none; }
.kpad.show { transform: translateY(0); }
.kp-top { display: flex; align-items: baseline; gap: 10px; padding: 4px 4px 10px; }
.kp-label { color: var(--muted); font-size: 14px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kp-val { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--accent); }
.kp-clear { border: 0; background: none; color: var(--muted); font-size: 14px; padding: 4px 6px; cursor: pointer; }
.kp-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(0, 1.15fr); grid-auto-rows: 54px; gap: 8px; max-width: 520px; margin: 0 auto; }
.kp-grid button { border: 0; border-radius: 12px; background: var(--soft); font-size: 26px; font-weight: 500; color: var(--ink); cursor: pointer; }
.kp-grid button:active { background: var(--line); }
.kp-grid .kp-act { grid-row: span 2; font-size: 18px; font-weight: 600; color: var(--accent); }
.kp-grid .kp-done { background: var(--accent); color: var(--accent-ink); }
.kp-grid .kp-x { font-size: 17px; font-weight: 600; color: var(--accent); }
.kp-grid .kp-x.on { background: color-mix(in srgb, var(--accent) 18%, var(--soft)); }
.kp-grid .kp-x:disabled { background: transparent; }

/* ---------- v6: brand ---------- */
:root { --brand-y: #F5BC1A; --brand-r: #E2202A; --brand-b: #53232B; --accent: #C81D25; --accent-ink: #fff; }
@media (prefers-color-scheme: dark) { :root { --accent: #F5BC1A; --accent-ink: #2a1608; } }
.hdr-logo { display: block; width: 112px; height: auto; margin: 0 0 2px -4px; }

body.on-login { background: var(--brand-y); color: var(--brand-b); }
body.on-login .login { padding-top: calc(28px + env(safe-area-inset-top)); justify-content: flex-start; }
.login-logo { width: 190px; height: auto; margin-bottom: 6px; }
body.on-login .login h1 { color: var(--brand-b); font-size: 26px; }
body.on-login .who .chip { border-color: var(--brand-b); color: var(--brand-b); }
body.on-login .who .chip.on { background: var(--brand-b); color: var(--brand-y); }
body.on-login .dots i { border-color: var(--brand-b); }
body.on-login .dots i.on { background: var(--brand-r); border-color: var(--brand-r); }
body.on-login .err { color: var(--brand-b); opacity: 0.8; }
body.on-login .err.bad { color: var(--brand-r); opacity: 1; font-weight: 600; }
body.on-login .pad button { background: rgba(255, 255, 255, 0.55); color: var(--brand-b); }
body.on-login .pad button:active { background: rgba(255, 255, 255, 0.85); }
body.on-login .pad button.ghost { background: transparent; }

/* keypad: full-width digits, Next/Done underneath */
.kp-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); grid-auto-rows: 58px; }
.kp-grid button { font-size: 30px; }
.kp-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; max-width: 520px; margin: 8px auto 0; }
.kp-actions .kp-act { min-height: 52px; border: 0; border-radius: 12px; background: var(--soft); font-size: 18px; font-weight: 600; color: var(--accent); cursor: pointer; }
.kp-actions .kp-done { background: var(--accent); color: var(--accent-ink); }
body.pad-open { padding-bottom: 440px; }

.setup-note { color: var(--brand-b); font-size: 15px; margin: -4px 0 4px; text-align: center; min-height: 0; }

.rembanner { display: flex; align-items: center; gap: 10px; background: color-mix(in srgb, var(--accent) 14%, var(--card)); border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); border-radius: 12px; padding: 10px 12px; margin: -6px 0 14px; font-size: 14px; }
.rembanner span { flex: 1; }
.rembanner a { color: var(--accent); font-weight: 700; text-decoration: none; white-space: nowrap; }
.rembanner button { border: 0; background: none; color: var(--muted); font-size: 20px; padding: 0 2px; cursor: pointer; }
.okline { color: var(--ok); font-weight: 600; }
.linkcard { display: flex; justify-content: space-between; align-items: center; text-decoration: none; color: var(--ink); font-weight: 600; }
.linkcard b { color: var(--muted); font-size: 22px; }
.notice b { font-weight: 700; }
.pill.paid { background: color-mix(in srgb, var(--ok) 22%, transparent); color: var(--ok); }
