*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface-2: #f7f7f8;
  --surface-3: #efeae2;
  --border: #e4e6eb;
  --border-strong: #d1d5db;
  --text: #111b21;
  --text-2: #3b4a54;
  --text-dim: #667781;
  --primary: #25d366;
  --primary-dark: #1da855;
  --danger: #d93025;
  --warn: #d97706;
  --in-bubble: #ffffff;
  --out-bubble: #d9fdd3;
  --out-manual: #fff3c4;
  --out-external: #dce9fb;
  --shadow-sm: 0 1px 0.5px rgba(0,0,0,0.08);
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13.5px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
}

body.state-loading #app, body.state-loading #login { display: none; }
body.state-login #app { display: none; }
body.state-app #login { display: none; }

/* ---- Login ---- */
.login {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 28px 28px 24px;
  width: 340px; max-width: calc(100% - 32px);
  display: flex; flex-direction: column; gap: 10px;
}
.login-card h1 { font-size: 17px; font-weight: 600; }
.login-card .muted { color: var(--text-dim); font-size: 12.5px; margin-bottom: 6px; }
.login-card input {
  border: 1px solid var(--border); border-radius: 6px; padding: 8px 11px;
  font-size: 13.5px; font-family: inherit; outline: none; transition: border-color .15s;
}
.login-card input:focus { border-color: var(--primary); }
.login-card button {
  background: var(--primary); color: white; border: none; border-radius: 6px;
  padding: 9px; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: background .15s;
}
.login-card button:hover { background: var(--primary-dark); }
.login-card .err { color: var(--danger); font-size: 12px; min-height: 16px; }

/* ---- App shell ---- */
.app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  height: 44px;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; }
.brand .muted { font-weight: 400; font-size: 11.5px; }
.dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-dim);
}
.dot.connected {
  background: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,211,102,0.35), 0 0 7px 1px rgba(37,211,102,0.55);
  animation: dotPulse 1.8s ease-in-out infinite;
}
.account-pill .dot.connected { width: 9px; height: 9px; background: var(--primary); }
@keyframes dotPulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(37,211,102,0.35), 0 0 7px 1px rgba(37,211,102,0.5); }
  50%      { box-shadow: 0 0 0 5px rgba(37,211,102,0.22), 0 0 12px 3px rgba(37,211,102,0.8); }
}
.dot.connecting { background: var(--warn); box-shadow: 0 0 0 2px rgba(217,119,6,0.18); }
.dot.logged-out { background: var(--danger); box-shadow: 0 0 0 2px rgba(217,48,37,0.18); }
/* Connected but bouncing every send — pulse red so it can't be mistaken for healthy green. */
.dot.send-failing {
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(217,48,37,0.30), 0 0 7px 1px rgba(217,48,37,0.55);
  animation: dotPulse 1.8s ease-in-out infinite;
}
.account-pill .dot.send-failing { width: 9px; height: 9px; }
/* Reconnected but not yet proven able to send — amber, not alarming. */
.dot.verifying { background: var(--warn); box-shadow: 0 0 0 2px rgba(217,119,6,0.25); }
.account-pill .dot.verifying { width: 9px; height: 9px; }
.muted { color: var(--text-dim); }
.small { font-size: 11px; }

.topbar-actions { display: flex; gap: 6px; align-items: center; }
.topbar-actions button {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-2);
  padding: 5px 13px; border-radius: 7px; font-size: 12px; font-weight: 600; cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.topbar-actions button:hover { background: var(--surface); border-color: var(--border-strong); color: var(--text); }

/* ---- Accounts panel ---- */
.accounts {
  display: flex; flex-direction: column;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.accounts:empty { display: none; }

.accounts-pills {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 8px 14px;
  max-height: 84px;          /* ~2 rows of pills; scroll past that */
  overflow-y: auto;
}

.account-pill {
  display: inline-flex; align-items: center; gap: 7px;
  height: 26px;
  padding: 0 11px 0 9px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 13px;
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  user-select: none;
  max-width: 220px;
  transition: background .12s, border-color .12s, color .12s, box-shadow .12s;
}
.account-pill:hover { background: var(--surface); border-color: var(--border-strong); }
.account-pill.expanded {
  background: #e7f3ec;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37,211,102,0.15);
}
.account-pill .pill-label {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 180px;
}
.account-pill .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-dim);
  flex-shrink: 0;
}
.account-pill.connected { border-color: rgba(37,211,102,0.7); background: #f1fdf4; }
.account-pill.qr { border-color: rgba(217,119,6,0.45); background: #fff7ec; }
.account-pill.qr .pill-label::after { content: " · QR"; font-size: 10px; color: var(--warn); font-weight: 600; }
.account-pill.logged-out { border-color: rgba(217,48,37,0.45); background: #fdecea; }
.account-pill.logged-out .pill-label::after { content: " · out"; font-size: 10px; color: var(--danger); font-weight: 600; }
.account-pill.send-failing { border-color: rgba(217,48,37,0.45); background: #fdecea; }
.account-pill.send-failing .pill-label::after { content: " · fail"; font-size: 10px; color: var(--danger); font-weight: 600; }
.account-pill.verifying { border-color: rgba(217,119,6,0.45); background: #fff7ec; }
.account-pill.verifying .pill-label::after { content: " · ?"; font-size: 10px; color: var(--warn); font-weight: 600; }

.account-pill.add {
  border-style: dashed;
  color: var(--text-dim);
  font-weight: 600;
  background: transparent;
}
.account-pill.add:hover {
  color: var(--primary-dark);
  border-color: var(--primary);
  background: var(--surface);
}

/* Expanded detail strip — shown for the currently active pill */
.accounts-detail {
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.accounts-detail .account {
  display: flex; align-items: center; gap: 10px;
  font-size: 12.5px;
  background: transparent;
  border: 0;
  padding: 0;
  min-height: 30px;
  flex-wrap: wrap;
}

.account-info { display: flex; align-items: center; gap: 8px; }
.account-label {
  font-weight: 600;
  cursor: pointer;
  border-bottom: 1px dashed transparent;
  transition: border-color .15s, color .15s;
}
.account-label:hover {
  color: var(--primary-dark);
  border-bottom-color: var(--border-strong);
}
.account-jid { font-size: 11.5px; }
.account-state {
  font-size: 11px; padding: 1px 6px; border-radius: 4px;
  background: var(--surface); color: var(--text-dim);
  border: 1px solid var(--border);
}
.account-state.qr { color: var(--warn); border-color: var(--warn); }
.account-state.refused { color: var(--danger); border-color: var(--danger); }
.account-warn {
  color: var(--danger); font-size: 11.5px;
  border-left: 2px solid var(--danger);
  padding-left: 8px;
}
.account-warn-info {
  color: var(--warn); font-size: 11.5px;
  border-left: 2px solid var(--warn);
  padding-left: 8px;
}
.account-actions { display: flex; gap: 6px; margin-left: auto; }
.account-actions button {
  background: transparent;
  border: 1px solid var(--border-strong);
  color: var(--text-2);
  padding: 3px 12px; border-radius: 4px; font-size: 11.5px; cursor: pointer;
  font-weight: 600;
  transition: all .15s;
}
.account-actions button:hover { background: var(--surface); }
.account-actions button.start { color: var(--primary-dark); border-color: var(--primary); }
.account-actions button.start:hover { background: var(--primary); color: white; }
.account-actions button.stop { color: var(--danger); border-color: var(--danger); }
.account-actions button.stop:hover { background: var(--danger); color: white; }
.account-actions button.qr { color: var(--warn); border-color: var(--warn); }
.account-actions button.qr:hover { background: var(--warn); color: white; }
.account-actions button.delete { color: var(--danger); border-color: var(--border-strong); }
.account-actions button.delete:hover { background: var(--danger); color: white; border-color: var(--danger); }
.account-actions button:disabled { opacity: 0.5; cursor: wait; }

.main { display: flex; flex: 1; min-height: 0; }

/* ---- Sidebar ---- */
.sidebar {
  width: 300px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.sidebar-head {
  padding: 8px 10px; border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 6px;
}
.sidebar-head input {
  width: 100%; border: 1px solid var(--border); border-radius: 18px;
  padding: 7px 14px; font-size: 12.5px; outline: none; font-family: inherit;
  background: var(--surface-2);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.sidebar-head input:focus {
  border-color: var(--primary); background: var(--surface);
  box-shadow: 0 0 0 3px rgba(37,211,102,0.12);
}
.sidebar-head select {
  width: 100%; border: 1px solid var(--border); border-radius: 18px;
  padding: 6px 11px; font-size: 12px; outline: none; font-family: inherit;
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.sidebar-head select:focus {
  border-color: var(--primary); background: var(--surface);
  box-shadow: 0 0 0 3px rgba(37,211,102,0.12);
}
/* Product + account filters share one row, each half-width */
.sidebar-head .filter-row { display: flex; gap: 6px; }
.sidebar-head .filter-row select { flex: 1 1 0; min-width: 0; width: auto; }

.conv-list { list-style: none; overflow-y: auto; flex: 1; padding: 4px 0; }

.conv-item {
  margin: 2px 6px; padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  display: flex; flex-direction: column; gap: 2px;
  transition: background .12s, box-shadow .12s;
}
.conv-item:hover { background: var(--surface-2); }
.conv-item.active { background: #e7f3ec; box-shadow: inset 0 0 0 1px rgba(37,211,102,0.25); }
.conv-item .row {
  display: flex; justify-content: space-between; align-items: baseline; gap: 6px;
}
.conv-item .name {
  font-weight: 500; font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.conv-item .ts {
  font-size: 10.5px; color: var(--text-dim); flex-shrink: 0;
}
.conv-item .preview {
  font-size: 12px; color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1;
}
.conv-item .phone {
  font-size: 11px; color: var(--text-dim);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  letter-spacing: 0.2px;
}
.conv-item .badges { display: flex; gap: 4px; align-items: center; flex-shrink: 0; }

.badge {
  font-size: 9.5px; font-weight: 600; padding: 1px 6px;
  border-radius: 8px; line-height: 1.4;
  background: var(--surface-2); color: var(--text-dim);
}
.badge.unread {
  background: var(--primary); color: white; min-width: 16px; text-align: center;
}
.badge.manual { background: var(--warn); color: white; }
.badge.blocked { background: var(--danger); color: white; }
.badge.account {
  background: rgba(37,99,235,0.10);
  color: #1e40af;
  border: 1px solid rgba(37,99,235,0.18);
}

/* ---- Chat panel ---- */
.chat {
  flex: 1; display: flex; flex-direction: column; min-width: 0;
  background: var(--surface-3);
}

.chat-empty {
  flex: 1;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  color: var(--text-dim);
  gap: 8px;
}
.chat-empty svg {
  width: 48px; height: 48px; opacity: 0.35;
}
.chat-empty p {
  font-size: 12.5px;
  color: var(--text-dim);
}

.chat-active { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.chat-head {
  padding: 8px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  min-height: 48px;
}
.chat-title { display: flex; flex-direction: column; gap: 0; }
.chat-title strong { font-size: 13.5px; font-weight: 600; }
.chat-title .muted { font-size: 11px; }

.chat-actions { display: flex; gap: 10px; align-items: center; }
.toggle {
  display: flex; align-items: center; gap: 5px;
  font-size: 12px; cursor: pointer; color: var(--text-2);
}
.toggle input { cursor: pointer; }

.danger {
  background: transparent; border: 1px solid var(--danger);
  color: var(--danger);
  padding: 4px 10px; border-radius: 5px; font-size: 12px; cursor: pointer;
  transition: all .15s;
}
.danger:hover { background: var(--danger); color: white; }
.danger.active { background: var(--danger); color: white; }

.ghost {
  background: transparent; border: 1px solid var(--border-strong);
  color: var(--text-2);
  padding: 4px 10px; border-radius: 5px; font-size: 12px; cursor: pointer;
  transition: all .15s;
}
.ghost:hover { background: var(--surface-2); border-color: var(--warn); color: var(--warn); }
.ghost.active { background: var(--warn); border-color: var(--warn); color: white; }
.ghost:disabled { opacity: 0.5; cursor: wait; }

.messages {
  flex: 1; overflow-y: auto; padding: 12px 16px;
  display: flex; flex-direction: column; gap: 2px;
  background-image: radial-gradient(rgba(0,0,0,0.025) 1px, transparent 1px);
  background-size: 32px 32px;
}

.msg {
  max-width: 65%;
  padding: 5px 8px 4px 9px;
  border-radius: 7px;
  font-size: 13.5px;
  line-height: 1.35;
  word-wrap: break-word;
  position: relative;
  box-shadow: var(--shadow-sm);
}
.msg + .msg.same-side { margin-top: 1px; }
.msg.in {
  align-self: flex-start;
  background: var(--in-bubble);
  border-top-left-radius: 2px;
}
.msg.out {
  align-self: flex-end;
  background: var(--out-bubble);
  border-top-right-radius: 2px;
}
.msg.out.manual { background: var(--out-manual); }
.msg.out.external { background: var(--out-external); }
.src-tag.src-external { background: rgba(30,90,180,0.18); color: #1a4a8f; }

.msg-text { white-space: pre-wrap; }

.msg-meta {
  display: inline-flex; gap: 4px; align-items: center;
  font-size: 10px; color: var(--text-dim);
  float: right; margin-left: 8px; margin-top: 2px;
  line-height: 1;
}
.msg.out .msg-meta { color: rgba(0,0,0,0.45); }
.src-tag {
  font-size: 9px; font-weight: 600;
  padding: 1px 4px; border-radius: 3px;
  background: rgba(0,0,0,0.06);
  letter-spacing: 0.3px;
}
.msg.out .src-tag { background: rgba(0,0,0,0.07); }

/* Delivery status. ERROR = WhatsApp rejected it; the recipient got nothing — so
   it must read as a failed reply, not a normal one. */
.msg-status { font-size: 10px; line-height: 1; white-space: nowrap; }
.msg-status.read { color: #1a7fd1; }
.msg-status.pending { opacity: 0.6; }
.msg-status.err { color: var(--danger); font-weight: 700; }
.msg.out.failed {
  background: #fdecea;
  border: 1px solid rgba(217,48,37,0.45);
}
.msg.out.failed .msg-text { color: #8a1c12; }
.msg.out.failed .msg-meta { color: rgba(138,28,18,0.7); }

.msg::after { content: ""; display: block; clear: both; }

/* ---- Send box ---- */
.send {
  display: flex; gap: 8px; padding: 8px 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  align-items: flex-end;
}
.send textarea {
  flex: 1;
  border: 1px solid var(--border); border-radius: 18px;
  padding: 8px 14px;
  font-family: inherit; font-size: 13.5px; line-height: 1.4;
  outline: none; resize: none;
  background: var(--surface);
  max-height: 120px;
}
.send textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,211,102,0.12);
}
.send button {
  background: var(--primary); color: white; border: none;
  border-radius: 18px;
  padding: 8px 18px; font-size: 12.5px; font-weight: 600; cursor: pointer;
  transition: background .15s;
  height: 36px;
}
.send button:hover { background: var(--primary-dark); }
.send button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- QR modal ---- */
.qr-modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.qr-modal-card {
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.25);
  padding: 0 0 18px;
  width: 360px; max-width: calc(100% - 32px);
  overflow: hidden;
}
.qr-modal-card header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.qr-modal-card header strong { font-size: 13.5px; }
.qr-modal-card header button {
  background: transparent; border: none; font-size: 20px;
  color: var(--text-dim); cursor: pointer; padding: 0 4px;
}
.qr-modal-body {
  padding: 18px;
  display: flex; flex-direction: column; align-items: center; gap: 10px;
}
.qr-modal-body img {
  width: 280px; height: 280px;
  border: 6px solid var(--surface-2);
  background: white;
}
.qr-modal-body p { text-align: center; }

/* ---- Add-account form ---- */
.add-form {
  padding: 16px 18px 18px;
  display: flex; flex-direction: column; gap: 12px;
}
.add-form label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; font-weight: 600;
  color: var(--text-2);
}
.add-form label em { font-style: normal; font-weight: 400; }
.add-form label code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--surface-2);
  padding: 0 4px; border-radius: 3px;
  font-size: 11px;
}
.add-form input {
  border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 11px;
  font-size: 13px; font-family: inherit; outline: none;
  transition: border-color .15s;
}
.add-form input:focus { border-color: var(--primary); }
.add-form .err {
  color: var(--danger); font-size: 12px; min-height: 16px;
  margin: 0;
}
.add-form-actions {
  display: flex; justify-content: flex-end;
}
.add-form button[type="submit"] {
  background: var(--primary); color: white; border: none;
  border-radius: 6px;
  padding: 8px 16px; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: background .15s;
}
.add-form button[type="submit"]:hover { background: var(--primary-dark); }
.add-form button[type="submit"]:disabled { opacity: 0.5; cursor: wait; }
.add-form select {
  border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 11px;
  font-size: 13px; font-family: inherit; outline: none;
  background: var(--surface);
}

/* ---- Profiles modal ---- */
.qr-modal-card.wide { width: 720px; max-width: calc(100% - 32px); }
/* Reports + Configuration modals — larger than the shared .wide modals */
#reportsModal .qr-modal-card { width: 1040px; }
#profilesModal .qr-modal-card { width: 1180px; }
#reportsModal .reports-body { height: min(78vh, 780px); }

/* ---- Workflow playground ---- */
#playgroundModal .qr-modal-card { width: 760px; }
.playground-body { display: flex; flex-direction: column; height: min(80vh, 820px); }
.playground-bar {
  display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.playground-bar label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-dim); }
.playground-bar select {
  min-width: 300px; padding: 6px 8px; font-size: 13px;
  border: 1px solid var(--border-strong); border-radius: 6px; background: var(--surface);
}
.playground-bar #pgInfo { margin-left: auto; max-width: 300px; text-align: right; }
.playground-foot { padding: 8px 16px 4px; }
.pg-hint { margin: auto; text-align: center; font-size: 13px; }
.msg.pg-pending { opacity: 0.55; }

.profiles-body {
  display: flex;
  gap: 0;
  height: min(78vh, 780px);
}
.profiles-list {
  width: 220px; flex: 0 0 auto;   /* resizable via the .pf-divider drag handle */
  display: flex; flex-direction: column;
  background: var(--surface-2);
}
/* Draggable splitter between the list and the editor */
.pf-divider {
  flex: 0 0 6px; align-self: stretch;
  cursor: col-resize;
  background: var(--border);
  transition: background .12s;
}
.pf-divider:hover, .pf-divider.dragging { background: var(--primary); }
.profiles-body > .profile-editor { flex: 1 1 auto; min-width: 0; }
.profiles-list-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-weight: 600; font-size: 12px; color: var(--text-2);
}
.profiles-list ul { list-style: none; overflow-y: auto; flex: 1; }
.profiles-list ul { padding: 6px 4px; }
.profiles-list li {
  cursor: pointer;
  display: flex; flex-direction: column; gap: 2px;
  transition: background .12s, border-color .12s;
}
.profiles-list li .pf-label { font-size: 12.5px; font-weight: 600; color: var(--text); }

/* ── Configuration modal: product group headers (accordion) ── */
.profiles-list li.pf-group {
  flex-direction: row; align-items: center; gap: 8px;
  margin: 2px 0; padding: 8px 10px;
  border-radius: 7px;
  background: transparent;
  user-select: none;
}
.profiles-list li.pf-group:hover { background: var(--surface); }
.profiles-list li.pf-group.expanded { background: var(--surface-2); }
.profiles-list li.pf-group.active {
  background: #e7f3ec; box-shadow: inset 0 0 0 1px rgba(37,211,102,0.4);
}
.profiles-list li.pf-group .pf-toggle {
  flex-shrink: 0; width: 12px; color: var(--text-dim);
  font-size: 10px; line-height: 1; text-align: center;
  transition: transform .15s, color .15s;
}
.profiles-list li.pf-group.expanded .pf-toggle { transform: rotate(90deg); color: var(--primary-dark); }
.profiles-list li.pf-group .pf-group-label {
  flex: 1; min-width: 0; font-size: 13px; font-weight: 700; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.profiles-list li.pf-group .pf-group-count {
  flex-shrink: 0; font-size: 10.5px; font-weight: 700; color: var(--text-dim);
  background: var(--surface-3); border-radius: 10px;
  padding: 1px 8px; min-width: 22px; text-align: center; line-height: 1.5;
}
.profiles-list li.pf-group.expanded .pf-group-count { background: var(--surface); }
.profiles-list li.pf-group .pf-edit-product {
  flex-shrink: 0; border: 0; background: transparent;
  color: var(--text-dim); border-radius: 5px; font-size: 12px;
  width: 22px; height: 22px; cursor: pointer; opacity: 0.4;
  transition: opacity .12s, background .12s, color .12s;
}
.profiles-list li.pf-group:hover .pf-edit-product { opacity: 1; }
.profiles-list li.pf-group .pf-edit-product:hover { background: var(--surface); color: var(--primary-dark); }

/* ── Workflow items (nested under a group, joined by a tree rail) ── */
.profiles-list li.pf-item {
  margin-left: 19px; padding: 6px 10px 6px 13px;
  border-left: 2px solid var(--border);   /* consecutive items form a continuous rail */
}
.profiles-list li.pf-item .pf-label { font-size: 12px; font-weight: 500; color: var(--text-2); }
.profiles-list li.pf-item:hover { background: var(--surface-2); border-left-color: var(--border-strong); }
.profiles-list li.pf-item.active { background: #e7f3ec; border-left-color: var(--primary); }
.profiles-list li.pf-item.active .pf-label { color: var(--text); font-weight: 600; }
/* configId — small, right-aligned at the top of the workflow detail pane (the
   integrator's /partner/send value). Kept out of the list so it's not the focus. */
.pf-configid-row {
  display: flex; align-items: center; justify-content: flex-end; gap: 6px;
  margin: -2px 0 12px; font-size: 11px; color: var(--text-dim);
}
.pf-configid-row .pf-cfg-k { text-transform: uppercase; letter-spacing: .4px; font-weight: 600; }
.pf-configid-row code.pf-cfg-v {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 4px;
  padding: 1px 6px; color: var(--text-2); cursor: copy;
}
.pf-configid-row code.pf-cfg-v:hover { color: var(--text); border-color: var(--border-strong); }

.profiles-list li.pf-empty {
  margin-left: 19px; padding: 6px 10px 8px 13px;
  border-left: 2px solid var(--border);
  color: var(--text-dim); font-size: 11px; font-style: italic; cursor: default;
}
.profiles-list li.pf-empty:hover { background: transparent; }

.ghost-primary {
  background: transparent; border: 1px solid var(--primary);
  color: var(--primary-dark);
  padding: 3px 10px; border-radius: 4px; font-size: 11.5px; font-weight: 600;
  cursor: pointer; transition: all .15s;
}
.ghost-primary:hover { background: var(--primary); color: white; }

.profile-editor {
  padding: 22px 24px;
  display: flex; flex-direction: column; gap: 16px;
  overflow-y: auto;
}
.profile-editor.empty {
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; color: var(--text-dim);
}
.profile-editor label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 11.5px; font-weight: 600; color: var(--text-2);
  letter-spacing: 0.2px;
}
.profile-editor label em { font-style: normal; font-weight: 400; }
.profile-editor input,
.profile-editor textarea,
.profile-editor select {
  border: 1px solid var(--border); border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px; font-family: inherit; outline: none;
  background: var(--surface-2);
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.profile-editor input:hover,
.profile-editor textarea:hover,
.profile-editor select:hover { border-color: var(--border-strong); }
.profile-editor input:focus,
.profile-editor textarea:focus,
.profile-editor select:focus {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(37,211,102,0.13);
}
.profile-editor textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  resize: vertical; line-height: 1.5;
}
/* Inputs (JSON) is the primary field — give it plenty of room */
#pfInputs { min-height: 480px; }
.profile-editor .err {
  color: var(--danger); font-size: 12px; min-height: 16px; margin: 0;
}
.profile-editor-actions {
  display: flex; gap: 8px; align-items: center;
  margin-top: auto; padding-top: 10px;   /* keep actions pinned to the bottom */
}
.profile-editor-actions button {
  border-radius: 8px; padding: 8px 18px;
  font-size: 12.5px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--border-strong);
  transition: all .15s;
}
/* Save = primary, Delete = danger — applied to BOTH the workflow + product forms */
#pfSave, #prodSave {
  background: var(--primary); color: white; border-color: var(--primary);
}
#pfSave:hover, #prodSave:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
#pfCancel, #prodCancel { background: transparent; color: var(--text-2); }
#pfCancel:hover, #prodCancel:hover { background: var(--surface-2); }
#pfDelete, #prodDelete {
  background: transparent; color: var(--danger); border-color: var(--danger); padding: 7px 14px;
}
#pfDelete:hover, #prodDelete:hover { background: var(--danger); color: white; }

/* ---- Reports modal ---- */
.reports-body {
  padding: 14px 18px 18px;
  display: flex; flex-direction: column;
  gap: 12px;
  height: 460px;
}
.reports-filters {
  display: flex; flex-wrap: wrap; gap: 10px;
  align-items: flex-end;
}
.reports-filters label {
  display: flex; flex-direction: column; gap: 3px;
  font-size: 11px; font-weight: 600; color: var(--text-2);
}
.reports-filters input,
.reports-filters select {
  border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 9px;
  font-size: 12.5px; font-family: inherit; outline: none;
  background: var(--surface);
}
.reports-filters input[type="date"] { min-width: 130px; }
.reports-filters input[type="text"] { min-width: 170px; }
.reports-filters select { min-width: 130px; }
.reports-filters button {
  background: var(--primary); color: white; border: none;
  border-radius: 6px;
  padding: 7px 14px; font-size: 12.5px; font-weight: 600;
  cursor: pointer; transition: background .15s;
  height: 32px;
}
.reports-filters button:hover { background: var(--primary-dark); }
.report-download {
  background: transparent; color: var(--text-2);
  border: 1px solid var(--border-strong); border-radius: 6px;
  padding: 7px 14px; font-size: 12.5px; font-weight: 600;
  cursor: pointer; text-decoration: none;
  height: 32px; display: inline-flex; align-items: center;
  transition: all .15s;
}
.report-download:hover { background: var(--surface-2); color: var(--text); }

.reports-table-wrap { flex: 1; overflow-y: auto; }
.reports-table {
  width: 100%; border-collapse: collapse;
  font-size: 12.5px;
}
.reports-table th {
  text-align: left;
  font-weight: 600; font-size: 11px;
  color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.3px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface);
}
.reports-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
}
.reports-table tr:hover td { background: var(--surface-2); }
.reports-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.reports-table td.num.highlight { font-weight: 600; color: var(--primary-dark); }
.reports-table td.phone {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  color: var(--text-2);
}

/* ---- Account card: dify chip ---- */
.account-dify {
  font-size: 10.5px;
  color: var(--text-dim);
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 4px;
  cursor: pointer;
  font-family: inherit;
  transition: border-color .15s, color .15s;
}
.account-dify:hover { border-color: var(--primary); color: var(--primary-dark); }
.account-dify select {
  border: none; background: transparent;
  font-size: inherit; color: inherit; font-family: inherit;
  outline: none; cursor: pointer;
}

/* Scrollbar polish */
.conv-list::-webkit-scrollbar, .messages::-webkit-scrollbar { width: 8px; }
.conv-list::-webkit-scrollbar-thumb, .messages::-webkit-scrollbar-thumb {
  background: rgba(0,0,0,0.12); border-radius: 4px;
}
.conv-list::-webkit-scrollbar-thumb:hover, .messages::-webkit-scrollbar-thumb:hover {
  background: rgba(0,0,0,0.2);
}

/* ─── Read-only monitor mode ──────────────────────────────────────────────
   Hides every write surface. Backend's monitor router has no write routes,
   so this is purely visual — the structural guarantee is server-side.       */
body.is-viewer .account-pill.add,
body.is-viewer .account-actions,
body.is-viewer .send,
body.is-viewer .chat-actions,
body.is-viewer #openProfiles {
  display: none !important;
}
body.is-viewer .account-dify {
  cursor: default;
}
body.is-viewer .account-dify select {
  pointer-events: none;
}
body.is-viewer .account-label {
  cursor: default;
}
body.is-viewer .brand span::before {
  content: "[view] ";
  font-size: 11px;
  color: var(--muted);
  letter-spacing: 0.5px;
}

/* ─── Persistent connection-loss banner (掉线 / 封禁) ──────────────────────
   Sits below the topbar and stays visible the whole time any account is
   disconnected or logged out; clears itself when everything recovers.       */
.alert-banner {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 14px;
  background: #fff7ec;                              /* orange = disconnect */
  border-bottom: 1px solid rgba(217,119,6,0.45);
  color: #8a5a00;
  font-size: 12.5px;
  flex-wrap: wrap;
}
.alert-banner.severe {                              /* red = at least one banned */
  background: #fdecea;
  border-bottom-color: rgba(217,48,37,0.5);
  color: var(--danger);
}
.alert-banner .ab-msg { font-weight: 700; display: inline-flex; align-items: center; gap: 6px; }
.alert-banner .ab-accounts { display: flex; gap: 6px; flex-wrap: wrap; }
.alert-banner .ab-acct {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,0.75);
  border: 1px solid rgba(217,119,6,0.45);
  border-radius: 12px;
  padding: 2px 10px;
  font-size: 11.5px; font-weight: 600;
  color: inherit; cursor: pointer; font-family: inherit;
  transition: background .12s;
}
.alert-banner .ab-acct.banned { border-color: rgba(217,48,37,0.5); }
.alert-banner .ab-acct:hover { background: #fff; }
.alert-banner .ab-acct .dot { flex-shrink: 0; }
.alert-banner .ab-acct .ab-tag { font-size: 10px; opacity: 0.85; }

/* ─── Toasts (action feedback) ─────────────────────────────────────────── */
.toast-host {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  z-index: 9999; display: flex; flex-direction: column; gap: 8px;
  align-items: center; pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--text); color: #fff;
  padding: 9px 16px; border-radius: 8px;
  font-size: 13px; font-weight: 600;
  box-shadow: 0 6px 24px rgba(0,0,0,0.25);
  opacity: 0; transform: translateY(-8px);
  transition: opacity .18s, transform .18s;
  max-width: 80vw;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { background: var(--primary-dark); }
.toast.error { background: var(--danger); }
