/* ============ RESET ============ */
*,*::before,*::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { min-height: 100%; height: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 13.5px;
  color: #1a1f3a;
  background: #f7f5ef;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  overflow: hidden;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; }
textarea { font-family: inherit; }
a { color: inherit; cursor: pointer; }

:root {
  --indigo-900: #11173d;
  --indigo-800: #1c2954;
  --indigo-700: #2c3a72;
  --indigo-600: #4351a0;
  --indigo-500: #6573c4;
  --indigo-100: #dde0ee;
  --indigo-50: #ecedf6;
  --gold: #e8c987;
  --gold-dark: #c9a55a;
  --gold-bg: #faf2dd;
  --cream-100: #f7f0dc;
  --cream-50: #fdf9ec;
  --bg: #f7f5ef;
  --paper: #ffffff;
  --paper-2: #fcfbf6;
  --gray-100: #ece9df;
  --gray-200: #ddd9cb;
  --gray-300: #c0bcae;
  --gray-500: #807a6b;
  --gray-700: #4a4438;
  --gray-900: #1a1f3a;
  --green: #1d6f42;
  --shadow-sm: 0 1px 2px rgba(28, 41, 84, 0.05), 0 1px 3px rgba(28, 41, 84, 0.07);
  --shadow-md: 0 4px 14px rgba(28, 41, 84, 0.06);
}

kbd {
  font-family: 'JetBrains Mono', monospace;
  font-size: 10.5px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 4px;
  padding: 1px 5px;
  color: rgba(255, 255, 255, 0.65);
  font-weight: 500;
  margin-left: auto;
}

/* ============ APP SHELL ============ */
.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
}

/* ============ SIDEBAR ============ */
.sidebar {
  background: var(--indigo-800);
  color: rgba(255, 255, 255, 0.92);
  display: flex;
  flex-direction: column;
  padding: 18px 14px 12px;
  overflow: hidden;
}
.side-brand {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 0 0 14px;
  margin-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.logo-pane {
  background: #fff;
  border-radius: 10px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 0 rgba(255,255,255,0.04), 0 4px 12px rgba(0,0,0,0.18);
}
.brand-logo {
  height: 38px;
  width: auto;
  max-width: 100%;
  display: block;
}
.product-name {
  display: inline-flex;
  align-self: center;
  align-items: center;
  gap: 7px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold);
  padding: 4px 12px;
  background: rgba(232, 201, 135, 0.08);
  border: 1px solid rgba(232, 201, 135, 0.18);
  border-radius: 999px;
}
.pn-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 0 rgba(232, 201, 135, 0.6);
  animation: pulse-dot-am 2.4s infinite;
}
@keyframes pulse-dot-am {
  0% { box-shadow: 0 0 0 0 rgba(232, 201, 135, 0.6); }
  70% { box-shadow: 0 0 0 6px rgba(232, 201, 135, 0); }
  100% { box-shadow: 0 0 0 0 rgba(232, 201, 135, 0); }
}

.new-chat {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 12px;
  background: var(--gold);
  color: var(--indigo-900);
  border-radius: 9px;
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 16px;
  transition: all 0.15s;
}
.new-chat:hover { background: #f0d590; transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.new-chat svg { width: 14px; height: 14px; }
.new-chat kbd { background: rgba(28, 41, 84, 0.12); border-color: rgba(28, 41, 84, 0.18); color: rgba(28, 41, 84, 0.7); }

/* ============ SIDE SECTIONS ============ */
.side-section {
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
/* Recent chats: capped, scrolls if too many */
.side-section:first-of-type .chat-list {
  max-height: 180px;
  overflow-y: auto;
  margin: 0 -4px;
  padding: 0 4px;
}
.side-section:first-of-type .chat-list::-webkit-scrollbar { width: 6px; }
.side-section:first-of-type .chat-list::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 999px; }
.side-section:first-of-type .chat-list::-webkit-scrollbar-track { background: transparent; }
/* Data sources: fills remaining space */
.side-section + .side-section {
  flex: 1 1 auto;
  min-height: 0;
}
.side-h {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: rgba(255, 255, 255, 0.45);
  padding: 0 8px;
  margin-bottom: 6px;
}
.src-count {
  background: rgba(232, 201, 135, 0.15);
  color: var(--gold);
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10px;
  letter-spacing: 0;
}

.chat-list { display: flex; flex-direction: column; gap: 1px; }
.chat-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 7px;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.72);
  font-weight: 500;
  transition: background 0.15s;
}
.chat-item:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.chat-item.active { background: rgba(255, 255, 255, 0.1); color: #fff; }
.chat-item svg { width: 14px; height: 14px; flex-shrink: 0; opacity: 0.6; }
.chat-item span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.src-list {
  display: flex;
  flex-direction: column;
  gap: 1px;
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  margin: 0 -4px;
  padding: 0 4px;
}
.src-list::-webkit-scrollbar { width: 6px; }
.src-list::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 999px; }
.src-list::-webkit-scrollbar-track { background: transparent; }
.src {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 7px;
  transition: background 0.15s;
  cursor: pointer;
}
.src:hover { background: rgba(255, 255, 255, 0.06); }
.src-icon {
  width: 26px; height: 26px;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.src-icon svg { width: 100%; height: 100%; }
.src-meta { flex: 1; min-width: 0; }
.src-name {
  font-size: 12px;
  font-weight: 500;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.src-info {
  font-size: 10.5px;
  color: rgba(255, 255, 255, 0.45);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}
.src-status {
  width: 7px; height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.src-status.synced { background: var(--green); box-shadow: 0 0 0 2px rgba(29, 111, 66, 0.2); }

.upload-more {
  display: flex; align-items: center; justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 9px 10px;
  margin-top: 8px;
  background: transparent;
  color: rgba(255, 255, 255, 0.6);
  border: 1px dashed rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.15s;
}
.upload-more:hover { background: rgba(255, 255, 255, 0.04); color: #fff; border-color: var(--gold); }
.upload-more svg { width: 12px; height: 12px; }

.side-foot {
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}
.user-row {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 6px;
  border-radius: 8px;
}
.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold), var(--gold-dark));
  color: var(--indigo-900);
  font-weight: 700;
  font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.u-name { font-size: 12.5px; font-weight: 600; color: #fff; line-height: 1.2; }
.u-role { font-size: 11px; color: rgba(255, 255, 255, 0.5); line-height: 1.2; }
.settings-btn {
  width: 28px; height: 28px;
  border-radius: 6px;
  margin-left: auto;
  color: rgba(255, 255, 255, 0.5);
  display: flex; align-items: center; justify-content: center;
}
.settings-btn:hover { color: #fff; background: rgba(255, 255, 255, 0.06); }
.settings-btn svg { width: 16px; height: 16px; }

/* ============ CHAT MAIN ============ */
.chat {
  background: var(--paper-2);
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
}

.chat-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 28px;
  border-bottom: 1px solid var(--gray-200);
  background: var(--paper);
}
.chat-head h1 {
  font-size: 16px;
  font-weight: 700;
  color: var(--indigo-900);
  letter-spacing: -0.01em;
}
.chat-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--gray-500);
  margin-top: 2px;
}
.grounded-dot {
  width: 7px; height: 7px;
  background: var(--green);
  border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(29, 111, 66, 0.5);
  animation: pulse 2.4s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(29, 111, 66, 0.5); }
  70% { box-shadow: 0 0 0 8px rgba(29, 111, 66, 0); }
  100% { box-shadow: 0 0 0 0 rgba(29, 111, 66, 0); }
}

.chat-head-actions { display: flex; gap: 4px; }
.head-btn {
  width: 32px; height: 32px;
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  color: var(--gray-500);
  transition: all 0.15s;
}
.head-btn:hover { background: var(--gray-100); color: var(--indigo-800); }
.head-btn svg { width: 16px; height: 16px; }

/* ============ CHAT STREAM ============ */
.chat-stream {
  flex: 1;
  overflow-y: auto;
  padding: 28px 28px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.chat-stream::-webkit-scrollbar { width: 8px; }
.chat-stream::-webkit-scrollbar-thumb { background: var(--gray-200); border-radius: 999px; }
.chat-stream::-webkit-scrollbar-track { background: transparent; }

/* ============ EMPTY STATE ============ */
.empty-state {
  max-width: 720px;
  margin: 32px auto 0;
  text-align: center;
}
.es-mark {
  width: 64px; height: 64px;
  margin: 0 auto 16px;
}
.es-mark svg { width: 100%; height: 100%; }
.empty-state h2 {
  font-size: 26px;
  font-weight: 700;
  color: var(--indigo-900);
  letter-spacing: -0.02em;
  margin-bottom: 10px;
}
.empty-state p {
  font-size: 14.5px;
  color: var(--gray-500);
  max-width: 540px;
  margin: 0 auto 28px;
  line-height: 1.55;
}

.suggestions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  text-align: left;
}
.sug {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 14px 16px;
  background: var(--paper);
  border: 1px solid var(--gray-200);
  border-radius: 12px;
  transition: all 0.15s;
}
.sug:hover {
  border-color: var(--indigo-500);
  background: var(--indigo-50);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.sug-cat {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  color: var(--indigo-600);
}
.sug-q {
  font-size: 13.5px;
  color: var(--gray-700);
  font-weight: 500;
  line-height: 1.45;
}

/* ============ MESSAGES ============ */
.msg {
  display: flex;
  gap: 14px;
  max-width: 820px;
  margin: 0 auto;
  width: 100%;
}
.msg-avatar {
  width: 32px; height: 32px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 12px;
  flex-shrink: 0;
}
.msg-user .msg-avatar {
  background: linear-gradient(135deg, var(--gold), var(--gold-dark));
  color: var(--indigo-900);
}
.msg-bot .msg-avatar {
  background: var(--indigo-800);
  color: var(--gold);
}
.msg-bot .msg-avatar svg { width: 18px; height: 18px; }

.msg-body { flex: 1; min-width: 0; padding-top: 4px; }
.msg-name { font-size: 12px; font-weight: 700; color: var(--indigo-900); margin-bottom: 4px; }
.msg-text {
  font-size: 14px;
  color: var(--gray-900);
  line-height: 1.6;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg-bot .msg-text {
  background: var(--paper);
  border: 1px solid var(--gray-200);
  padding: 12px 16px;
  border-radius: 12px;
  border-bottom-left-radius: 2px;
}
.msg-error .msg-text {
  background: #fdf3f3;
  border-color: #f0d4d4;
  color: #8b3030;
}
.msg-error .msg-avatar {
  background: #f0d4d4;
  color: #8b3030;
}
.msg-error .msg-name { color: #8b3030; }
.msg-error .msg-text::before {
  content: '';
  display: inline-block;
  width: 14px; height: 14px;
  margin-right: 8px;
  vertical-align: -2px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b3030' stroke-width='2'%3E%3Cpath d='M1 1l22 22 M16.72 11.06A10.94 10.94 0 0 1 19 12.55 M5 12.55a10.94 10.94 0 0 1 5.17-2.39 M10.71 5.05A16 16 0 0 1 22.58 9 M1.42 9a15.91 15.91 0 0 1 4.7-2.88 M8.53 16.11a6 6 0 0 1 6.95 0 M12 20h.01'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-size: contain;
}

.typing {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  background: var(--paper);
  border: 1px solid var(--gray-200);
  border-radius: 12px;
  border-bottom-left-radius: 2px;
  width: fit-content;
}
.typing span {
  width: 7px; height: 7px;
  background: var(--gray-300);
  border-radius: 50%;
  animation: type-bounce 1.4s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes type-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ============ COMPOSER ============ */
.composer-wrap {
  padding: 16px 28px 18px;
  background: var(--paper-2);
  border-top: 1px solid var(--gray-200);
}
.composer {
  max-width: 820px;
  margin: 0 auto;
  background: var(--paper);
  border: 1.5px solid var(--gray-200);
  border-radius: 16px;
  padding: 8px 8px 8px 14px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px;
  align-items: end;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.composer:focus-within {
  border-color: var(--indigo-500);
  box-shadow: 0 0 0 4px rgba(101, 115, 196, 0.1);
}
.comp-btn {
  width: 32px; height: 32px;
  border-radius: 8px;
  color: var(--gray-500);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 2px;
  transition: background 0.15s;
}
.comp-btn:hover { background: var(--gray-100); color: var(--indigo-800); }
.comp-btn svg { width: 16px; height: 16px; }

#composer-input {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  resize: none;
  font-size: 14px;
  color: var(--gray-900);
  padding: 8px 0;
  line-height: 1.5;
  max-height: 180px;
}
#composer-input::placeholder { color: var(--gray-300); }

.comp-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}
.grounded-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  color: var(--indigo-700);
  background: var(--indigo-50);
  padding: 5px 9px;
  border-radius: 999px;
}
.grounded-chip svg { width: 11px; height: 11px; }

.send-btn {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: var(--indigo-800);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.15s;
}
.send-btn:hover:not(:disabled) { background: var(--indigo-900); transform: translateY(-1px); }
.send-btn:disabled { background: var(--gray-200); color: var(--gray-300); cursor: not-allowed; }
.send-btn svg { width: 16px; height: 16px; }

.comp-foot {
  max-width: 820px;
  margin: 6px auto 0;
  font-size: 11px;
  color: var(--gray-500);
  text-align: center;
}
