:root {
  --bg: #0a0a0a;
  --bg-card: rgba(20,22,30,0.8);
  --surface: #111;
  --surface-hover: #1a1a1a;
  --border: rgba(255,255,255,0.08);
  --border-strong: rgba(255,255,255,0.14);
  --text: #fff;
  --text-primary: #f0f0f5;
  --text-secondary: #a0a0b0;
  --text-muted: #6c6c7a;
  --accent: #60a5fa;
  --accent-cyan: #22d3ee;
  --accent-green: #34d399;
  --radius: 16px;
  --radius-sm: 12px;
  --radius-xs: 8px;
  --shadow-lg: 0 20px 60px rgba(0,0,0,0.5);
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Space Grotesk', sans-serif;
  --error: #ef4444;
  --success: #22c55e;
}

* { margin:0; padding:0; box-sizing:border-box; }

html, body {
  height: 100%;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

/* ---- Starfield canvas ---- */
#starfield {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
}

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

.login-container {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 48px 40px;
  box-shadow: var(--shadow-lg);
}

.login-brand {
  text-align: center;
  margin-bottom: 32px;
}

.logo-ring {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 1.5px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
  background: var(--surface);
  overflow: hidden;
}

.logo-ring.small {
  width: 36px;
  height: 36px;
}

.logo-ring.large {
  width: 80px;
  height: 80px;
  margin-bottom: 20px;
}

.logo-ring img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.login-brand h1 {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.tagline {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 6px;
}

.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-group input {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color .2s;
}

.form-group input:focus {
  border-color: var(--accent);
}

#login-btn {
  width: 100%;
  padding: 14px;
  border-radius: var(--radius-xs);
  border: none;
  background: var(--accent);
  color: #0a0a0a;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

#login-btn:disabled {
  opacity: .6;
  cursor: default;
}

.btn-loader {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(0,0,0,0.2);
  border-top-color: #0a0a0a;
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.error-msg {
  margin-top: 12px;
  font-size: 13px;
  color: var(--error);
  text-align: center;
  min-height: 18px;
}

.login-footer {
  margin-top: 28px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.status-dot.online { background: var(--accent-green); box-shadow: 0 0 8px var(--accent-green); }

/* ---- Google Sign-In ---- */
.divider {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 20px 0;
  color: var(--text-secondary);
  font-size: 13px;
}
.divider span {
  flex: 1;
  height: 1px;
  background: var(--border);
}
.google-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 12px 16px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  text-decoration: none;
  transition: all .2s ease;
  cursor: pointer;
}
.google-btn:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

/* ---- Chat page layout ---- */
.chat-body {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: 280px;
  height: 100%;
  background: rgba(10,10,10,0.6);
  backdrop-filter: blur(12px);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px;
  transition: transform .3s ease;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
}

.sidebar-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
}

.sidebar-close {
  display: none;
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 22px;
  cursor: pointer;
}

.new-conv-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 10px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: 12px;
  transition: background .2s;
}

.new-conv-btn:hover { background: var(--surface-hover); }

.conv-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 12px;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-xs);
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-item:hover, .conv-item.active {
  background: var(--surface-hover);
  color: var(--text);
}

.conv-item svg {
  flex-shrink: 0;
  opacity: .6;
}

.sidebar-nav {
  margin-bottom: 12px;
}

.nav-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  margin-bottom: 8px;
  padding-left: 4px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-xs);
  font-size: 13px;
  color: var(--text-secondary);
  text-decoration: none;
  transition: background .15s, color .15s;
}

.nav-link:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.nav-link svg { flex-shrink: 0; opacity: .6; }

.sidebar-footer {
  margin-top: auto;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.model-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.sidebar-actions {
  display: flex;
  gap: 8px;
}

.sidebar-actions button {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  transition: all .15s;
}

.sidebar-actions button:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 40;
  display: none;
}

.sidebar-overlay.open { display: block; }

/* ---- Chat main area ---- */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  margin-left: 0;
  position: relative;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(10,10,10,0.6);
  backdrop-filter: blur(12px);
}

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

.chat-header h1 {
  font-family: var(--font-display);
  font-size: 16px;
  font-weight: 600;
}

#user-display {
  font-size: 13px;
  color: var(--text-secondary);
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--surface);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .15s, color .15s;
}

.icon-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}

/* ---- Messages ---- */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.message {
  display: flex;
  flex-direction: column;
  max-width: 82%;
  animation: fadeIn .25s ease;
}

.message.user { align-self: flex-end; }
.message.assistant { align-self: flex-start; }

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

.message-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 4px;
  font-weight: 500;
}

.message-content {
  padding: 14px 18px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 14.5px;
  line-height: 1.65;
  color: var(--text-primary);
  word-break: break-word;
}

.message.user .message-content {
  background: var(--accent);
  color: #0a0a0a;
  border-color: transparent;
}

.message-content.streaming {
  border-left: 3px solid var(--accent-cyan);
}

.message-content.markdown-body pre {
  background: rgba(0,0,0,0.3);
  padding: 12px;
  border-radius: var(--radius-xs);
  overflow-x: auto;
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 13px;
  margin: 8px 0;
}

.message-content.markdown-body code {
  background: rgba(0,0,0,0.3);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'SF Mono', Monaco, monospace;
  font-size: 13px;
}

.message-content.markdown-body p { margin-bottom: 10px; }
.message-content.markdown-body p:last-child { margin-bottom: 0; }

.msg-file-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.msg-file-chip {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 20px;
  background: rgba(255,255,255,0.08);
  color: var(--text-secondary);
}

/* ---- Welcome ---- */
.welcome-msg {
  align-self: center;
  text-align: center;
  margin-top: auto;
  margin-bottom: auto;
}

.welcome-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.welcome-hero h2 {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 8px;
}

.welcome-hero p {
  color: var(--text-secondary);
  font-size: 15px;
  margin-bottom: 24px;
}

.welcome-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
}

.pill {
  padding: 8px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all .2s;
}

.pill:hover {
  background: var(--surface-hover);
  color: var(--text);
  border-color: var(--border-strong);
}

/* ---- Upload bar ---- */
.upload-bar {
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
}

.upload-details summary {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  user-select: none;
  list-style: none;
}

.upload-details summary::-webkit-details-marker { display: none; }

.upload-fields {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.upload-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.upload-field label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.upload-field select, .upload-field input[type="file"] {
  padding: 8px 10px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  outline: none;
}

#upload-btn {
  padding: 10px 16px;
  border-radius: var(--radius-xs);
  border: none;
  background: var(--accent);
  color: #0a0a0a;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

#upload-status {
  margin-top: 10px;
  font-size: 13px;
}

/* ---- Input area ---- */
.chat-input-area {
  padding: 14px 24px 20px;
  border-top: 1px solid var(--border);
  background: rgba(10,10,10,0.6);
  backdrop-filter: blur(12px);
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

#message-input {
  flex: 1;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  resize: none;
  outline: none;
  max-height: 150px;
  min-height: 46px;
  line-height: 1.5;
  font-family: inherit;
}

#message-input:focus { border-color: var(--accent); }

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #0a0a0a;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform .15s;
  flex-shrink: 0;
}

.send-btn:hover { transform: scale(1.05); }

.send-btn:disabled { opacity: .5; transform: none; cursor: default; }

.file-chips {
  display: none;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 12px;
  color: var(--text-secondary);
}

.file-chip button {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  line-height: 1;
}

.file-chip button:hover { color: var(--text); }

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

/* ---- Typing indicator ---- */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 24px;
  margin-bottom: 8px;
}

.typing-bubble {
  display: flex;
  align-items: center;
  gap: 4px;
}

.typing-bubble span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: bounce 1.4s infinite ease-in-out both;
}

.typing-bubble span:nth-child(1) { animation-delay: -0.32s; }
.typing-bubble span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}

.typing-label {
  font-size: 12px;
  color: var(--text-muted);
}

/* ---- Vault graph ---- */
.vault-graph-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--bg);
  display: none;
  flex-direction: column;
}

.vault-graph-overlay.open { display: flex; }

.vault-graph-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(10,10,10,0.8);
  backdrop-filter: blur(12px);
}

.vault-graph-toolbar h2 {
  font-family: var(--font-display);
  font-size: 16px;
}

.vault-graph-controls {
  display: flex;
  align-items: center;
  gap: 12px;
}

.vault-graph-controls select {
  padding: 6px 10px;
  border-radius: var(--radius-xs);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
}

.vault-graph-controls button {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 24px;
  cursor: pointer;
}

.vault-graph-container {
  flex: 1;
  position: relative;
}

.vault-graph-info {
  position: absolute;
  bottom: 24px;
  left: 24px;
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  max-width: 380px;
  max-height: 320px;
  overflow-y: auto;
  font-size: 13px;
  color: var(--text-primary);
  display: none;
  z-index: 1000;
  line-height: 1.6;
  white-space: pre-wrap;
  box-shadow: var(--shadow-lg);
}

.vault-graph-info .info-title {
  color: var(--accent-cyan);
  font-weight: 700;
  font-size: 14px;
  margin-bottom: 6px;
  font-family: var(--font-display);
}

.vault-graph-info .info-group {
  color: var(--text-muted);
  font-size: 11px;
  margin-bottom: 10px;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); position: fixed; z-index: 50; }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close { display: block; }
  .chat-main { margin-left: 0 !important; }
  .message { max-width: 92%; }
  .chat-header { padding: 10px 14px; }
  .chat-messages { padding: 14px; }
  .welcome-hero h2 { font-size: 24px; }
  .vault-graph-info { max-width: 90vw; left: 12px; bottom: 12px; }
}

@media (max-width: 480px) {
  .login-container { margin: 16px; padding: 32px 24px; }
  .welcome-pills { gap: 6px; }
  .pill { font-size: 12px; padding: 6px 10px; }
}
