:root {
  --bg: #0f1115;
  --card: #1a1d24;
  --card2: #22262f;
  --line: #2c3038;
  --text: #e6e8ec;
  --muted: #9aa0aa;
  --green: #25d366;
  --green-d: #1da851;
  --red: #e25555;
  --amber: #e0a32e;
  --blue: #4a90d9;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", "Microsoft JhengHei", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}

header h1 { font-size: 18px; margin: 0; }

main { padding: 20px 24px 40px; }

.accounts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-head .name { font-weight: 600; font-size: 16px; flex: 1; }

.badge {
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--card2);
  color: var(--muted);
}
.badge.ready { background: rgba(37, 211, 102, 0.15); color: var(--green); }
.badge.qr { background: rgba(224, 163, 46, 0.15); color: var(--amber); }
.badge.authenticating { background: rgba(74, 144, 217, 0.15); color: var(--blue); }
.badge.disconnected, .badge.idle { background: rgba(226, 85, 85, 0.12); color: var(--red); }

.qr-area {
  text-align: center;
  padding: 8px;
  background: #fff;
  border-radius: 8px;
}
.qr-area img { width: 220px; height: 220px; }
.qr-hint { text-align: center; color: var(--muted); font-size: 13px; margin-top: 6px; }

.modes { display: flex; gap: 6px; }
.modes button {
  flex: 1;
  background: var(--card2);
  color: var(--muted);
}
.modes button.active { background: var(--green-d); color: #fff; }

.drafts { display: flex; flex-direction: column; gap: 8px; }
.drafts .empty { color: var(--muted); font-size: 13px; padding: 6px 0; }

.draft {
  background: var(--card2);
  border-radius: 8px;
  padding: 10px;
  font-size: 14px;
}
.draft .from { color: var(--muted); font-size: 12px; margin-bottom: 4px; }
.draft .incoming { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.draft .text { white-space: pre-wrap; }
.draft .suggest { color: var(--amber); font-size: 12px; margin-top: 6px; }
.draft .row { display: flex; gap: 6px; margin-top: 8px; }
.draft .row button { flex: 1; font-size: 13px; padding: 5px; }

button {
  cursor: pointer;
  border: none;
  border-radius: 7px;
  padding: 7px 12px;
  font-size: 14px;
  background: var(--card2);
  color: var(--text);
}
button:hover { filter: brightness(1.15); }
button.primary { background: var(--green-d); color: #fff; }
button.danger { background: transparent; color: var(--red); border: 1px solid var(--red); }
button.ghost { background: transparent; color: var(--muted); }
button.sm { padding: 4px 9px; font-size: 13px; }

.card-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.logwrap { margin-top: 24px; }
.logbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}
.log {
  background: #0a0c10;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  height: 180px;
  overflow-y: auto;
  font-family: Consolas, monospace;
  font-size: 12px;
  line-height: 1.6;
  color: var(--muted);
}
.log .err { color: var(--red); }

/* modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}
.modal.hidden { display: none; }
.modal-box {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  width: min(520px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
}
.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px; display: flex; flex-direction: column; gap: 14px; }

label { font-size: 13px; color: var(--muted); display: block; margin-bottom: 4px; }
input[type="text"], input[type="number"], textarea, select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 10px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
textarea { resize: vertical; min-height: 70px; }
.checkrow { display: flex; align-items: center; gap: 8px; }
.checkrow input { width: auto; }
.checkrow label { margin: 0; }
.field-hint { font-size: 12px; color: var(--muted); margin-top: 3px; }
.section-title { font-weight: 600; font-size: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.modal-body .row2 { display: flex; gap: 8px; }
.modal-body .row2 > * { flex: 1; }

.script-row {
  background: var(--card2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
}
.script-row .sc-del { align-self: flex-end; }

.groupwrap { margin-top: 28px; }
.grouphdr { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.grouphdr h2 { margin: 0; font-size: 16px; }

.simgroups { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.sg-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
}
.sg-card .sg-name { font-weight: 600; margin-bottom: 4px; }
.sg-card .sg-meta { color: var(--muted); font-size: 12px; margin-bottom: 10px; }
.sg-card .sg-actions { display: flex; gap: 6px; }
.sg-card .sg-actions button { flex: 1; }
.sg-purpose { color: var(--muted); font-size: 12px; margin-bottom: 10px; line-height: 1.5; }

.reg-row {
  background: var(--card2);
  border-radius: 7px;
  padding: 9px 12px;
  margin-bottom: 6px;
  font-size: 13px;
  display: grid;
  grid-template-columns: 200px 80px 1fr;
  gap: 12px;
  align-items: center;
}
.reg-num { font-family: Consolas, monospace; color: var(--text); }
.reg-phase { color: var(--blue); font-size: 12px; }
.reg-msg { font-size: 12px; }
.reg-msg.ok { color: var(--green); }
.reg-msg.fail { color: var(--red); }
.reg-msg.running { color: var(--muted); font-style: italic; }

.mem-card {
  background: var(--card2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
}
.mem-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  gap: 8px;
}
.mem-label {
  font-weight: 600;
  font-size: 14px;
}
.mem-body { font-size: 13px; line-height: 1.7; color: var(--text); }
.mem-body div { margin-bottom: 2px; }
.mem-time { color: var(--muted); font-size: 11px; margin-top: 4px; }
.mem-stage {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(74,144,217,0.2);
  color: var(--blue);
  font-size: 12px;
}

.purpose-box {
  background: rgba(74,144,217,0.08);
  border-left: 3px solid var(--blue);
  padding: 8px 12px;
  border-radius: 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  margin-bottom: 4px;
}

.transcript {
  background: #0a0c10;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  height: 280px;
  overflow-y: auto;
  font-size: 13px;
  line-height: 1.6;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.t-turn { padding: 6px 10px; border-radius: 8px; max-width: 90%; word-wrap: break-word; }
.t-turn.lead { background: rgba(74,144,217,0.18); align-self: flex-end; }
.t-turn.bot { background: var(--card2); align-self: flex-start; }
.t-turn .sender { font-size: 11px; color: var(--muted); margin-bottom: 2px; }
.silent-line { color: var(--muted); font-size: 11px; font-style: italic; padding-left: 4px; }
