:root {
  --bg: #f6f7f5;
  --card: #ffffff;
  --text: #1d2420;
  --muted: #66706a;
  --line: #e2e6e2;
  --accent: #2f7d4f;
  --accent-text: #ffffff;
  --warn: #b5541c;
  --danger: #c0392b;
  --star: #e0a400;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141816;
    --card: #1d2320;
    --text: #e6ebe7;
    --muted: #9aa49e;
    --line: #2d3531;
    --accent: #4caf73;
    --accent-text: #0e1410;
    --warn: #e3894f;
    --danger: #ef6b5e;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 190px;
}
header {
  position: sticky; top: 0; z-index: 2;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding: 10px 16px 0;
}
.titlebar { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
h1 { margin: 0; font-size: 1.15rem; }
#lang {
  font: inherit; font-size: .85rem; font-weight: 600; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px;
}
nav { display: flex; justify-content: space-between; gap: 2px; overflow-x: auto; }
nav button {
  flex: 1 1 auto;
  background: none; border: 0; border-bottom: 3px solid transparent; border-radius: 0;
  color: var(--muted); padding: 8px 4px; font-weight: 600; font-size: .9rem; white-space: nowrap;
}
nav button.active { color: var(--text); border-bottom-color: var(--accent); }
main { max-width: 760px; margin: 0 auto; padding: 12px 16px; }
button {
  font: inherit; cursor: pointer;
  background: var(--accent); color: var(--accent-text);
  border: 1px solid var(--accent); border-radius: 8px; padding: 8px 14px;
}
button.ghost { background: transparent; color: var(--text); border-color: var(--line); }
button:disabled { opacity: .5; cursor: wait; }
input, textarea {
  font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%;
}
.toolbar { display: flex; gap: 8px; margin-bottom: 10px; }
.toolbar input { flex: 1; }
.hint { color: var(--muted); font-size: .9rem; margin: 0 0 10px; }
.empty { color: var(--muted); text-align: center; padding: 30px 0; }
a { color: var(--accent); }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.item {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px;
}
.item.selected { border-color: var(--accent); }
.item.gone { opacity: .55; }
.item img, .item .noimg { width: 48px; height: 48px; object-fit: contain; border-radius: 6px; background: #fff; flex: none; }
.item .info { flex: 1; min-width: 0; }
.item .name { font-weight: 600; overflow-wrap: anywhere; }
.item .meta { color: var(--muted); font-size: .85rem; }
.qty { display: flex; align-items: center; gap: 6px; flex: none; }
.qty button { width: 40px; height: 40px; padding: 0; font-size: 1.3rem; line-height: 1; }
.qty span { min-width: 1.6em; text-align: center; font-weight: 700; font-size: 1.1rem; }
.star { background: none; border: 0; font-size: 1.5rem; color: var(--muted); padding: 4px; }
.star.on { color: var(--star); }
.weight { width: 84px; flex: none; text-align: right; }
.weight.manual { border-color: var(--accent); }
footer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 2;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
}
footer > * { max-width: 728px; margin-left: auto; margin-right: auto; }
.meter { margin-bottom: 6px; }
.meter-label { display: flex; justify-content: space-between; font-size: .9rem; font-variant-numeric: tabular-nums; }
.bar { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.bar div { height: 100%; width: 0; background: var(--accent); transition: width .15s; }
.bar div.over { background: var(--danger); }
.over-text { color: var(--danger); font-weight: 700; }
.warn { color: var(--warn); font-size: .85rem; margin: 4px auto; }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }
.actions #send { flex: 1; max-width: 260px; }
#settings-form { display: flex; flex-direction: column; gap: 12px; max-width: 420px; }
#settings-form label { display: flex; flex-direction: column; gap: 4px; font-size: .9rem; color: var(--muted); }
#settings-form button { align-self: flex-start; }
.order-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.status-sent { color: var(--accent); font-weight: 700; }
.status-failed { color: var(--danger); font-weight: 700; }
.status-tested { color: var(--muted); font-weight: 700; }
.history .info ul { margin: 4px 0 0; padding-left: 18px; font-size: .9rem; }
#toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: 200px; z-index: 3;
  max-width: calc(100% - 32px); background: var(--text); color: var(--bg);
  padding: 10px 14px; border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
#toast.error { background: var(--danger); color: #fff; }
body.no-footer { padding-bottom: 20px; }
body.no-footer footer { display: none; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; margin-bottom: 12px; }
.panel h2 { font-size: 1rem; margin: 0 0 6px; }
.panel p { margin: 0 0 8px; }
#run { border-color: var(--accent); }
#run .bar { margin-bottom: 8px; }
.backup { margin-top: 20px; max-width: 420px; }
.actions.start { justify-content: flex-start; flex-wrap: wrap; }
#settings-form select { font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
#open-portal { flex: none; }
body.no-footer #toast { bottom: calc(24px + env(safe-area-inset-bottom)); }
.header-tools { display: flex; align-items: center; gap: 8px; }
button.icon {
  width: 32px; height: 32px; padding: 0; border-radius: 50%;
  background: var(--card); color: var(--text); border: 1px solid var(--line);
  font-weight: 700; font-size: 1rem; line-height: 1;
}
dialog#help {
  width: min(560px, calc(100% - 32px)); max-height: calc(100dvh - 48px);
  padding: 0; border: 1px solid var(--line); border-radius: 14px;
  background: var(--card); color: var(--text);
  display: none; flex-direction: column;
}
dialog#help[open] { display: flex; }
dialog#help::backdrop { background: rgba(0, 0, 0, .45); }
.help-body { overflow-y: auto; padding: 16px 18px 4px; }
.help-body h2 { font-size: 1.15rem; margin: 0 0 8px; }
.help-body h3 { font-size: 1rem; margin: 14px 0 4px; }
.help-body p, .help-body li { font-size: .95rem; }
.help-body ol { padding-left: 20px; margin: 0; }
.help-body li { margin-bottom: 6px; }
.help-actions { padding: 10px 18px 14px; border-top: 1px solid var(--line); margin: 0; }
