:root {
  --bg: #0d0d0f;
  --surface: #16171b;
  --surface-2: #1c1e22;
  --surface-3: #24262b;
  --border: rgba(245, 241, 230, 0.08);
  --border-hover: rgba(222, 161, 46, 0.4);
  --accent: #dea12e;
  --accent-dim: rgba(222, 161, 46, 0.15);
  --text: #f5f1e6;
  --text-secondary: rgba(245, 241, 230, 0.6);
  --text-tertiary: rgba(245, 241, 230, 0.4);
  --serif: 'DM Serif Display', 'Times New Roman', serif;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Microsoft YaHei', sans-serif;
  --mono: 'JetBrains Mono', 'SF Mono', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { background: var(--bg); color: var(--text); font-family: var(--sans); height: 100vh; }
body { display: flex; flex-direction: column; overflow: hidden; }
em { font-style: italic; font-family: var(--serif); color: var(--accent); }
a { color: inherit; text-decoration: none; }

/* ── topbar ──────────────────────────────────────────────────────────── */
.topbar {
  height: 56px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; border-bottom: 1px solid var(--border);
  background: rgba(13, 13, 15, 0.92); backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 28px; height: 28px; border: 2px solid var(--accent); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--serif); font-size: 16px; color: var(--accent);
}
.brand-name { font-family: var(--serif); font-size: 18px; letter-spacing: 0.4px; }
.who { font-size: 13px; color: var(--text-secondary); }

/* ── layout ──────────────────────────────────────────────────────────── */
.layout {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: 280px 1fr;
}
.col { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.col-bots { border-right: 1px solid var(--border); background: var(--surface); }
.col-threads { border-right: 1px solid var(--border); background: rgba(22, 23, 27, 0.5); }
.col-messages { display: flex; flex-direction: column; min-height: 0; }

.col-header {
  height: 48px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px; border-bottom: 1px solid var(--border);
}
.col-title { font-size: 12px; font-weight: 500; letter-spacing: 0.12em; color: var(--text-secondary); text-transform: uppercase; }

.ghost-btn {
  background: transparent; border: 1px solid var(--border); color: var(--text-secondary);
  padding: 4px 10px; border-radius: 6px; font-family: inherit; font-size: 12px; cursor: pointer;
}
.ghost-btn:hover { border-color: var(--border-hover); color: var(--text); }

/* ── bots col ────────────────────────────────────────────────────────── */
.bot-list { overflow-y: auto; flex: 1; padding: 8px 0; }
.bot-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; cursor: pointer; transition: background 0.15s;
  border-left: 2px solid transparent;
}
.bot-item:hover { background: var(--surface-2); }
.bot-item.active { background: var(--accent-dim); border-left-color: var(--accent); }
.bot-avatar {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--surface-3); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--serif); color: var(--accent); font-size: 16px; flex-shrink: 0;
}
.bot-info { flex: 1; min-width: 0; }
.bot-name { font-size: 14px; font-weight: 500; }
.bot-engine { font-size: 11px; color: var(--text-tertiary); font-family: var(--mono); margin-top: 2px; }

/* ── threads col ─────────────────────────────────────────────────────── */
.thread-list { overflow-y: auto; flex: 1; padding: 6px 0; }
.thread-item {
  padding: 10px 16px; cursor: pointer; border-left: 2px solid transparent;
  transition: background 0.15s; min-width: 0;
}
.thread-item:hover { background: var(--surface-2); }
.thread-item.active { background: var(--accent-dim); border-left-color: var(--accent); }
.thread-label { font-size: 13px; font-weight: 500; margin-bottom: 4px; }
.thread-chatid { font-size: 11px; color: var(--text-tertiary); font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread-last { font-size: 11px; color: var(--text-tertiary); margin-top: 4px; }
.thread-section-header {
  padding: 8px 16px 4px; font-size: 10px; color: var(--text-tertiary);
  letter-spacing: 0.18em; text-transform: uppercase;
}
.thread-empty {
  padding: 30px 16px; text-align: center; color: var(--text-tertiary); font-size: 12px;
}

/* ── messages col ────────────────────────────────────────────────────── */
/* Several elements here explicitly set display:flex which beats [hidden]'s
   default display:none — same gotcha as .modal above. Override per element. */
.thread-header[hidden],
.messages[hidden],
.composer-bar[hidden],
.empty-hint[hidden] { display: none !important; }

.thread-header {
  height: 56px; flex-shrink: 0;
  padding: 10px 24px; border-bottom: 1px solid var(--border);
  display: flex; flex-direction: column; justify-content: center;
}
.thread-header-title { font-family: var(--serif); font-size: 18px; }
.thread-header-meta { font-size: 11px; color: var(--text-tertiary); font-family: var(--mono); margin-top: 2px; }

.messages { flex: 1; overflow-y: auto; padding: 24px 24px 8px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 70%; padding: 12px 16px; border-radius: 12px; line-height: 1.6; font-size: 14px; }
.msg-user { align-self: flex-end; background: var(--accent-dim); border: 1px solid var(--border-hover); border-radius: 12px 12px 4px 12px; }
.msg-assistant { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px 12px 12px 4px; }
.msg-system { align-self: center; background: transparent; color: var(--text-tertiary); font-size: 12px; font-style: italic; }
.msg-meta { font-size: 10px; color: var(--text-tertiary); margin-top: 4px; font-family: var(--mono); }
.msg-content { white-space: pre-wrap; word-wrap: break-word; }
.msg-content code { background: var(--surface-3); padding: 1px 6px; border-radius: 4px; font-family: var(--mono); font-size: 12px; }

.composer-bar {
  flex-shrink: 0;
  border-top: 1px solid var(--border);
  padding: 14px 20px;
  display: flex; gap: 10px; align-items: flex-end;
  background: var(--surface);
}
.composer-bar textarea {
  flex: 1;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 14px; font-family: inherit; font-size: 14px; line-height: 1.5;
  resize: none; min-height: 44px; max-height: 200px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.composer-bar textarea:focus { outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-dim);
}

.primary-btn {
  background: var(--accent); color: #1a1a1a; border: none; padding: 10px 18px;
  border-radius: 8px; font-family: inherit; font-weight: 500; font-size: 13px;
  cursor: pointer; transition: all 0.2s;
}
.primary-btn:hover { background: #e9b34a; transform: translateY(-1px); }
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.empty-hint {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text-secondary); text-align: center; padding: 0 40px; gap: 14px;
}
.empty-serif { font-family: var(--serif); color: var(--accent); font-size: 48px; line-height: 1.1; }
.empty-sub { font-size: 14px; color: var(--text-tertiary); max-width: 420px; }

/* Centered composer that shows in the empty state — first message auto-
   creates a thread and the layout flips to chat view. */
.hero-composer {
  margin-top: 22px; width: 100%; max-width: 640px;
  display: flex; gap: 10px; align-items: flex-end;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px 14px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.35);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.hero-composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-dim), 0 8px 32px rgba(0,0,0,0.35); }
.hero-composer textarea {
  flex: 1;
  background: transparent; color: var(--text); border: none; outline: none;
  font-family: inherit; font-size: 15px; line-height: 1.55;
  resize: none; min-height: 44px; max-height: 220px;
  text-align: left;
}
.hero-composer textarea::placeholder { color: var(--text-tertiary); }

/* ── modal ──────────────────────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
}
.modal[hidden] { display: none; }
.modal-backdrop {
  position: absolute; inset: 0; background: rgba(0,0,0,0.7); backdrop-filter: blur(4px);
}
.modal-body {
  position: relative; max-width: 480px; width: 90vw; background: var(--surface);
  border-radius: 16px; padding: 28px; border: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 14px;
}
.modal-close {
  position: absolute; top: 10px; right: 14px;
  background: transparent; border: none; color: var(--text-secondary);
  font-size: 24px; cursor: pointer; line-height: 1;
}
.modal-body h3 { font-family: var(--serif); font-size: 22px; color: var(--accent); }
.dialog-help { font-size: 13px; color: var(--text-secondary); }
.dialog-help code { font-family: var(--mono); color: var(--accent); background: var(--accent-dim); padding: 1px 6px; border-radius: 4px; }
.modal-body input {
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
  padding: 10px 14px; border-radius: 8px; font-family: inherit; font-size: 13px;
}
.modal-body input:focus { outline: none; border-color: var(--accent); }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }

/* ── spinner ────────────────────────────────────────────────────────── */
@keyframes spin { to { transform: rotate(360deg); } }
.spin {
  display: inline-block; width: 12px; height: 12px; border-radius: 50%;
  border: 2px solid var(--accent-dim); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

/* ── narrow ─────────────────────────────────────────────────────────── */
@media (max-width: 1000px) {
  .layout { grid-template-columns: 240px 1fr; }
}
@media (max-width: 720px) {
  .layout { grid-template-columns: 1fr; }
  .col-threads { display: none; }
}
