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

:root {
  --bg:       #0d0d10;
  --surface:  #14141a;
  --card:     #1a1a22;
  --card-h:   #202029;
  --border:   #26262f;
  --border2:  #32323e;
  --text:     #e2e2ee;
  --muted:    #7070888;
  --sub:      #70708a;
  --accent:   #8b7cf6;
  --accent-d: #6b5cd6;
  --danger:   #e05555;
  --bot-bubble-bg: var(--card);
  --bot-bubble-text: var(--text);
  --bot-bubble-border: var(--border);
  --chat-bubble-bg: var(--accent);
  --chat-bubble-text: #ffffff;
  --chat-bubble-border: rgba(255,255,255,0.12);
  --r:        12px;
  --r-sm:     8px;
}

html, body { height: 100%; overflow: hidden; }
body { min-height: 0; }
body {
  font-family: 'Sora', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  font-size: 14px;
}

/* ── SIDEBAR ── */
#sidebar {
  width: 220px;
  min-width: 230px;
  height: 100vh;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  gap: 8px;
}
.sidebar-top { display: flex; flex-direction: column; gap: 16px; margin-bottom: 8px; }
.logo { font-size: 16px; font-weight: 600; color: var(--text); padding: 4px 8px; letter-spacing: -0.3px; }

.create-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--r-sm);
  padding: 10px 14px;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
  text-align: left;
}
.create-btn:hover { background: var(--accent-d); }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--r-sm);
  color: var(--sub);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.12s, color 0.12s;
  text-decoration: none;
  user-select: none;
}
.nav-item:hover { background: var(--card); color: var(--text); }
.nav-item.active { background: var(--card); color: var(--text); }

.recents-section { margin-top: 16px; flex: 1; overflow-y: auto; }
.recents-label { font-size: 11px; font-weight: 600; color: var(--sub); text-transform: uppercase; letter-spacing: 0.8px; padding: 0 10px 8px; }
.sidebar-legal { margin-top: 16px; padding: 16px 10px 0; border-top: 1px solid var(--border); display: grid; gap: 10px; }
.sidebar-legal-label { font-size: 11px; font-weight: 600; color: var(--sub); text-transform: uppercase; letter-spacing: 0.8px; }
.sidebar-legal-links { display: flex; flex-wrap: wrap; gap: 8px 12px; }
.sidebar-legal-links a { color: var(--sub); text-decoration: none; font-size: 13px; transition: color 0.12s ease; }
.sidebar-legal-links a:hover { color: var(--text); }

.recent-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--r-sm);
  cursor: pointer; color: var(--sub); font-size: 13px;
  transition: background 0.12s, color 0.12s;
  overflow: hidden; white-space: nowrap;
}
.recent-item:hover { background: var(--card); color: var(--text); }
.recent-item.active { background: var(--card); color: var(--text); }
.recent-emoji { font-size: 16px; flex-shrink: 0; }
.recent-name { overflow: hidden; text-overflow: ellipsis; }

/* ── MAIN ── */
#main { flex: 1; height: 100vh; overflow: hidden; position: relative; }
.view { position: absolute; inset: 0; overflow-y: auto; display: none; flex-direction: column; min-height: 0; }
.view.active { display: flex; }

/* ── HOME ── */
#homeView { padding: 40px 40px 60px; gap: 32px; }
.home-header h1 { font-size: 28px; font-weight: 600; letter-spacing: -0.5px; }
.home-header p { color: var(--sub); font-size: 14px; margin-top: 4px; }
.bot-section { display: flex; flex-direction: column; gap: 16px; }
.section-title { font-size: 13px; font-weight: 600; color: var(--sub); text-transform: uppercase; letter-spacing: 0.8px; }
.bots-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.hidden { display: none !important; }

.bot-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 20px 18px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
  display: flex; flex-direction: column; gap: 10px;
}
.bot-card:hover { background: var(--card-h); border-color: var(--border2); transform: translateY(-1px); }
.bot-card-emoji { font-size: 32px; line-height: 1; }
.bot-card-name { font-size: 15px; font-weight: 600; color: var(--text); }
.bot-card-desc { font-size: 12px; color: var(--sub); line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.bot-card-meta { font-size: 11px; color: var(--sub); margin-top: 2px; }

/* ── CHAT ── */
#chatView { display: none; flex-direction: column; overflow: hidden; min-height: 0; }
#chatView.active { display: flex; }

.chat-topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  position: relative;
  z-index: 25;
  overflow: visible;
}
.chat-bot-info { display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0; }
.chat-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--card); display: flex; align-items: center; justify-content: center; font-size: 18px; flex-shrink: 0; }
.chat-name { font-size: 15px; font-weight: 600; }
.chat-desc { font-size: 12px; color: var(--sub); }

.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: scroll;
  overflow-x: hidden;
  padding: 24px 20px 28px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: var(--border2) transparent;
}
.messages::-webkit-scrollbar { width: 10px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: rgba(50, 50, 62, 0.92); border-radius: 999px; border: 2px solid transparent; background-clip: content-box; }

.msg { display: flex; gap: 12px; max-width: 75%; overflow: visible; }
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.assistant { align-self: flex-start; }

.msg-avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--card); display: flex; align-items: center; justify-content: center; font-size: 14px; flex-shrink: 0; margin-top: 2px; }

.bubble {
  padding: 12px 16px; border-radius: 16px;
  font-size: 14px; line-height: 1.6; color: var(--text);
}
.msg.user .bubble { background: var(--chat-bubble-bg); color: var(--chat-bubble-text); border: 1px solid var(--chat-bubble-border); border-bottom-right-radius: 4px; }
.msg.assistant .bubble { background: var(--bot-bubble-bg); color: var(--bot-bubble-text); border: 1px solid var(--bot-bubble-border); border-bottom-left-radius: 4px; }

.typing-dots { display: flex; gap: 4px; align-items: center; padding: 4px 0; }
.typing-dots span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--sub);
  animation: bounce 1.2s 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); } 30% { transform: translateY(-5px); } }

.input-bar {
  display: flex; align-items: flex-end; gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
#msgInput {
  flex: 1; background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; color: var(--text); font-family: inherit;
  font-size: 14px; padding: 10px 14px; resize: none; outline: none;
  max-height: 120px; line-height: 1.5; transition: border-color 0.15s;
}
#msgInput:focus { border-color: var(--border2); }
#msgInput::placeholder { color: var(--sub); }
#sendBtn {
  width: 38px; height: 38px; border-radius: 10px;
  background: var(--accent); border: none; color: #fff;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; transition: background 0.15s;
}
#sendBtn:hover { background: var(--accent-d); }
#sendBtn:disabled { background: var(--border2); cursor: not-allowed; }
#sendBtn.is-stop { background: #ff4d4f; }
#sendBtn.is-stop:hover { background: #ff6768; }
#sendBtn svg { display: block; pointer-events: none; }

/* ── CREATE / EDIT ── */
#createView { display: none; flex-direction: column; }
#createView.active { display: flex; }

.create-topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  background: var(--surface); flex-shrink: 0;
}
.create-title { font-size: 16px; font-weight: 600; }

.create-body {
  flex: 1; overflow-y: auto;
  padding: 28px 40px 60px;
  display: flex; flex-direction: column; gap: 20px;
  max-width: 760px; width: 100%;
}

.avatar-row { display: flex; align-items: center; gap: 20px; }
.big-avatar {
  width: 72px; height: 72px; border-radius: 50%;
  background: var(--card); border: 2px solid var(--border);
  font-size: 36px; display: flex; align-items: center;
  justify-content: center; flex-shrink: 0;
}
.emoji-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.emoji-opt {
  width: 36px; height: 36px; border-radius: 8px;
  background: var(--card); border: 1px solid var(--border);
  font-size: 18px; cursor: pointer; display: flex;
  align-items: center; justify-content: center;
  transition: background 0.1s, border-color 0.1s;
}
.emoji-opt:hover { background: var(--card-h); border-color: var(--border2); }
.emoji-opt.selected { border-color: var(--accent); background: rgba(139,124,246,0.15); }

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 12px; font-weight: 600; color: var(--sub); text-transform: uppercase; letter-spacing: 0.6px; }
.form-group input, .form-group textarea, .form-group select {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--r-sm); color: var(--text);
  font-family: inherit; font-size: 14px;
  padding: 10px 12px; outline: none; resize: vertical;
  transition: border-color 0.15s;
}
.form-group input:focus, .form-group textarea:focus { border-color: var(--border2); }
.form-group input::placeholder, .form-group textarea::placeholder { color: var(--sub); }
.form-group select { appearance: none; }

.form-row {
  display: flex; align-items: center;
  justify-content: space-between;
  padding: 12px 0; border-top: 1px solid var(--border);
}
.form-label { font-size: 14px; font-weight: 500; }

.toggle { cursor: pointer; }
.toggle input { display: none; }
.toggle-track {
  display: block; width: 42px; height: 24px;
  background: var(--border2); border-radius: 12px;
  position: relative; transition: background 0.2s;
}
.toggle-track::after {
  content: ''; position: absolute;
  top: 3px; left: 3px; width: 18px; height: 18px;
  border-radius: 50%; background: #fff; transition: left 0.2s;
}
.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle input:checked + .toggle-track::after { left: 21px; }

.form-actions { display: flex; justify-content: flex-end; gap: 10px; padding-top: 8px; }
.btn-save {
  background: var(--accent); color: #fff; border: none;
  border-radius: var(--r-sm); padding: 10px 22px;
  font-family: inherit; font-size: 14px; font-weight: 500;
  cursor: pointer; transition: background 0.15s;
}
.btn-save:hover { background: var(--accent-d); }
.btn-delete {
  background: transparent; color: var(--danger);
  border: 1px solid var(--danger); border-radius: var(--r-sm);
  padding: 10px 18px; font-family: inherit; font-size: 14px;
  cursor: pointer; transition: background 0.15s;
}
.btn-delete:hover { background: rgba(224,85,85,0.1); }

/* ── SHARED BUTTONS ── */
.icon-btn {
  width: 34px; height: 34px; border-radius: var(--r-sm);
  background: transparent; border: none; color: var(--sub);
  cursor: pointer; display: flex; align-items: center;
  justify-content: center; transition: background 0.12s, color 0.12s;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--card); color: var(--text); }
.text-btn { width: auto; padding: 0 10px; font-family: inherit; font-size: 13px; font-weight: 500; }

/* ── NEW IMAGE / ROLEPLAY FEATURES ── */
.avatar-column {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

.avatar-controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.mini-btn {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: var(--r-sm);
  padding: 8px 12px;
  font-family: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.mini-btn:hover {
  background: var(--card-h);
  border-color: var(--border2);
}

.mini-btn.ghost {
  background: transparent;
  color: var(--sub);
}

.mini-btn.tiny {
  padding: 6px 10px;
  font-size: 11px;
}

.avatar-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: inherit;
}

.big-avatar,
.chat-avatar,
.bot-card-avatar,
.msg-avatar {
  overflow: hidden;
}

.bot-card-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--card);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.bot-card-top {
  display: flex;
  align-items: center;
  gap: 12px;
}

.emoji-picker-wrap {
  flex: 1;
  min-width: 230px;
}

.input-stack {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.attachment-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--card);
  max-width: 100%;
}

.attachment-preview img {
  width: 54px;
  height: 54px;
  object-fit: cover;
  border-radius: 10px;
  flex-shrink: 0;
}

.attachment-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

#attachmentName {
  font-size: 12px;
  color: var(--sub);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attach-btn {
  margin-left: 2px;
}

.msg {
  overflow: visible;
}

.bubble {
  overflow-wrap: anywhere;
}

.msg-image {
  display: block;
  width: 100%;
  max-width: 360px;
  max-height: 320px;
  object-fit: cover;
  border-radius: 12px;
  margin-top: 10px;
  border: 1px solid var(--border2);
}

.rich-strong {
  color: #355b9f;
  font-weight: 700;
}

.rich-speech {
  color: inherit;
  font-weight: 500;
}

.rich-whisper {
  color: #8090c8;
  font-style: italic;
  opacity: 0.82;
}

.rich-action {
  color: #5d79bb;
  font-style: italic;
}


/* ── UPDATED PROFILE + SETTINGS ── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--sub);
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.panel-subtitle {
  font-size: 12px;
  font-weight: 600;
  color: var(--sub);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-top: 4px;
}

.form-grid {
  display: grid;
  gap: 12px;
}

.form-grid.two-col {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.form-grid .full {
  grid-column: 1 / -1;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.profile-actions {
  justify-content: flex-end;
  padding-top: 0;
}

.btn-save.secondary {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-save.secondary:hover {
  background: var(--card-h);
  border-color: var(--border2);
}

#chatView, #createView, #homeView {
  min-height: 0;
}

#homeView {
  overflow-y: auto;
}

#chatView {
  overflow: hidden;
}

#chatView .messages {
  overscroll-behavior: contain;
  padding-right: 14px;
}

.chat-desc {
  font-size: 12px;
  color: var(--sub);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bubble {
  word-break: break-word;
}

.rich-strong {
  color: #5d7fbf;
  font-weight: 700;
}

.rich-speech {
  color: inherit;
  font-weight: 500;
}

.rich-whisper {
  color: #8090c8;
  font-style: italic;
  opacity: 0.82;
}

.rich-action {
  color: #5d79bb;
  font-style: italic;
}


/* ── Updated layout and message controls ───────────────── */
.profile-avatar-row {
  display: flex;
  align-items: center;
  gap: 20px;
}

.chat-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.chat-action-btn {
  padding: 0 10px;
  height: 30px;
  border-radius: 999px;
  font-size: 12px;
  white-space: nowrap;
}

.stop-generating-btn {
  border-color: var(--danger);
  color: var(--danger);
}

.stop-generating-btn:hover {
  background: rgba(224, 85, 85, 0.12);
  border-color: var(--danger);
  color: var(--danger);
}

.msg-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  flex: 1;
}

.msg-meta {
  font-size: 11px;
  line-height: 1.2;
  color: var(--sub);
  opacity: 0.92;
  padding-left: 2px;
}


.msg-controls {
  display: flex;
  gap: 8px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  min-height: 34px;
  transition: opacity 0.12s ease, visibility 0.12s ease, transform 0.12s ease;
  transform: translateY(-2px);
}

.msg:hover .msg-controls,
.msg:focus-within .msg-controls,
.msg-controls:focus-within {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0);
}

.msg-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0.03));
  color: var(--sub);
  font-family: inherit;
  font-size: 11px;
  border-radius: 999px;
  padding: 6px 10px;
  cursor: pointer;
  transition: transform 0.12s ease, background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
  box-shadow: 0 8px 18px rgba(0,0,0,0.08);
}

.msg-action-btn svg {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
}

.msg-action-btn:hover {
  transform: translateY(-1px);
  background: var(--card-h);
  color: var(--text);
  border-color: rgba(255,255,255,0.14);
}

.msg-action-btn.danger {
  color: var(--danger);
}

.msg-action-btn.danger:hover {
  border-color: rgba(224,85,85,0.28);
}

.bubble {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  max-width: 100%;
}

.scene-divider {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 4px 0;
  padding: 6px 10px;
  color: var(--sub);
  font-size: 11px;
  letter-spacing: 0.4px;
}

.scene-divider span {
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--card);
  border: 1px solid var(--border);
}


.form-group input[type="color"] {
  width: 100%;
  min-height: 42px;
  padding: 4px;
}

.messages {
  scroll-behavior: smooth;
}

.range-wrap {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.message-modal {
  position: fixed;
  inset: 0;
  background: rgba(6, 6, 10, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.message-modal.hidden {
  display: none;
}

.message-modal-card {
  width: min(640px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.message-modal-title {
  font-size: 16px;
  font-weight: 600;
}

#messageEditorInput {
  width: 100%;
  min-height: 160px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  padding: 12px;
  resize: vertical;
}

.message-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.credit-modal-copy {
  color: var(--sub);
  line-height: 1.55;
}

.credit-modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

@media (max-width: 960px) {
  .chat-actions {
    display: flex;
  }
  .msg-controls {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: none;
    flex-wrap: wrap;
  }
  .profile-avatar-row,
  .avatar-row {
    flex-direction: column;
    align-items: flex-start;
  }
  .form-grid.two-col,
  .settings-grid {
    grid-template-columns: 1fr;
  }
}


.memory-panel {
  margin: 12px 0 10px;
  padding: 14px;
  border: 1px solid rgba(255,255,255,0.10);
  border-radius: 18px;
  background: rgba(255,255,255,0.04);
  backdrop-filter: blur(12px);
  display: grid;
  gap: 10px;
}

.memory-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.memory-title {
  font-size: 0.98rem;
  font-weight: 600;
}

.memory-subtitle {
  margin-top: 4px;
  font-size: 0.82rem;
  opacity: 0.72;
}

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

.memory-actions .mini-btn {
  min-width: 0;
}

#conversationSummaryInput {
  width: 100%;
  min-height: 110px;
  max-height: 190px;
  resize: vertical;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.10);
  background: rgba(8,10,18,0.60);
  color: inherit;
  padding: 12px 14px;
  line-height: 1.45;
  outline: none;
}

#conversationSummaryInput:focus {
  border-color: rgba(255,255,255,0.22);
}

#conversationSummaryInput:disabled {
  opacity: 0.7;
}


/* ── CLEANER REDESIGN OVERRIDES ───────────────────────── */
#sidebar {
  width: 260px;
  min-width: 260px;
  padding: 18px 14px;
  background: linear-gradient(180deg, #13131a 0%, #101015 100%);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border: 0;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: block;
}

.brand-text {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.4px;
}

.sidebar-top {
  gap: 12px;
}

.create-btn {
  border-radius: 12px;
  box-shadow: 0 0 0 1px rgba(139,124,246,0.15) inset;
}

#main {
  background:
    radial-gradient(1200px 700px at 50% 0%, rgba(139,124,246,0.08), transparent 40%),
    var(--bg);
}

.view {
  scrollbar-gutter: stable;
}

#homeView {
  padding: 28px 28px 56px;
  gap: 22px;
}

.home-hero {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding: 4px 2px 2px;
}

.home-hero h1 {
  font-size: 30px;
  font-weight: 700;
  letter-spacing: -0.8px;
}

.home-hero p {
  margin-top: 6px;
  color: var(--sub);
}

.home-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.search-field {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: min(520px, 54vw);
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255,255,255,0.02);
}

.search-field svg { color: var(--sub); flex-shrink: 0; }

.search-field input {
  width: 100%;
  height: 42px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  outline: none;
}

.search-field input::placeholder {
  color: var(--sub);
}

.home-toolbar select {
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
  color: var(--text);
  padding: 0 12px;
  font: inherit;
  outline: none;
}

.bot-section {
  gap: 12px;
}

.bots-grid {
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
}

.bot-card {
  padding: 16px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
  border-color: rgba(255,255,255,0.06);
  box-shadow: 0 1px 0 rgba(255,255,255,0.03) inset;
}

.bot-card-top {
  align-items: flex-start;
}

.bot-card-avatar {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  font-size: 22px;
  background: rgba(255,255,255,0.04);
}

.bot-card-name {
  font-size: 16px;
}

.bot-card-desc {
  margin-top: 2px;
}

.bot-card-meta {
  margin-top: 4px;
  padding-top: 12px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

#chatView {
  background: linear-gradient(180deg, rgba(255,255,255,0.02), transparent 26%), var(--bg);
}

.chat-topbar {
  padding: 12px 18px;
  background: rgba(18,18,24,0.86);
  backdrop-filter: blur(16px);
}

.chat-bot-info {
  min-width: 0;
}

.chat-meta {
  min-width: 0;
}

.chat-name {
  font-size: 16px;
}

.chat-desc {
  max-width: 60ch;
}

.chat-actions {
  gap: 8px;
}

.chat-action-btn {
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
}

.messages {
  padding: 26px 22px 30px;
  gap: 18px;
}

.msg {
  max-width: 68%;
  gap: 10px;
}

.msg.user {
  margin-left: auto;
}

.msg-avatar {
  width: 34px;
  height: 34px;
  border-radius: 12px;
  background: rgba(255,255,255,0.04);
}

.bubble {
  border-radius: 18px;
  padding: 13px 15px;
}

.msg.user .bubble {
  border-bottom-right-radius: 6px;
  background: var(--chat-bubble-bg);
  color: var(--chat-bubble-text);
  border: 1px solid var(--chat-bubble-border);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.05) inset;
}

.msg.assistant .bubble {
  border-bottom-left-radius: 6px;
  background: var(--bot-bubble-bg);
  color: var(--bot-bubble-text);
  border: 1px solid var(--bot-bubble-border);
}

.input-bar {
  padding: 14px 18px 18px;
  background: rgba(18,18,24,0.86);
  backdrop-filter: blur(16px);
}

#msgInput {
  min-height: 46px;
  max-height: 160px;
  border-radius: 14px;
  background: rgba(255,255,255,0.03);
}

#sendBtn {
  border-radius: 14px;
}

.create-topbar {
  background: rgba(18,18,24,0.86);
  backdrop-filter: blur(16px);
}

.create-body {
  max-width: 1080px;
}

.panel {
  border-radius: 18px;
  background: rgba(255,255,255,0.03);
}

.big-avatar {
  width: 84px;
  height: 84px;
  border-radius: 22px;
}

.avatar-row,
.profile-avatar-row {
  align-items: flex-start;
}

.emoji-grid {
  max-width: 520px;
}

.splash-screen {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  background: radial-gradient(circle at 50% 20%, rgba(139,124,246,0.14), transparent 40%), #09090d;
}

.splash-screen.hidden {
  display: none;
}

.splash-card {
  display: grid;
  justify-items: center;
  gap: 12px;
  padding: 28px 30px;
  border-radius: 24px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.03);
  backdrop-filter: blur(18px);
}

.splash-logo {
  width: 68px;
  height: 68px;
}

.splash-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.splash-subtitle {
  color: var(--sub);
  font-size: 13px;
}

@media (max-width: 1100px) {
  #sidebar {
    width: 230px;
    min-width: 230px;
  }

  .search-field {
    min-width: min(380px, 52vw);
  }
}

@media (max-width: 960px) {
  body {
    flex-direction: column;
  }

  #sidebar {
    display: none;
  }

  #main {
    width: 100%;
    height: 100vh;
  }

  #homeView {
    padding: 20px 16px 24px;
    gap: 24px;
  }

  .home-hero {
    flex-direction: column;
    align-items: flex-start;
    gap: 14px;
  }

  .home-toolbar {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .search-field {
    min-width: 0;
    flex: 1 1 100%;
  }

  #homeSort {
    flex: 1 1 48%;
    min-width: 0;
  }

  .mobile-create-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 1 1 48%;
    min-width: 120px;
    height: 40px;
    border: 1px solid var(--border2);
    border-radius: 10px;
    background: var(--accent);
    color: #fff;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
  }

  .chat-actions {
    flex-wrap: wrap;
  }

  .msg {
    max-width: 86%;
  }
}

.mobile-create-btn {
  display: none;
}


.chat-actions {
  position: relative;
  margin-left: auto;
  z-index: 30;
}

.chat-menu-btn {
  border-radius: 12px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.07);
}

.chat-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 12px);
  min-width: 230px;
  padding: 8px;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(13,13,18,0.98);
  backdrop-filter: blur(18px);
  box-shadow: 0 18px 48px rgba(0,0,0,0.35);
  z-index: 220;
  display: grid;
  gap: 4px;
}

.chat-menu.hidden { display: none; }

.chat-menu button {
  display: flex;
  width: 100%;
  align-items: center;
  justify-content: flex-start;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
}

.chat-menu button:hover {
  background: rgba(255,255,255,0.06);
}

.recent-item {
  gap: 8px;
}

.recent-avatar-image {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.history-topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(18,18,24,0.86);
  backdrop-filter: blur(16px);
}

.history-title {
  font-size: 16px;
  font-weight: 700;
}

.history-subtitle {
  margin-top: 3px;
  color: var(--sub);
  font-size: 12px;
}

.history-body {
  padding: 20px 22px 28px;
  display: grid;
  gap: 16px;
}

#historyView,
.credit-history-list,
.archive-modal-body {
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: var(--border2) transparent;
}

#historyView::-webkit-scrollbar,
.credit-history-list::-webkit-scrollbar,
.archive-modal-body::-webkit-scrollbar {
  width: 10px;
}

#historyView::-webkit-scrollbar-track,
.credit-history-list::-webkit-scrollbar-track,
.archive-modal-body::-webkit-scrollbar-track {
  background: transparent;
}

#historyView::-webkit-scrollbar-thumb,
.credit-history-list::-webkit-scrollbar-thumb,
.archive-modal-body::-webkit-scrollbar-thumb {
  background: rgba(50, 50, 62, 0.92);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: content-box;
}

.history-list {
  display: grid;
  gap: 12px;
}

.history-card {
  border: 1px solid rgba(255,255,255,0.06);
  background: rgba(255,255,255,0.03);
  border-radius: 18px;
  padding: 16px;
  display: grid;
  gap: 12px;
}

.history-card-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.history-card-avatar {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  background: rgba(255,255,255,0.04);
  display: grid;
  place-items: center;
  overflow: hidden;
  flex-shrink: 0;
}

.history-card-avatar .recent-emoji {
  font-size: 22px;
}

.history-card-avatar .recent-avatar-image {
  width: 100%;
  height: 100%;
}

.history-card-main {
  min-width: 0;
  flex: 1;
}

.history-card-title {
  font-size: 15px;
  font-weight: 700;
}

.history-card-subtitle {
  margin-top: 3px;
  color: var(--sub);
  font-size: 12px;
}

.history-card-sessions {
  display: grid;
  gap: 8px;
}

.history-session {
  text-align: left;
  width: 100%;
  border: 1px solid rgba(255,255,255,0.05);
  background: rgba(255,255,255,0.02);
  color: var(--text);
  padding: 12px;
  border-radius: 14px;
  cursor: pointer;
  display: grid;
  gap: 8px;
}

.history-session:hover {
  background: rgba(255,255,255,0.05);
}

.history-session-title {
  font-weight: 600;
  font-size: 13px;
}

.history-session-meta,
.history-session-preview {
  color: var(--sub);
  font-size: 12px;
  line-height: 1.4;
}

.history-empty {
  color: var(--sub);
  padding: 22px 4px;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 2500;
  display: grid;
  place-items: center;
  background: rgba(6, 6, 10, 0.72);
  backdrop-filter: blur(12px);
}

.loading-overlay.hidden {
  display: none;
}

.loading-card {
  min-width: 260px;
  padding: 26px 28px;
  border-radius: 24px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(15,15,20,0.92);
  display: grid;
  justify-items: center;
  gap: 12px;
}

.loading-logo {
  width: 64px;
  height: 64px;
}

.loading-title {
  font-size: 20px;
  font-weight: 700;
}

.loading-subtitle {
  color: var(--sub);
  font-size: 13px;
  text-align: center;
}

.loading-spinner {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.14);
  border-top-color: rgba(255,255,255,0.8);
  animation: spin 0.9s linear infinite;
}

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

.archive-modal {
  position: fixed;
  inset: 0;
  z-index: 2400;
  display: grid;
  place-items: center;
  background: rgba(6, 6, 10, 0.72);
  padding: 20px;
}

.archive-modal.hidden { display: none; }

.archive-modal-card {
  width: min(780px, 100%);
  max-height: min(84vh, 900px);
  overflow: hidden;
  border-radius: 22px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(14,14,18,0.98);
  display: grid;
  grid-template-rows: auto 1fr;
}

.archive-modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.archive-modal-title {
  font-size: 16px;
  font-weight: 700;
}

.archive-modal-subtitle {
  margin-top: 3px;
  color: var(--sub);
  font-size: 12px;
}

.archive-modal-body {
  overflow-y: auto;
  padding: 18px;
  display: grid;
  gap: 12px;
}

.archive-msg {
  display: grid;
  gap: 6px;
}

.archive-msg.user .archive-msg-bubble {
  justify-self: end;
}

.archive-msg.assistant .archive-msg-bubble {
  justify-self: start;
}

.archive-msg-meta {
  color: var(--sub);
  font-size: 11px;
}

.archive-msg-bubble {
  max-width: 85%;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,0.06);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  white-space: pre-wrap;
  line-height: 1.5;
}

.memory-panel.hidden { display: none; }

#historyView {
  display: none;
}

#historyView.active {
  display: flex;
  flex-direction: column;
}

.setting-help { margin-top: 6px; font-size: 11px; line-height: 1.45; color: var(--sub); }
.setting-help.full-line { margin-top: 10px; }
#chatView.menu-open .chat-topbar { z-index: 40; }


/* ── Added discovery / auth styles ─────────────────── */
.sidebar-top { gap: 12px; }
.auth-box {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--card);
}
.auth-title { font-size: 12px; font-weight: 700; color: var(--sub); text-transform: uppercase; letter-spacing: .8px; }
.auth-status { font-size: 12px; line-height: 1.4; color: var(--text); }
.auth-box input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  color: var(--text);
  font: inherit;
  padding: 9px 10px;
  outline: none;
}
.auth-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.auth-actions .mini-btn { padding-inline: 10px; }
.section-subtitle { color: var(--sub); font-size: 12px; margin-top: -10px; }
.home-toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.home-toolbar select {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 9px 10px;
  font: inherit;
}
.bot-card-top { align-items: flex-start; }
.bot-card-avatar { width: 48px; height: 48px; border-radius: 14px; overflow: hidden; background: var(--surface); flex-shrink: 0; border: 1px solid var(--border); }
.bot-card-copy { display: grid; gap: 6px; }
.bot-card-badges { font-size: 11px; color: var(--sub); line-height: 1.4; }
.bot-card-meta { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.bot-card-meta::after {
  content: 'Open';
  font-size: 11px;
  color: var(--accent);
  border: 1px solid rgba(139,124,246,.35);
  padding: 4px 8px;
  border-radius: 999px;
}
.recent-avatar-image { width: 22px; height: 22px; border-radius: 999px; object-fit: cover; }
.msg-image { max-width: 100%; border-radius: 14px; margin-top: 10px; display: block; border: 1px solid var(--border); }
.chat-desc { max-width: 100%; line-height: 1.45; }
.chat-menu button[data-action="rate"] { color: var(--accent); }
.chat-credit-pill {
  margin-left: auto;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.04);
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
}
.credits-page {
  padding: 28px;
  display: grid;
  gap: 18px;
  min-width: 0;
}
.credits-hero {
  display: flex;
  gap: 16px;
  justify-content: space-between;
  align-items: stretch;
  flex-wrap: wrap;
}
.credits-hero > div:first-child {
  flex: 1 1 320px;
  min-width: 0;
}
.credits-hero h1,
.credits-hero p {
  overflow-wrap: anywhere;
}
.credits-balance-card,
.credits-panel {
  border: 1px solid var(--border);
  background: var(--card);
  border-radius: 24px;
  padding: 18px;
  box-shadow: var(--shadow);
  min-width: 0;
}
.credits-panel .section-title,
.credits-panel .section-subtitle {
  display: block;
  overflow-wrap: anywhere;
}
.credits-panel .section-title {
  line-height: 1.35;
}
.credits-panel .section-subtitle {
  margin-top: 8px;
  line-height: 1.5;
}
.credits-balance-card {
  flex: 0 1 280px;
  min-width: min(280px, 100%);
  display: grid;
  gap: 6px;
}
.credits-daily-card {
  margin-top: 12px;
  display: grid;
  gap: 10px;
  padding: 14px;
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.03);
}
.credits-daily-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text);
}
.credits-daily-copy {
  color: var(--sub);
  line-height: 1.5;
}
.credits-daily-card .btn-save {
  width: 100%;
  justify-content: center;
}
.credits-daily-card .btn-save[disabled] {
  cursor: not-allowed;
  opacity: 0.7;
}
.credits-balance-label,
.credits-balance-sub,
.credits-inline-note,
.credit-history-meta {
  color: var(--sub);
}
.credits-balance-value {
  font-size: 42px;
  font-weight: 700;
  line-height: 1;
}
.credits-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  align-items: start;
}
.credit-offers,
.credit-history-list {
  display: grid;
  gap: 12px;
  margin-top: 14px;
  min-width: 0;
}
.credit-history-list {
  max-height: min(52vh, 520px);
  overflow-y: auto;
  padding-right: 4px;
}
.credit-offer-card,
.credit-history-item {
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 14px;
  background: rgba(255,255,255,.03);
  min-width: 0;
}
.credit-offer-card.muted {
  opacity: .82;
}
.credit-offer-top,
.credit-history-item {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
}
.credit-offer-top > div:first-child,
.credit-history-item > div:first-child {
  flex: 1 1 220px;
  min-width: 0;
}
.credit-offer-title,
.credit-history-title {
  font-weight: 700;
  overflow-wrap: anywhere;
}
.credit-offer-copy {
  color: var(--sub);
  font-size: 12px;
  margin-top: 4px;
  overflow-wrap: anywhere;
}
.credit-offer-amount,
.credit-offer-price,
.credit-history-delta {
  font-weight: 700;
  white-space: nowrap;
  flex-shrink: 0;
}
.credit-offer-card .btn-save,
.credit-offer-card .btn-save.secondary {
  width: 100%;
  margin-top: 14px;
  justify-content: center;
}
.credit-history-meta {
  margin-top: 4px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.credit-history-delta.positive {
  color: #64d69a;
}
.credit-history-delta.negative {
  color: #ff8f8f;
}
.credit-history-empty {
  color: var(--sub);
  padding: 18px;
  border: 1px dashed var(--border);
  border-radius: 18px;
}
.credits-warning {
  margin-top: 12px;
  border: 1px solid rgba(255, 184, 77, .35);
  background: rgba(255, 184, 77, .1);
  color: #ffd08a;
  padding: 12px 14px;
  border-radius: 16px;
  line-height: 1.5;
}

@media (max-width: 920px) {
  #sidebar { width: 260px; min-width: 260px; }
  #homeView { padding: 24px 18px 40px; }
  .home-toolbar { flex-direction: column; align-items: stretch; }
  .home-toolbar > * { width: 100%; }
  .credits-page { padding: 20px 16px 32px; }
  .credits-grid { grid-template-columns: 1fr; }
  .chat-credit-pill { order: 3; width: 100%; text-align: center; margin-left: 0; }
}
