:root {
  --bg: #1e1f22;
  --sidebar: #2b2d31;
  --panel: #313338;
  --text: #dbdee1;
  --muted: #949ba4;
  --accent: #5865f2;
  --you: #2b5cd9;
  --sophia: #3a3b45;
  --ok: #23a55a;
  --err: #f23f42;
  --info: #f0b232;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
}

.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  background: var(--sidebar);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow: hidden;
  min-height: 0;
}

.brand { font-weight: 700; font-size: 16px; display: flex; flex-direction: column; gap: 2px; }
.deployment, .identity { color: var(--muted); font-size: 11px; word-break: break-all; }

.connect {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 8px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 600;
}
.connect:hover { filter: brightness(1.1); }

.auth-banner { padding: 8px; border-radius: 4px; font-size: 12px; word-break: break-word; }
.auth-banner.ok { background: #1b3a2a; color: #a3e6c0; }
.auth-banner.error { background: #3a1b1b; color: #ffb3b3; }
.auth-banner.info { background: #3a301b; color: #f0d29b; }

.channel-list { display: flex; flex-direction: column; gap: 2px; }
.category {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 10px 0 2px;
}
.channel {
  padding: 6px 8px;
  border-radius: 4px;
  cursor: pointer;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.channel:hover { background: #35373c; color: var(--text); }
.channel.active { background: #404249; color: #fff; }
.channel-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.channel-retire {
  display: none;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  padding: 0 4px;
}
.channel:hover .channel-retire { display: inline-block; }
.channel-retire:hover { color: var(--err); }

.new-channel {
  background: transparent;
  border: 1px dashed #3f4147;
  color: var(--muted);
  border-radius: 4px;
  padding: 6px;
  margin-top: 6px;
  cursor: pointer;
  font-size: 13px;
}
.new-channel:hover { color: var(--text); border-color: var(--accent); }

.link-identity {
  background: transparent;
  border: 1px solid #3f4147;
  color: var(--muted);
  border-radius: 4px;
  padding: 6px;
  cursor: pointer;
  font-size: 13px;
}
.link-identity:hover { color: var(--text); border-color: var(--accent); }
.identity-status { font-size: 12px; color: var(--muted); word-break: break-word; }
.identity-status.ok { color: var(--ok); }
.identity-status.pending { color: var(--info); }
.identity-status.error { color: var(--err); }
.cv-link { font-size: 12px; color: #8ab4ff; text-decoration: none; }
.cv-link:hover { text-decoration: underline; }
.modal-hint { margin: 0; font-size: 12px; color: var(--muted); line-height: 1.4; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
}
.modal[hidden] { display: none; }
.modal-card {
  background: var(--panel);
  border: 1px solid #26272b;
  border-radius: 8px;
  padding: 20px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.modal-card h3 { margin: 0; }
.modal-card label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.modal-card input, .modal-card select {
  background: #383a40;
  color: var(--text);
  border: 1px solid #3f4147;
  border-radius: 5px;
  padding: 8px;
  font-family: inherit;
  font-size: 14px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.modal-actions button {
  background: transparent;
  color: var(--text);
  border: 1px solid #3f4147;
  border-radius: 5px;
  padding: 8px 14px;
  cursor: pointer;
}
.modal-actions button.send { background: var(--accent); border-color: var(--accent); color: #fff; }

.ctx-menu {
  position: fixed;
  z-index: 20;
  background: #1e1f22;
  border: 1px solid #3f4147;
  border-radius: 6px;
  padding: 4px;
  min-width: 160px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4);
}
.ctx-menu[hidden] { display: none; }
.ctx-menu .ctx-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 7px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
}
.ctx-menu .ctx-item:hover { background: var(--accent); color: #fff; }
.ctx-menu .ctx-item.danger { color: var(--err); }
.ctx-menu .ctx-item.danger:hover { background: var(--err); color: #fff; }

.chat { display: flex; flex-direction: column; background: var(--panel); min-height: 0; overflow: hidden; }
.chat-header {
  padding: 14px 16px;
  border-bottom: 1px solid #26272b;
  font-weight: 700;
  flex-shrink: 0;
}

.messages { flex: 1 1 0; min-height: 0; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.msg { display: flex; }
.msg.you { justify-content: flex-end; }
.msg.sophia { justify-content: flex-start; }
.msg.system { justify-content: center; }
.msg-stack { display: flex; flex-direction: column; gap: 3px; max-width: 78%; }
.msg.you .msg-stack { align-items: flex-end; }
.msg.sophia .msg-stack { align-items: flex-start; }
.msg.system .msg-stack { align-items: center; max-width: 100%; }
.sender { font-size: 11px; color: var(--muted); font-weight: 600; padding: 0 4px; }
.bubble {
  max-width: 100%;
  padding: 9px 12px;
  border-radius: 10px;
  white-space: pre-wrap;
  word-break: break-word;
}
.msg.you .bubble { background: var(--you); color: #fff; }
.msg.sophia .bubble { background: var(--sophia); color: var(--text); }
.msg.system .bubble { background: transparent; color: var(--muted); font-size: 12px; }

/* Markdown content rendered inside a bubble */
.bubble h1, .bubble h2, .bubble h3, .bubble h4, .bubble h5, .bubble h6 {
  margin: 10px 0 6px;
  font-weight: 700;
  line-height: 1.25;
}
.bubble h1 { font-size: 1.35em; }
.bubble h2 { font-size: 1.2em; }
.bubble h3 { font-size: 1.08em; }
.bubble h4, .bubble h5, .bubble h6 { font-size: 1em; }
.bubble p { margin: 4px 0; }
.bubble code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: rgba(0, 0, 0, 0.28);
  padding: 1px 5px;
  border-radius: 4px;
}
.bubble pre {
  background: rgba(0, 0, 0, 0.28);
  padding: 10px 12px;
  border-radius: 6px;
  overflow-x: auto;
  margin: 8px 0;
}
.bubble pre code { background: transparent; padding: 0; }
.bubble ul, .bubble ol { margin: 4px 0; padding-left: 22px; }
.bubble li { margin: 2px 0; }
.bubble blockquote {
  margin: 6px 0;
  padding: 2px 12px;
  border-left: 3px solid var(--accent);
  color: var(--muted);
}
.bubble a { color: #8ab4ff; text-decoration: none; }
.bubble a:hover { text-decoration: underline; }
.bubble hr { border: none; border-top: 1px solid #3f4147; margin: 10px 0; }
.bubble table {
  border-collapse: collapse;
  margin: 8px 0;
  display: block;
  overflow-x: auto;
  max-width: 100%;
}
.bubble th, .bubble td {
  border: 1px solid #4a4d55;
  padding: 6px 10px;
  text-align: left;
  font-size: 0.92em;
  white-space: nowrap;
}
.bubble th { background: rgba(0, 0, 0, 0.22); font-weight: 700; }
.bubble strong { font-weight: 700; }

/* copy buttons for links + code blocks */
.url-wrap { display: inline-flex; align-items: center; gap: 2px; }
.attach-fig { display: inline-flex; flex-direction: column; align-items: flex-start; gap: 2px; margin-top: 6px; }
.url-copy {
  background: rgba(0, 0, 0, 0.22);
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 4px;
  line-height: 1.2;
}
.url-copy:hover { color: var(--text); background: rgba(0, 0, 0, 0.4); }
.url-copy.copied { color: var(--ok); }

.code-block { position: relative; margin: 8px 0; }
.code-block .copy-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid #4a4d55;
  color: var(--muted);
  cursor: pointer;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  z-index: 1;
}
.code-block .copy-btn:hover { color: #fff; background: rgba(255, 255, 255, 0.2); }
.code-block .copy-btn.copied { color: var(--ok); border-color: var(--ok); }

.composer { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid #26272b; align-items: flex-end; flex-shrink: 0; }
.composer textarea {
  flex: 1;
  resize: none;
  background: #383a40;
  color: var(--text);
  border: none;
  border-radius: 6px;
  padding: 10px;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.35;
  max-height: 220px;
  overflow-y: auto;
}
.composer textarea:focus { outline: 1px solid var(--accent); }
.composer .send {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0 18px;
  cursor: pointer;
  font-weight: 600;
  height: 38px;
}
.composer .attach {
  background: transparent;
  color: var(--muted);
  border: 1px solid #3f4147;
  border-radius: 6px;
  padding: 8px 10px;
  cursor: pointer;
  height: 38px;
}
.composer .attach:hover { color: var(--text); background: #383a40; }

.msg .bubble img.attach {
  max-width: 100%;
  max-height: 280px;
  border-radius: 8px;
  margin-top: 8px;
  display: block;
}
.msg .bubble a.attach-link {
  color: #8ab4ff;
  word-break: break-all;
  display: block;
  margin-top: 6px;
}

.reactions { display: flex; gap: 4px; align-items: center; padding-left: 2px; }
.reaction {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 1px 6px;
  font-size: 14px;
  cursor: pointer;
  color: var(--muted);
}
.reaction:hover { background: #3a3b45; }
.reaction.active { background: #2b3a55; border-color: var(--accent); color: #fff; }

