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

/* ─── Design tokens ─────────────────────────────────────────── */
:root {
  --sidebar-bg:   #202123;
  --main-bg:      #343541;
  --msg-bot-bg:   #444654;
  --input-bg:     #40414f;
  --border:       rgba(255,255,255,0.08);
  --border-hover: rgba(255,255,255,0.16);
  --tx:           #ececf1;
  --tx2:          #acacbe;
  --tx3:          #565869;
  --ac:           #10a37f;
  --ac-hover:     #0d9474;
  --rtg:          #d0312d;
  --rtg-dim:      rgba(208, 49, 45, 0.14);
  --error:        #ef4146;
  --error-bg:     rgba(239, 65, 70, 0.1);
  --sidebar-w:    260px;
  --r:            8px;
  --r-lg:         12px;
  --font-ui:      'Plus Jakarta Sans', system-ui, sans-serif;
}

/* ─── Base ──────────────────────────────────────────────────── */
html, body { height: 100%; overflow: hidden; }

body {
  font-family: var(--font-ui);
  font-size: 14px;
  color: var(--tx);
  background: var(--main-bg);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  position: relative;
}

#app {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 100%;
}

/* ─── Shell ─────────────────────────────────────────────────── */
.shell {
  display: flex;
  height: 100%;
}

/* ─── Sidebar ───────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--sidebar-bg);
  overflow: hidden;
}

.sidebar-hd {
  padding: 14px 10px 10px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 6px;
  border-radius: var(--r);
}

.brand-icon { flex-shrink: 0; }

.brand-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--tx);
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 11px;
  color: var(--tx3);
  margin-top: 1px;
}

.sidebar-body {
  flex: 1;
  overflow-y: auto;
  padding: 6px 8px;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.08) transparent;
}

.sidebar-body::-webkit-scrollbar { width: 3px; }
.sidebar-body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }

.sidebar-section-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--tx3);
  padding: 8px 8px 5px;
}

/* ─── Agent list ────────────────────────────────────────────── */
.agent-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.agent-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 10px;
  border-radius: var(--r);
  border: none;
  background: transparent;
  color: var(--tx2);
  font-family: var(--font-ui);
  font-size: 13.5px;
  font-weight: 400;
  cursor: pointer;
  text-align: left;
  transition: background 120ms, color 120ms;
}

.agent-item:hover { background: rgba(255,255,255,0.07); color: var(--tx); }
.agent-item--active { background: rgba(255,255,255,0.1); color: var(--tx); }
.agent-item--loading { opacity: 0.6; cursor: wait; }

.agent-icon {
  width: 28px;
  height: 28px;
  flex-shrink: 0;
  border-radius: 6px;
  background: var(--rtg-dim);
  color: var(--rtg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}

.agent-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agent-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--tx3);
  transition: background 300ms;
}
.agent-dot--on { background: #10a37f; }
.agent-dot--connecting { background: #f5a623; animation: pulse 1.2s ease-in-out infinite; }

.agent-empty {
  padding: 10px 10px;
  color: var(--tx3);
  font-size: 12.5px;
}

/* ─── Sidebar footer ────────────────────────────────────────── */
.sidebar-footer {
  flex-shrink: 0;
  padding: 8px 8px 12px;
  border-top: 1px solid var(--border);
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 8px;
  border-radius: var(--r);
  transition: background 120ms;
  cursor: default;
}

.user-badge:hover { background: rgba(255,255,255,0.05); }

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--rtg);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-badge-name {
  flex: 1;
  font-size: 13px;
  color: var(--tx);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-signout {
  background: none;
  border: none;
  color: var(--tx3);
  cursor: pointer;
  padding: 5px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: color 120ms, background 120ms;
  flex-shrink: 0;
}
.btn-signout:hover { color: var(--error); background: var(--error-bg); }

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

/* ─── Chat header ───────────────────────────────────────────── */
.chat-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-hd-left {
  display: flex;
  align-items: center;
  gap: 9px;
}

.chat-hd-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.chat-agent-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--tx);
}

/* ─── Connection dot ────────────────────────────────────────── */
.conn-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--tx3);
  transition: background 300ms;
}
.conn-dot--on { background: #10a37f; }
.conn-dot--connecting { background: #f5a623; animation: pulse 1.2s ease-in-out infinite; }
.conn-dot--reconnecting { background: #f5a623; animation: pulse 1.2s ease-in-out infinite; }
.conn-dot--error { background: #e53935; animation: pulse 1.2s ease-in-out infinite; }
.conn-dot--off { background: var(--tx3); }

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

.reconnect-btn {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid currentColor;
  background: transparent;
  color: var(--tx2);
  cursor: pointer;
  margin-left: 6px;
}
.reconnect-btn:hover { color: var(--tx); }

/* ─── Header icon buttons ───────────────────────────────────── */
.btn-hd-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--r);
  border: none;
  background: transparent;
  color: var(--tx2);
  cursor: pointer;
  transition: background 120ms, color 120ms;
}

.btn-hd-icon:hover { background: rgba(255,255,255,0.08); color: var(--tx); }
.btn-hd-icon--active { color: var(--ac); }

/* ─── Messages ──────────────────────────────────────────────── */
.chat-msgs {
  flex: 1;
  overflow-y: auto;
  padding: 0;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.08) transparent;
}

.chat-msgs::-webkit-scrollbar { width: 4px; }
.chat-msgs::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 4px; }

.msg {
  display: flex;
  gap: 16px;
  padding: 20px 24px;
  animation: msgIn 180ms ease-out both;
  line-height: 1.65;
}

.msg.bot { background: var(--msg-bot-bg); }
.msg.user { justify-content: flex-end; padding: 12px 24px; }
.msg.system { justify-content: center; padding: 8px 24px; }

.msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 4px;
  background: var(--rtg-dim);
  color: var(--rtg);
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}

.msg-content { flex: 1; min-width: 0; }

.msg-sender {
  font-size: 12px;
  font-weight: 600;
  color: var(--tx2);
  margin-bottom: 5px;
}

.msg-text {
  font-size: 14px;
  color: var(--tx);
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-text a {
  color: #6db3f2;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.msg-text a:hover {
  color: #99ccf8;
}

.msg-text h1,
.msg-text h2,
.msg-text h3,
.msg-text h4,
.msg-text h5,
.msg-text h6 {
  margin: 14px 0 6px;
  font-weight: 600;
  color: var(--tx);
  line-height: 1.3;
}

.msg-text h1 { font-size: 18px; }
.msg-text h2 { font-size: 16px; }
.msg-text h3 { font-size: 15px; }
.msg-text h4,
.msg-text h5,
.msg-text h6 { font-size: 14px; }

.msg-text hr {
  border: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  margin: 12px 0;
}

.msg-text table {
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 13px;
  width: auto;
  max-width: 100%;
  display: block;
  overflow-x: auto;
  white-space: normal;
}

.msg-text th,
.msg-text td {
  border: 1px solid rgba(255, 255, 255, 0.15);
  padding: 6px 10px;
  text-align: left;
  vertical-align: top;
}

.msg-text th {
  background: rgba(255, 255, 255, 0.06);
  font-weight: 600;
}

.msg-text tbody tr:nth-child(even) td {
  background: rgba(255, 255, 255, 0.03);
}

.msg-bubble {
  background: rgba(255,255,255,0.1);
  border-radius: 18px 18px 4px 18px;
  padding: 10px 15px;
  max-width: 70%;
  font-size: 14px;
  color: var(--tx);
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-system-text {
  font-size: 11.5px;
  color: var(--tx3);
  text-align: center;
}

.suggestions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 4px 0 12px 52px;
}

.suggestion-btn {
  background: transparent;
  border: 1px solid var(--border-hover);
  border-radius: 20px;
  color: var(--tx);
  cursor: pointer;
  font-family: var(--font-ui);
  font-size: 13px;
  padding: 6px 16px;
  transition: background 0.15s, border-color 0.15s;
}

.suggestion-btn:hover {
  background: rgba(255,255,255,0.06);
  border-color: rgba(255,255,255,0.3);
}

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

/* ─── Welcome screen ────────────────────────────────────────── */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 40px 24px;
  text-align: center;
}

.welcome-logo { margin-bottom: 18px; }

.welcome-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--tx);
  letter-spacing: -0.02em;
  margin-bottom: 8px;
}

.welcome-sub {
  font-size: 14px;
  color: var(--tx2);
  margin-bottom: 32px;
}

.welcome-agents {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
}

.welcome-agent-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 22px 28px;
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  color: var(--tx);
  font-family: var(--font-ui);
  cursor: pointer;
  min-width: 130px;
  transition: background 130ms, border-color 130ms, transform 130ms;
}

.welcome-agent-card:hover {
  background: rgba(255,255,255,0.08);
  border-color: var(--border-hover);
  transform: translateY(-2px);
}

.welcome-agent-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--rtg-dim);
  color: var(--rtg);
  font-size: 18px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.welcome-agent-name {
  font-size: 13.5px;
  font-weight: 500;
}

/* ─── Input zone ────────────────────────────────────────────── */
.input-zone {
  flex-shrink: 0;
  padding: 12px 20px 16px;
}

.input-wrap {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  background: var(--input-bg);
  border-radius: 14px;
  padding: 7px 8px 7px 10px;
  border: 1px solid var(--border);
  max-width: 720px;
  margin: 0 auto;
  transition: border-color 150ms, box-shadow 150ms;
}

.input-wrap:focus-within {
  border-color: rgba(255,255,255,0.22);
  box-shadow: 0 0 0 3px rgba(16, 163, 127, 0.12);
}

.msg-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--tx);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  max-height: 140px;
  overflow-y: auto;
  padding: 5px 4px;
  outline: none;
}

.msg-input::placeholder { color: var(--tx3); }
.msg-input:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-mic {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: 8px;
  background: transparent;
  border: none;
  color: var(--tx2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 120ms, color 120ms;
}

.btn-mic:hover:not(:disabled) { background: rgba(255,255,255,0.1); color: var(--tx); }
.btn-mic--active { color: var(--error) !important; background: var(--error-bg) !important; }
.btn-mic:disabled { opacity: 0.3; cursor: not-allowed; }

.btn-send {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: 8px;
  background: var(--ac);
  border: none;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 120ms, transform 120ms;
}

.btn-send:hover:not(:disabled) { background: var(--ac-hover); transform: scale(1.05); }
.btn-send:disabled { opacity: 0.3; cursor: not-allowed; transform: none; }

/* ─── Status bar ────────────────────────────────────────────── */
.status-bar {
  font-size: 11.5px;
  color: transparent;
  text-align: center;
  padding: 5px 0 0;
  min-height: 20px;
  max-width: 720px;
  margin: 0 auto;
  transition: color 150ms;
}

.status-bar--error { color: var(--error); }
.status-bar--info  { color: var(--tx2); }
.status-bar--ok    { color: var(--ac); }

/* ─── Login overlay ─────────────────────────────────────────── */
#login-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--main-bg);
  z-index: 100;
}

.login-card {
  background: #2a2b36;
  border: 1px solid var(--border-hover);
  border-radius: var(--r-lg);
  padding: 40px 44px;
  max-width: 360px;
  width: 90%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.5);
}

.login-logo { margin-bottom: 4px; }

.login-card-title {
  font-size: 20px;
  font-weight: 700;
  color: var(--tx);
  letter-spacing: -0.02em;
  text-align: center;
}

.login-card-subtitle {
  font-size: 13px;
  color: var(--tx2);
  text-align: center;
  line-height: 1.6;
}

.login-error {
  font-size: 12.5px;
  color: var(--error);
  text-align: center;
  padding: 8px 12px;
  background: var(--error-bg);
  border: 1px solid rgba(239, 65, 70, 0.25);
  border-radius: var(--r);
  width: 100%;
}

.btn-ms-login {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 12px 20px;
  margin-top: 4px;
  background: #fff;
  color: #1a1a1a;
  border: none;
  border-radius: var(--r);
  font-size: 13.5px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 150ms, transform 120ms;
}

.btn-ms-login:hover:not(:disabled) { opacity: 0.92; transform: translateY(-1px); }
.btn-ms-login:active:not(:disabled) { transform: translateY(0); }
.btn-ms-login:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-auth-card {
  margin-top: 8px;
  padding: 6px 14px;
  font-size: 0.8rem;
  font-weight: 500;
  border: 1px solid var(--ac);
  border-radius: 6px;
  background: transparent;
  color: var(--ac);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn-auth-card:hover { background: var(--ac); color: #fff; }

.consent-actions { display: flex; gap: 8px; margin-top: 10px; }
.btn-consent {
  padding: 6px 16px;
  font-size: 0.8rem;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--tx-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.btn-consent:hover:not(:disabled) { background: rgba(255,255,255,0.06); }
.btn-consent--allow { border-color: var(--ac); color: var(--ac); }
.btn-consent--allow:hover:not(:disabled) { background: var(--ac); color: #fff; }
.btn-consent:disabled { opacity: 0.4; cursor: not-allowed; }

/* ─── Responsive ────────────────────────────────────────────── */
@media (max-width: 680px) {
  :root { --sidebar-w: 220px; }
  .msg { padding: 16px 16px; gap: 12px; }
  .msg.user { padding: 10px 16px; }
  .input-zone { padding: 10px 12px 14px; }
  .msg-input { font-size: 16px; }
}

/* ─── Typing indicator ───────────────────────────────────────── */
.typing-dots { display: flex; align-items: center; gap: 4px; min-height: 1em; }
.typing-dots span {
  display: inline-block;
  width: 7px; height: 7px;
  background: var(--text-muted, #888);
  border-radius: 50%;
  animation: typing-blink 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typing-blink {
  0%, 80%, 100% { opacity: 0.2; transform: scale(0.8); }
  40%            { opacity: 1;   transform: scale(1);   }
}

@media (max-width: 500px) {
  .shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex-direction: row;
    flex-shrink: 0;
    height: 56px;
    align-items: center;
    padding: 0 12px;
    gap: 12px;
  }
  .sidebar-hd { padding: 0; flex-shrink: 0; }
  .sidebar-body { display: none; }
  .sidebar-footer { padding: 0; border-top: none; margin-left: auto; }
  .brand-sub { display: none; }
}

/* ─── Citation badges ───────────────────────────── */
.cite-ref {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: rgba(109, 179, 242, 0.18);
  color: #6db3f2;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  vertical-align: super;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  transition: background 120ms, color 120ms;
  text-decoration: none;
}
.cite-ref:hover {
  background: rgba(109, 179, 242, 0.32);
  color: #99ccf8;
}

/* ─── Sources accordion ─────────────────────────── */
.sources-box {
  margin-top: 4px;
  border-top: 1px solid var(--border);
  padding-top: 6px;
}
.sources-summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--tx2);
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
  padding: 2px 0;
  outline: none;
  width: fit-content;
}
.sources-summary::-webkit-details-marker { display: none; }
.sources-summary::before {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  border-top: 4px solid transparent;
  border-bottom: 4px solid transparent;
  border-left: 6px solid var(--tx2);
  transition: transform 160ms ease;
  flex-shrink: 0;
}
.sources-box[open] .sources-summary::before {
  transform: rotate(90deg);
}
.sources-summary:hover { color: var(--tx); }
.sources-summary:hover::before { border-left-color: var(--tx); }
.sources-list {
  list-style: none;
  margin-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.source-item a {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 6px;
  border-radius: var(--r);
  color: var(--tx2);
  text-decoration: none;
  font-size: 12.5px;
  transition: background 120ms, color 120ms;
  min-width: 0;
}
.source-item a:hover {
  background: rgba(255,255,255,0.06);
  color: #6db3f2;
}
.source-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.source-item svg { flex-shrink: 0; opacity: 0.5; }
.source-item a:hover svg { opacity: 1; }
