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

:root {
  --bg: #0d0f13;
  --surface: #13161e;
  --surface2: #1a1e28;
  --border: #252836;
  --accent: #7c5cfc;
  --accent2: #a78bfa;
  --text: #e8eaf0;
  --muted: #6b7280;
  --user-bubble: #1e1b4b;
  --ai-bubble: #161b27;
  --success: #34d399;
  --danger: #f87171;
  --radius: 16px;
}

html, body {
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

body { display: flex; }

/* ── Sidebar ── */
#sidebar {
  width: 270px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-top {
  padding: 22px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-top h2 {
  font-size: 16px;
  font-weight: 700;
  color: var(--accent2);
  letter-spacing: .3px;
  margin-bottom: 2px;
}

.sidebar-top p {
  font-size: 11px;
  color: var(--muted);
}

.sidebar-body { padding: 16px 16px; flex: 1; display: flex; flex-direction: column; gap: 20px; }

.s-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

/* Tone buttons */
.tone-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
}

.tone-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 12px;
  padding: 8px 4px;
  min-height: 44px;
  cursor: pointer;
  transition: all .18s;
  text-align: center;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.tone-btn:hover { border-color: var(--accent); color: var(--accent2); }
.tone-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.tone-btn.full { grid-column: span 2; }

/* Voice toggle */
.voice-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.voice-row span { font-size: 13px; color: var(--text); }

.toggle {
  position: relative;
  width: 42px;
  height: 22px;
  cursor: pointer;
}

.toggle input { display: none; }

.toggle-track {
  position: absolute;
  inset: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 11px;
  transition: background .2s;
}

.toggle input:checked + .toggle-track { background: var(--accent); border-color: var(--accent); }

.toggle-thumb {
  position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  background: #fff;
  border-radius: 50%;
  transition: left .2s;
}

.toggle input:checked ~ .toggle-thumb { left: 23px; }

/* ── Session list ── */
.sessions-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sessions-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.new-chat-btn {
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  min-height: 44px;
  cursor: pointer;
  transition: background .18s;
  white-space: nowrap;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.new-chat-btn:hover { background: var(--accent2); }

.sessions-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 200px;
  overflow-y: auto;
}

.session-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border-radius: 9px;
  cursor: pointer;
  transition: background .15s;
  position: relative;
  border: 1px solid transparent;
}

.session-item:hover { background: var(--surface2); border-color: var(--border); }

.session-item.active {
  background: rgba(124, 92, 252, 0.15);
  border-color: rgba(124, 92, 252, 0.35);
}

.session-item-icon {
  font-size: 13px;
  flex-shrink: 0;
  opacity: .6;
}

.session-item-info {
  flex: 1;
  min-width: 0;
}

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

.session-item.active .session-item-title { color: var(--accent2); }

.session-item-date {
  font-size: 10px;
  color: var(--muted);
  margin-top: 1px;
}

.session-item-share {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 13px;
  cursor: pointer;
  padding: 0 2px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity .15s, color .15s;
  line-height: 1;
}

.session-item:hover .session-item-share { opacity: 1; }
.session-item-share:hover { color: var(--accent2); }

.session-item-menu {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  padding: 0 2px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity .15s;
  line-height: 1;
}

.session-item:hover .session-item-menu { opacity: 1; }

/* Session context menu dropdown */
.session-ctx-menu {
  position: fixed;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
  z-index: 9999;
  min-width: 140px;
  padding: 4px 0;
  animation: fadeInDown .12s ease;
}

.session-ctx-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 8px 14px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: background .12s;
}

.session-ctx-menu button:hover { background: var(--surface); }
.session-ctx-menu button.danger { color: var(--danger); }

.sessions-empty {
  font-size: 11px;
  color: var(--muted);
  font-style: italic;
  padding: 4px 2px;
}

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

/* Memory panel */
#memory-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 160px;
  overflow-y: auto;
}

.mem-item {
  font-size: 12px;
  color: var(--muted);
  padding: 6px 10px;
  background: var(--surface2);
  border-radius: 8px;
  border: 1px solid var(--border);
  line-height: 1.4;
}

.empty-mem { font-size: 12px; color: var(--muted); font-style: italic; }

/* Action buttons */
.action-btn {
  width: 100%;
  padding: 9px 14px;
  min-height: 44px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  text-align: left;
  transition: all .18s;
  display: flex;
  align-items: center;
  gap: 7px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.action-btn:hover { border-color: var(--accent); color: var(--accent2); }
.action-btn.danger:hover { border-color: var(--danger); color: var(--danger); }

/* ── Main area ── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100%;
  height: 100dvh;
}

/* Header */
#header {
  padding: 14px 22px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

#menu-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
  padding: 0 6px 0 0;
  line-height: 1;
  flex-shrink: 0;
}

.header-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #6366f1);
  display: flex; align-items: center; justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
}

.header-info { flex: 1; min-width: 0; }
.header-info h1 { font-size: 15px; font-weight: 700; }
.header-info p { font-size: 11px; color: var(--muted); margin-top: 1px; }

#status-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
  transition: background .3s;
}

#status-dot.online { background: var(--success); box-shadow: 0 0 6px var(--success); }
#status-dot.offline { background: var(--danger); }

#header-signout-btn {
  flex-shrink: 0;
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  padding: 4px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: color .15s, border-color .15s;
  white-space: nowrap;
}

#header-signout-btn:hover {
  color: var(--danger);
  border-color: var(--danger);
}

/* Messages */
#messages {
  flex: 1;
  overflow-y: auto;
  padding: 22px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 0;
}

.msg-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  max-width: 820px;
}

.msg-row.user { flex-direction: row-reverse; align-self: flex-end; }

.msg-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--surface2);
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
}

.msg-row.user .msg-avatar {
  background: linear-gradient(135deg, var(--accent), #6366f1);
  border: none;
}

.bubble {
  max-width: 68%;
  padding: 11px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.55;
  border: 1px solid var(--border);
}

.msg-row.ai .bubble {
  background: var(--ai-bubble);
  border-radius: 4px 18px 18px 18px;
}

.msg-row.user .bubble {
  background: var(--user-bubble);
  border-radius: 18px 18px 4px 18px;
  border-color: #312e81;
}

/* Welcome */
#welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px;
  gap: 8px;
  flex: 1;
}

#welcome h3 { font-size: 22px; font-weight: 700; color: var(--text); }
#welcome p { font-size: 14px; color: var(--muted); max-width: 340px; line-height: 1.6; margin-top: 4px; }
#welcome .chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 14px; }
#welcome .chip {
  padding: 7px 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface2);
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  transition: all .18s;
}
#welcome .chip:hover { border-color: var(--accent); color: var(--accent2); }

/* Input area */
#input-area {
  padding: 12px 18px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
}

#input-wrap {
  flex: 1;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px 12px;
  display: flex;
  align-items: flex-end;
  transition: border-color .2s;
}

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

#msg-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  max-height: 120px;
  min-height: 22px;
  line-height: 1.5;
}

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

#talk-btn, #send-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 19px;
  flex-shrink: 0;
  transition: all .18s;
}

#talk-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--text);
}

#talk-btn.listening {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
  animation: pulse 1.2s infinite;
}

#talk-btn.mic-unsupported {
  opacity: 0.4;
  cursor: not-allowed;
  pointer-events: none;
}

#send-btn {
  background: var(--accent);
  color: #fff;
}

#send-btn:hover { background: var(--accent2); }
#send-btn:disabled { opacity: .45; cursor: default; }

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(248,113,113,.4); }
  50% { box-shadow: 0 0 0 8px rgba(248,113,113,0); }
}

/* Typing indicator */
.typing-bubble {
  background: var(--ai-bubble);
  border: 1px solid var(--border);
  border-radius: 4px 18px 18px 18px;
  padding: 11px 16px;
  display: flex;
  gap: 5px;
  align-items: center;
}

.dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: bounce .9s ease-in-out infinite;
}
.dot:nth-child(2) { animation-delay: .18s; }
.dot:nth-child(3) { animation-delay: .36s; }

@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

/* Overlay */
#sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 99;
}
#sidebar-overlay.visible { display: block; }

/* ── Mobile ── */
@media (max-width: 640px) {
  #menu-btn { display: block; }

  #sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100%; height: 100dvh;
    width: 82vw;
    max-width: 300px;
    z-index: 100;
    transform: translateX(-110%);
    transition: transform .28s ease;
    box-shadow: 6px 0 28px rgba(0,0,0,.6);
  }

  #sidebar.open { transform: translateX(0); }
  #main { width: 100%; }

  #header { padding: 10px 14px; gap: 8px; }
  #header h1 { font-size: 14px; }
  #header p { font-size: 10px; }
  .header-avatar { width: 30px; height: 30px; font-size: 14px; }

  #messages { padding: 14px 12px; gap: 10px; }
  .bubble { max-width: 86%; font-size: 13px; padding: 9px 13px; }
  .msg-avatar { width: 24px; height: 24px; font-size: 12px; }

  #input-area { padding: 8px 10px; padding-bottom: calc(8px + env(safe-area-inset-bottom)); gap: 6px; }
  #talk-btn, #send-btn { width: 40px; height: 40px; font-size: 17px; }

  #welcome h3 { font-size: 18px; }
  #welcome p { font-size: 13px; }
  #welcome .chips { gap: 6px; }
  #welcome .chip { font-size: 11px; padding: 6px 12px; }
}

/* ── Web search UI ── */

/* Column wrapper used when a response includes a live badge or citations */
.msg-content {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-width: 72%;
  min-width: 0;
  align-items: flex-start;
}

.msg-content .bubble {
  max-width: 100%;
}

/* "🌐 Live" pill shown above the AI bubble */
.live-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .6px;
  text-transform: uppercase;
  color: #34d399;
  padding: 2px 8px;
  border: 1px solid rgba(52, 211, 153, 0.28);
  border-radius: 20px;
  background: rgba(52, 211, 153, 0.07);
  flex-shrink: 0;
}

/* Citation chips below the AI bubble */
.citations {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 2px;
}

.cite-link {
  font-size: 10px;
  color: var(--accent2);
  text-decoration: none;
  padding: 2px 9px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface2);
  transition: border-color .15s, color .15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

.cite-link:hover {
  border-color: var(--accent);
  color: var(--accent2);
  background: rgba(124, 92, 252, 0.08);
}

/* ── Markdown-rendered bubble content ── */
.md-bubble { line-height: 1.6; }

.md-bubble p { margin: 0 0 8px; }
.md-bubble p:last-child { margin-bottom: 0; }

.md-bubble h1, .md-bubble h2, .md-bubble h3,
.md-bubble h4, .md-bubble h5, .md-bubble h6 {
  font-weight: 700;
  line-height: 1.3;
  margin: 10px 0 4px;
  color: var(--accent2);
}
.md-bubble h1 { font-size: 1.15em; }
.md-bubble h2 { font-size: 1.08em; }
.md-bubble h3 { font-size: 1em; }

.md-bubble ul, .md-bubble ol {
  margin: 6px 0 8px 18px;
  padding: 0;
}
.md-bubble li { margin: 3px 0; }

.md-bubble strong { font-weight: 700; color: var(--text); }
.md-bubble em     { font-style: italic; color: var(--accent2); }

.md-bubble code {
  background: rgba(124,92,252,0.12);
  border: 1px solid rgba(124,92,252,0.2);
  border-radius: 4px;
  padding: 1px 6px;
  font-family: 'Fira Code', 'Cascadia Code', Consolas, monospace;
  font-size: 0.88em;
  color: #c4b5fd;
}

.md-bubble pre {
  background: rgba(10,8,30,0.7);
  border: 1px solid rgba(124,92,252,0.2);
  border-radius: 8px;
  padding: 12px 14px;
  overflow-x: auto;
  margin: 8px 0;
}
.md-bubble pre code {
  background: none;
  border: none;
  padding: 0;
  font-size: 0.85em;
  color: #d4d4ff;
}

.md-bubble blockquote {
  border-left: 3px solid var(--accent);
  margin: 8px 0;
  padding: 4px 12px;
  color: var(--muted);
  font-style: italic;
}

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

.md-bubble a { color: var(--accent2); }

/* "Searching the web…" placeholder bubble */
.searching-bubble {
  font-size: 13px;
  font-style: italic;
  color: #34d399;
  border-color: rgba(52, 211, 153, 0.22);
  background: rgba(52, 211, 153, 0.05);
  animation: pulse-search 1.6s ease-in-out infinite;
}

@keyframes pulse-search {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.55; }
}

/* ── Attach button ── */
#attach-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all .18s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#attach-btn:hover { border-color: var(--accent); color: var(--accent2); }
#attach-btn.has-file { border-color: var(--success); color: var(--success); }

#screenshot-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 1px solid rgba(124,92,252,0.45);
  background: rgba(124,92,252,0.1);
  color: var(--accent2);
  font-size: 20px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all .18s;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
#screenshot-btn:hover { border-color: var(--accent); background: rgba(124,92,252,0.2); color: #c4b5fd; }
#screenshot-btn.has-file { border-color: var(--success); background: rgba(52,211,153,0.1); color: var(--success); }

/* ── Attach preview bar (above input area) ── */
#attach-preview {
  padding: 0 18px;
  background: var(--surface);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

#attach-preview:empty { padding: 0; }

#ab-attach-preview {
  padding: 0 18px;
  background: var(--surface);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
#ab-attach-preview:empty { padding: 0; }

.ab-attach-chip {
  border-color: rgba(124,92,252,0.5);
  background: rgba(124,92,252,0.08);
}

.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 5px 10px 5px 8px;
  max-width: 280px;
  animation: chipIn .18s ease;
}

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

.attach-chip-thumb {
  width: 40px; height: 40px;
  border-radius: 8px;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid var(--border);
}

.attach-chip-icon {
  font-size: 22px;
  flex-shrink: 0;
}

.attach-chip-name {
  font-size: 12px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 160px;
}

.attach-chip-remove {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  padding: 0;
  line-height: 1;
  flex-shrink: 0;
  transition: color .15s;
}

.attach-chip-remove:hover { color: var(--danger); }

.attach-error {
  font-size: 12px;
  color: var(--danger);
  padding: 6px 4px;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ── Attachment rendering in user bubbles ── */
.bubble-image {
  display: block;
  max-width: 260px;
  max-height: 200px;
  border-radius: 10px;
  object-fit: cover;
  margin-bottom: 6px;
  border: 1px solid rgba(255,255,255,0.12);
}

.bubble-file-preview {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 6px;
  max-width: 320px;
}

.bubble-file-label {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  font-size: 12px;
}

.bubble-file-icon { font-size: 16px; flex-shrink: 0; }
.bubble-file-name {
  color: var(--accent2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
  font-weight: 600;
}

.bubble-file-code {
  margin: 0;
  padding: 8px 10px;
  background: rgba(0,0,0,0.25);
  font-size: 11px;
  line-height: 1.5;
  color: rgba(220,220,255,0.75);
  font-family: 'Courier New', 'Consolas', monospace;
  overflow-x: auto;
  max-height: 140px;
  overflow-y: auto;
  white-space: pre;
}

.bubble-text { margin-top: 2px; }

/* Drag-over highlight on messages area */
#messages.drag-over {
  outline: 2px dashed var(--accent);
  outline-offset: -6px;
  background: rgba(124, 92, 252, 0.04);
}

/* Mobile attachment adjustments */
@media (max-width: 640px) {
  #attach-btn, #screenshot-btn { width: 40px; height: 40px; font-size: 18px; }
  #attach-preview, #ab-attach-preview { padding: 0 10px; }
  .attach-chip-thumb { width: 34px; height: 34px; }
  .bubble-image { max-width: 200px; max-height: 160px; }
}

/* ── App Builder toggle button ── */
.app-builder-toggle { position: relative; }
.app-builder-toggle.active {
  background: rgba(124, 92, 252, 0.18);
  border-color: var(--accent);
  color: var(--accent2);
  font-weight: 600;
}

/* ── Play bar beneath AI code blocks ── */
.sandbox-play-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255,255,255,0.07);
}

.sandbox-play-btn {
  padding: 5px 14px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .3px;
  transition: all .17s;
  background: var(--accent);
  color: #fff;
}

.sandbox-play-btn:hover { background: var(--accent2); }
.sandbox-play-btn.sb-secondary {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--accent2);
}
.sandbox-play-btn.sb-secondary:hover { border-color: var(--accent); }

/* ── Sandbox panel (slide in from right) ── */
.sandbox-panel {
  position: fixed;
  top: 0; right: 0;
  width: min(680px, 96vw);
  height: 100%; height: 100dvh;
  background: #0f1117;
  border-left: 1px solid var(--border);
  z-index: 300;
  display: flex;
  flex-direction: column;
  transform: translateX(105%);
  transition: transform .3s cubic-bezier(.4,0,.2,1);
  box-shadow: -8px 0 40px rgba(0,0,0,.6);
}

.sandbox-panel.open { transform: translateX(0); }

#sandbox-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 299;
}

#sandbox-overlay.visible { display: block; }

.sandbox-titlebar {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  gap: 8px;
  min-width: 0;
}

.sandbox-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 140px;
  flex-shrink: 0;
}

.sandbox-controls {
  display: flex;
  gap: 6px;
  align-items: center;
  flex: 1;
  overflow-x: auto;
  min-width: 0;
  scrollbar-width: none;
}
.sandbox-controls::-webkit-scrollbar { display: none; }

/* Always-visible close button — sits outside the scrollable controls */
.sb-close-fixed {
  flex-shrink: 0;
  margin-left: 4px;
}

.sb-btn {
  padding: 4px 10px;
  min-height: 36px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.sb-btn:hover { border-color: var(--accent); color: var(--accent2); }
.sb-btn.active { background: rgba(124,92,252,.2); border-color: var(--accent); color: var(--accent2); }
.sb-btn.sb-close { color: var(--muted); }
.sb-btn.sb-close:hover { border-color: var(--danger); color: var(--danger); }
.sb-btn.sb-btn-ai { border-color: var(--accent); color: var(--accent2); background: rgba(124,92,252,.12); }
.sb-btn.sb-btn-ai:hover { background: rgba(124,92,252,.25); }
.sb-btn.sb-btn-fix { border-color: #f59e0b; color: #fbbf24; background: rgba(245,158,11,.1); }
.sb-btn.sb-btn-fix:hover { background: rgba(245,158,11,.22); }
.sb-btn.sb-btn-dpad { border-color: #34d399; color: #34d399; background: rgba(52,211,153,.08); }
.sb-btn.sb-btn-dpad:hover { background: rgba(52,211,153,.2); }
.sb-btn.sb-btn-dpad.active { background: rgba(52,211,153,.18); border-color: #34d399; }
.sb-btn.sb-btn-dpad:not(.active) { opacity: 0.5; }

.sandbox-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

/* ── Split (side-by-side) layout ── */
.sandbox-body.split {
  flex-direction: row;
}

.sandbox-iframe {
  flex: 1;
  width: 100%;
  border: none;
  background: #fff;
  min-height: 0;
  min-width: 0;
}

/* ── Right pane: wraps console + editor together ── */
.sandbox-right-pane {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* Bottom layout default */
  width: 100%;
  height: 38%;
  border-top: 1px solid var(--border);
}

/* Split layout: right-side panel */
.sandbox-body.split .sandbox-right-pane {
  width: 40%;
  height: 100%;
  border-top: none;
  border-left: 1px solid var(--border);
}

.sandbox-editor-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #0a0c10;
  border-top: 1px solid var(--border);
}

.sandbox-editor-row {
  flex: 1;
  display: flex;
  min-height: 0;
}

.sandbox-tab-bar {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 2px;
  padding: 4px 6px 0;
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
}

.sandbox-tab-bar::-webkit-scrollbar { display: none; }

.sandbox-tab {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  color: var(--muted);
  font-size: 11px;
  font-family: 'Courier New', monospace;
  padding: 5px 13px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s;
}

.sandbox-tab:hover { background: var(--surface); color: var(--text); }
.sandbox-tab.active { background: #0a0c10; color: var(--accent2); border-color: var(--accent); }
.sandbox-tab.dirty::after { content: '●'; font-size: 7px; color: #f39c12; margin-left: 5px; vertical-align: super; }

/* When console is NOT open, editor wrap sits at top of right pane — no top border */
.sandbox-right-pane:not(.console-open) .sandbox-editor-wrap {
  border-top: none;
}

/* ── Resize handle ── */
.sandbox-resize-handle {
  flex-shrink: 0;
  background: var(--border);
  transition: background .15s;
  z-index: 2;
}

/* Horizontal handle (bottom layout) */
.sandbox-body:not(.split) .sandbox-resize-handle {
  height: 4px;
  width: 100%;
  cursor: ns-resize;
}

/* Vertical handle (split layout) */
.sandbox-body.split .sandbox-resize-handle {
  width: 4px;
  height: 100%;
  cursor: ew-resize;
}

.sandbox-resize-handle:hover,
.sandbox-resize-handle.dragging {
  background: var(--accent);
}

/* ── Mobile: force split back to column layout on narrow screens ── */
@media (max-width: 900px) {
  .sandbox-body.split {
    flex-direction: column;
  }
  .sandbox-body.split .sandbox-right-pane {
    width: 100%;
    height: 38%;
    border-left: none;
    border-top: 1px solid var(--border);
  }
  .sandbox-body.split .sandbox-resize-handle {
    width: 100%;
    height: 4px;
    cursor: ns-resize;
  }
}

.sandbox-ln-gutter {
  width: 42px;
  flex-shrink: 0;
  background: #0a0c10;
  color: #3d4a5c;
  font-family: 'Courier New', 'Consolas', monospace;
  font-size: 12px;
  line-height: 1.6;
  padding: 12px 6px 12px 0;
  text-align: right;
  overflow: hidden;
  user-select: none;
  border-right: 1px solid #1a1e28;
  white-space: pre;
}

.sandbox-editor {
  flex: 1;
  background: #0a0c10;
  color: #c9d1d9;
  border: none;
  outline: none;
  font-family: 'Courier New', 'Consolas', monospace;
  font-size: 12px;
  line-height: 1.6;
  padding: 12px 14px;
  resize: none;
  tab-size: 2;
  overflow: auto;
}

/* ── App Library overlay ── */
.library-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.75);
  z-index: 400;
  align-items: center;
  justify-content: center;
}

.library-overlay.open { display: flex; }

.library-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  width: min(860px, 96vw);
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,.7);
}

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

.library-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent2);
}

.library-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  transition: color .15s;
}

.library-close:hover { color: var(--danger); }

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  padding: 20px;
  overflow-y: auto;
}

.library-empty, .library-loading {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  padding: 40px 0;
  font-size: 14px;
  line-height: 1.7;
}

.library-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color .18s, box-shadow .18s;
}

.library-card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 20px rgba(124,92,252,.15);
}

.library-thumb {
  width: 100%;
  aspect-ratio: 16/9;
  background: #0d0f13;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.library-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.library-thumb-icon { font-size: 36px; }

.library-info {
  padding: 10px 12px 6px;
}

.library-card-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.library-card-date {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.library-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  padding: 8px 12px 10px;
}

.lib-btn {
  flex: 1;
  min-width: 55px;
  padding: 5px 4px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 11px;
  cursor: pointer;
  text-align: center;
  transition: all .15s;
  white-space: nowrap;
}

.lib-btn:hover { border-color: var(--accent); color: var(--accent2); }
.lib-btn.lib-secondary { color: var(--muted); }
.lib-btn.lib-danger:hover { border-color: var(--danger); color: var(--danger); }

/* ── Sandbox fullscreen ── */
.sandbox-panel.fullscreen {
  width: 100vw !important;
  height: 100vh !important;
  height: 100dvh !important;
  z-index: 9999;
}

/* ── Sandbox console panel ── */
.sandbox-console-panel {
  flex-direction: column;
  flex-shrink: 0;
  height: 180px;
  border-top: 1px solid var(--border);
  background: #080b10;
  overflow: hidden;
}

.sandbox-console-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px;
  background: #0d1118;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  flex-shrink: 0;
}

.console-bar-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .8px;
  text-transform: uppercase;
  color: var(--muted);
  flex: 1;
}

.console-count {
  font-size: 10px;
  font-weight: 700;
  background: var(--danger);
  color: #fff;
  border-radius: 8px;
  padding: 1px 6px;
}

.console-clear-btn {
  background: none;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--muted);
  font-size: 10px;
  padding: 2px 7px;
  cursor: pointer;
  transition: all .15s;
}

.console-clear-btn:hover { border-color: var(--accent); color: var(--accent2); }

.sandbox-console-output {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
  font-family: 'Courier New', Consolas, monospace;
  font-size: 11px;
}

.console-empty {
  display: block;
  padding: 10px 12px;
  color: rgba(255,255,255,0.2);
  font-style: italic;
  font-size: 11px;
}

.con-entry {
  display: flex;
  gap: 8px;
  padding: 2px 12px;
  line-height: 1.5;
  border-bottom: 1px solid rgba(255,255,255,0.03);
}

.con-entry:hover { background: rgba(255,255,255,0.03); }

.con-time {
  color: rgba(255,255,255,0.2);
  flex-shrink: 0;
  font-size: 10px;
  padding-top: 1px;
}

.con-text { color: rgba(200,210,255,0.75); word-break: break-all; }

.con-log  .con-text { color: rgba(200,210,255,0.75); }
.con-warn .con-text { color: #fbbf24; }
.con-warn { background: rgba(251,191,36,0.04); }
.con-error .con-text { color: #f87171; }
.con-error { background: rgba(248,113,113,0.06); }

/* Console button error state */
.sb-btn.has-errors {
  border-color: rgba(248,113,113,0.5);
  color: #f87171;
}

/* ── Library "Edit with AI" button ── */
.lib-btn.lib-edit-ai {
  border-color: rgba(124,92,252,0.4);
  color: var(--accent2);
}
.lib-btn.lib-edit-ai:hover {
  background: rgba(124,92,252,0.12);
  border-color: var(--accent);
}

/* Mobile library */
@media (max-width: 640px) {
  .library-grid { grid-template-columns: 1fr 1fr; gap: 10px; padding: 12px; }
  .sandbox-panel { width: 100vw; }
  .sandbox-controls { gap: 4px; }
  .sb-btn { padding: 4px 7px; font-size: 11px; }
  .sandbox-name { max-width: 110px; }
  .sandbox-console-panel { height: 140px; }
}

/* ── Imagine / sparkle button ── */
#imagine-btn {
  background: none;
  border: 1px solid rgba(167,139,250,0.35);
  border-radius: 8px;
  color: var(--accent2);
  padding: 7px 9px;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}
#imagine-btn:hover {
  background: rgba(124,92,252,0.15);
  border-color: var(--accent);
  color: #c4b5fd;
}
#imagine-btn.active {
  background: rgba(124,92,252,0.25);
  border-color: var(--accent);
  color: #fff;
}

/* ── Image generation bubble ── */
.img-gen-bubble {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.img-gen-spinner {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}
.img-gen-spinner::before {
  content: '';
  width: 16px;
  height: 16px;
  border: 2px solid rgba(167,139,250,0.3);
  border-top-color: var(--accent2);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: inline-block;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.img-gen-result img {
  max-width: 100%;
  border-radius: 10px;
  display: block;
  border: 1px solid rgba(124,92,252,0.25);
}
.img-gen-result-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 6px;
}
.img-gen-prompt-text {
  font-size: 11px;
  color: var(--muted);
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.img-gen-download-btn {
  background: rgba(124,92,252,0.15);
  border: 1px solid rgba(124,92,252,0.4);
  color: var(--accent2);
  border-radius: 7px;
  padding: 4px 9px;
  font-size: 12px;
  cursor: pointer;
  text-decoration: none;
  flex-shrink: 0;
  transition: background 0.2s;
}
.img-gen-download-btn:hover { background: rgba(124,92,252,0.28); }

.img-gen-error {
  color: var(--danger);
  font-size: 13px;
}

/* ── Personas section ── */
.personas-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.new-persona-btn {
  background: rgba(124,92,252,0.18);
  border: 1px solid rgba(124,92,252,0.4);
  color: var(--accent2);
  border-radius: 7px;
  padding: 2px 8px;
  font-size: 15px;
  cursor: pointer;
  line-height: 1.3;
  transition: background 0.2s;
}
.new-persona-btn:hover { background: rgba(124,92,252,0.32); }

.personas-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-height: 8px;
}
.persona-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 5px 10px;
  cursor: pointer;
  font-size: 12px;
  color: var(--text);
  transition: border-color 0.2s, background 0.2s;
  user-select: none;
}
.persona-chip:hover { border-color: rgba(124,92,252,0.5); background: rgba(124,92,252,0.08); }
.persona-chip.active {
  border-color: var(--accent);
  background: rgba(124,92,252,0.18);
  color: var(--accent2);
  font-weight: 600;
}
.persona-chip-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.persona-chip-del {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  padding: 0 2px;
  line-height: 1;
  flex-shrink: 0;
  border-radius: 4px;
  transition: color 0.2s;
}
.persona-chip-del:hover { color: var(--danger); }
.persona-chip-builtin .persona-chip-del { display: none; }

/* ── Persona creation modal ── */
.persona-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.persona-modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}
.persona-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: min(90vw, 420px);
  padding: 0;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  overflow: hidden;
}
.persona-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  font-weight: 600;
  color: var(--accent2);
}
.persona-modal-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
  padding: 2px 5px;
  border-radius: 5px;
  transition: color 0.2s;
}
.persona-modal-close:hover { color: var(--danger); }
.persona-modal-body { padding: 18px 20px; display: flex; flex-direction: column; }
.persona-field-label {
  font-size: 11px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}
.persona-name-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 12px;
  font-size: 13px;
  width: 100%;
  outline: none;
  transition: border-color 0.2s;
}
.persona-name-input:focus { border-color: var(--accent); }
.persona-prompt-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 8px 12px;
  font-size: 13px;
  width: 100%;
  outline: none;
  resize: vertical;
  font-family: inherit;
  transition: border-color 0.2s;
}
.persona-prompt-input:focus { border-color: var(--accent); }
.persona-modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 16px;
}
.persona-cancel-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  transition: color 0.2s, border-color 0.2s;
}
.persona-cancel-btn:hover { color: var(--text); border-color: var(--muted); }
.persona-save-btn {
  background: rgba(124,92,252,0.2);
  border: 1px solid var(--accent);
  color: var(--accent2);
  padding: 8px 18px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.2s;
}
.persona-save-btn:hover { background: rgba(124,92,252,0.35); }

/* ── Share toast ── */
.share-toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface2);
  border: 1px solid rgba(124,92,252,0.45);
  border-radius: 14px;
  box-shadow: 0 8px 32px rgba(0,0,0,.55), 0 0 0 1px rgba(124,92,252,0.12);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 280px;
  max-width: min(480px, 90vw);
  z-index: 10000;
  animation: toastIn .22s cubic-bezier(.34,1.56,.64,1);
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(16px) scale(0.95); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0)    scale(1); }
}

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

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

.share-toast-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent2);
  margin-bottom: 2px;
}

.share-toast-url {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.share-toast-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  flex-shrink: 0;
  padding: 2px 4px;
  border-radius: 4px;
  transition: color .15s;
}
.share-toast-close:hover { color: var(--text); }

/* ── Sidebar user row ── */
.sidebar-user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 4px 0;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

.sidebar-user-email {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.sidebar-logout-btn {
  flex-shrink: 0;
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: color .15s, border-color .15s;
  white-space: nowrap;
}

.sidebar-logout-btn:hover {
  color: var(--danger);
  border-color: var(--danger);
}

/* ── Auth overlay ── */
.auth-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 18, 0.95);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20000;
  padding: 20px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 24px 64px rgba(0,0,0,.6), 0 0 0 1px rgba(124,92,252,0.1);
  padding: 36px 32px 32px;
  width: 100%;
  max-width: 400px;
}

.auth-logo {
  text-align: center;
  margin-bottom: 28px;
}

.auth-logo-icon {
  font-size: 36px;
  margin-bottom: 8px;
}

.auth-logo-name {
  font-size: 22px;
  font-weight: 800;
  color: var(--accent2);
  letter-spacing: .3px;
  margin-bottom: 4px;
}

.auth-logo-tagline {
  font-size: 12px;
  color: var(--muted);
}

.auth-tabs {
  display: flex;
  gap: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  margin-bottom: 24px;
}

.auth-tab {
  flex: 1;
  background: none;
  border: none;
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 12px;
  cursor: pointer;
  transition: all .18s;
}

.auth-tab.active {
  background: var(--accent);
  color: #fff;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

.auth-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .4px;
  text-transform: uppercase;
}

.auth-input {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  padding: 11px 14px;
  outline: none;
  transition: border-color .2s;
  width: 100%;
}

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

.auth-error {
  font-size: 13px;
  color: var(--danger);
  min-height: 18px;
  text-align: center;
}

.auth-submit {
  width: 100%;
  background: var(--accent);
  border: none;
  border-radius: 12px;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  padding: 13px;
  cursor: pointer;
  transition: background .18s, opacity .18s;
  margin-top: 4px;
}

.auth-submit:hover { background: var(--accent2); }
.auth-submit:disabled { opacity: .55; cursor: not-allowed; }

/* ── Usage bar ── */
.usage-bar {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 9px 12px;
  margin-top: 2px;
}

.usage-bar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 7px;
}

.usage-text {
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
}

.usage-upgrade-link {
  background: none;
  border: none;
  color: var(--accent2);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
  letter-spacing: .2px;
  transition: color .15s;
}

.usage-upgrade-link:hover { color: #fff; }

.usage-track {
  height: 4px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.usage-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
  transition: width .4s ease, background .3s;
}

.usage-fill.warn { background: #f59e0b; }
.usage-fill.full { background: var(--danger); }

/* ── Plan badge ── */
.plan-badge {
  display: inline-flex;
  align-items: center;
  background: linear-gradient(135deg, #f59e0b, #fbbf24);
  color: #0a0a0f;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 1px;
  padding: 2px 7px;
  border-radius: 6px;
  margin-left: 4px;
  flex-shrink: 0;
}

/* ── Upgrade bubble ── */
.upgrade-bubble {
  background: linear-gradient(135deg, rgba(124,92,252,.12), rgba(99,102,241,.08)) !important;
  border-color: rgba(124,92,252,.4) !important;
  text-align: center;
  padding: 20px 18px !important;
}

.upgrade-bubble.success {
  background: linear-gradient(135deg, rgba(52,211,153,.12), rgba(16,185,129,.08)) !important;
  border-color: rgba(52,211,153,.4) !important;
}

.upgrade-icon {
  font-size: 28px;
  margin-bottom: 8px;
}

.upgrade-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

.upgrade-body {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.55;
  margin-bottom: 14px;
}

.upgrade-body strong { color: var(--text); }

.upgrade-cta-btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 20px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: background .18s, transform .12s;
  width: 100%;
  margin-bottom: 8px;
}

.upgrade-cta-btn:hover {
  background: var(--accent2);
  transform: translateY(-1px);
}

.upgrade-reset {
  font-size: 11px;
  color: var(--muted);
  margin: 0;
}

/* ── Knowledge Base ── */
.kb-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.kb-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  padding: 2px 0;
}

.kb-header:hover .s-label { color: var(--accent2); }

.kb-toggle-icon {
  font-size: 11px;
  color: var(--muted);
  line-height: 1;
}

.kb-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.kb-list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 150px;
  overflow-y: auto;
}

.kb-empty {
  font-size: 12px;
  color: var(--muted);
  font-style: italic;
  padding: 2px 0;
}

.kb-doc-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.kb-doc-icon {
  font-size: 13px;
  flex-shrink: 0;
  opacity: .7;
}

.kb-doc-info {
  flex: 1;
  min-width: 0;
}

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

.kb-doc-chunks {
  font-size: 10px;
  color: var(--muted);
  margin-top: 1px;
}

.kb-doc-delete {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  transition: color .15s, background .15s;
  line-height: 1;
}

.kb-doc-delete:hover { color: var(--danger); background: rgba(248,113,113,.1); }
.kb-doc-delete:disabled { opacity: .4; cursor: not-allowed; }

.kb-upload-btn {
  width: 100%;
  padding: 7px 10px;
  background: var(--surface2);
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  text-align: center;
  transition: border-color .18s, color .18s;
}

.kb-upload-btn:hover { border-color: var(--accent); color: var(--accent2); }
.kb-upload-btn:disabled { opacity: .5; cursor: not-allowed; }

.kb-upload-status {
  font-size: 11px;
  padding: 5px 8px;
  border-radius: 6px;
  line-height: 1.4;
}

.kb-upload-status.loading {
  color: var(--accent2);
  background: rgba(124,92,252,.1);
  display: flex !important;
  align-items: center;
  gap: 6px;
}
.kb-upload-status.loading::before {
  content: '';
  display: inline-block;
  width: 10px;
  height: 10px;
  border: 2px solid rgba(167,139,250,.3);
  border-top-color: var(--accent2);
  border-radius: 50%;
  animation: kb-spin .7s linear infinite;
  flex-shrink: 0;
}
@keyframes kb-spin { to { transform: rotate(360deg); } }
.kb-upload-status.success { color: var(--success); background: rgba(52,211,153,.1); }
.kb-upload-status.error   { color: var(--danger);  background: rgba(248,113,113,.1); }

/* RAG badge on AI messages */
.rag-badge {
  display: inline-block;
  margin-top: 8px;
  padding: 3px 8px;
  background: rgba(52,211,153,.12);
  border: 1px solid rgba(52,211,153,.3);
  border-radius: 6px;
  font-size: 11px;
  color: var(--success);
  font-weight: 500;
}

/* ── Referral Section ── */
.referral-section {
  padding: 12px;
  background: rgba(124,92,252,.07);
  border: 1px solid rgba(124,92,252,.2);
  border-radius: 12px;
}

.referral-desc {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.5;
  margin-bottom: 10px;
}

.referral-desc strong {
  color: var(--accent2);
}

.referral-link-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.referral-link-input {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-size: 10px;
  padding: 6px 8px;
  outline: none;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.referral-copy-btn {
  flex-shrink: 0;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  padding: 4px 8px;
  cursor: pointer;
  transition: border-color .15s;
}

.referral-copy-btn:hover { border-color: var(--accent); }

.referral-copied {
  font-size: 11px;
  color: var(--success);
  margin-top: 5px;
  text-align: center;
}

/* ── Thinking bubble (App Builder architect phase) ── */
.thinking-bubble {
  max-width: 68%;
  background: #0e111a;
  border: 1px solid rgba(124, 92, 252, 0.25);
  border-radius: 4px 18px 18px 18px;
  overflow: hidden;
  font-size: 13px;
}

.thinking-header {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 14px;
  border-bottom: 1px solid rgba(124, 92, 252, 0.15);
  user-select: none;
}

.thinking-header.done {
  cursor: pointer;
  transition: background .15s;
}

.thinking-header.done:hover {
  background: rgba(124, 92, 252, 0.08);
}

.thinking-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent2);
  letter-spacing: .2px;
}

/* Animated pulsing dot shown while planning streams */
.thinking-pulse {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  animation: thinkPulse 1.1s ease-in-out infinite;
}

@keyframes thinkPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.4; transform: scale(0.7); }
}

.thinking-content {
  max-height: 320px;
  overflow-y: auto;
  padding: 12px 14px;
  transition: max-height 0.28s ease, padding 0.28s ease, opacity 0.2s ease;
  opacity: 1;
}

.thinking-content.collapsed {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  opacity: 0;
  overflow: hidden;
}

.thinking-text {
  font-family: 'SF Mono', 'Cascadia Code', 'Fira Code', 'Consolas', monospace;
  font-size: 11.5px;
  color: #7c8494;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.65;
  margin: 0;
}

/* "Building your app…" label inside the dots indicator */
.building-label {
  font-size: 13px;
  color: var(--accent2);
  font-weight: 500;
  animation: buildingPulse 1.4s ease-in-out infinite;
}

@keyframes buildingPulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.55; }
}
