:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #f7f9f8;
  --border: #e3e8e6;
  --text: #15201b;
  --muted: #66746e;
  --brand: #128c5e;
  --brand-hover: #0e7550;
  --brand-soft: #e3f4ec;
  --ok: #138a52;
  --ok-soft: #e2f5ea;
  --bad: #c9372c;
  --bad-soft: #fbe7e5;
  --warn: #a86a00;
  --warn-soft: #fbf0d9;
  --info: #2563c9;
  --info-soft: #e5edfb;
  --shadow: 0 1px 2px rgba(16, 24, 20, .05), 0 4px 16px rgba(16, 24, 20, .04);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1412;
    --surface: #161e1b;
    --surface-2: #1c2622;
    --border: #2a3632;
    --text: #e7eeeb;
    --muted: #8d9b95;
    --brand: #25b07a;
    --brand-hover: #2ec589;
    --brand-soft: #173a2c;
    --ok: #3dc985;
    --ok-soft: #173a29;
    --bad: #f0695e;
    --bad-soft: #3e1d1a;
    --warn: #e5a93a;
    --warn-soft: #3a2e15;
    --info: #6f9ef0;
    --info-soft: #1b2a45;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h2, h3 { margin: 0; letter-spacing: -.01em; }
h2 { font-size: 20px; }
h3 { font-size: 15px; font-weight: 650; }
code { background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
[hidden] { display: none !important; }

/* Topbar */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 20px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; gap: 12px; align-items: center; }
.logo {
  width: 36px; height: 36px; border-radius: 10px;
  display: grid; place-items: center;
  background: var(--brand); color: #fff; font-weight: 800;
}
.brand-title { font-weight: 700; }
.brand-sub { font-size: 12.5px; color: var(--muted); }
.topbar-right { display: flex; gap: 10px; align-items: center; }

.badge {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 11px; border-radius: 99px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 12.5px; font-weight: 600;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.badge.ok .dot { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.badge.wait .dot { background: var(--warn); animation: pulse 1.2s infinite; }
.badge.bad .dot { background: var(--bad); }
@keyframes pulse { 50% { opacity: .35; } }

/* Layout */
.layout {
  display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 16px; padding: 16px 20px 32px; max-width: 1400px; margin: 0 auto;
}
.side { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 12px 16px 24px; }
}

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow);
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 12px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: var(--muted); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--brand-hover); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); border-color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.link {
  background: none; border: 0; padding: 0; cursor: pointer;
  color: var(--brand); font: inherit; font-size: 12.5px; font-weight: 600;
}
.link:hover { text-decoration: underline; }
.danger-link { color: var(--bad); margin-top: 14px; }

/* Connect screen */
.center-screen { min-height: calc(100vh - 62px); display: grid; place-items: center; padding: 20px 16px; }
.connect-card { width: 100%; max-width: 420px; text-align: center; padding: 32px 24px; }
.connect-state { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.qr-box {
  padding: 14px; background: #fff; border-radius: 14px; border: 1px solid var(--border);
  width: 248px; height: 248px; display: grid; place-items: center;
}
.qr-box img { width: 220px; height: 220px; image-rendering: pixelated; }
.steps { text-align: left; color: var(--muted); padding-left: 20px; margin: 4px 0 0; }
.steps li { margin: 3px 0; }
.big-icon {
  width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 800; font-size: 24px;
}
.big-icon.err { background: var(--bad-soft); color: var(--bad); }

/* Spinner */
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2.5px solid var(--border); border-top-color: var(--brand);
  animation: spin .8s linear infinite; flex: none;
}
.spinner.sm { width: 16px; height: 16px; border-width: 2px; }
.spinner.lg { width: 40px; height: 40px; border-width: 3.5px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Groups */
.groups-card { display: flex; flex-direction: column; height: calc(100vh - 62px - 48px); min-height: 480px; position: sticky; top: 78px; }
@media (max-width: 900px) { .groups-card { position: static; height: 70vh; } }

.search {
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); color: var(--muted);
}
.search:focus-within { border-color: var(--brand); }
.search input { flex: 1; border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; padding: 10px 0; }

.tabs { display: flex; gap: 6px; margin: 12px 0 8px; overflow-x: auto; scrollbar-width: none; }
.tabs button {
  flex: none; border: 1px solid var(--border); background: transparent; color: var(--muted);
  padding: 5px 10px; border-radius: 99px; font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.tabs button span { opacity: .75; margin-left: 2px; }
.tabs button.active { background: var(--text); color: var(--surface); border-color: var(--text); }

.bulk { display: flex; justify-content: space-between; align-items: center; padding: 6px 4px 8px; border-bottom: 1px solid var(--border); }
.check-all { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; cursor: pointer; }
.bulk-actions { display: flex; gap: 14px; }

.list { overflow-y: auto; flex: 1; margin: 0 -8px; padding: 4px 8px; }
.list-empty { text-align: center; padding: 40px 0; }
.row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 8px; border-radius: 9px; cursor: pointer;
}
.row:hover { background: var(--surface-2); }
.row.disabled { opacity: .55; }
.row.is-sending { background: var(--info-soft); }
.row-main { flex: 1; min-width: 0; }
.row-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 550; }
.row-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--brand); cursor: pointer; flex: none; margin: 0; }

.chip {
  flex: none; display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 650; padding: 3px 8px; border-radius: 99px;
}
.chip.sent { background: var(--ok-soft); color: var(--ok); }
.chip.failed { background: var(--bad-soft); color: var(--bad); }
.chip.skipped { background: var(--warn-soft); color: var(--warn); }
.chip.sending { background: var(--info-soft); color: var(--info); }
.chip.admin { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.chip .spinner { width: 10px; height: 10px; border-width: 1.5px; border-top-color: var(--info); }

/* Stats & progress */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 14px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 10px; text-align: center; }
.stat-num { font-size: 22px; font-weight: 750; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 11.5px; color: var(--muted); font-weight: 600; }
.stat.ok .stat-num { color: var(--ok); }
.stat.bad .stat-num { color: var(--bad); }
.stat.warn .stat-num { color: var(--warn); }
@media (max-width: 420px) { .stats { grid-template-columns: repeat(2, 1fr); } }

.progress { height: 10px; border-radius: 99px; background: var(--surface-2); overflow: hidden; border: 1px solid var(--border); }
.progress.thin { height: 6px; width: 200px; margin-top: 6px; }
.progress-fill { height: 100%; width: 0; background: var(--brand); border-radius: 99px; transition: width .4s ease; }
.progress-fill.indeterminate { width: 40%; animation: indet 1.2s ease-in-out infinite; }
@keyframes indet { 0% { transform: translateX(-100%); } 100% { transform: translateX(260%); } }
.prog-meta { display: flex; justify-content: space-between; margin-top: 6px; font-variant-numeric: tabular-nums; }

.now {
  display: flex; align-items: center; gap: 12px; margin-top: 14px;
  padding: 10px 12px; border-radius: 10px; background: var(--info-soft);
}
.now-text { min-width: 0; }
.now-text div { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.controls { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.controls .btn.primary { flex: 1; min-width: 160px; padding: 11px 16px; }
.hint { margin-top: 8px; min-height: 18px; }

.toggle { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-size: 13px; font-weight: 600; cursor: pointer; user-select: none; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle-track {
  position: relative; width: 36px; height: 20px; flex: none; border-radius: 99px;
  background: var(--border); transition: background .15s;
}
.toggle-thumb {
  position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .15s;
}
.toggle input:checked + .toggle-track { background: var(--warn); }
.toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(16px); }
.toggle input:focus-visible + .toggle-track { outline: 2px solid var(--brand); outline-offset: 2px; }
.toggle input:disabled ~ * { opacity: .5; }

.pill { font-size: 12px; font-weight: 650; padding: 4px 10px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.pill.running { background: var(--info-soft); color: var(--info); }
.pill.paused { background: var(--warn-soft); color: var(--warn); }
.pill.done { background: var(--ok-soft); color: var(--ok); }
.pill.stopped { background: var(--bad-soft); color: var(--bad); }

/* Message */
.field-label { display: block; font-size: 12.5px; font-weight: 650; margin: 10px 0 6px; }
.field-label:first-of-type { margin-top: 0; }
textarea, .grid2 input {
  width: 100%; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); color: var(--text); font: inherit; padding: 10px 12px; outline: 0;
}
textarea { resize: vertical; }
textarea:focus, .grid2 input:focus { border-color: var(--brand); }

.file-box { display: flex; flex-direction: column; gap: 8px; }
.file-info {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2);
}
.file-icon {
  width: 40px; height: 40px; border-radius: 8px; display: grid; place-items: center;
  background: var(--bad-soft); color: var(--bad); font-size: 11px; font-weight: 800; flex: none;
}
.file-meta { flex: 1; min-width: 0; }
.file-meta div:first-child { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drop {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 16px; border: 1.5px dashed var(--border); border-radius: 10px;
  cursor: pointer; text-align: center; font-weight: 600; transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--brand); background: var(--brand-soft); }

/* Settings */
details summary { display: flex; justify-content: space-between; align-items: center; cursor: pointer; list-style: none; gap: 10px; }
details summary::-webkit-details-marker { display: none; }
details summary h3::before { content: '▸ '; color: var(--muted); }
details[open] summary h3::before { content: '▾ '; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.grid2 label { font-size: 12.5px; font-weight: 600; color: var(--muted); display: flex; flex-direction: column; gap: 5px; }
.grid2 input { padding: 8px 10px; }

/* Log */
.log {
  max-height: 260px; overflow-y: auto; font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--surface-2); border-radius: 10px; padding: 8px 10px;
}
.log-line { display: flex; gap: 8px; padding: 1px 0; }
.log-line time { color: var(--muted); flex: none; }
.log-line.success span { color: var(--ok); }
.log-line.error span { color: var(--bad); }
.log-line.warn span { color: var(--warn); }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 10px;
  font-weight: 600; box-shadow: 0 8px 30px rgba(0,0,0,.2); z-index: 50; max-width: calc(100vw - 32px);
}
.toast.err { background: var(--bad); color: #fff; }
