:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1b1f24;
  --muted: #5d6673;
  --border: #dde1e6;
  --accent: #3b5bdb;
  --accent-text: #ffffff;
  --ok: #2b8a3e;
  --warn: #b35c00;
  --danger: #c92a2a;
  --code: #eef1f5;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418;
    --surface: #191d23;
    --surface-2: #20252d;
    --text: #e6e9ee;
    --muted: #98a2b1;
    --border: #2c333d;
    --accent: #748ffc;
    --accent-text: #0d1117;
    --ok: #69db7c;
    --warn: #ffa94d;
    --danger: #ff6b6b;
    --code: #151a20;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}
code, pre { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 13px; }
code { background: var(--code); padding: 1px 5px; border-radius: 4px; }
h1 { font-size: 20px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.error { color: var(--danger); }

.top {
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 2;
}
.brand { font-weight: 650; display: flex; align-items: center; gap: 8px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.who { margin-left: auto; color: var(--muted); font-size: 14px; display: flex; gap: 10px; align-items: center; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button {
  background: none; border: 0; color: var(--muted); padding: 6px 10px; border-radius: 6px; font: inherit; cursor: pointer;
}
.tabs button.active, .tabs button:hover { background: var(--surface-2); color: var(--text); }
.badge {
  display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent);
  color: var(--accent-text); font-size: 12px; text-align: center;
}

main { max-width: 1100px; margin: 0 auto; padding: 20px 16px 60px; }
.panel.narrow { max-width: 440px; margin: 48px auto; }
#login .error { margin: 0 0 12px; }
.section-head { margin-bottom: 14px; }
.section-head.row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 12px; }

input, select, textarea, button {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 7px 10px;
}
textarea { width: 100%; min-height: 160px; resize: vertical; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
button { cursor: pointer; }
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.danger { color: var(--danger); }
button.link { border: 0; background: none; padding: 0; color: var(--accent); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.card .meta { color: var(--muted); font-size: 13px; display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.card .actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.pill { font-size: 12px; padding: 1px 8px; border-radius: 10px; background: var(--surface-2); color: var(--muted); }
.pill.open { color: var(--warn); }
.pill.answered { color: var(--ok); }
.pill.pending_approval { color: var(--warn); }
.pill.rejected { color: var(--danger); }
.body { white-space: pre-wrap; overflow-wrap: anywhere; }
.context { border-left: 3px solid var(--border); padding-left: 10px; margin: 8px 0; color: var(--muted); white-space: pre-wrap; overflow-wrap: anywhere; }
.warn-note { color: var(--warn); font-size: 13px; margin-top: 6px; }

.split { display: grid; grid-template-columns: minmax(240px, 340px) 1fr; gap: 16px; }
.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.list li button {
  width: 100%; text-align: left; display: block; background: var(--surface); padding: 10px 12px;
}
.list li button.active { border-color: var(--accent); }
.list .title { display: block; font-weight: 550; overflow-wrap: anywhere; }
.list .sub { display: block; font-size: 12px; color: var(--muted); }
.detail .msg { border-top: 1px solid var(--border); padding: 12px 0; }
.detail .msg:first-of-type { border-top: 0; }

.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 16px; }
.inline-form h2 { width: 100%; }
.token { margin-top: 12px; overflow-wrap: anywhere; }
.code-wrap { position: relative; }
.code-wrap pre {
  background: var(--code); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px;
  overflow-x: auto; white-space: pre; margin: 0;
}
.copy { position: absolute; top: 8px; right: 8px; font-size: 13px; padding: 4px 10px; }
.checks { display: flex; gap: 12px; flex-wrap: wrap; font-size: 14px; }
.notice { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; font-size: 14px; }
.choices { display: flex; flex-direction: column; gap: 6px; margin: 10px 0 14px; }
.choices label { display: flex; align-items: center; gap: 8px; font-size: 14px; flex-wrap: wrap; }
.choices input[type="text"] { flex: 1; min-width: 140px; }
.consent-actions { display: flex; gap: 8px; margin-top: 14px; }
.consent-actions button { flex: 1; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 8px 14px; border-radius: 8px; font-size: 14px; max-width: calc(100% - 32px);
}

@media (max-width: 720px) {
  .split { grid-template-columns: 1fr; }
  .top { padding: 10px 16px; }
}
[hidden] { display: none !important; }

/* ---- sign-in, admin ---- */
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.block { display: block; text-align: center; }
a.button {
  display: inline-block; text-decoration: none; padding: 9px 14px; border-radius: 8px;
  border: 1px solid var(--border); color: var(--text); background: var(--surface);
}
a.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.or { text-align: center; margin: 14px 0; }
#login-form label { display: block; font-size: 14px; margin-bottom: 6px; color: var(--muted); }
.row-input { display: flex; gap: 8px; }
.row-input input { flex: 1; min-width: 0; }
.pill { margin-left: 6px; }

.subtabs { display: flex; gap: 4px; flex-wrap: wrap; }
.subtabs button { background: none; border: 1px solid transparent; color: var(--muted); }
.subtabs button.active { border-color: var(--border); background: var(--surface); color: var(--text); }
.sub { display: flex; flex-direction: column; gap: 14px; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px 14px; align-items: end; }
.form-grid h2, .form-grid .span { grid-column: 1 / -1; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.form-grid fieldset { border: 0; padding: 0; margin: 0; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.check { flex-direction: row !important; align-items: center; gap: 6px !important; color: var(--text) !important; font-size: 14px !important; }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-weight: 600; font-size: 12px; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--border); }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table tr.dim td { opacity: 0.6; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.row-actions button { font-size: 13px; padding: 4px 9px; }
.detail-cell { font-family: ui-monospace, Menlo, monospace; font-size: 12px; overflow-wrap: anywhere; max-width: 420px; }

.secret { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 8px 0; }
.secret code { overflow-wrap: anywhere; user-select: all; }
.bridge-setup { border-top: 1px solid var(--border); margin-top: 14px; padding-top: 12px; }
.bridge-setup h3 { margin: 0 0 6px; font-size: 15px; }
.bridge-setup .actions { margin: 10px 0; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; margin-bottom: 8px; }
.segmented .seg { border: 0; border-radius: 0; background: none; font-size: 13px; padding: 5px 12px; }
.segmented .seg + .seg { border-left: 1px solid var(--border); }
.segmented .seg.active { background: var(--accent); color: var(--accent-text); }
.copy-inline { font-size: 12px; padding: 3px 9px; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px 2px 10px; border-radius: 14px; background: var(--surface-2); font-size: 13px; }
.chip-x { border: 0; background: none; padding: 0 6px; color: var(--muted); font-size: 15px; line-height: 1; }
.chip-x:hover { color: var(--danger); }
.row-card { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.row-card .meta { margin-bottom: 0; }

.thread-view { margin-bottom: 0; }
.thread-filters { margin-bottom: 14px; align-items: center; }
.thread-filters label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.thread-filters input[type="search"] { flex: 1; min-width: 180px; }
.list .thread-id { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 11px; }
.thread-id-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 13px; margin-bottom: 6px; }
.teams-row { display: flex; flex-direction: column; gap: 6px; margin: 6px 0 10px; }
.teams-row input[type="url"] { flex: 1; min-width: 220px; }
.teams-row .check { display: inline-flex; }
.attachments { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-direction: column; gap: 4px; }
.attachments li::before { content: "📎 "; }
.attachments a { overflow-wrap: anywhere; }
.pill.urgent { color: var(--danger); font-weight: 600; }
.list .title .pill.urgent { margin: 0 6px 0 0; }
.prompt-text { min-height: 90px; font-family: inherit; font-size: 14px; }
.prompt-preview { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12.5px; background: var(--code); border: 1px solid var(--border); border-radius: 8px; padding: 10px; overflow-wrap: anywhere; }
.prompt-preview.off { opacity: 0.45; text-decoration: line-through; }
.connect-steps { list-style: none; padding: 0; margin: 12px 0; display: flex; flex-direction: column; gap: 10px; }
.connect-steps li { display: flex; gap: 10px; align-items: flex-start; }
.connect-steps .step-mark { width: 22px; height: 22px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 13px; border: 1px solid var(--border); flex: none; }
.connect-steps li.done .step-mark { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.connect-steps li.waiting { color: var(--muted); }
