:root {
  --bg: #0d0d0f;
  --surface: #141416;
  --surface2: #1c1c1f;
  --border: #262629;
  --border-hover: #3a3a3f;
  --text: #e2e2e5;
  --text-muted: #5a5a65;
  --text-dim: #888892;
  --accent: #4ade80;
  --accent-bg: rgba(74, 222, 128, 0.08);
  --accent-border: rgba(74, 222, 128, 0.25);
  --agent: #60a5fa;
  --agent-bg: rgba(96, 165, 250, 0.08);
  --agent-border: rgba(96, 165, 250, 0.25);
  --danger: #f87171;
  --warning: #fbbf24;
  --radius: 5px;
  --mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', 'Cascadia Code', 'Courier New', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; overflow: hidden; }

body {
  font-family: var(--mono);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
}

#app { height: 100vh; display: flex; flex-direction: column; }

a { color: inherit; text-decoration: none; }

/* ── AUTH ── */
.auth-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: radial-gradient(ellipse at center, #111114 0%, #0d0d0f 70%);
}

.auth-box {
  width: 340px;
  padding: 2rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.auth-logo { font-size: 1.4rem; color: var(--accent); letter-spacing: -0.02em; }
.auth-tag { color: var(--text-muted); font-size: 0.72rem; margin-bottom: 2rem; margin-top: 2px; }

/* ── LAYOUT ── */
.layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.thread-layout {
  flex: 1;
  display: flex;
  overflow: hidden;
}

/* ── SIDEBAR ── */
.sidebar {
  width: 210px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}

.sb-brand {
  padding: 1rem;
  font-size: 1rem;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
  letter-spacing: -0.02em;
}

.sb-user {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.75rem;
  color: var(--text-dim);
}

.sb-nav { padding: 0.4rem 0; flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 1rem;
  color: var(--text-muted);
  font-size: 0.78rem;
  cursor: pointer;
  transition: color 0.1s, background 0.1s;
  border-radius: 0;
}

.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.agent-item { color: var(--agent); }

.sb-label {
  padding: 0.8rem 1rem 0.3rem;
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--text-muted);
}

.sb-footer {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
}

/* ── MAIN ── */
.main {
  flex: 1;
  overflow-y: auto;
  padding: 1.75rem 2rem;
}

.page-hd {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  gap: 1rem;
}

.page-hd h2 { font-size: 1.1rem; font-weight: 600; }
.page-hd .sub { font-size: 0.73rem; color: var(--text-muted); margin-top: 3px; }
.back { font-size: 0.7rem; color: var(--text-muted); display: block; margin-bottom: 4px; cursor: pointer; }
.back:hover { color: var(--accent); }

/* ── STATS ── */
.stats {
  display: flex;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
  font-size: 0.72rem;
  color: var(--text-muted);
}

.stat { display: flex; align-items: center; gap: 5px; }

/* ── CARDS ── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.75rem;
}

.card {
  padding: 1.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.card:hover { border-color: var(--accent); background: var(--accent-bg); }
.card-name { font-size: 0.85rem; font-weight: 500; margin-bottom: 0.4rem; }
.card-path { font-size: 0.7rem; color: var(--text-muted); word-break: break-all; }

/* ── THREAD LIST ── */
.thread-list { display: flex; flex-direction: column; gap: 0.5rem; }

.thread-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s;
}

.thread-row:hover { border-color: var(--border-hover); }
.thread-row-title { font-size: 0.85rem; }
.thread-row-meta { display: flex; gap: 0.75rem; align-items: center; font-size: 0.7rem; color: var(--text-muted); }

/* ── THREAD VIEW ── */
.thread-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.thread-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.thread-hd h2 { font-size: 0.95rem; }

.messages-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.msg {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  gap: 3px;
}

.msg-mine { align-self: flex-end; }
.msg-agent { max-width: 90%; }

.msg-meta {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.67rem;
  color: var(--text-muted);
}

.msg-sender { color: var(--text-dim); font-size: 0.75rem; }
.msg-time { margin-left: auto; }
.msg-status-label { font-size: 0.62rem; }

.msg-body {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.55rem 0.8rem;
  font-size: 0.82rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-mine .msg-body {
  background: var(--accent-bg);
  border-color: var(--accent-border);
}

.msg-agent .msg-body {
  background: var(--agent-bg);
  border-color: var(--agent-border);
}

.msg-tags {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  margin-top: 3px;
}

/* ── INPUT ── */
.input-wrap {
  border-top: 1px solid var(--border);
  padding: 0.85rem 1.25rem;
  position: relative;
  flex-shrink: 0;
}

.input-wrap textarea {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.82rem;
  padding: 0.65rem 0.8rem;
  resize: none;
  outline: none;
  transition: border-color 0.15s;
}

.input-wrap textarea:focus { border-color: var(--border-hover); }

.input-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 0.5rem;
}

.tag-row { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.input-hint { font-size: 0.65rem; color: var(--text-muted); }

.mentions-drop {
  position: absolute;
  bottom: 100%;
  left: 1.25rem;
  right: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  max-height: 180px;
  overflow-y: auto;
  z-index: 50;
}

.mention-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.45rem 0.75rem;
  cursor: pointer;
  font-size: 0.78rem;
}

.mention-row:hover { background: var(--surface2); }
.mention-type-label { color: var(--text-muted); font-size: 0.65rem; }

/* ── THREAD SIDEBAR ── */
.thread-panel {
  width: 220px;
  flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  overflow-y: auto;
}

.panel-section {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border);
}

.panel-label {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 0.65rem;
}

.participant-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.participant-info { display: flex; align-items: center; gap: 0.5rem; }
.participant-name { font-size: 0.78rem; }
.participant-role { font-size: 0.67rem; color: var(--text-muted); display: flex; align-items: center; gap: 3px; }

.add-row { display: flex; gap: 0.4rem; margin-top: 0.5rem; }
.add-row select {
  flex: 1;
  min-width: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.72rem;
  padding: 0.35rem 0.5rem;
  outline: none;
}

/* ── CONFIG FORM ── */
.config-form { max-width: 620px; }

.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 0.75rem;
}

.form-card h3 {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.status-badge-lg {
  font-size: 0.72rem;
  padding: 0.25rem 0.65rem;
  border-radius: 3px;
}

.status-free { background: var(--accent-bg); color: var(--accent); border: 1px solid var(--accent-border); }
.status-busy { background: rgba(251, 191, 36, 0.08); color: var(--warning); border: 1px solid rgba(251, 191, 36, 0.25); }

/* ── AVATAR ── */
.av {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent-bg);
  color: var(--accent);
  border: 1px solid var(--accent-border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
  flex-shrink: 0;
  text-transform: uppercase;
}

.av.agent-av {
  background: var(--agent-bg);
  color: var(--agent);
  border-color: var(--agent-border);
}

/* ── BADGES ── */
.badge {
  padding: 0.1rem 0.45rem;
  border-radius: 3px;
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.badge-active { background: var(--accent-bg); color: var(--accent); border: 1px solid var(--accent-border); }
.badge-archived { background: var(--surface2); color: var(--text-muted); border: 1px solid var(--border); }
.badge-agent { background: var(--agent-bg); color: var(--agent); border: 1px solid var(--agent-border); }

/* ── DOTS ── */
.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.dot-green { background: var(--accent); }
.dot-yellow { background: var(--warning); }
.dot-free { background: var(--accent); }
.dot-busy { background: var(--warning); }

/* ── TAGS ── */
.tag {
  background: var(--accent-bg);
  color: var(--accent);
  border: 1px solid var(--accent-border);
  padding: 0.1rem 0.45rem;
  border-radius: 3px;
  font-size: 0.68rem;
}

/* ── FORMS ── */
.field { margin-bottom: 0.9rem; }

.field label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}

.field input,
.field textarea,
.field select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.82rem;
  padding: 0.55rem 0.7rem;
  outline: none;
  transition: border-color 0.15s;
}

.field input:focus,
.field textarea:focus,
.field select:focus { border-color: var(--border-hover); }

.form-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.75rem; }

/* ── BUTTONS ── */
.btn {
  padding: 0.48rem 1rem;
  border-radius: var(--radius);
  border: none;
  font-family: var(--mono);
  font-size: 0.78rem;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s;
  white-space: nowrap;
}

.btn:hover { opacity: 0.85; }

.btn-primary { background: var(--accent); color: #000; font-weight: 600; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text-dim); }
.btn-ghost:hover { color: var(--text); border-color: var(--border-hover); opacity: 1; }
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.72rem; }
.btn-xs { padding: 0.2rem 0.5rem; font-size: 0.68rem; }

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0.15rem 0.35rem;
  font-size: 0.7rem;
  border-radius: 3px;
  transition: color 0.1s, background 0.1s;
}

.btn-icon:hover { color: var(--danger); background: rgba(248, 113, 113, 0.08); }

/* ── MODAL ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(2px);
}

.modal-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 1.5rem;
  width: 400px;
  max-width: calc(100vw - 2rem);
}

.modal-box h3 { font-size: 0.9rem; margin-bottom: 1.25rem; }
.modal-footer { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; }

/* ── MISC ── */
.err-msg { color: var(--danger); font-size: 0.75rem; margin-top: 0.5rem; }
.ok-msg { color: var(--accent); font-size: 0.75rem; margin-top: 0.5rem; }
.empty { color: var(--text-muted); font-size: 0.78rem; padding: 2.5rem 0; text-align: center; }
.hidden { display: none !important; }
.monospace { font-family: var(--mono); }
