:root {
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #17201d;
  --muted: #5f6b67;
  --line: #dde3e1;
  --accent: #128c7e;
  --accent-ink: #ffffff;
  --accent-soft: #e3f3f0;
  --danger: #c0392b;
  --warn-bg: #fff6e0;
  --warn-ink: #6b4d00;
  --ok: #1f9d55;
  --bad: #d64545;
  --pending: #d99a00;
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1513;
    --card: #182120;
    --text: #e6ecea;
    --muted: #94a39e;
    --line: #2a3533;
    --accent: #25b39f;
    --accent-ink: #062520;
    --accent-soft: #163631;
    --danger: #ff7b6b;
    --warn-bg: #3a2f10;
    --warn-ink: #f3d68a;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 0.95rem; margin-top: 8px; }
code { background: var(--accent-soft); padding: 1px 5px; border-radius: 4px; font-size: 0.9em; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; }
.logo { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); display: inline-block; }
.who { display: flex; align-items: center; gap: 10px; font-size: 0.9rem; color: var(--muted); min-width: 0; }

main { max-width: 820px; margin: 0 auto; padding: 16px; }
main.narrow { max-width: 440px; padding-top: 40px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; min-width: 0;
}
.stack { display: flex; flex-direction: column; gap: 14px; }
.pad { padding-top: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.row > input { flex: 1; min-width: 0; }
.muted { color: var(--muted); font-weight: normal; }
.pre { white-space: pre-wrap; word-break: break-word; margin: 0; }

label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 0.92rem; }
input, textarea, select {
  font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 9px; padding: 10px 12px; width: 100%;
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus, button:focus-visible, summary:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 1px;
}

button { font: inherit; cursor: pointer; border-radius: 9px; border: 1px solid transparent; padding: 10px 16px; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.primary { background: var(--accent); color: var(--accent-ink); font-weight: 650; }
.primary.small, .ghost.small { padding: 7px 12px; font-size: 0.9rem; }
.ghost { background: transparent; border-color: var(--line); color: var(--text); }
.ghost.danger, .link.danger { color: var(--danger); }
.link { background: none; border: none; padding: 0; color: var(--accent); font-weight: 600; }

.tabs {
  display: flex; gap: 4px; margin-bottom: 16px; padding: 4px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  overflow-x: auto;
}
.tabs button { flex: 1; background: none; color: var(--muted); font-weight: 600; white-space: nowrap; }
.tabs button[aria-selected="true"] { background: var(--accent-soft); color: var(--text); }

.status-line { display: flex; align-items: center; gap: 10px; margin: 14px 0 6px; font-size: 1.05rem; }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--pending); flex: none; }
.dot.ok { background: var(--ok); }
.dot.bad { background: var(--bad); }
.facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 10px 0 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; word-break: break-word; }
.qr { margin-top: 14px; text-align: center; }
.qr img { width: 260px; max-width: 100%; background: #fff; padding: 10px; border-radius: 10px; }

.warn { background: var(--warn-bg); color: var(--warn-ink); padding: 10px 12px; border-radius: 9px; margin: 0; font-size: 0.9rem; }
.msg { margin: 0; min-height: 1.2em; font-size: 0.92rem; }
.msg.error { color: var(--danger); }
.msg.ok { color: var(--ok); }

.file { flex-direction: row; align-items: center; cursor: pointer; color: var(--accent); }
.file input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file:focus-within { outline: 2px solid var(--accent); border-radius: 6px; }

details summary { cursor: pointer; font-weight: 600; }

.bar { height: 10px; background: var(--accent-soft); border-radius: 99px; overflow: hidden; margin: 12px 0 8px; }
.bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width 0.4s; }

ul.list, ul.batches, ul.results { list-style: none; margin: 10px 0 0; padding: 0; }
ul.list li, ul.batches li, ul.results li {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 2px; border-top: 1px solid var(--line); min-width: 0;
}
ul.list li:first-child, ul.batches li:first-child, ul.results li:first-child { border-top: none; }
ul.list li.clickable { cursor: pointer; }
ul.list li.clickable:hover { background: var(--accent-soft); }
.grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.badge { font-size: 0.75rem; padding: 2px 8px; border-radius: 99px; background: var(--accent-soft); color: var(--text); white-space: nowrap; }
.badge.bad { background: transparent; border: 1px solid var(--bad); color: var(--bad); }
.member-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
#groupFilter { margin-top: 12px; }

dialog {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); color: var(--text);
  width: min(460px, calc(100vw - 32px)); padding: 20px;
}
dialog::backdrop { background: rgb(0 0 0 / 0.45); }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  max-width: calc(100vw - 32px); z-index: 20; box-shadow: 0 6px 24px rgb(0 0 0 / 0.2);
}

.stack-tight { display: flex; flex-direction: column; gap: 4px; }
.filters { margin-top: 12px; }
.filters select { width: auto; }
.filters input { flex: 1; min-width: 160px; width: auto; }
ul.msglog li { align-items: flex-start; }
.msg-body { color: var(--muted); font-size: 0.9rem; white-space: pre-wrap; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.msg-body.open { display: block; }
.msg-meta { font-size: 0.8rem; color: var(--muted); }
.msg-error { font-size: 0.85rem; color: var(--danger); }
.badge.ok { background: transparent; border: 1px solid var(--ok); color: var(--ok); }
.badge.wait { background: transparent; border: 1px solid var(--pending); color: var(--text); }

@media (max-width: 520px) {
  main { padding: 12px; }
  .card { padding: 14px; }
  .who #whoPhone { display: none; }
}
