/* ─── GP Light Theme Variables ─────────────────────────────────── */
:root {
  --bg-base: #f5f7fb;
  --bg-card: #ffffff;
  --bg-elevated: #f0f2f7;
  --bg-hover: #edf0f7;
  --bg-input: #ffffff;
  --text-primary: #1a202c;
  --text-secondary: #4b5563;
  --text-muted: #9ca3af;
  --border: #e2e5ed;
  --border-hover: #d1d5db;
  --gp-blue: #1478FF;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: rgba(79, 70, 229, 0.08);
  --success: #16a34a;
  --success-light: rgba(22, 163, 74, 0.08);
  --warning: #ca8a04;
  --error: #dc2626;
  --error-light: rgba(220, 38, 38, 0.08);
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,0.1);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --sidebar-width: 280px;
  --source-panel-width: 340px;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

/* ─── Reset & Base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--bg-base);
  -webkit-font-smoothing: antialiased;
}

/* ─── Layout ───────────────────────────────────────────────────── */
#app {
  display: flex;
  height: 100vh;
  width: 100vw;
}

/* ─── Sidebar ──────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-mark {
  width: 36px;
  height: 36px;
  background: var(--gp-blue);
  color: #fff;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  letter-spacing: -0.5px;
}

.logo-text { display: flex; flex-direction: column; }
.logo-title { font-weight: 600; font-size: 15px; color: var(--text-primary); }
.logo-subtitle { font-size: 11px; color: var(--text-muted); font-weight: 500; }

.conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.conversation-list::-webkit-scrollbar { width: 4px; }
.conversation-list::-webkit-scrollbar-track { background: transparent; }
.conversation-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.conv-item {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 150ms ease;
  margin-bottom: 2px;
}

.conv-item:hover { background: var(--bg-hover); }
.conv-item.active { background: var(--primary-light); }

.conv-item-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-item-date {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.admin-controls {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.admin-divider {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

/* ─── Main Chat Area ───────────────────────────────────────────── */
#chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
}

/* Welcome Screen */
.welcome-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.welcome-content {
  text-align: center;
  max-width: 520px;
}

.welcome-logo {
  width: 64px;
  height: 64px;
  background: var(--gp-blue);
  color: #fff;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 24px;
  margin-bottom: 20px;
}

.welcome-content h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 12px;
}

.welcome-content p {
  color: var(--text-secondary);
  font-size: 15px;
  line-height: 1.7;
  margin-bottom: 28px;
}

.welcome-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.suggestion-chip {
  padding: 8px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 150ms ease;
  font-family: var(--font-body);
}

.suggestion-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

/* Messages */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px 0;
}

.messages-container::-webkit-scrollbar { width: 6px; }
.messages-container::-webkit-scrollbar-track { background: transparent; }
.messages-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.messages {
  max-width: 780px;
  margin: 0 auto;
  padding: 0 24px;
}

.message {
  margin-bottom: 24px;
  animation: fadeIn 200ms ease;
}

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

.message-user {
  display: flex;
  justify-content: flex-end;
}

.message-user .message-bubble {
  background: var(--primary);
  color: #fff;
  border-radius: var(--radius-md) var(--radius-md) 4px var(--radius-md);
  padding: 12px 16px;
  max-width: 70%;
  font-size: 14px;
}

.message-assistant .message-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px var(--radius-md) var(--radius-md) var(--radius-md);
  padding: 16px 20px;
  font-size: 14px;
  line-height: 1.7;
  box-shadow: var(--shadow-sm);
}

.message-assistant .message-bubble h1,
.message-assistant .message-bubble h2,
.message-assistant .message-bubble h3 {
  font-size: 15px;
  font-weight: 600;
  margin: 16px 0 8px 0;
  color: var(--text-primary);
}

.message-assistant .message-bubble h2:first-child,
.message-assistant .message-bubble h3:first-child { margin-top: 0; }

.message-assistant .message-bubble p { margin-bottom: 10px; }
.message-assistant .message-bubble p:last-child { margin-bottom: 0; }

.message-assistant .message-bubble ul,
.message-assistant .message-bubble ol {
  padding-left: 20px;
  margin-bottom: 10px;
}

.message-assistant .message-bubble li { margin-bottom: 4px; }

.message-assistant .message-bubble table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 13px;
}

.message-assistant .message-bubble th,
.message-assistant .message-bubble td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 13px;
}

.message-assistant .message-bubble th {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 12px;
  text-transform: none;
  letter-spacing: 0;
  background: var(--bg-elevated);
  white-space: nowrap;
}

.message-assistant .message-bubble td:first-child {
  font-variant-numeric: tabular-nums;
}

.message-assistant .message-bubble code {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--bg-elevated);
  padding: 2px 5px;
  border-radius: 4px;
}

/* Source citations in text */
.citation {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 11px;
  font-weight: 600;
  border-radius: 4px;
  cursor: pointer;
  margin: 0 1px;
  vertical-align: super;
  line-height: 1;
  transition: all 150ms ease;
}

.citation:hover {
  background: var(--primary);
  color: #fff;
}

/* Feedback buttons */
.message-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--bg-elevated);
}

.feedback-btn {
  padding: 4px 8px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  transition: all 150ms ease;
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-body);
}

.feedback-btn:hover { border-color: var(--text-secondary); color: var(--text-secondary); }
.feedback-btn.active-up { background: var(--success-light); border-color: var(--success); color: var(--success); }
.feedback-btn.active-down { background: var(--error-light); border-color: var(--error); color: var(--error); }

/* Loading indicator */
.typing-indicator {
  display: inline-flex;
  gap: 5px;
  padding: 12px 4px;
  align-items: center;
}

.typing-dot {
  width: 6px;
  height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: typingBounce 1.2s infinite;
}

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

@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* ─── Input Area ───────────────────────────────────────────────── */
.input-area {
  padding: 0 24px 20px;
  max-width: 828px;
  margin: 0 auto;
  width: 100%;
}

.action-chips {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.action-chip {
  padding: 6px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 150ms ease;
  font-family: var(--font-body);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.action-chip:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

.chat-form { width: 100%; }

.input-wrapper {
  display: flex;
  align-items: flex-end;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 8px 8px 16px;
  transition: border-color 200ms ease, box-shadow 200ms ease;
  box-shadow: var(--shadow-sm);
}

.input-wrapper:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

#query-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-primary);
  resize: none;
  max-height: 120px;
  padding: 4px 0;
}

#query-input::placeholder { color: var(--text-muted); }

.send-btn {
  width: 36px;
  height: 36px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 150ms ease;
  flex-shrink: 0;
}

.send-btn:hover:not(:disabled) { background: var(--primary-hover); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.input-footer {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 8px;
}

/* ─── Source Panel ─────────────────────────────────────────────── */
.source-panel {
  width: 0;
  min-width: 0;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width 250ms ease, min-width 250ms ease;
}

.source-panel.open {
  width: var(--source-panel-width);
  min-width: var(--source-panel-width);
}

.source-panel-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.source-panel-header h3 {
  font-size: 14px;
  font-weight: 600;
}

.source-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
}

.source-list::-webkit-scrollbar { width: 4px; }
.source-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.source-empty {
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
  padding: 40px 20px;
}

.source-card {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 8px;
  transition: border-color 150ms ease;
}

.source-card:hover { border-color: var(--primary); }
.source-card.highlighted { border-color: var(--primary); background: var(--primary-light); }

.source-card-header {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 8px;
}

.source-index {
  width: 22px;
  height: 22px;
  background: var(--primary);
  color: #fff;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  flex-shrink: 0;
}

.source-doc-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.4;
}

.source-section {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  font-style: italic;
}

.source-excerpt {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.5;
  max-height: 60px;
  overflow: hidden;
  margin-bottom: 8px;
}

.source-download {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  font-family: var(--font-body);
}

.source-download:hover { text-decoration: underline; }

/* ─── Buttons ──────────────────────────────────────────────────── */
.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 150ms ease;
  font-family: var(--font-body);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-primary:hover { background: var(--primary-hover); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 150ms ease;
  font-family: var(--font-body);
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-ghost:hover { background: var(--bg-hover); border-color: var(--border-hover); }

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }
.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  border-radius: 4px;
  transition: all 150ms ease;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); }

/* ─── Modal ────────────────────────────────────────────────────── */
.modal[open] {
  border: none;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 0;
  max-width: 440px;
  width: 90vw;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
  z-index: 1000;
}

.modal::backdrop { background: rgba(0,0,0,0.3); backdrop-filter: blur(4px); }

.modal-content {
  padding: 24px;
}

.modal-content h3 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
}

.modal-content p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 16px;
}

.modal-content label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.modal-content input[type="email"],
.modal-content input[type="text"] {
  display: block;
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-family: var(--font-body);
  margin-top: 4px;
  outline: none;
  transition: border-color 200ms;
}

.modal-content input:focus { border-color: var(--primary); }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
}

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-md);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: all 200ms ease;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.upload-zone:hover { border-color: var(--primary); color: var(--primary); }
.upload-zone.dragover { border-color: var(--primary); background: var(--primary-light); }

.upload-status { margin-top: 12px; font-size: 13px; }

.invite-result {
  margin-top: 12px;
  padding: 12px;
  background: var(--success-light);
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.invite-result input {
  width: 100%;
  margin-top: 8px;
  padding: 6px 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg-card);
}

/* ─── Responsive ───────────────────────────────────────────────── */
@media (max-width: 900px) {
  #sidebar { width: 60px; min-width: 60px; }
  .sidebar-header { padding: 12px; }
  .logo-text, #new-chat-btn span, .conv-item-title, .conv-item-date,
  .admin-controls { display: none; }
  #new-chat-btn { padding: 6px; }
  .source-panel.open { width: 280px; min-width: 280px; }
}
