/* ── Design tokens ── */
:root {
  --ink: #2D3250;
  --ink-muted: #6B7094;
  --ink-faint: #A0A4BE;
  --surface: #FAFAFC;
  --surface-raised: #ffffff;
  --accent: #4A5899;
  --accent-soft: #E8ECFF;
  --accent-glow: rgba(74, 88, 153, 0.08);
  --border: rgba(45, 50, 80, 0.08);
  --border-strong: rgba(45, 50, 80, 0.14);
  --sidebar-bg: #1E2140;
  --sidebar-text: #C5C8E0;
  --sidebar-text-bright: #ECEDF5;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --success: #2E7D32;
  --error: #C62828;
}

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

body {
  font-family: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, sans-serif;
  color: var(--ink);
  background: var(--surface);
  min-height: 100vh;
  overflow: hidden;
}

h1, h2, h3 {
  font-family: "DM Serif Display", Georgia, serif;
  font-weight: 400;
}

/* ── Noise overlay ── */
.noise {
  position: fixed; inset: 0;
  pointer-events: none; z-index: 999;
  opacity: 0.03;
  background: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

/* ── Layout: sidebar + chat ── */
.layout {
  display: flex;
  height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  animation: slideIn 0.5s ease;
}

@keyframes slideIn {
  from { transform: translateX(-20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.sidebar-content {
  display: flex;
  flex-direction: column;
  height: 100%;
  padding: 24px 20px;
  overflow-y: auto;
}

/* Logo */
.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.logo-mark {
  color: var(--accent);
  flex-shrink: 0;
}

.logo-text {
  display: flex;
  flex-direction: column;
}

.logo-name {
  font-family: "DM Serif Display", Georgia, serif;
  font-size: 20px;
  color: var(--sidebar-text-bright);
  letter-spacing: -0.01em;
}

.logo-tag {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-faint);
  margin-top: 1px;
}

.sidebar-description {
  margin-bottom: 24px;
}

.sidebar-description p {
  font-size: 13px;
  line-height: 1.5;
  color: var(--sidebar-text);
}

/* Upload section */
.upload-section {
  margin-bottom: 20px;
}

.upload-section h3 {
  font-size: 13px;
  font-family: "IBM Plex Sans", sans-serif;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  margin-bottom: 10px;
}

.upload-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.upload-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 20px 16px;
  border: 1.5px dashed rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  color: var(--sidebar-text);
  font-size: 12px;
  text-align: center;
}

.upload-drop:hover,
.upload-drop.drag-over {
  border-color: var(--accent);
  background: rgba(74, 88, 153, 0.1);
}

.upload-btn {
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-family: "IBM Plex Sans", sans-serif;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}

.upload-btn:hover:not(:disabled) {
  background: #3D4A80;
}

.upload-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.upload-status {
  font-size: 12px;
  min-height: 16px;
  color: var(--sidebar-text);
}

.upload-status.success { color: #66BB6A; }
.upload-status.error { color: #EF5350; }

.usage-info {
  font-size: 11px;
  color: var(--ink-faint);
  margin-top: 4px;
}

/* Documents list */
.documents-section {
  margin-bottom: 20px;
  display: none;
}

.documents-section h3 {
  font-size: 13px;
  font-family: "IBM Plex Sans", sans-serif;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-faint);
  margin-bottom: 8px;
}

.documents-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.documents-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.05);
  font-size: 12px;
  gap: 6px;
}

.doc-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.doc-name {
  color: var(--sidebar-text-bright);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.doc-meta {
  color: var(--ink-faint);
  font-size: 11px;
}

.doc-delete {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--ink-faint);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, color 0.15s;
}

.doc-delete:hover {
  background: rgba(239, 83, 80, 0.2);
  color: #EF5350;
}

/* Sidebar footer */
.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.user-info {
  font-size: 13px;
  color: var(--sidebar-text-bright);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 160px;
}

.logout-link {
  font-size: 12px;
  color: var(--ink-faint);
  text-decoration: none;
  flex-shrink: 0;
}

.logout-link:hover {
  color: var(--sidebar-text-bright);
}

/* ── Chat area ── */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  background: var(--surface-raised);
  border-bottom: 1px solid var(--border);
  animation: fadeDown 0.4s ease;
}

@keyframes fadeDown {
  from { transform: translateY(-10px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

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

.header-agent-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.agent-avatar {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
}

.header-agent-info h1 {
  font-size: 16px;
  color: var(--ink);
}

.header-agent-info p {
  font-size: 12px;
  color: var(--ink-muted);
}

.header-actions {
  display: flex;
  align-items: center;
}

.connection-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(46, 125, 50, 0.08);
  font-size: 12px;
  color: #2E7D32;
}

.conn-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #2E7D32;
  animation: pulse 2s infinite;
}

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

.chat-container {
  flex: 1;
  display: flex;
  animation: fadeUp 0.5s ease;
}

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

/* ── Login page ── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.login-card {
  background: var(--surface-raised);
  border-radius: var(--radius-lg);
  padding: 48px 40px;
  max-width: 400px;
  width: 100%;
  text-align: center;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
  animation: fadeUp 0.5s ease;
}

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

.login-logo .logo-mark {
  display: inline-flex;
  margin-bottom: 16px;
}

.login-logo h1 {
  font-size: 28px;
  margin-bottom: 8px;
  color: var(--ink);
}

.login-logo p {
  font-size: 14px;
  color: var(--ink-muted);
  line-height: 1.5;
}

.google-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 24px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-raised);
  color: var(--ink);
  font-family: "IBM Plex Sans", sans-serif;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.google-btn:hover {
  border-color: var(--accent);
  box-shadow: 0 2px 8px var(--accent-glow);
}

.login-error {
  margin-top: 16px;
  font-size: 13px;
  color: var(--error);
  min-height: 20px;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar {
    display: none;
  }

  .chat-header {
    padding: 12px 16px;
  }

  .header-agent-info h1 {
    font-size: 14px;
  }
}
