:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --ink: #1d1b18;
  --muted: #7a746b;
  --line: #e7e1d8;
  --brand: #1f4d3a;
  --brand-soft: #e4efe8;
  --amber: #c98a12;
  --amber-soft: #fbf1dc;
  --red: #c2412d;
  --red-soft: #fbe6e1;
  --radius: 22px;
  --shadow: 0 1px 2px rgba(29, 27, 24, .05), 0 8px 24px rgba(29, 27, 24, .06);
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-tap-highlight-color: transparent;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); }
body { padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom); }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input, select { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ---------- layout ---------- */
.wrap { max-width: 720px; margin: 0 auto; padding: 20px 18px 120px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0 18px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; letter-spacing: -.01em; }
.brand-mark { width: 34px; height: 34px; border-radius: 11px; background: var(--brand); display: grid; place-items: center; color: #fff; font-size: 17px; }
.brand small { display: block; font-weight: 500; color: var(--muted); font-size: 12.5px; letter-spacing: 0; }
.eyebrow { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; margin: 26px 2px 10px; }
h1 { font-size: 30px; letter-spacing: -.025em; margin: 8px 0 6px; font-weight: 680; }
h2 { font-size: 20px; letter-spacing: -.015em; margin: 0 0 4px; font-weight: 650; }
p.lead { color: var(--muted); margin: 0 0 22px; line-height: 1.5; }

.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.stack > * + * { margin-top: 12px; }

/* ---------- controls ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 48px; padding: 0 20px; border-radius: 14px; font-weight: 600; background: var(--brand); color: #fff; transition: transform .12s ease, opacity .2s; }
.btn:active { transform: scale(.97); }
.btn.ghost { background: var(--surface); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.btn.soft { background: var(--brand-soft); color: var(--brand); }
.btn.danger { background: var(--red-soft); color: var(--red); }
.btn.block { width: 100%; }
.btn.sm { height: 38px; padding: 0 14px; border-radius: 11px; font-size: 14px; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.field { display: block; }
.field span { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px 2px; font-weight: 550; }
.field input, .field select { width: 100%; height: 50px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); padding: 0 14px; outline: none; font-size: 16px; }
.field input:focus, .field select:focus { border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1; }
.chip { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; background: #f0ece5; color: var(--muted); }
.chip.low { background: var(--amber-soft); color: var(--amber); }
.chip.out { background: var(--red-soft); color: var(--red); }
.chip.urgent { background: var(--red); color: #fff; }
.chip.ordered { background: var(--brand-soft); color: var(--brand); }
.toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(30px); opacity: 0; background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 14px; font-weight: 550; font-size: 14.5px; transition: .25s ease; z-index: 50; max-width: 90vw; text-align: center; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- PIN pad ---------- */
.pin-dots { display: flex; justify-content: center; gap: 14px; margin: 18px 0 22px; }
.pin-dots i { width: 14px; height: 14px; border-radius: 50%; background: var(--line); transition: .15s; }
.pin-dots i.on { background: var(--brand); transform: scale(1.1); }
.pinpad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; max-width: 320px; margin: 0 auto; }
.pinpad button { height: 68px; border-radius: 20px; background: var(--surface); box-shadow: var(--shadow); font-size: 26px; font-weight: 550; }
.pinpad button:active { background: var(--brand-soft); }
.people { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.person { background: var(--surface); box-shadow: var(--shadow); border-radius: var(--radius); padding: 18px 14px; text-align: center; }
.person .avatar { width: 62px; height: 62px; border-radius: 50%; margin: 0 auto 10px; display: grid; place-items: center; font-size: 26px; font-weight: 650; color: #fff; }
.person b { display: block; font-weight: 620; }
.person small { color: var(--muted); }

/* ---------- staff screen ---------- */
.staff-body { padding-bottom: 210px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(98px, 1fr)); gap: 12px; }
.tile { position: relative; background: var(--surface); border-radius: 20px; box-shadow: var(--shadow); aspect-ratio: 1 / 1.05; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; padding: 8px; transition: transform .12s ease; }
.tile:active { transform: scale(.95); }
.tile .e { font-size: 40px; line-height: 1; }
.tile .n { font-size: 12.5px; color: var(--muted); font-weight: 560; text-align: center; line-height: 1.2; }
.tile.low { box-shadow: inset 0 0 0 3px var(--amber), var(--shadow); background: var(--amber-soft); }
.tile.out { box-shadow: inset 0 0 0 3px var(--red), var(--shadow); background: var(--red-soft); }
.tile.ordered { box-shadow: inset 0 0 0 3px var(--brand), var(--shadow); background: var(--brand-soft); }
.tile .badge { position: absolute; top: 8px; right: 8px; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; color: #fff; }
.tile.low .badge { background: var(--amber); }
.tile.out .badge { background: var(--red); }
.tile.ordered .badge { background: var(--brand); }

.dock { position: fixed; left: 0; right: 0; bottom: 0; padding: 18px 20px calc(18px + env(safe-area-inset-bottom)); background: linear-gradient(to top, var(--bg) 70%, rgba(246, 243, 238, 0)); display: flex; align-items: center; justify-content: center; gap: 22px; z-index: 10; }
.mic { width: 116px; height: 116px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; box-shadow: 0 14px 30px rgba(31, 77, 58, .35); position: relative; touch-action: none; user-select: none; -webkit-user-select: none; }
.mic svg { width: 46px; height: 46px; }
.mic.rec { background: var(--red); box-shadow: 0 14px 34px rgba(194, 65, 45, .4); }
.mic.rec::before, .mic.rec::after { content: ""; position: absolute; inset: -10px; border-radius: 50%; border: 3px solid var(--red); opacity: .5; animation: pulse 1.4s ease-out infinite; }
.mic.rec::after { animation-delay: .7s; }
.mic.busy { background: #9c968c; box-shadow: none; }
@keyframes pulse { from { transform: scale(.9); opacity: .6; } to { transform: scale(1.35); opacity: 0; } }
.round { width: 72px; height: 72px; border-radius: 50%; display: grid; place-items: center; background: var(--surface); box-shadow: var(--shadow); font-size: 28px; }
.round.urgent.on { background: var(--red); color: #fff; box-shadow: 0 10px 24px rgba(194, 65, 45, .35); }
.round small { display: none; }
.timer { position: absolute; bottom: -26px; left: 50%; transform: translateX(-50%); font-size: 13px; color: var(--red); font-weight: 650; font-variant-numeric: tabular-nums; }

.sheet-bg { position: fixed; inset: 0; background: rgba(29, 27, 24, .35); z-index: 30; opacity: 0; pointer-events: none; transition: .2s; }
.sheet-bg.show { opacity: 1; pointer-events: auto; }
.sheet { position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface); border-radius: 28px 28px 0 0; padding: 22px 20px calc(26px + env(safe-area-inset-bottom)); z-index: 31; transform: translateY(105%); transition: transform .28s cubic-bezier(.2, .8, .2, 1); max-width: 720px; margin: 0 auto; }
.sheet.show { transform: translateY(0); }
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: -8px auto 16px; }
.sheet-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.sheet-head .e { font-size: 46px; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.choice { border-radius: 20px; padding: 18px 10px 14px; display: flex; flex-direction: column; align-items: center; gap: 10px; font-weight: 620; }
.choice.low { background: var(--amber-soft); color: var(--amber); }
.choice.out { background: var(--red-soft); color: var(--red); }
.level { width: 46px; height: 64px; border-radius: 10px; border: 3px solid currentColor; position: relative; overflow: hidden; }
.level::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; background: currentColor; opacity: .85; }
.level.half::after { height: 35%; }
.level.empty::after { height: 0; }
.choice.urgent { grid-column: span 2; flex-direction: row; justify-content: center; background: var(--red); color: #fff; padding: 16px; }

.confirm { position: fixed; inset: 0; z-index: 40; background: rgba(246, 243, 238, .97); display: grid; place-items: center; text-align: center; padding: 30px; opacity: 0; pointer-events: none; transition: .2s; }
.confirm.show { opacity: 1; pointer-events: auto; }
.confirm .tick { width: 96px; height: 96px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; margin: 0 auto 18px; font-size: 48px; }
.confirm .tick.bad { background: var(--amber); }
.confirm .emojis { font-size: 44px; letter-spacing: 6px; margin-bottom: 12px; }
.confirm .reply { font-size: 20px; font-weight: 600; line-height: 1.4; max-width: 520px; }

/* ---------- family screen ---------- */
.tabs { display: flex; gap: 6px; background: #ece7df; padding: 5px; border-radius: 16px; margin-bottom: 18px; }
.tabs button { flex: 1; height: 40px; border-radius: 12px; font-weight: 600; color: var(--muted); font-size: 14.5px; }
.tabs button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.summary { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.summary .big { font-size: 15px; color: var(--muted); }
.summary .big b { font-size: 28px; color: var(--ink); letter-spacing: -.02em; margin-right: 6px; }
.list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.item { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-top: 1px solid var(--line); }
.item:first-child { border-top: 0; }
.item .e { font-size: 30px; width: 40px; text-align: center; }
.item .t { flex: 1; min-width: 0; }
.item .t b { font-weight: 620; display: block; }
.item .t small { color: var(--muted); display: block; margin-top: 3px; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .chips { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.item .act { display: flex; gap: 6px; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: #f2eee8; font-size: 17px; }
.icon-btn.ok { background: var(--brand-soft); color: var(--brand); }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.empty .e { font-size: 44px; margin-bottom: 10px; }
.group-title { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 650; margin: 20px 4px 8px; }
.act-row { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.act-row .btn { flex: 1; min-width: 150px; }
.log { font-size: 14px; }
.log .item .e { font-size: 22px; }
.setting { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 0; border-top: 1px solid var(--line); }
.setting:first-child { border-top: 0; padding-top: 0; }
.setting .t small { display: block; color: var(--muted); font-size: 12.5px; margin-top: 3px; line-height: 1.4; }
.seg { display: inline-flex; background: #f0ece5; border-radius: 12px; padding: 3px; }
.seg button { height: 34px; padding: 0 12px; border-radius: 9px; font-size: 13.5px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.time-input { height: 40px; border-radius: 11px; border: 1px solid var(--line); padding: 0 10px; background: var(--surface); }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; background: #f2eee8; padding: 8px 10px; border-radius: 10px; word-break: break-all; }
.add-bar { display: flex; gap: 8px; margin-bottom: 14px; }
.add-bar input { flex: 1; height: 48px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); padding: 0 14px; font-size: 16px; outline: none; }
.add-bar input:focus { border-color: var(--brand); box-shadow: 0 0 0 4px var(--brand-soft); }

@media (min-width: 560px) {
  .grid { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); }
  .tile .e { font-size: 46px; }
}

/* polish fixes */
.btn, .seg button { white-space: nowrap; }
.add-bar input { min-width: 0; }
.act-row .btn { min-width: 0; font-size: 15px; padding: 0 12px; }
.level { display: block; }
.choice.out .level { border-color: var(--red); }
.setting.col { flex-direction: column; align-items: stretch; }
.setting.col .times { display: flex; gap: 8px; align-items: center; }
.setting.col .times input { flex: 1; min-width: 0; }
.setting .t { min-width: 0; }
.level { flex: 0 0 auto; height: 64px; min-height: 64px; }
.choice { justify-content: center; }
