/* ── Reset & Variables ──────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --sidebar-w: 280px;
  --header-h:  64px;

  /* Brand accent – clean teal-blue */
  --primary:        #0ea5e9;
  --primary-dark:   #0284c7;
  --primary-light:  #e0f2fe;
  --primary-alpha:  rgba(14,165,233,.12);
  --gradient:       linear-gradient(135deg, #0ea5e9 0%, #6366f1 100%);
  --gradient-hover: linear-gradient(135deg, #0284c7 0%, #4f46e5 100%);

  /* Sidebar – clean white */
  --sb-bg:           #ffffff;
  --sb-hover:        #f0f9ff;
  --sb-border:       #e2e8f0;
  --sb-text:         #0f172a;
  --sb-muted:        #64748b;
  --sb-active:       #e0f2fe;
  --sb-active-text:  #0284c7;
  --sb-active-border:#0ea5e9;

  /* Main */
  --bg:         #f8fafc;
  --bg-alt:     #f1f5f9;
  --surface:    #ffffff;
  --border:     #e2e8f0;
  --text:       #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;

  /* Bubbles */
  --user-bg:   #0f172a;
  --user-text: #f8fafc;
  --bot-bg:    #f1f5f9;
  --bot-text:  #0f172a;

  /* Radius */
  --radius:    8px;
  --radius-lg: 18px;
  --radius-xl: 24px;

  /* Shadows */
  --shadow-xs: 0 1px 2px rgba(15,23,42,.04);
  --shadow-sm: 0 2px 8px rgba(15,23,42,.06);
  --shadow:    0 4px 20px rgba(15,23,42,.08);
  --shadow-md: 0 8px 32px rgba(15,23,42,.1);
  --shadow-lg: 0 24px 56px rgba(15,23,42,.15);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --mono: 'Fira Code', 'Cascadia Code', Consolas, monospace;
  --transition: .15s ease;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.hidden { display: none !important; }

/* ════════════════════════════════════════════════════════════════════════════
   LOGIN SCREEN
════════════════════════════════════════════════════════════════════════════ */
#login-screen {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: #f8fafc;
  overflow: hidden;
}

/* Decorative gradient blobs */
#login-screen::before,
#login-screen::after {
  content: '';
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  pointer-events: none;
}

#login-screen::before {
  width: 640px; height: 640px;
  top: -200px; right: -160px;
  background: radial-gradient(circle, rgba(14,165,233,.18) 0%, transparent 70%);
}

#login-screen::after {
  width: 480px; height: 480px;
  bottom: -160px; left: -120px;
  background: radial-gradient(circle, rgba(99,102,241,.14) 0%, transparent 70%);
}

.login-card {
  position: relative; z-index: 1;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 48px 44px 40px;
  max-width: 420px;
  width: 90%;
  text-align: center;
  box-shadow: var(--shadow-lg);
  animation: loginIn .4s cubic-bezier(.22,.68,0,1.15);
}

@keyframes loginIn {
  from { opacity: 0; transform: translateY(24px) scale(.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.login-logo {
  width: 72px; height: 72px;
  border-radius: 20px;
  background: var(--gradient);
  display: flex; align-items: center; justify-content: center;
  font-size: 36px;
  margin: 0 auto 28px;
  box-shadow: 0 8px 24px rgba(14,165,233,.3);
}

.login-card h1 {
  font-size: 26px; font-weight: 800;
  color: var(--text);
  margin-bottom: 10px;
  letter-spacing: -.5px;
}

.login-card > p {
  color: var(--text-muted);
  font-size: 14.5px;
  line-height: 1.75;
  margin-bottom: 32px;
}

.login-card .divider {
  display: flex; align-items: center; gap: 12px;
  margin: 28px 0;
  color: var(--text-light);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 500;
}

.login-card .divider::before,
.login-card .divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

.ms-login-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 12px;
  width: 100%; padding: 14px 22px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-size: 15px; font-weight: 600;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}

.ms-login-btn:hover:not(:disabled) {
  border-color: #94a3b8;
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.ms-login-btn:active:not(:disabled) { transform: translateY(0); }
.ms-login-btn:disabled { opacity: .6; cursor: not-allowed; }

#login-error {
  margin-top: 16px;
  padding: 11px 15px;
  border-radius: 10px;
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
  font-size: 13px;
  text-align: left;
  line-height: 1.5;
}

/* ════════════════════════════════════════════════════════════════════════════
   APP SHELL
════════════════════════════════════════════════════════════════════════════ */
#app {
  display: flex; height: 100vh; overflow: hidden;
}

/* ════════════════════════════════════════════════════════════════════════════
   SIDEBAR  (light)
════════════════════════════════════════════════════════════════════════════ */
#sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex; flex-direction: column;
  background: var(--sb-bg);
  border-right: 1px solid var(--sb-border);
  overflow: hidden;
}

/* Brand */
.sidebar-brand {
  padding: 22px 20px 18px;
  display: flex; align-items: center; gap: 12px;
}

.sidebar-brand-icon {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--gradient);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(14,165,233,.3);
}

.sidebar-brand-name {
  font-size: 16px; font-weight: 800;
  color: var(--text);
  letter-spacing: -.3px;
}

/* User header */
.sidebar-header {
  padding: 12px 16px;
  border-top: 1px solid var(--sb-border);
  border-bottom: 1px solid var(--sb-border);
  display: flex; align-items: center; gap: 10px;
}

.user-avatar-wrap {
  width: 34px; height: 34px;
  border-radius: 9px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  color: #fff;
}

.user-details { flex: 1; min-width: 0; }

.user-name {
  display: block;
  font-size: 13px; font-weight: 600;
  color: var(--sb-text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.user-email {
  display: block;
  font-size: 11px; color: var(--sb-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.logout-btn {
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--sb-muted);
  font-size: 11.5px; font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}

.logout-btn:hover {
  background: var(--bg-alt);
  color: var(--text);
  border-color: #94a3b8;
}

/* Tabs */
.sidebar-tabs {
  display: flex;
  margin: 14px 14px 0;
  background: var(--bg);
  border-radius: 10px;
  padding: 3px;
  border: 1px solid var(--border);
}

.tab-btn {
  flex: 1;
  padding: 7px 0;
  border: none; border-radius: 8px;
  background: transparent;
  color: var(--sb-muted);
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), box-shadow var(--transition);
  letter-spacing: -.1px;
}

.tab-btn.active {
  background: var(--surface);
  color: var(--primary-dark);
  box-shadow: var(--shadow-xs), 0 0 0 1px var(--border);
}

.tab-btn:not(.active):hover { color: var(--text); background: rgba(0,0,0,.03); }

/* Search */
.sidebar-search {
  padding: 12px 14px 6px;
}

.sidebar-search input {
  width: 100%;
  padding: 9px 13px;
  border-radius: 9px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.sidebar-search input::placeholder { color: var(--text-light); }

.sidebar-search input:focus {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--primary-alpha);
}

/* List */
.sidebar-list {
  flex: 1; overflow-y: auto; padding: 8px 10px 16px;
}

.sidebar-list::-webkit-scrollbar { width: 4px; }
.sidebar-list::-webkit-scrollbar-track { background: transparent; }
.sidebar-list::-webkit-scrollbar-thumb { background: #e2e8f0; border-radius: 2px; }

.sidebar-empty {
  color: var(--text-light); font-size: 13px;
  text-align: center; padding: 32px 0;
}

.sidebar-error {
  color: #dc2626; font-size: 13px; padding: 12px 16px;
  white-space: pre-wrap; word-break: break-word;
}

.sidebar-loading {
  color: var(--text-light); font-size: 13px;
  text-align: center; padding: 28px 0;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}

.sidebar-item {
  display: flex; align-items: flex-start; gap: 11px;
  width: 100%;
  padding: 10px 11px;
  border: none; border-radius: 10px;
  background: transparent;
  text-align: left; cursor: pointer;
  transition: background var(--transition);
  margin-bottom: 1px;
  position: relative;
}

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

.sidebar-item.active {
  background: var(--sb-active);
}

.sidebar-item.active::before {
  content: '';
  position: absolute; left: 0; top: 8px; bottom: 8px;
  width: 3px; border-radius: 0 2px 2px 0;
  background: var(--sb-active-border);
}

.sidebar-item-avatar {
  width: 36px; height: 36px;
  border-radius: 10px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff;
}

.sidebar-item-body { flex: 1; min-width: 0; }

.sidebar-item-name {
  display: block;
  font-size: 13.5px; font-weight: 600;
  color: var(--sb-text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.sidebar-item.active .sidebar-item-name {
  color: var(--sb-active-text);
}

.sidebar-item-desc {
  font-size: 11.5px; color: var(--sb-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: 1px;
}

.sidebar-item-badge {
  display: inline-block; margin-top: 5px;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--primary-light);
  color: var(--primary-dark);
  font-size: 10.5px; font-weight: 600;
}

/* ════════════════════════════════════════════════════════════════════════════
   MAIN AREA
════════════════════════════════════════════════════════════════════════════ */
#main {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
  background: var(--bg);
}

/* Welcome state */
#welcome-state {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center; padding: 48px 40px;
}

.welcome-icon {
  font-size: 56px; margin-bottom: 24px;
  line-height: 1;
}

#welcome-state h2 {
  font-size: 22px; font-weight: 800;
  color: var(--text); margin-bottom: 10px;
  letter-spacing: -.4px;
}

#welcome-state p {
  font-size: 14.5px; max-width: 320px;
  line-height: 1.75;
  color: var(--text-muted);
}

.welcome-tips {
  margin-top: 32px; display: flex; gap: 10px;
  flex-wrap: wrap; justify-content: center;
}

.welcome-tip {
  display: flex; align-items: center; gap: 7px;
  padding: 8px 16px; border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 13px; color: var(--text-muted);
  box-shadow: var(--shadow-xs);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.welcome-tip:hover {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-alpha);
}

/* Chat area */
#chat-area {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
}

/* Chat header */
#chat-header {
  height: var(--header-h);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-header-left { display: flex; align-items: center; gap: 14px; }

#chat-header-avatar {
  width: 40px; height: 40px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 700; color: #fff;
  flex-shrink: 0;
}

#chat-name {
  font-size: 15px; font-weight: 700;
  color: var(--text);
  letter-spacing: -.2px;
}

#chat-description {
  font-size: 12.5px; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-width: 400px;
}

#chat-type-badge {
  padding: 3px 10px; border-radius: 999px;
  background: var(--primary-light);
  color: var(--primary-dark);
  font-size: 11.5px; font-weight: 700;
  border: 1px solid #bae6fd;
}

.chat-header-right { display: flex; align-items: center; gap: 8px; }

.new-chat-btn {
  padding: 8px 16px;
  border-radius: 9px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px; font-weight: 600;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), box-shadow var(--transition), transform var(--transition);
}

.new-chat-btn:hover {
  background: var(--bg);
  border-color: #94a3b8;
  box-shadow: var(--shadow-xs);
  transform: translateY(-1px);
}

.new-chat-btn:active { transform: translateY(0); }

/* Messages container */
#messages-container {
  flex: 1; overflow-y: auto;
  padding: 28px 32px;
  display: flex; flex-direction: column; gap: 4px;
  background: var(--bg);
}

#messages-container::-webkit-scrollbar { width: 5px; }
#messages-container::-webkit-scrollbar-track { background: transparent; }
#messages-container::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

#messages { display: flex; flex-direction: column; gap: 14px; }

/* ── Message rows ─────────────────────────────────────────────────────────── */
.message-row {
  display: flex; align-items: flex-end; gap: 10px;
  max-width: 76%;
  animation: msgIn .18s ease;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message-row--user {
  align-self: flex-end; flex-direction: row-reverse;
}

.message-row--bot { align-self: flex-start; }

.message-avatar {
  width: 30px; height: 30px; border-radius: 9px;
  flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  font-size: 10.5px; font-weight: 700; color: #fff;
  margin-bottom: 2px;
}

/* ── Bubbles ──────────────────────────────────────────────────────────────── */
.bubble {
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  position: relative;
  word-break: break-word;
  max-width: 100%;
}

.bubble--user {
  background: var(--user-bg);
  color: var(--user-text);
  border-bottom-right-radius: 4px;
}

.bubble--bot {
  background: var(--bot-bg);
  color: var(--bot-text);
  border-bottom-left-radius: 4px;
}

.bubble--team {
  border: 1px solid #bae6fd;
  background: #f0f9ff;
}

.bubble-team-header {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid #bae6fd;
}

.bubble-team-name {
  font-size: 11.5px; font-weight: 800;
  color: var(--primary-dark);
  text-transform: uppercase; letter-spacing: .6px;
}

.bubble-workflow-badge {
  padding: 2px 9px; border-radius: 999px;
  background: var(--primary-light); color: var(--primary-dark);
  font-size: 10.5px; font-weight: 700;
  border: 1px solid #bae6fd;
}

.bubble-agent-name {
  font-size: 11px; font-weight: 700; color: var(--text-muted);
  margin-bottom: 4px;
  text-transform: uppercase; letter-spacing: .5px;
}

/* Team multi-agent response blocks */
.team-agent-response {
  padding: 10px 0;
  border-bottom: 1px solid #e0f2fe;
}

.team-agent-response:last-child { border-bottom: none; padding-bottom: 0; }

.team-agent-name {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase; letter-spacing: .5px;
}

.team-agent-dot {
  width: 7px; height: 7px; border-radius: 50%;
  flex-shrink: 0;
}

.bubble-text { font-size: 14px; line-height: 1.65; }

/* Markdown inside bubbles */
.bubble-text--md { line-height: 1.65; }

.bubble-text--md h1,
.bubble-text--md h2,
.bubble-text--md h3 {
  font-size: 15px; font-weight: 700;
  margin: 12px 0 6px; color: var(--text);
}

.bubble-text--md p { margin: 0 0 8px; }
.bubble-text--md p:last-child { margin-bottom: 0; }

.bubble-text--md ul,
.bubble-text--md ol {
  padding-left: 20px; margin: 6px 0 8px;
}

.bubble-text--md li { margin-bottom: 4px; }

.bubble-text--md code {
  background: rgba(0,0,0,.06);
  border-radius: 5px;
  padding: 2px 6px;
  font-family: var(--mono);
  font-size: 12.5px;
  border: 1px solid rgba(0,0,0,.07);
}

.bubble-text--md pre {
  background: #0f172a;
  border-radius: 10px;
  padding: 14px 16px;
  overflow-x: auto;
  margin: 10px 0;
}

.bubble-text--md pre code {
  background: none;
  color: #e2e8f0;
  padding: 0;
  font-family: var(--mono);
  font-size: 13px;
  border: none;
}

.bubble-text--md blockquote {
  border-left: 3px solid var(--primary);
  padding-left: 14px;
  color: var(--text-muted);
  margin: 8px 0;
  font-style: italic;
}

.bubble-text--md a { color: var(--primary-dark); text-decoration: underline; }
.bubble-text--md strong { font-weight: 700; }
.bubble-text--md hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }

.bubble-time {
  font-size: 10.5px;
  color: rgba(255,255,255,.45);
  text-align: right;
  margin-top: 6px;
}

.bubble--bot .bubble-time { color: var(--text-light); }

/* ── Typing indicator ─────────────────────────────────────────────────────── */
#typing-indicator {
  display: flex; align-items: center; gap: 10px;
  align-self: flex-start;
  padding: 8px 14px;
  margin: 2px 0;
}

.typing-bubble {
  background: var(--bot-bg);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: 4px;
  padding: 13px 18px;
  display: flex; align-items: center; gap: 5px;
}

.typing-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  animation: typingDot 1.4s infinite;
}

.typing-dot:nth-child(2) { animation-delay: .2s; }
.typing-dot:nth-child(3) { animation-delay: .4s; }

@keyframes typingDot {
  0%, 60%, 100% { transform: translateY(0); opacity: .35; }
  30%            { transform: translateY(-5px); opacity: 1; }
}

/* ── Input area ───────────────────────────────────────────────────────────── */
#input-area {
  display: flex; align-items: flex-end; gap: 10px;
  padding: 14px 24px 18px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#message-input {
  flex: 1;
  padding: 12px 16px;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  resize: none;
  overflow-y: auto;
  max-height: 160px;
  min-height: 46px;
  outline: none;
  transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
  line-height: 1.55;
}

#message-input:focus {
  border-color: var(--primary);
  background: var(--surface);
  box-shadow: 0 0 0 3px var(--primary-alpha);
}

#message-input:disabled { opacity: .5; cursor: not-allowed; }
#message-input::placeholder { color: var(--text-light); }

#send-btn {
  width: 46px; height: 46px;
  border-radius: 13px; border: none;
  background: var(--gradient);
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: opacity var(--transition), transform var(--transition), box-shadow var(--transition);
  box-shadow: 0 4px 12px rgba(14,165,233,.4);
}

#send-btn:hover:not(:disabled) {
  opacity: .9;
  transform: scale(1.05) translateY(-1px);
  box-shadow: 0 6px 18px rgba(14,165,233,.45);
}

#send-btn:active:not(:disabled) { transform: scale(1); }
#send-btn:disabled { opacity: .35; cursor: not-allowed; transform: none; box-shadow: none; }

#send-btn svg { pointer-events: none; }

/* ── Error banner ─────────────────────────────────────────────────────────── */
.error-banner {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #fef2f2; color: #dc2626;
  border: 1px solid #fecaca;
  padding: 11px 20px; border-radius: 12px;
  font-size: 13px; font-weight: 600;
  box-shadow: var(--shadow-md);
  z-index: 500;
  animation: fadeInUp .25s ease;
  white-space: nowrap;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to   { opacity: 1; transform: translate(-50%, 0); }
}

/* ── Scrollbar (Firefox) ──────────────────────────────────────────────────── */
.sidebar-list { scrollbar-width: thin; scrollbar-color: #e2e8f0 transparent; }
#messages-container { scrollbar-width: thin; scrollbar-color: #cbd5e1 transparent; }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  :root { --sidebar-w: 64px; }

  .sidebar-brand-name,
  .sidebar-tabs,
  .sidebar-search,
  .sidebar-item-body,
  .user-details,
  .logout-btn { display: none; }

  .sidebar-brand { justify-content: center; padding: 16px; }
  .sidebar-item { padding: 10px; justify-content: center; }
  .sidebar-item-avatar { margin: 0; }
  .user-avatar-wrap { margin: auto; }
  .sidebar-header { justify-content: center; padding: 12px; }

  .message-row { max-width: 95%; }

  #messages-container { padding: 16px; }
  #input-area { padding: 12px 16px 16px; }
  #chat-header { padding: 0 16px; }
}
