:root {
  --bg:        #1a1b1e;
  --surface:   #25262b;
  --border:    #373a40;
  --muted:     #5c5f66;
  --text:      #c1c2c5;
  --bright:    #e9ecef;
  --accent:    #4dabf7;
  --ai:        #a9e34b;
  --system:    #868e96;
  --error:     #ff6b6b;
  --join:      #51cf66;
  --leave:     #ff6b6b;
  --sidebar-w: 200px;
  --input-h:   52px;
  --font:      'Menlo', 'Consolas', 'Liberation Mono', monospace;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  overflow: hidden;
}

/* ── Layout ─────────────────────────────────────────────────── */

#app {
  display: flex;
  height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────────── */

#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-section {
  padding: 12px 10px 6px;
}

.sidebar-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin-bottom: 4px;
}

.sidebar-item {
  padding: 3px 6px;
  border-radius: 4px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}

.sidebar-item:hover { background: var(--border); }

.sidebar-item.active {
  background: rgba(77, 171, 247, 0.15);
  color: var(--accent);
}

#member-list { flex: 1; overflow-y: auto; }
#member-list .sidebar-item { cursor: default; }
#member-list .sidebar-item:hover { background: none; }

.ai-badge {
  font-size: 10px;
  color: var(--ai);
  margin-left: 4px;
}

/* ── Main ────────────────────────────────────────────────────── */

#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#topbar {
  height: 40px;
  min-height: 40px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 10px;
}

#current-room {
  color: var(--accent);
  font-weight: 600;
}

#conn-status {
  font-size: 12px;
  color: var(--muted);
  margin-left: auto;
}

#conn-status.connected { color: var(--join); }
#conn-status.error     { color: var(--error); }

/* ── Messages ────────────────────────────────────────────────── */

#chat-panel {
  flex: 1;
  min-height: 80px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.msg {
  display: flex;
  gap: 10px;
  padding: 2px 0;
  line-height: 1.45;
}

.msg-time {
  color: var(--muted);
  font-size: 12px;
  min-width: 44px;
  padding-top: 1px;
  user-select: none;
}

.msg-nick {
  min-width: 110px;
  max-width: 110px;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--accent);
  font-weight: 600;
}

.msg-nick.ai    { color: var(--ai); }
.msg-nick.system { color: var(--system); font-weight: 400; font-style: italic; }

.msg-content { flex: 1; word-break: break-word; color: var(--bright); }
.msg.system .msg-content { color: var(--system); font-style: italic; }

.msg-file-link {
  color: var(--accent);
  text-decoration: none;
}
.msg-file-link:hover { text-decoration: underline; }
.msg-file-size { color: var(--muted); font-size: 12px; margin-left: 6px; }

/* ── Input bar ───────────────────────────────────────────────── */

#inputbar {
  height: var(--input-h);
  min-height: var(--input-h);
  background: var(--surface);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 10px;
  gap: 8px;
}

#msg-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--bright);
  font: inherit;
  padding: 8px 12px;
  outline: none;
}

#msg-input:focus { border-color: var(--accent); }
#msg-input::placeholder { color: var(--muted); }

.icon-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  cursor: pointer;
  font-size: 16px;
  padding: 6px 10px;
  line-height: 1;
}

.icon-btn:hover { border-color: var(--accent); color: var(--accent); }

#file-input { display: none; }

/* ── Nick modal ──────────────────────────────────────────────── */

#modal h2 { color: var(--bright); font-size: 18px; font-weight: 600; }
#modal p  { color: var(--muted);  font-size: 13px; }

#modal input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--bright);
  font: inherit;
  padding: 10px 12px;
  outline: none;
  width: 100%;
}

#modal input:focus { border-color: var(--accent); }

#modal button {
  background: var(--accent);
  border: none;
  border-radius: 6px;
  color: #000;
  cursor: pointer;
  font: 600 14px var(--font);
  padding: 10px;
  width: 100%;
}

#modal button:hover { opacity: .9; }
#modal-error { color: var(--error); font-size: 13px; min-height: 18px; }

/* ── Drop zone overlay ───────────────────────────────────────── */

#drop-overlay {
  position: fixed;
  inset: 0;
  background: rgba(77,171,247,.08);
  border: 2px dashed var(--accent);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--accent);
  pointer-events: none;
  opacity: 0;
  transition: opacity .15s;
  z-index: 50;
}

#drop-overlay.visible { opacity: 1; }

/* ── Scrollbar ───────────────────────────────────────────────── */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* style-auth-additions.css
 * Add these rules to the bottom of style.css
 * They replace the old #modal-backdrop / #modal rules
 */

/* ── Auth modal ──────────────────────────────────────────────── */

#auth-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

#auth-modal.hidden { display: none; }

#modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 28px 32px;
  width: 340px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

#modal h2 { color: var(--bright); font-size: 18px; font-weight: 600; }
#modal p  { color: var(--muted);  font-size: 13px; line-height: 1.5; }

#modal input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--bright);
  font: inherit;
  padding: 10px 12px;
  outline: none;
  width: 100%;
}

#modal input:focus { border-color: var(--accent); }

#modal button {
  background: var(--accent);
  border: none;
  border-radius: 6px;
  color: #000;
  cursor: pointer;
  font: 600 14px var(--font);
  padding: 10px;
  width: 100%;
}

#modal button:disabled { opacity: .5; cursor: default; }
#modal button:not(:disabled):hover { opacity: .9; }

#auth-error {
  color: var(--error);
  font-size: 13px;
  min-height: 18px;
}

#auth-recovery-info {
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 6px;
  color: var(--accent);
  font-size: 16px;
  font-weight: 600;
  letter-spacing: .12em;
  padding: 14px;
  text-align: center;
  word-break: break-all;
}

#auth-alt {
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

#auth-alt:hover { color: var(--text); }

/* ── Raw message toggle ──────────────────────────────────────── */

.msg-raw-toggle {
  display: inline-block;
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
  margin-top: 4px;
}
.msg-raw-toggle:hover { color: var(--text); }
.msg-raw-toggle::before { content: '▶ '; font-size: 9px; }
.msg-raw-toggle.open::before { content: '▼ '; }

.msg-raw-box {
  display: none;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 10px;
  margin-top: 4px;
  white-space: pre-wrap;
  word-break: break-all;
  font-size: 12px;
  color: var(--muted);
  max-height: 400px;
  overflow-y: auto;
  line-height: 1.4;
}
.msg-raw-box.open { display: block; }

/* ── Code blocks (inline in messages) ────────────────────────── */

.msg-code-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  margin: 6px 0;
  overflow: hidden;
}

.msg-code-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  color: var(--muted);
}

.msg-code-lang { color: var(--accent); font-weight: 600; }
.msg-code-file { color: var(--text); }

.msg-code-copy {
  margin-left: auto;
  background: none;
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--muted);
  cursor: pointer;
  font: 11px var(--font);
  padding: 1px 6px;
}
.msg-code-copy:hover { color: var(--accent); border-color: var(--accent); }

.msg-code-pre {
  margin: 0;
  padding: 8px 10px;
  white-space: pre-wrap;
  word-break: break-all;
  font-size: 12px;
  color: var(--bright);
  max-height: 500px;
  overflow-y: auto;
  line-height: 1.4;
}

/* ── Rich code message (type: code) ──────────────────────────── */

.msg-rich-code { flex-direction: column; }
.msg-rich-code .msg-meta { display: flex; gap: 10px; align-items: baseline; }

/* ── Diff viewer ─────────────────────────────────────────────── */

.msg-diff {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  margin: 6px 0;
  overflow: hidden;
  font-size: 12px;
}

.msg-diff-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  color: var(--muted);
}

.msg-diff-file { color: var(--text); font-weight: 600; }

.msg-diff-body {
  padding: 0;
  max-height: 500px;
  overflow-y: auto;
}

.diff-line {
  padding: 0 10px;
  white-space: pre-wrap;
  word-break: break-all;
  line-height: 1.4;
  font-family: var(--font);
}

.diff-add { background: rgba(81, 207, 102, 0.1); color: var(--join); }
.diff-del { background: rgba(255, 107, 107, 0.1); color: var(--error); }
.diff-ctx { color: var(--muted); }
.diff-hunk { color: var(--accent); background: rgba(77, 171, 247, 0.05); font-style: italic; }

/* ── Status indicator in member list ─────────────────────────── */

.member-status {
  font-size: 11px;
  color: var(--muted);
  font-style: italic;
  margin-left: 4px;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.member-nick { display: flex; align-items: baseline; gap: 4px; }
.member-nick .ai-badge { color: var(--ai); font-size: 11px; }

/* ── Ask modal ───────────────────────────────────────────────── */

#ask-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
#ask-modal.hidden { display: none; }

#ask-dialog {
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 24px 28px;
  width: 400px;
  max-width: 90vw;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#ask-from {
  color: var(--ai);
  font-weight: 600;
  font-size: 13px;
}

#ask-question {
  color: var(--bright);
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
}

#ask-input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--bright);
  font: inherit;
  padding: 10px 12px;
  outline: none;
  width: 100%;
}
#ask-input:focus { border-color: var(--accent); }

#ask-buttons {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

#ask-buttons button {
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font: 600 13px var(--font);
  padding: 8px 16px;
}

#ask-cancel {
  background: var(--border);
  color: var(--text);
}
#ask-cancel:hover { background: var(--muted); }

#ask-confirm {
  background: var(--accent);
  color: #000;
}
#ask-confirm:hover { opacity: .9; }

/* ── Quick-reply (trailing follow-up questions) ──────────────── */

.msg-quick-reply {
  background: rgba(77, 171, 247, 0.06);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  margin-top: 6px;
}

.quick-reply-question {
  color: var(--text);
  font-size: 13px;
  margin-bottom: 8px;
  font-style: italic;
}

.quick-reply-buttons {
  display: flex;
  gap: 6px;
  align-items: center;
}

.quick-reply-btn {
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  font: 600 12px var(--font);
  padding: 4px 12px;
  background: var(--surface);
  color: var(--text);
}
.quick-reply-btn:hover { border-color: var(--accent); color: var(--accent); }

.quick-reply-yes {
  background: rgba(81, 207, 102, 0.1);
  border-color: rgba(81, 207, 102, 0.3);
  color: var(--join);
}
.quick-reply-yes:hover { border-color: var(--join); }

.quick-reply-no {
  background: rgba(255, 107, 107, 0.1);
  border-color: rgba(255, 107, 107, 0.3);
  color: var(--error);
}
.quick-reply-no:hover { border-color: var(--error); }

.quick-reply-input {
  flex: 1;
  min-width: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--bright);
  font: 12px var(--font);
  padding: 4px 8px;
  outline: none;
}
.quick-reply-input:focus { border-color: var(--accent); }
.quick-reply-input::placeholder { color: var(--muted); }

.quick-reply-sent {
  color: var(--muted);
  font-size: 12px;
  font-style: italic;
}

/* ── Terminal panel ──────────────────────────────────────────── */

#terminal-panel {
  flex: 0 0 60%;
  min-height: 100px;
  display: flex;
  flex-direction: column;
  background: #000;
  position: relative;
  overflow: hidden;
}

#terminal-panel.hidden { display: none; }

#terminal-container {
  flex: 1;
  padding: 2px;
  overflow: hidden;
}

/* Focus ring when terminal is active */
#terminal-panel.focused {
  outline: 1px solid var(--accent);
  outline-offset: -1px;
}

#terminal-mode-hint {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(77, 171, 247, 0.15);
  color: var(--accent);
  font-size: 11px;
  padding: 2px 10px;
  text-align: center;
  z-index: 5;
}
#terminal-mode-hint.hidden { display: none; }

/* ── Resize handle ───────────────────────────────────────────── */

#resize-handle {
  height: 4px;
  min-height: 4px;
  background: var(--border);
  cursor: ns-resize;
  flex-shrink: 0;
}

#resize-handle:hover,
#resize-handle.dragging {
  background: var(--accent);
}

#resize-handle.hidden { display: none; }

/* ── Topbar additions ────────────────────────────────────────── */

.topbar-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  cursor: pointer;
  font: 12px var(--font);
  padding: 2px 8px;
  margin-left: 8px;
}
.topbar-btn:hover { border-color: var(--accent); color: var(--accent); }
.topbar-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(77,171,247,.1); }

#terminal-status {
  font-size: 11px;
  color: var(--muted);
  margin-left: 6px;
}
#terminal-status.live { color: var(--join); }
#terminal-status.offline { color: var(--error); }
