:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #15181d;
  --muted: #5d6673;
  --line: #e2e5ea;
  --primary: #1f6feb;
  --primary-text: #ffffff;
  --accent: #0f9d58;
  --danger: #d1242f;
  --warn: #b25e00;
  --warn-bg: #fff3e0;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #171b22;
    --text: #e8ebf0;
    --muted: #98a2b0;
    --line: #2a303a;
    --primary: #4c8dff;
    --primary-text: #07101f;
    --accent: #34c27a;
    --danger: #ff6b73;
    --warn: #ffb454;
    --warn-bg: #2a2012;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.5);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}
[hidden] { display: none !important; }
h1, h2 { margin: 0 0 12px; font-size: 1.3rem; }
code { background: var(--line); padding: 1px 6px; border-radius: 6px; }

input, textarea, button { font: inherit; color: inherit; }
input, textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
input:focus-visible, textarea:focus-visible, button:focus-visible, .btn:focus-within {
  outline: 3px solid var(--primary);
  outline-offset: 1px;
}
label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 12px; }
label input, label textarea { margin-top: 4px; color: var(--text); font-size: 1rem; }

button {
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
}
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); font-weight: 600; }
button.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
button.ghost { background: transparent; }
button.icon { padding: 0; width: 48px; flex: none; }
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 16px; margin: 0;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); color: var(--text); cursor: pointer; font-size: 1rem;
}

.center { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.card { width: 100%; max-width: 380px; background: var(--surface); padding: 24px; border-radius: var(--radius); box-shadow: var(--shadow); }
.card .primary { width: 100%; margin-top: 4px; }
.err { color: var(--danger); min-height: 1.2em; margin: 8px 0 0; font-size: 0.9rem; }

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; gap: 8px; padding: 12px 16px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.summary { margin: 10px 16px 0; color: var(--muted); font-size: 0.9rem; }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }

.list { list-style: none; margin: 10px 0 0; padding: 0 16px 150px; display: grid; gap: 10px; }
.item {
  display: grid; grid-template-columns: 64px 1fr auto; gap: 12px; align-items: center;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px;
}
.item.low { border-color: var(--warn); }
.thumb {
  width: 64px; height: 64px; border-radius: 10px; background: var(--line) center / cover no-repeat;
  display: grid; place-items: center; color: var(--muted); font-weight: 700; font-size: 1.4rem;
}
.info { min-width: 0; text-align: left; background: none; border: 0; padding: 0; min-height: 64px; display: block; cursor: pointer; }
.info b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.info small { display: block; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { display: inline-block; margin-top: 2px; padding: 1px 8px; border-radius: 99px; background: var(--warn-bg); color: var(--warn); font-size: 0.75rem; font-weight: 600; }
.qty { display: flex; align-items: center; gap: 6px; }
.qty button { width: 44px; padding: 0; font-size: 1.3rem; }
.qty span { min-width: 34px; text-align: center; font-weight: 700; font-size: 1.15rem; font-variant-numeric: tabular-nums; }

.fabs { position: fixed; right: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); display: grid; gap: 12px; z-index: 6; }
.fab {
  width: 60px; height: 60px; border-radius: 50%; padding: 0; display: grid; place-items: center;
  background: var(--primary); color: var(--primary-text); border: 0; box-shadow: var(--shadow);
}
.fab.accent { background: var(--accent); color: #fff; }
.fab.listening, #cmdMic.listening { animation: pulse 1s infinite; background: var(--danger); color: #fff; }
@keyframes pulse { 50% { transform: scale(1.08); } }
@media (prefers-reduced-motion: reduce) { .fab.listening, #cmdMic.listening { animation: none; } }

dialog {
  width: min(520px, 100% - 24px); max-height: calc(100dvh - 24px); overflow: auto;
  border: 0; border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 20px; box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.stepper { display: flex; gap: 6px; margin-top: 4px; }
.stepper input { margin: 0; text-align: center; font-weight: 700; }
.stepper button { width: 44px; padding: 0; font-size: 1.3rem; flex: none; }
.photo { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.photoPrev { width: 96px; height: 96px; border-radius: 12px; background: var(--line) center / cover no-repeat; flex: none; }
.actions { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.spacer { flex: 1; }

.cmdrow { display: flex; gap: 8px; }
.hint { color: var(--muted); font-size: 0.85rem; min-height: 1.2em; margin: 6px 0; }
.actionsList { list-style: none; margin: 8px 0; padding: 0; display: grid; gap: 8px; }
.actionsList li { --st: var(--muted); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px 10px 32px; position: relative; }
.actionsList li::before { content: ""; position: absolute; left: 12px; top: 17px; width: 10px; height: 10px; border-radius: 50%; background: var(--st); }
.actionsList li.ok { --st: var(--accent); }
.actionsList li.info { --st: var(--primary); }
.actionsList li.error { --st: var(--danger); border-color: var(--danger); }
.actionsList li.ambiguous { --st: var(--warn); border-color: var(--warn); }
.actionsList li.done { opacity: 0.6; }
.actionsList .cands { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.actionsList .cands button { min-height: 40px; }
.check { display: flex; gap: 8px; align-items: center; margin: 8px 0 0; }
.check input { width: 20px; height: 20px; margin: 0; flex: none; }

#toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: min(92vw, 460px); padding: 12px 16px; border-radius: 12px;
  background: var(--text); color: var(--bg); box-shadow: var(--shadow); z-index: 50;
  opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
#toast.show { opacity: 1; }
