[hidden] { display: none !important; }

:root {
  --bg:          #f4f5f7;
  --panel:       #ffffff;
  --ink:         #111827;
  --muted:       #6b7280;
  --line:        #e5e7eb;
  --accent:      #1d4ed8;
  --accent-dark: #1e40af;
  --soft:        #eff6ff;
  --danger:      #dc2626;
  --ai-bg:       #f0f4ff;
  --ai-border:   #c7d7fd;
  --user-bg:     #1d4ed8;
  --user-ink:    #ffffff;
  --sidebar-w:   260px;
}

* { box-sizing: border-box; }
html { height: 100%; }

body {
  margin: 0;
  height: 100%;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 13px/1.5 system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

button, input, select, textarea { font: inherit; }

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  min-height: 32px;
  padding: 0 12px;
  white-space: nowrap;
}
button:hover { border-color: var(--accent); color: var(--accent-dark); }
button:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { border-color: var(--danger); background: #fef2f2; }
.btn-ghost { border: none; background: none; color: var(--muted); padding: 4px 8px; min-height: 28px; border-radius: 4px; }
.btn-ghost:hover { background: var(--bg); color: var(--ink); border: none; }

/* ── SSO banner ──────────────────────────────────────────────────────────────── */
.sso-banner {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 16px; background: #1e293b; color: #e2e8f0; font-size: 12px;
  flex-shrink: 0;
}
.sso-avatar { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; }
.sso-name { flex: 1; font-weight: 500; }
.sso-actions { display: flex; gap: 6px; align-items: center; }
.btn-link { color: #94a3b8; font-size: 12px; text-decoration: none; padding: 3px 8px;
            border-radius: 4px; border: none; background: none; cursor: pointer; }
.btn-link:hover { color: #e2e8f0; background: rgba(255,255,255,.08); }
.btn-sm { font-size: 12px; min-height: 26px; padding: 0 10px; }

/* ── Topbar ──────────────────────────────────────────────────────────────────── */
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.topbar h1 { margin: 0; font-size: 16px; font-weight: 700; }
.eyebrow { margin: 0; font-size: 10px; font-weight: 600; text-transform: uppercase;
           letter-spacing: .06em; color: var(--muted); }
.topbar-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

/* ── Main layout ─────────────────────────────────────────────────────────────── */
.chat-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}
.chat-layout.sidebar-collapsed .chat-sidebar {
  width: var(--sidebar-collapsed-w, 36px);
  overflow: visible;
}
.chat-layout.sidebar-collapsed .chat-sidebar > :not(#chatSidebarToggle):not(.sidebar-rail-label) {
  opacity: 0;
  pointer-events: none;
}
.chat-layout.sidebar-collapsed .chat-sidebar .sidebar-rail-label {
  display: block;
}
.chat-layout.sidebar-collapsed #chatSidebarToggle svg {
  transform: rotate(180deg);
}

/* ── Sidebar ─────────────────────────────────────────────────────────────────── */
.chat-sidebar {
  width: var(--sidebar-w);
  border-right: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: visible;
  position: relative;
}
.sidebar-header {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-bottom: 1px solid var(--line); flex-shrink: 0;
}
.sidebar-header h2 { margin: 0; font-size: 13px; font-weight: 600; flex: 1; }
.conversation-list {
  flex: 1; overflow-y: auto; padding: 4px 0;
}
.conversation-item {
  display: flex; align-items: flex-start; gap: 8px;
  padding: 8px 12px; cursor: pointer; border-left: 3px solid transparent;
  transition: background .1s;
}
.conversation-item:hover { background: var(--bg); }
.conversation-item.active { background: var(--soft); border-left-color: var(--accent); }
.conv-icon {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; background: var(--bg);
}
.conv-icon.ai { background: var(--ai-bg); }
.conv-icon.team { background: #f0fdf4; }
.conv-meta { flex: 1; min-width: 0; }
.conv-name { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-preview { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 10px; color: var(--muted); flex-shrink: 0; margin-top: 2px; }

.sidebar-section-label {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); padding: 10px 12px 4px; flex-shrink: 0;
}

/* ── Chat area ───────────────────────────────────────────────────────────────── */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.chat-header {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); flex-shrink: 0;
}
.chat-header-icon { font-size: 18px; }
.chat-header-info { flex: 1; }
.chat-header-title { font-size: 14px; font-weight: 600; margin: 0; }
.chat-header-sub { font-size: 11px; color: var(--muted); margin: 0; }
.chat-header-actions { display: flex; gap: 6px; }

.messages {
  flex: 1; overflow-y: auto;
  padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
}

.msg-row {
  display: flex; gap: 8px; max-width: 720px;
}
.msg-row.user { flex-direction: row-reverse; align-self: flex-end; }
.msg-row.ai, .msg-row.team { align-self: flex-start; }

.msg-avatar {
  width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; background: var(--bg); border: 1px solid var(--line);
  margin-top: 2px;
}
.msg-avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }

.msg-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.msg-sender { font-size: 11px; color: var(--muted); font-weight: 600; padding: 0 4px; }
.msg-row.user .msg-sender { text-align: right; }

.msg-bubble {
  padding: 8px 12px; border-radius: 12px; font-size: 13px; line-height: 1.55;
  word-break: break-word; white-space: pre-wrap;
}
.msg-row.user .msg-bubble {
  background: var(--user-bg); color: var(--user-ink);
  border-bottom-right-radius: 3px;
}
.msg-row.ai .msg-bubble {
  background: var(--ai-bg); border: 1px solid var(--ai-border);
  border-bottom-left-radius: 3px;
}
.msg-row.team .msg-bubble {
  background: var(--panel); border: 1px solid var(--line);
  border-bottom-left-radius: 3px;
}

.msg-time { font-size: 10px; color: var(--muted); padding: 0 4px; }
.msg-row.user .msg-time { text-align: right; }

/* Typing indicator */
.typing-indicator .msg-bubble {
  display: flex; gap: 4px; align-items: center; padding: 10px 14px;
}
.typing-dot {
  width: 6px; height: 6px; border-radius: 50%; background: var(--muted);
  animation: typingBounce 1.2s infinite;
}
.typing-dot:nth-child(2) { animation-delay: .2s; }
.typing-dot:nth-child(3) { animation-delay: .4s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ── Composer ────────────────────────────────────────────────────────────────── */
.composer {
  padding: 10px 16px; background: var(--panel); border-top: 1px solid var(--line);
  display: flex; gap: 8px; align-items: flex-end; flex-shrink: 0;
}
.composer-input {
  flex: 1; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 12px; resize: none; outline: none; max-height: 140px;
  line-height: 1.5; background: var(--bg); color: var(--ink); font-size: 13px;
  overflow-y: auto;
}
.composer-input:focus { border-color: var(--accent); background: #fff; }
.composer-send {
  background: var(--accent); color: #fff; border: none; border-radius: 8px;
  width: 36px; height: 36px; padding: 0; display: flex; align-items: center;
  justify-content: center; cursor: pointer; flex-shrink: 0;
}
.composer-send:hover { background: var(--accent-dark); }
.composer-send svg { width: 16px; height: 16px; }
.composer-send:disabled { opacity: .45; cursor: not-allowed; }

/* ── Empty state ─────────────────────────────────────────────────────────────── */
.chat-empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
  color: var(--muted); padding: 32px;
}
.chat-empty-icon { font-size: 48px; opacity: .4; }
.chat-empty h3 { margin: 0; font-size: 15px; color: var(--ink); }
.chat-empty p { margin: 0; font-size: 13px; text-align: center; max-width: 300px; }

/* ── New channel modal ───────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-box {
  background: var(--panel); border-radius: 12px; padding: 24px;
  width: 340px; max-width: 95vw; display: flex; flex-direction: column; gap: 14px;
}
.modal-box h3 { margin: 0; font-size: 15px; }
.modal-box label { font-size: 12px; font-weight: 600; color: var(--muted); display: block; margin-bottom: 4px; }
.modal-box input, .modal-box select {
  width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 6px;
  outline: none; font-size: 13px; background: var(--bg);
}
.modal-box input:focus, .modal-box select:focus { border-color: var(--accent); background: #fff; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ── Scrollbar ───────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }

/* ── Responsive ──────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .chat-sidebar { width: 200px; }
}
@media (max-width: 480px) {
  .chat-layout:not(.sidebar-collapsed) .chat-sidebar { width: 0; overflow: hidden; border: none; }
}
