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

:root {
  --bg: #0F172A;
  --surface: #1E293B;
  --border: #334155;
  --text: #E2E8F0;
  --text-muted: #94A3B8;
  --text-dim: #475569;
  --teal: #0D9488;
  --teal-dark: #0F766E;
  --teal-glow: rgba(13,148,136,0.15);
  --sidebar-w: 260px;
}

body {
  font-family: -apple-system, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  display: flex;
  overflow: hidden;
}

/* === Sidebar === */
#sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

#sidebar-header {
  padding: 16px 16px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

#sidebar-header h1 { font-size: 18px; font-weight: 700; color: var(--teal); }
#me-name { font-size: 13px; color: var(--text-muted); margin-left: auto; }

#channels-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.channel-item {
  padding: 10px 16px;
  cursor: pointer;
  border-radius: 0;
  transition: background 0.15s;
  display: flex;
  align-items: center;
  gap: 10px;
  border-left: 3px solid transparent;
}

.channel-item:hover { background: rgba(255,255,255,0.04); }
.channel-item.active { background: var(--teal-glow); border-left-color: var(--teal); }

.channel-name { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.channel-preview { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.channel-everyone { color: var(--teal); }

.channel-members-avatars { display: flex; gap: 2px; flex-shrink: 0; }
.mini-avatar { width: 20px; height: 20px; border-radius: 50%; background: var(--border); display: flex; align-items: center; justify-content: center; font-size: 11px; }

#new-channel-btn {
  margin: 8px 12px;
  padding: 8px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  text-align: left;
}
#new-channel-btn:hover { border-color: var(--teal); color: var(--teal); }

/* === Main area === */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#channel-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 57px;
}

#channel-title { font-size: 16px; font-weight: 600; }
#channel-members-bar { display: flex; gap: 8px; align-items: center; margin-left: auto; flex-wrap: wrap; }

.member-pill {
  display: flex; align-items: center; gap: 5px;
  padding: 3px 8px; border-radius: 20px;
  background: rgba(255,255,255,0.05);
  font-size: 12px; color: var(--text-muted);
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--text-dim);
  transition: background 0.3s;
}
.status-dot.idle { background: var(--text-dim); }
.status-dot.thinking { background: #F59E0B; animation: pulse 1s ease-in-out infinite; }
.status-dot.working { background: #F59E0B; }

@keyframes pulse {
  0%, 100% { opacity: 1; } 50% { opacity: 0.4; }
}

.status-detail { font-size: 11px; color: #F59E0B; font-style: italic; }

/* === Messages === */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.msg-row {
  display: flex;
  gap: 10px;
  padding: 4px 0;
  border-radius: 6px;
  transition: background 0.1s;
}
.msg-row:hover { background: rgba(255,255,255,0.02); }
.msg-row:hover .msg-actions { opacity: 1; }

.msg-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--border); display: flex; align-items: center;
  justify-content: center; font-size: 16px; flex-shrink: 0; margin-top: 2px;
}

.msg-body { flex: 1; min-width: 0; }
.msg-meta { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.msg-sender { font-size: 13px; font-weight: 600; }
.msg-sender.ai { color: var(--teal); }
.msg-time { font-size: 11px; color: var(--text-dim); }
.msg-edited { font-size: 11px; color: var(--text-dim); font-style: italic; }

.msg-content { font-size: 14px; line-height: 1.6; word-wrap: break-word; color: var(--text); }
.msg-content.deleted { color: var(--text-dim); font-style: italic; }
.msg-content p { margin: 0 0 4px; }
.msg-content p:last-child { margin: 0; }
.msg-content code { background: rgba(255,255,255,0.08); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.msg-content pre { background: rgba(255,255,255,0.06); padding: 10px; border-radius: 6px; overflow-x: auto; margin: 6px 0; }
.msg-content pre code { background: none; padding: 0; }

.msg-actions { opacity: 0; display: flex; gap: 4px; margin-top: 2px; }
.msg-action-btn { background: none; border: none; color: var(--text-dim); font-size: 12px; cursor: pointer; padding: 2px 6px; border-radius: 4px; }
.msg-action-btn:hover { color: var(--text); background: var(--border); }

.msg-file { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: rgba(255,255,255,0.04); border-radius: 8px; border: 1px solid var(--border); margin-top: 4px; font-size: 13px; }
.msg-file a { color: var(--teal); text-decoration: none; }
.msg-file a:hover { text-decoration: underline; }

#typing-indicator { font-size: 13px; color: var(--text-muted); padding: 4px 20px 0; min-height: 22px; font-style: italic; }

/* === Input === */
#input-area {
  padding: 12px 20px 16px;
  border-top: 1px solid var(--border);
}

#input-row { display: flex; gap: 8px; align-items: flex-end; }

#message-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text);
  font-size: 14px;
  resize: none;
  outline: none;
  max-height: 180px;
  min-height: 42px;
  line-height: 1.5;
  font-family: inherit;
  transition: border-color 0.2s;
}
#message-input:focus { border-color: var(--teal); }

.input-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text-muted);
  padding: 10px 12px;
  cursor: pointer;
  font-size: 16px;
  transition: all 0.15s;
  line-height: 1;
}
.input-btn:hover { border-color: var(--teal); color: var(--teal); }

#send-btn {
  background: var(--teal);
  border-color: var(--teal);
  color: white;
  font-size: 14px;
  padding: 10px 16px;
  font-weight: 600;
}
#send-btn:hover { background: var(--teal-dark); border-color: var(--teal-dark); }
#send-btn:disabled { background: var(--border); border-color: var(--border); color: var(--text-dim); cursor: default; }

#input-hint { font-size: 12px; color: var(--text-dim); margin-top: 6px; }

/* === New Channel Modal === */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 28px; width: 400px; }
.modal h2 { font-size: 18px; margin-bottom: 16px; }
.member-select { display: flex; flex-direction: column; gap: 6px; margin-bottom: 20px; max-height: 240px; overflow-y: auto; }
.member-check { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px; cursor: pointer; }
.member-check:hover { background: rgba(255,255,255,0.04); }
.member-check input { width: 16px; height: 16px; accent-color: var(--teal); }
.member-check label { cursor: pointer; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.btn-secondary { padding: 8px 16px; background: transparent; border: 1px solid var(--border); border-radius: 8px; color: var(--text-muted); cursor: pointer; font-size: 14px; }
.btn-secondary:hover { border-color: var(--text-muted); }
.btn-primary { padding: 8px 16px; background: var(--teal); border: none; border-radius: 8px; color: white; cursor: pointer; font-size: 14px; font-weight: 600; }
.btn-primary:hover { background: var(--teal-dark); }

/* === Empty states === */
#no-channel { display: flex; align-items: center; justify-content: center; flex: 1; color: var(--text-muted); font-size: 15px; }

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