:root {
  --bg: #f6f7f9; --panel: #fff; --ink: #1a1d21; --muted: #6b7280;
  --line: #e5e7eb; --accent: #2563eb; --accent-ink: #fff;
  --ok: #15803d; --warn: #b45309; --bad: #b91c1c;
  --chip: #eef2ff; --chip-ink: #3730a3;
  --alert: #eab308; --alert-bg: #fefce8;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --panel: #171a21; --ink: #e6e8eb; --muted: #9aa3af;
    --line: #262b35; --accent: #3b82f6; --accent-ink: #fff;
    --ok: #4ade80; --warn: #fbbf24; --bad: #f87171;
    --chip: #1e2537; --chip-ink: #a5b4fc;
    --alert: #eab308; --alert-bg: #2a2410;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}
.muted { color: var(--muted); }
button {
  cursor: pointer; border: 1px solid var(--line);
  background: var(--panel); color: var(--ink);
  padding: 4px 9px; border-radius: 7px; font-size: 12.5px; line-height: 1.4;
}
button.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.danger { background: var(--bad); color: #fff; border-color: var(--bad); font-weight: 600; }
button:disabled { opacity: .5; cursor: not-allowed; }

/* login */
body.login { display: grid; place-items: center; min-height: 100vh; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
  padding: 28px; width: min(360px, 92vw); display: flex; flex-direction: column; gap: 12px;
}
.card h1 { margin: 0; font-size: 20px; }
.card input { padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); }
.err { color: var(--bad); font-size: 13px; margin: 0; }

/* header */
header {
  position: sticky; top: 0; z-index: 5; background: var(--panel);
  border-bottom: 1px solid var(--line); padding: 10px 16px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
header h1 { font-size: 16px; margin: 0 6px 0 0; }
.spacer { flex: 1; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }
.pill { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--chip); color: var(--chip-ink); }
.pill.off { background: #fee2e2; color: #991b1b; }
@media (prefers-color-scheme: dark) { .pill.off { background: #3f1d1d; color: #fca5a5; } }
.bell { position: relative; }
.badge {
  position: absolute; top: -6px; right: -6px; background: var(--bad); color: #fff;
  border-radius: 999px; font-size: 11px; padding: 0 5px; min-width: 16px; text-align: center;
}

/* 3-column layout */
.cols {
  display: grid; grid-template-columns: 260px 1fr 460px; gap: 14px;
  padding: 14px; align-items: start; max-width: 1650px; margin: 0 auto;
}
.col-right { font-size: 13px; }
.col-right h2 { font-size: 12px; }
.col-right .text, .col-right textarea { font-size: 13px; }
@media (max-width: 1000px) { .cols { grid-template-columns: 1fr; } }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.panel h2 { font-size: 13px; margin: 0 0 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.col-left, .col-right { position: sticky; top: 70px; max-height: calc(100vh - 90px); overflow: auto; }

/* left: channels */
.chan {
  width: 100%; text-align: left; display: flex; align-items: center; gap: 8px;
  padding: 9px 10px; margin-bottom: 6px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--panel);
}
.chan:hover { background: var(--bg); }
.chan.active { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.chan.nofile { opacity: .5; font-style: italic; }
.chan.hasreplies { border-color: var(--alert); box-shadow: inset 0 0 0 2px var(--alert); background: var(--alert-bg); }
.chan .chan-name { flex: 1; font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chan .chan-num { font-variant-numeric: tabular-nums; font-size: 12px; color: var(--muted); }
.chan .reply-badge {
  background: var(--alert); color: #3a2f00; font-weight: 700; font-size: 11px;
  border-radius: 999px; padding: 1px 7px; margin-left: 4px;
}
.chan.special { background: var(--chip); color: var(--chip-ink); border-color: transparent; }
.chan.special.active { border-color: var(--accent); }
.chan.sender { display: flex; align-items: center; gap: 7px; background: var(--panel); color: var(--ink); border: 1px solid var(--line); font-size: 12.5px; }
.chan.sender .chan-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
h2.collapsible { cursor: pointer; user-select: none; display: flex; align-items: center; justify-content: space-between; }
h2.collapsible .arrow { font-size: 20px; line-height: 1; font-weight: 700; color: var(--ink); }
h2.collapsible.section { margin: 16px 0 8px; }
h2.collapsible.section:first-of-type { margin-top: 0; }
/* thin reply outline for the All-guests + Sender-Email items */
.chan.hasreplies-thin { border-color: var(--alert); box-shadow: inset 0 0 0 1px var(--alert); }
.muted.small, .small { font-size: 11.5px; }
.bad-txt { color: var(--bad); }
.reply-sub { font-weight: 600; font-size: 13px; }
.reply-snip { color: var(--muted); font-size: 12.5px; margin: 3px 0 6px; }
.reply-form textarea, .detail textarea { width: 100%; }

/* center: table */
.center-head { display: flex; align-items: center; gap: 12px; justify-content: space-between; flex-wrap: wrap; }
#centerTitle { text-transform: none; letter-spacing: 0; font-size: 15px; color: var(--ink); }
.filter { flex: 1; min-width: 160px; padding: 8px 10px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--bg); color: var(--ink); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--panel); }
tbody tr:hover { background: var(--bg); }
.tablewrap { max-height: 68vh; overflow: auto; border: 1px solid var(--line); border-radius: 8px; margin-top: 10px; }
.role-chip { font-size: 12px; padding: 1px 7px; border-radius: 999px; background: var(--chip); color: var(--chip-ink); }
.multi-chip { font-size: 11px; padding: 1px 6px; border-radius: 999px; background: transparent;
  color: var(--alert); border: 1px solid var(--alert); margin-left: 6px; }
/* expandable guest rows + channel chips */
tr.guest { cursor: pointer; }
tr.guest.open { background: var(--bg); }
tr.guest .caret { color: var(--muted); font-size: 11px; margin-right: 4px; }
tr.replied { background: var(--alert-bg); }
tr.replied td:first-child { border-left: 3px solid var(--alert); }
.replied-tag { font-size: 11px; color: var(--alert); border: 1px solid var(--alert);
  border-radius: 999px; padding: 0 6px; margin-left: 6px; }
.detail td { background: var(--bg); padding-top: 4px; }
.chan-chip { display: inline-block; font-size: 12px; padding: 1px 8px; margin: 2px 4px 2px 0;
  border-radius: 999px; background: var(--chip); color: var(--chip-ink); }
.waiting { color: var(--muted); padding: 24px; text-align: center; }
.banner { background: var(--warn); color: #000; padding: 6px 10px; border-radius: 8px; font-size: 13px; margin-bottom: 8px; }

/* right: request + alerts */
.text, textarea { width: 100%; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); font: inherit; margin-bottom: 8px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.testrow { margin-top: 8px; }
.numlabel { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.numin { width: 64px; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); font: inherit; }
.imgblock { margin: 4px 0 8px; }
#imgPreview img { max-width: 100%; max-height: 160px; margin-top: 8px; border: 1px solid var(--line); border-radius: 8px; }
small.hint { color: var(--muted); display: block; margin-top: 6px; }
.accounts { margin-top: 8px; }
.acct-head { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.acct { display: flex; align-items: center; gap: 6px; font-size: 12.5px; padding: 2px 0; }
.acct-email { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acct-sent { color: var(--muted); font-size: 11.5px; }
.acct-ctrl { border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; margin-bottom: 8px; }
.acct-top { display: flex; align-items: center; gap: 6px; }
.acct-top .acct-email { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; }
.acct-sub { color: var(--muted); font-size: 11.5px; margin: 3px 0 6px; }
.state-pill.stopped { background: #fee2e2; color: #991b1b; }
.state-pill.idle { background: var(--chip); color: var(--chip-ink); }
@media (prefers-color-scheme: dark) { .state-pill.stopped { background: #3f1d1d; color: #fca5a5; } }
.pace { font-size: 11.5px; color: var(--muted); margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--line); }
.acct-summary { font-size: 13px; padding: 3px 0; }
.progress { margin-top: 12px; }
.bar { height: 10px; background: var(--line); border-radius: 999px; overflow: hidden; }
.bar .fill { height: 100%; width: 0; background: var(--accent); transition: width .4s; }
.state-pill { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--chip); color: var(--chip-ink); }
.state-pill.running { background: #dcfce7; color: #166534; }
.state-pill.paused { background: #fef9c3; color: #854d0e; }
.state-pill.done { background: #e0e7ff; color: #3730a3; }
.alert { padding: 9px 0; border-bottom: 1px solid var(--line); }
.alert .who { font-weight: 600; }
.alert .sub { color: var(--muted); font-size: 13px; }
.alert .snip { color: var(--muted); font-size: 12.5px; margin: 2px 0; }
.alert .actions { display: flex; gap: 10px; margin-top: 3px; }
.alert a { color: var(--accent); text-decoration: none; font-size: 13px; }
.alert.unseen { border-left: 3px solid var(--alert); padding-left: 8px; }
.toast {
  position: fixed; right: 16px; bottom: 16px; background: var(--panel); color: var(--ink);
  border: 1px solid var(--alert); border-left: 4px solid var(--alert); border-radius: 10px;
  padding: 12px 14px; box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: 360px; z-index: 20;
}
