/* ═══════════════════════════════════════════════════════════════════
   Design tokens
═══════════════════════════════════════════════════════════════════ */
:root {
  --bg:            #07070f;
  --bg-2:          #0e0e1a;
  --bg-3:          #141428;
  --surface:       rgba(255,255,255,0.04);
  --surface-hover: rgba(255,255,255,0.07);
  --border:        rgba(255,255,255,0.08);
  --border-focus:  rgba(99,102,241,0.6);

  --accent:        #6366f1;
  --accent-2:      #8b5cf6;
  --accent-glow:   rgba(99,102,241,0.25);

  --text-primary:  #f1f0ff;
  --text-secondary:#9892c8;
  --text-muted:    #5a5480;

  --user-bubble:   linear-gradient(135deg,#6366f1,#8b5cf6);
  --asst-bubble:   rgba(255,255,255,0.05);

  --success:       #22d3a5;
  --error:         #f87171;

  --radius-sm:     6px;
  --radius:        12px;
  --radius-lg:     18px;
  --radius-xl:     24px;

  --sidebar-w:     260px;
  --header-h:      60px;
  --input-h:       112px;

  --font-sans: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  --ease-spring: cubic-bezier(0.34,1.56,0.64,1);
  --ease-smooth: cubic-bezier(0.4,0,0.2,1);
}

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

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

/* ═══════════════════════════════════════════════════════════════════
   Animated background orbs
═══════════════════════════════════════════════════════════════════ */
.bg-orbs {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  overflow: hidden;
}

.orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(80px);
  opacity: 0.18;
  animation: drift 20s ease-in-out infinite;
}

.orb-1 {
  width: 600px; height: 600px;
  background: radial-gradient(circle, #6366f1, transparent 70%);
  top: -200px; left: -150px;
  animation-duration: 22s;
}
.orb-2 {
  width: 500px; height: 500px;
  background: radial-gradient(circle, #8b5cf6, transparent 70%);
  bottom: -150px; right: -100px;
  animation-duration: 28s;
  animation-delay: -8s;
}
.orb-3 {
  width: 350px; height: 350px;
  background: radial-gradient(circle, #06b6d4, transparent 70%);
  top: 40%; left: 60%;
  animation-duration: 35s;
  animation-delay: -14s;
  opacity: 0.1;
}

@keyframes drift {
  0%, 100% { transform: translate(0, 0) scale(1); }
  33%       { transform: translate(40px, -60px) scale(1.05); }
  66%       { transform: translate(-30px, 40px) scale(0.95); }
}

/* ═══════════════════════════════════════════════════════════════════
   App shell
═══════════════════════════════════════════════════════════════════ */
.app-shell {
  position: relative;
  z-index: 1;
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* ═══════════════════════════════════════════════════════════════════
   Sidebar
═══════════════════════════════════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100%;
  background: rgba(14,14,26,0.8);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s var(--ease-smooth), opacity 0.3s;
  z-index: 10;
}

.sidebar.collapsed {
  transform: translateX(calc(-1 * var(--sidebar-w)));
  opacity: 0;
  pointer-events: none;
}

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

.model-badge {
  display: flex;
  align-items: center;
  gap: 8px;
}

.model-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
  animation: pulse-dot 2.5s ease-in-out infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; box-shadow: 0 0 8px var(--success); }
  50%       { opacity: 0.6; box-shadow: 0 0 14px var(--success); }
}

.model-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 0.02em;
}

/* Conversation list */
.conversation-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.conversation-list::-webkit-scrollbar { width: 4px; }
.conversation-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.conv-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.15s, color 0.15s;
  border: 1px solid transparent;
  position: relative;
}
.conv-item:hover { background: var(--surface-hover); color: var(--text-primary); }
.conv-item.active {
  background: var(--surface-hover);
  color: var(--text-primary);
  border-color: var(--border);
}
.conv-item svg { flex-shrink: 0; opacity: 0.5; }

.conv-item .conv-delete {
  margin-left: auto;
  flex-shrink: 0;
  opacity: 0;
  transition: opacity 0.15s;
  cursor: pointer;
  color: var(--text-muted);
  background: none;
  border: none;
  padding: 2px;
  display: flex;
  align-items: center;
}
.conv-item:hover .conv-delete { opacity: 1; }
.conv-item .conv-delete:hover { color: var(--error); }

.conv-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.6;
}

.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.status-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}
.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--success);
  flex-shrink: 0;
  transition: background 0.3s;
}
.status-dot.error { background: var(--error); }
.status-dot.loading {
  background: #f59e0b;
  animation: pulse-dot 1.2s ease-in-out infinite;
}

/* ═══════════════════════════════════════════════════════════════════
   Chat area
═══════════════════════════════════════════════════════════════════ */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100%;
  overflow: hidden;
  transition: margin-left 0.3s var(--ease-smooth);
}

/* Header */
.chat-header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(7,7,15,0.6);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  flex-shrink: 0;
  z-index: 5;
}

.header-title {
  flex: 1;
  min-width: 0;
}

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

/* Messages */
.messages-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 24px 0 12px;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  display: flex;
  flex-direction: column;
}
.messages-container::-webkit-scrollbar { width: 5px; }
.messages-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

#messages-list { flex: 1; }

/* Welcome screen */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  padding: 40px 20px;
  text-align: center;
  animation: fade-up 0.6s var(--ease-smooth) both;
}
.welcome-screen.hidden { display: none; }

@keyframes fade-up {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

.welcome-logo {
  margin-bottom: 20px;
  filter: drop-shadow(0 0 40px var(--accent-glow));
  animation: logo-float 5s ease-in-out infinite;
}

@keyframes logo-float {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-6px); }
}

.welcome-title {
  font-size: 32px;
  font-weight: 700;
  background: linear-gradient(135deg, #f1f0ff, #9892c8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}

.welcome-subtitle {
  font-size: 15px;
  color: var(--text-secondary);
  margin-bottom: 40px;
}

.suggestion-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  max-width: 560px;
  width: 100%;
}

.suggestion-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: background 0.2s, border-color 0.2s, transform 0.2s var(--ease-spring);
  font-family: var(--font-sans);
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.5;
}
.suggestion-card:hover {
  background: var(--surface-hover);
  border-color: rgba(99,102,241,0.4);
  color: var(--text-primary);
  transform: translateY(-2px);
}
.suggestion-card:active { transform: translateY(0); }

.suggestion-icon { font-size: 20px; }

/* ── Messages ── */
.message-row {
  display: flex;
  gap: 14px;
  padding: 10px 24px;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  animation: message-in 0.3s var(--ease-smooth) both;
}

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

.message-row.user-row {
  flex-direction: row-reverse;
}

.message-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
  margin-top: 2px;
}

.assistant-avatar {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 0 16px var(--accent-glow);
}

.user-avatar {
  background: rgba(255,255,255,0.1);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.message-body { flex: 1; min-width: 0; }

.message-bubble {
  display: inline-block;
  max-width: 100%;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: 14.5px;
  line-height: 1.75;
  word-wrap: break-word;
}

.user-row .message-bubble {
  background: var(--user-bubble);
  color: #fff;
  border-bottom-right-radius: var(--radius-sm);
}

.assistant-row .message-bubble {
  background: var(--asst-bubble);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-bottom-left-radius: var(--radius-sm);
  width: 100%;
  display: block;
}

/* Markdown content inside bubbles */
.message-bubble h1,
.message-bubble h2,
.message-bubble h3 {
  margin: 16px 0 8px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
}
.message-bubble h1 { font-size: 1.25em; }
.message-bubble h2 { font-size: 1.1em; }
.message-bubble h3 { font-size: 1em; }

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

.message-bubble ul, .message-bubble ol {
  margin: 8px 0 8px 20px;
}
.message-bubble li { margin: 4px 0; }

.message-bubble a {
  color: #818cf8;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.message-bubble strong { font-weight: 600; }
.message-bubble em { font-style: italic; color: var(--text-secondary); }

.message-bubble blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 14px;
  margin: 10px 0;
  color: var(--text-secondary);
}

.message-bubble hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 12px 0;
}

.message-bubble table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
  font-size: 13px;
}
.message-bubble th,
.message-bubble td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: left;
}
.message-bubble th {
  background: rgba(255,255,255,0.06);
  font-weight: 600;
}

/* Code blocks */
.code-block-wrapper {
  position: relative;
  margin: 10px 0;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.1);
}

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  background: rgba(255,255,255,0.06);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.code-lang {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.btn-copy-code {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 11px;
  font-family: var(--font-sans);
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn-copy-code:hover { background: var(--surface-hover); color: var(--text-primary); }
.btn-copy-code.copied { color: var(--success); border-color: var(--success); }

.message-bubble pre {
  margin: 0;
  overflow-x: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.message-bubble pre code.hljs {
  padding: 14px 16px;
  background: #0d0d1a;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
}

.message-bubble code:not(.hljs) {
  font-family: var(--font-mono);
  font-size: 13px;
  background: rgba(255,255,255,0.08);
  padding: 2px 6px;
  border-radius: 4px;
  color: #c4b5fd;
}

/* Message meta */
.message-meta {
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-row .message-meta { flex-direction: row-reverse; }

.msg-time {
  font-size: 11px;
  color: var(--text-muted);
}

.btn-copy-msg {
  background: none;
  border: none;
  padding: 3px 6px;
  cursor: pointer;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  font-size: 11px;
  display: flex;
  align-items: center;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s, color 0.15s;
}
.message-row:hover .btn-copy-msg { opacity: 1; }
.btn-copy-msg:hover { color: var(--text-secondary); }

/* Typing indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 24px;
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
}
.typing-indicator.hidden { display: none; }

.typing-dots {
  display: flex;
  gap: 5px;
  padding: 14px 18px;
  background: var(--asst-bubble);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: var(--radius-sm);
}

.typing-dots span {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: bounce 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30%            { transform: translateY(-6px); opacity: 1; }
}

/* ── Streaming cursor ── */
.stream-cursor::after {
  content: '▍';
  animation: blink 0.8s step-end infinite;
  color: var(--accent);
  margin-left: 2px;
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0; }
}

/* ═══════════════════════════════════════════════════════════════════
   Input area
═══════════════════════════════════════════════════════════════════ */
.input-area {
  padding: 12px 24px 16px;
  background: rgba(7,7,15,0.7);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 10px 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
  max-width: 820px;
  margin: 0 auto;
}
.input-wrapper:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.chat-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14.5px;
  line-height: 1.6;
  resize: none;
  max-height: 200px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  placeholder-color: var(--text-muted);
}
.chat-input::placeholder { color: var(--text-muted); }

.input-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.char-count {
  font-size: 11px;
  color: var(--text-muted);
  transition: color 0.2s;
}
.char-count.warn { color: #f59e0b; }

.btn-send {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s var(--ease-spring), opacity 0.2s, box-shadow 0.2s;
  flex-shrink: 0;
}
.btn-send:not(:disabled):hover {
  transform: scale(1.1);
  box-shadow: 0 0 20px var(--accent-glow);
}
.btn-send:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-send.loading {
  pointer-events: none;
  animation: spin 1s linear infinite;
}
@keyframes spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

.input-disclaimer {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 10px;
  max-width: 820px;
  margin-left: auto;
  margin-right: auto;
}

/* ═══════════════════════════════════════════════════════════════════
   Buttons
═══════════════════════════════════════════════════════════════════ */
.btn-icon {
  width: 34px; height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: none;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.btn-icon:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
  border-color: var(--border);
}

.btn-clear:hover { color: var(--error) !important; }

/* ═══════════════════════════════════════════════════════════════════
   Toast notifications
═══════════════════════════════════════════════════════════════════ */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: rgba(20,20,40,0.95);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  color: var(--text-primary);
  font-size: 13px;
  max-width: 320px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
  animation: toast-in 0.3s var(--ease-spring) both;
  pointer-events: auto;
}
.toast.toast-out { animation: toast-out 0.25s var(--ease-smooth) forwards; }

@keyframes toast-in {
  from { opacity:0; transform: translateY(12px) scale(0.95); }
  to   { opacity:1; transform: translateY(0) scale(1); }
}
@keyframes toast-out {
  from { opacity:1; transform: translateY(0) scale(1); }
  to   { opacity:0; transform: translateY(6px) scale(0.95); }
}

.toast-icon { font-size: 16px; flex-shrink: 0; }

/* ═══════════════════════════════════════════════════════════════════
   Responsive
═══════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
  :root { --sidebar-w: 100vw; }

  .sidebar {
    position: fixed;
    inset: 0;
    width: 100vw;
    z-index: 100;
    transform: translateX(-100%);
    opacity: 0;
  }
  .sidebar.mobile-open {
    transform: translateX(0);
    opacity: 1;
  }
  .sidebar.collapsed {
    transform: translateX(-100%);
    opacity: 0;
  }

  .message-row { padding: 8px 14px; }
  .input-area { padding: 10px 14px 14px; }
  .suggestion-grid { grid-template-columns: 1fr; }
  .welcome-title { font-size: 24px; }
}

/* ═══════════════════════════════════════════════════════════════════
   Google Auth Box in Sidebar
═══════════════════════════════════════════════════════════════════ */
.google-auth-box {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.google-auth-box.hidden {
  display: none !important;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  padding: 8px 10px;
  border-radius: var(--radius);
}
.user-profile.hidden {
  display: none !important;
}

.user-pic {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
}

.user-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
  min-width: 0;
}

.user-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-signout {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 11px;
  cursor: pointer;
  text-align: left;
  padding: 0;
  transition: color 0.15s;
}
.btn-signout:hover {
  color: var(--error);
}

