/* Calm, high-contrast, mobile-first. Light and dark via prefers-color-scheme. */
:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f0;
  --text: #0f1a17;
  --muted: #4d5b56;
  --line: #c9d3cf;
  --brand: #0f5c4d;
  --brand-ink: #ffffff;
  --accent: #0b4fa8;
  --ok: #146c2e;
  --ok-bg: #e3f4e8;
  --warn: #8a4b00;
  --warn-bg: #fff1d6;
  --danger: #b3261e;
  --danger-bg: #fde7e5;
  --consume: #9c2b1f;
  --add: #146c2e;
  --transfer: #0b4fa8;
  --chip-strength-bg: #10231f;
  --chip-strength-ink: #ffffff;
  --chip-brand-bg: #fff4c2;
  --chip-brand-ink: #3a2c00;
  --radius: 14px;
  --tap: 52px;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 2px 10px rgb(0 0 0 / .05);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1211;
    --surface: #161d1b;
    --surface-2: #1e2725;
    --text: #eef3f1;
    --muted: #a9b7b2;
    --line: #34413d;
    --brand: #3fbf9f;
    --brand-ink: #04211a;
    --accent: #7db3ff;
    --ok: #7ad99a;
    --ok-bg: #12301d;
    --warn: #ffc46b;
    --warn-bg: #3a2a0d;
    --danger: #ff8f86;
    --danger-bg: #3d1513;
    --consume: #ff9b8f;
    --add: #7ad99a;
    --transfer: #8dbdff;
    --chip-strength-bg: #eef3f1;
    --chip-strength-ink: #0d1211;
    --chip-brand-bg: #4a3d05;
    --chip-brand-ink: #ffe98a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 17px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}
[hidden] { display: none !important; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.center { text-align: center; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* --- buttons ----------------------------------------------------------------------------- */
.btn {
  min-height: var(--tap);
  padding: 0 18px;
  border-radius: 12px;
  border: 2px solid var(--line);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: var(--surface); }
.btn.danger { border-color: var(--danger); color: var(--danger); background: transparent; }
.btn.ghost { background: transparent; }
.btn.big { min-height: 58px; font-size: 1.1rem; }
.btn.wide { width: 100%; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* --- login ------------------------------------------------------------------------------- */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(420px, 100%);
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
}
label { display: grid; gap: 6px; font-weight: 600; }
input, select, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  min-height: var(--tap);
  width: 100%;
}
textarea { resize: vertical; min-height: 64px; }
.error-text { color: var(--danger); font-weight: 600; margin: 0; }

/* --- layout ------------------------------------------------------------------------------ */
#app { min-height: 100dvh; padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 16px;
  background: var(--brand); color: var(--brand-ink);
}
.topbar .who { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.screen { max-width: 760px; margin: 0 auto; padding: 16px; }
.screen-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.screen-head h2 { margin: 0; flex: 1; }
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  min-height: 64px; border: 0; background: none; color: var(--muted);
  font: inherit; font-size: .78rem; font-weight: 600; display: grid; justify-items: center; gap: 2px; cursor: pointer;
}
.tabbar .ti { width: 24px; height: 24px; }
.tabbar button.active { color: var(--brand); box-shadow: inset 0 3px 0 var(--brand); }

/* --- switch ------------------------------------------------------------------------------ */
.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; min-height: var(--tap); }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { flex: none; width: 52px; height: 30px; border-radius: 15px; background: var(--line); position: relative; transition: background .15s; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + .track { background: var(--warn); }
.switch input:checked + .track::after { transform: translateX(22px); }
.switch input:focus-visible + .track { outline: 3px solid var(--accent); outline-offset: 2px; }
.topbar .switch { font-size: .85rem; min-height: 44px; }
.topbar .switch input:checked + .track { background: #ffc46b; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; min-height: 44px; }
.check input { width: 22px; height: 22px; min-height: 0; }

.banner { border-radius: 10px; padding: 10px 14px; font-weight: 600; margin-bottom: 12px; }
.banner.warn { background: var(--warn-bg); color: var(--warn); border: 2px solid var(--warn); }

/* --- push to talk ------------------------------------------------------------------------ */
.talk { display: grid; justify-items: center; gap: 4px; margin: 0 0 10px; }
.talk p { margin: 0; }
.ptt {
  width: min(46vw, 176px); aspect-ratio: 1; border-radius: 50%;
  border: 0; background: var(--brand); color: var(--brand-ink);
  display: grid; place-content: center; justify-items: center; gap: 6px;
  font: inherit; font-weight: 700; cursor: pointer;
  box-shadow: 0 6px 20px rgb(15 92 77 / .35);
  user-select: none; -webkit-user-select: none; touch-action: none; -webkit-touch-callout: none;
}
.ptt-label { font-size: 1rem; max-width: 150px; text-align: center; }
.ptt.recording { background: var(--danger); color: #fff; animation: pulse 1.2s infinite; }
.ptt.busy { background: var(--muted); color: var(--surface); cursor: progress; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgb(179 38 30 / .5); } 50% { box-shadow: 0 0 0 18px rgb(179 38 30 / 0); } }
@media (prefers-reduced-motion: reduce) { .ptt.recording { animation: none; } }
.state:empty { display: none; }
.state { margin: 4px 0 0; font-weight: 700; text-align: center; }

.cmd { display: grid; gap: 6px; margin-bottom: 16px; }
.cmd-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: stretch; }

/* --- cards ------------------------------------------------------------------------------- */
.results { display: grid; gap: 14px; }
.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  border: 2px solid var(--line); padding: 16px; display: grid; gap: 12px;
}
.card.proposal { border-left-width: 8px; }
.card.proposal.consume { border-left-color: var(--consume); }
.card.proposal.add { border-left-color: var(--add); }
.card.proposal.transfer { border-left-color: var(--transfer); }
.card.done { border-color: var(--ok); background: var(--ok-bg); }
.card.undone { border-color: var(--line); opacity: .8; }
.card.error { border-color: var(--danger); background: var(--danger-bg); }
.card.question { border-color: var(--accent); }
.action-tag {
  justify-self: start; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; font-size: .85rem;
  padding: 4px 10px; border-radius: 6px; color: var(--surface);
}
.action-tag.consume { background: var(--consume); }
.action-tag.add { background: var(--add); }
.action-tag.transfer { background: var(--transfer); }
.amount { font-size: 1.6rem; font-weight: 800; line-height: 1.1; }
.product-name { font-size: 1.35rem; font-weight: 800; line-height: 1.2; overflow-wrap: anywhere; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border-radius: 8px; padding: 4px 10px; font-weight: 800; font-size: 1.15rem; }
.chip.strength { background: var(--chip-strength-bg); color: var(--chip-strength-ink); }
.chip.brand { background: var(--chip-brand-bg); color: var(--chip-brand-ink); border: 2px solid currentColor; }
.chip.cold { background: var(--transfer); color: var(--surface); font-size: .95rem; }
.meta { color: var(--muted); font-size: .95rem; }
.place { display: grid; gap: 2px; }
.place .lbl { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; }
.place .val { font-size: 1.15rem; font-weight: 700; overflow-wrap: anywhere; }
.places { display: grid; gap: 8px; }
.places.transfer { grid-template-columns: 1fr auto 1fr; align-items: end; }
.places .arrow { font-size: 1.5rem; font-weight: 800; color: var(--transfer); padding-bottom: 2px; }
.expiry { font-weight: 800; font-size: 1.1rem; }
.actions { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 8px; }
.actions .btn { padding: 0 8px; }
.status-line { font-weight: 800; color: var(--ok); }
.card.undone .status-line { color: var(--muted); }
.fulltext { font-size: .9rem; color: var(--muted); }
.question .q { font-size: 1.2rem; font-weight: 800; }
.cands { display: grid; gap: 8px; }
.cand {
  text-align: left; min-height: 56px; padding: 10px 14px; border-radius: 12px; border: 2px solid var(--line);
  background: var(--surface-2); color: var(--text); font: inherit; font-weight: 700; cursor: pointer;
  display: flex; justify-content: space-between; gap: 12px; align-items: center;
}
.cand .stock { font-weight: 600; color: var(--muted); white-space: nowrap; font-size: .9rem; }
.cand .stock.zero { color: var(--danger); }
.err-title { font-weight: 800; color: var(--danger); font-size: 1.1rem; }
.alias-offer { background: var(--surface-2); border-radius: 10px; padding: 12px; display: grid; gap: 8px; }
.edit-form { display: grid; gap: 10px; background: var(--surface-2); padding: 12px; border-radius: 10px; }
.edit-form .two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* --- history ----------------------------------------------------------------------------- */
.history { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.hist { background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: grid; gap: 6px; }
.hist .top { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: .85rem; color: var(--muted); }
.hist .said { font-style: italic; color: var(--muted); overflow-wrap: anywhere; }
.hist .what { font-weight: 700; overflow-wrap: anywhere; }
.hist.undone .what { text-decoration: line-through; color: var(--muted); }
.badge { font-size: .78rem; font-weight: 800; padding: 2px 8px; border-radius: 6px; text-transform: uppercase; letter-spacing: .04em; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.undone { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.badge.err { background: var(--danger-bg); color: var(--danger); }
.badge.info { background: var(--surface-2); color: var(--muted); }

/* --- stock ------------------------------------------------------------------------------- */
.search { margin-bottom: 8px; }
.legend { display: flex; gap: 6px; flex-wrap: wrap; }
.site { margin-bottom: 18px; }
.site h3 { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
details.box { background: var(--surface); border: 2px solid var(--line); border-radius: 12px; margin-bottom: 8px; }
details.box summary { padding: 12px 14px; font-weight: 700; cursor: pointer; min-height: var(--tap); display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.stock-list { list-style: none; margin: 0; padding: 0 14px 10px; }
.stock-list li { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 8px 0; border-top: 1px solid var(--line); }
.stock-list .n { font-weight: 600; overflow-wrap: anywhere; }
.stock-list .q { font-weight: 800; text-align: right; white-space: nowrap; }
.stock-list .d { grid-column: 1 / -1; font-size: .85rem; color: var(--muted); }
.exp-badge { font-size: .78rem; font-weight: 800; padding: 1px 7px; border-radius: 6px; }
.exp-badge.expired { background: var(--danger); color: #fff; }
.exp-badge.soon { background: var(--warn-bg); color: var(--warn); border: 1px solid var(--warn); }
.exp-badge.later { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.stock-list li.expired { background: var(--danger-bg); }
.stock-list li.soon { background: var(--warn-bg); }

/* --- settings ---------------------------------------------------------------------------- */
.panel { background: var(--surface); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; border: 1px solid var(--line); }
.choices { border: 0; padding: 0; margin: 0; display: grid; gap: 10px; }
.choice { display: grid; grid-template-columns: 28px 1fr; gap: 10px; font-weight: 400; align-items: start; padding: 10px; border: 2px solid var(--line); border-radius: 10px; cursor: pointer; }
.choice:has(input:checked) { border-color: var(--brand); background: var(--surface-2); }
.choice input { width: 22px; height: 22px; min-height: 0; margin-top: 2px; }
.sub { margin-top: 12px; display: grid; gap: 10px; }
progress { width: 100%; height: 14px; }

/* --- debug ------------------------------------------------------------------------------- */
.debug { margin-top: 16px; font-size: .85rem; }
.debug details { background: var(--surface); border: 1px dashed var(--line); border-radius: 10px; padding: 8px 12px; }
.debug summary { cursor: pointer; font-weight: 700; min-height: 40px; display: flex; align-items: center; }
.debug pre { white-space: pre-wrap; overflow-wrap: anywhere; font-size: .78rem; max-height: 60vh; overflow: auto; margin: 6px 0; }
.debug table { border-collapse: collapse; width: 100%; }
.debug td, .debug th { border-bottom: 1px solid var(--line); padding: 3px 6px; text-align: left; vertical-align: top; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 10;
  background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 12px; font-weight: 600; max-width: calc(100% - 32px);
}

@media (min-width: 900px) {
  .screen { padding: 24px; }
  .tabbar { left: 50%; transform: translateX(-50%); max-width: 760px; border: 1px solid var(--line); border-bottom: 0; border-radius: 14px 14px 0 0; }
}
