:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #16181d;
  --muted: #6b7280;
  --border: #e3e5ea;
  --primary: #128c4a;
  --primary-text: #ffffff;
  --danger: #c62828;
  --warn: #b26a00;
  --wa-bg: #e9e2d7;
  --wa-bubble: #ffffff;
  --radius: 10px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1a1d23;
    --text: #e8eaed;
    --muted: #9aa0a6;
    --border: #2c3038;
    --primary: #25a35f;
    --danger: #ef5350;
    --warn: #f0a336;
    --wa-bg: #0b141a;
    --wa-bubble: #202c33;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); }
h1, h2, h3 { margin: 0 0 12px; }
h2 { font-size: 18px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); min-height: 1em; white-space: pre-line; }
.center { text-align: center; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

button { font: inherit; cursor: pointer; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: 7px 12px; }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); }
button.ghost { background: transparent; }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; color: var(--primary); padding: 0; }
button.link.danger { color: var(--danger); }
input, select, textarea { font: inherit; width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }
textarea { resize: vertical; }
label { display: block; margin-bottom: 12px; font-weight: 500; }
label > input, label > select, label > textarea { margin-top: 4px; font-weight: 400; }
label.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
label.check input, .filters input { width: auto; margin: 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 360px; }
.login-card button { width: 100%; }

.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 2; }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.tab { border: 0; background: none; color: var(--muted); }
.tab.active { color: var(--text); background: var(--bg); }
main { max-width: 1000px; margin: 0 auto; padding: 20px 16px 60px; }
.filters { margin-bottom: 12px; color: var(--muted); }
.filters label { display: inline-flex; gap: 6px; align-items: center; font-weight: 400; margin: 0; }

.list { display: grid; gap: 10px; }
.item { display: grid; grid-template-columns: 72px 1fr auto; gap: 14px; align-items: start; }
.item.noimg { grid-template-columns: 1fr auto; }
.thumb { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; background: var(--bg); }
.item h3 { font-size: 15px; margin: 0 0 4px; }
.item .meta { color: var(--muted); font-size: 12px; display: flex; flex-wrap: wrap; gap: 4px 12px; }
.item .snippet { margin-top: 6px; white-space: pre-line; max-height: 3.2em; overflow: hidden; }
.item .err { color: var(--danger); font-size: 12px; margin-top: 6px; white-space: pre-line; }
.item .buttons { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; max-width: 220px; }
.badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 99px; text-transform: uppercase; letter-spacing: .03em; background: var(--bg); color: var(--muted); }
.badge.scheduled, .badge.open { background: #128c4a22; color: var(--primary); }
.badge.sent { background: #1565c022; color: #3b82f6; }
.badge.failed, .badge.logged_out { background: #c6282822; color: var(--danger); }
.badge.partial, .badge.paused, .badge.qr, .badge.connecting { background: #b26a0022; color: var(--warn); }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

dialog { border: 1px solid var(--border); border-radius: 14px; padding: 20px; background: var(--surface); color: var(--text); width: min(960px, calc(100vw - 32px)); max-height: calc(100vh - 32px); }
dialog::backdrop { background: #0008; }
#link-dialog { width: min(420px, calc(100vw - 32px)); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid2.tight { gap: 10px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.group-picker { margin-top: 6px; border: 1px solid var(--border); border-radius: 8px; max-height: 210px; overflow: auto; font-weight: 400; }
.group-picker label { display: flex; gap: 8px; align-items: center; margin: 0; padding: 7px 10px; border-bottom: 1px solid var(--border); font-weight: 400; }
.group-picker label:last-child { border-bottom: 0; }
.group-picker input { width: auto; margin: 0; }
.group-picker .gname { flex: 1; }
.group-picker .empty { padding: 16px; }
#group-search { margin-top: 6px; }
.image-preview { display: flex; align-items: center; gap: 10px; margin: -4px 0 12px; }
.image-preview img { height: 56px; border-radius: 6px; }
.wa-preview { background: var(--wa-bg); border-radius: 10px; padding: 12px; max-height: 360px; overflow: auto; }
.bubble { background: var(--wa-bubble); border-radius: 8px; padding: 6px 8px; max-width: 320px; white-space: pre-wrap; word-break: break-word; box-shadow: 0 1px 1px #0002; }
.bubble img { width: 100%; border-radius: 6px; display: block; margin-bottom: 6px; }
.qr { width: 260px; height: 260px; background: #fff; padding: 8px; border-radius: 8px; }
.pair-code { font: 600 32px/1 ui-monospace, Menlo, monospace; letter-spacing: .15em; padding: 16px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 8px; z-index: 10; max-width: calc(100vw - 32px); }

@media (max-width: 720px) {
  .grid2 { grid-template-columns: 1fr; }
  .item, .item.noimg { grid-template-columns: 1fr; }
  .thumb { width: 100%; height: 140px; }
  .item .buttons { justify-content: flex-start; max-width: none; }
  .topbar { flex-wrap: wrap; }
}
