/* ─── Reset & Base ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Colors - Emochi Theme */
  --bg:            #000000;
  --bg2:           #09090b;
  --surface:       #18181b;
  --surface-hover: #27272a;
  --surface-active:#3f3f46;
  --border:        #27272a;
  --border-hover:  #3f3f46;

  --accent:        #FFD600;
  --accent2:       #FFB800;
  --accent-img:    #FFD600;
  --accent-img2:   #FFB800;
  --cyan:          #FFD600; 

  --text:          #fafafa;
  --text2:         #a1a1aa;
  --text-secondary: var(--text2);
  --muted:         #71717a;
  --muted2:        #52525b;

  --error:         #ef4444;
  --danger:        var(--error);
  --primary:       var(--accent);
  --success:       #22c55e;
  --warning:       #eab308;

  --sidebar-w: 280px;
  --chat-bg: none; /* Dynamic character background */
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--bg);
  background-image: var(--chat-bg);
  background-size: cover;
  background-position: center;
  color: var(--text);
  font-size: 16px; 
  line-height: 1.7; 
  letter-spacing: 0.2px;
}

body::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 0;
  pointer-events: none;
}

/* ─── Scrollbar ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-hover); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted2); }

/* ─── Layout ─────────────────────────────────────────────────────────────── */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
  position: relative;
  z-index: 1;
}

/* ─── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: rgba(0, 0, 0, 0.85); /* Solid dark for sidebar */

  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  position: relative;
  z-index: 10;
}

.sidebar-header {
  padding: 1.2rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(255,214,0,0.3);
}

.sidebar-title {
  font-weight: 700;
  font-size: 1rem;
  background: linear-gradient(135deg, #fff, #a3aabf);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-subtitle {
  font-size: 0.7rem;
  color: var(--muted);
}

/* Mode toggle */
.mode-toggle {
  margin: 0.8rem;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
  gap: 4px;
}

.mode-btn {
  padding: 0.5rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-family: 'Inter', sans-serif;
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  white-space: nowrap;
}

.mode-btn.active {
  background: var(--surface-active);
  color: var(--text);
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.mode-btn.active.img-mode {
  background: linear-gradient(135deg, rgba(245,158,11,0.2), rgba(239,68,68,0.2));
  color: var(--accent-img);
}

/* New Chat btn */
.btn-new-chat {
  margin: 0 0.8rem 0.5rem;
  padding: 0.7rem 1rem;
  background: var(--accent);
  border: none;
  border-radius: 10px;
  color: #000;
  font-family: 'Inter', sans-serif;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-new-chat:hover {
  background: var(--accent2);
  transform: translateY(-1px);
}

/* Conversations list */
.conv-section-title {
  padding: 0.5rem 1rem 0.3rem;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.conversations-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 0.5rem;
}

.conv-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0.6rem 0.7rem;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
  margin-bottom: 2px;
  group: true;
}

.conv-item:hover { background: var(--surface-hover); }
.conv-item.active { background: var(--surface-active); }

.conv-item-icon {
  font-size: 14px;
  flex-shrink: 0;
  opacity: 0.7;
}

.conv-item-text {
  flex: 1;
  font-size: 0.85rem;
  color: var(--text2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conv-item.active .conv-item-text { color: var(--text); }

.conv-favorite-btn, .conv-edit-btn, .conv-delete-btn {
  opacity: 0;
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  font-size: 14px;
  transition: opacity 0.15s, background 0.15s;
  flex-shrink: 0;
}

.conv-favorite-btn { color: var(--warning, #facc15); }
.conv-edit-btn { color: var(--cyan); }
.conv-delete-btn { color: var(--error); }

.conv-item:hover .conv-favorite-btn,
.conv-item:hover .conv-edit-btn,
.conv-item:hover .conv-delete-btn { opacity: 1; }

.conv-avatar, .conv-avatar-fallback {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.conv-avatar-fallback {
  background: var(--surface-active);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.conv-favorite-btn:hover { background: rgba(250,204,21,0.15); }
.conv-edit-btn:hover { background: rgba(255,214,0,0.15); }
.conv-delete-btn:hover { background: rgba(239,68,68,0.15); }

/* Sidebar footer */
.sidebar-footer {
  padding: 0.8rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0.6rem 0.7rem;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s;
}

.sidebar-user:hover { background: var(--surface-hover); }

.user-avatar {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

.user-info { flex: 1; overflow: hidden; }
.user-name { font-size: 0.85rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { font-size: 0.7rem; color: var(--muted); }

.btn-sidebar-action {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  background: none;
  border: none;
  color: var(--muted);
  font-family: 'Inter', sans-serif;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  width: 100%;
  text-align: left;
}

.btn-sidebar-action:hover { background: var(--surface-hover); color: var(--text); }
.btn-sidebar-action.danger:hover { background: rgba(248,113,113,0.1); color: var(--error); }

/* ─── Main Content ──────────────────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

/* Top bar */
.topbar {
  padding: 0.9rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(8,11,20,0.8);
  backdrop-filter: blur(10px);
  z-index: 5;
}

.topbar-title {
  flex: 1;
  font-size: 0.95rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0.4rem 0.8rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer;
  transition: border-color 0.2s;
  position: relative;
}

.model-selector:hover { border-color: var(--border-hover); }

.model-selector select {
  background: transparent;
  border: none;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 0.82rem;
  cursor: pointer;
  outline: none;
  max-width: 200px;
}

.model-selector select option { background: var(--bg2); color: var(--text); }

/* Hamburger (mobile) */
.hamburger {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
}

/* ─── Chat Area ─────────────────────────────────────────────────────────── */
.chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.2rem;
  scroll-behavior: smooth;
}

/* Welcome screen */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  animation: fadeIn 0.5s ease;
}

.welcome-icon {
  width: 80px; height: 80px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-radius: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  margin-bottom: 1.5rem;
  box-shadow: 0 20px 40px rgba(255,214,0,0.3);
  animation: pulse-glow 3s ease-in-out infinite;
}

@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 20px 40px rgba(255,214,0,0.3); }
  50% { box-shadow: 0 20px 60px rgba(168,85,247,0.6); }
}

.welcome h2 {
  font-size: 1.8rem;
  font-weight: 700;
  background: linear-gradient(135deg, #fff, #a3aabf);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 0.5rem;
}

.welcome p { color: var(--muted); font-size: 0.95rem; margin-bottom: 2rem; }

.suggestion-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 600px;
}

.suggestion-dock:empty { display: none; }

.suggestion-dock {
  margin-bottom: 0.6rem;
}

.chip {
  padding: 0.5rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 99px;
  color: var(--text2);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all 0.2s;
  font-family: 'Inter', sans-serif;
}

.chip:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
  color: var(--text);
  transform: translateY(-2px);
}

/* Messages */
.msg {
  display: flex;
  gap: 12px;
  animation: msgIn 0.3s ease;
  max-width: 880px;
  width: 100%;
  margin: 0 auto;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg.user { flex-direction: row-reverse; }

.msg-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  align-self: flex-end;
}

.msg.assistant .msg-avatar {
  background: var(--surface-hover);
}

.msg.user .msg-avatar {
  background: var(--surface-hover);
}

.msg-bubble {
  max-width: calc(100% - 60px);
  padding: 1rem 1.4rem;
  border-radius: 24px; 
  font-size: 1rem;
  line-height: 1.7;
}

.msg.user .msg-bubble {
  background: rgba(255, 255, 255, 0.1); 
  border: none;
  border-bottom-right-radius: 8px;
  color: var(--text);
  backdrop-filter: blur(10px);
}

.msg.assistant .msg-bubble {
  background: rgba(24, 24, 27, 0.85);
  border: none;
  border-bottom-left-radius: 8px;
  color: var(--text);
  backdrop-filter: blur(10px);
}

/* Image messages */
.msg-image-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg-image-container img {
  max-width: 400px;
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.msg-image-container img:hover {
  transform: scale(1.02);
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}

.img-download-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0.4rem 0.8rem;
  background: rgba(245,158,11,0.15);
  border: 1px solid rgba(245,158,11,0.3);
  border-radius: 8px;
  color: var(--accent-img);
  font-size: 0.8rem;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s;
  width: fit-content;
}

.img-download-btn:hover { background: rgba(245,158,11,0.25); }

/* Markdown styling */
.msg-bubble code {
  background: rgba(255,255,255,0.08);
  padding: 2px 6px;
  border-radius: 5px;
  font-family: 'Fira Code', 'Courier New', monospace;
  font-size: 0.85em;
  color: var(--cyan);
}

.msg-bubble pre {
  background: rgba(0,0,0,0.4);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem;
  overflow-x: auto;
  margin: 0.5rem 0;
}

.msg-bubble pre code {
  background: transparent;
  padding: 0;
  color: var(--text);
  font-size: 0.88em;
}

.msg-bubble h1, .msg-bubble h2, .msg-bubble h3 {
  margin: 0.8rem 0 0.4rem;
  color: var(--text);
}

.msg-bubble p { margin: 0.8rem 0; }
.msg-bubble ul, .msg-bubble ol { padding-left: 1.5rem; margin: 0.5rem 0; }
.msg-bubble li { margin: 0.3rem 0; }
.msg-bubble strong { color: #fff; font-weight: 600; }
.msg-bubble em { color: var(--text2); font-style: italic; opacity: 0.9; } /* Roleplay prose */

.msg-bubble blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 1rem;
  color: var(--text2);
  margin: 0.5rem 0;
}

.msg-bubble a { color: var(--accent); text-decoration: underline; }
.msg-bubble hr { border: none; border-top: 1px solid var(--border); margin: 0.5rem 0; }

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 5px;
  align-items: center;
  padding: 0.4rem 0;
}

.typing-dot {
  width: 8px; height: 8px;
  background: var(--accent);
  border-radius: 50%;
  animation: typingBounce 1.2s ease-in-out infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 100% { transform: translateY(0); opacity: 0.5; }
  50% { transform: translateY(-6px); opacity: 1; }
}

/* ─── Image Generation View ─────────────────────────────────────────────── */
.img-gen-area {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.img-gen-header {
  text-align: center;
  max-width: 600px;
  margin: 0 auto;
}

.img-gen-header h2 {
  font-size: 1.6rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-img), var(--accent-img2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 0.4rem;
}

.img-gen-header p { color: var(--muted); font-size: 0.9rem; }

.img-params {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 600px;
  margin: 0 auto;
}

.param-select {
  padding: 0.5rem 0.8rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 0.82rem;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s;
}

.param-select:focus { border-color: var(--accent-img); }
.param-select option { background: var(--bg2); }

/* Image gallery */
.img-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  max-width: 1000px;
  margin: 0 auto;
  width: 100%;
}

.img-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
  animation: msgIn 0.3s ease;
}

.img-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 12px 30px rgba(0,0,0,0.4);
}

.img-card img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  cursor: pointer;
}

.img-card-info {
  padding: 0.8rem;
}

.img-card-prompt {
  font-size: 0.82rem;
  color: var(--text2);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  margin-bottom: 0.5rem;
}

.img-card-actions {
  display: flex;
  gap: 6px;
}

.img-card-btn {
  flex: 1;
  padding: 0.4rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-family: 'Inter', sans-serif;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

.img-card-btn:hover { background: var(--surface-hover); color: var(--text); }

/* ─── Buttons ─────────────────────────────────────────────────────────────── */
button {
  font-family: inherit;
}

.send-btn {
  background: var(--surface-hover);
  color: var(--text);
  border: none;
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
}

.send-btn:hover:not(:disabled) {
  background: var(--accent);
  color: #000;
  transform: translateY(-2px);
}

.input-area {
  padding: 1rem;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.input-wrapper {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  background: rgba(24, 24, 27, 0.8);
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: 30px; /* Pill shape */
  backdrop-filter: blur(10px);
  max-width: 800px;
  width: 100%;
}

#msgInput, #imgPromptInput {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  resize: none;
  min-height: 24px;
  max-height: 150px;
  outline: none;
  padding: 8px 0;
}

.input-hint {
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted2);
  margin-top: 0.5rem;
  max-width: 880px;
  margin-left: auto;
  margin-right: auto;
}

/* ─── Settings Panel ─────────────────────────────────────────────────────── */
.settings-panel {
  position: fixed;
  top: 0; right: 0;
  width: 460px;
  height: 100vh;
  background: rgba(8, 11, 20, 0.97);
  border-left: 1px solid var(--border);
  backdrop-filter: blur(20px);
  z-index: 100;
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  box-shadow: -20px 0 60px rgba(0,0,0,0.5);
}

.settings-panel.open { transform: translateX(0); }

.settings-header {
  padding: 1.2rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.settings-header h2 { flex: 1; font-size: 1.1rem; font-weight: 700; }

.btn-close {
  width: 32px; height: 32px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: background 0.15s;
}

.btn-close:hover { background: var(--surface-hover); }

.settings-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.settings-section h3 {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.settings-section h3::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.setting-row {
  margin-bottom: 1.2rem;
}

.setting-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text2);
  margin-bottom: 6px;
}

.setting-desc {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 8px;
}

.setting-input {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.setting-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255,214,0,0.1);
}

.setting-input.danger:focus {
  border-color: var(--error);
  box-shadow: 0 0 0 3px rgba(248,113,113,0.12);
}

.model-browser-input {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.model-browser-input .setting-input {
  min-width: 0;
  flex: 1;
}

.btn-browse-models {
  flex: 0 0 auto;
  min-width: 112px;
  padding: 0.75rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border-hover);
  border-radius: 10px;
  color: var(--accent);
  font-family: 'Inter', sans-serif;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, transform 0.2s;
}

.btn-browse-models:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--accent);
  transform: translateY(-1px);
}

.btn-browse-models:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

textarea.setting-input {
  resize: vertical;
  min-height: 100px;
  line-height: 1.6;
  font-size: 0.85rem;
}

.btn-save {
  width: 100%;
  padding: 0.8rem;
  background: var(--accent);
  border: none;
  border-radius: 24px;
  color: #000;
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-save:hover { background: var(--accent2); transform: translateY(-1px); }

.btn-danger {
  width: 100%;
  padding: 0.8rem;
  background: rgba(248,113,113,0.1);
  border: 1px solid rgba(248,113,113,0.3);
  border-radius: 10px;
  color: var(--error);
  font-family: 'Inter', sans-serif;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-danger:hover { background: rgba(248,113,113,0.2); }

.status-msg {
  padding: 0.6rem 1rem;
  border-radius: 8px;
  font-size: 0.82rem;
  margin-top: 0.8rem;
  display: none;
}

.status-msg.show { display: block; }
.status-msg.error { background: rgba(248,113,113,0.15); color: var(--error); border: 1px solid rgba(248,113,113,0.3); }
.status-msg.success { background: rgba(74,222,128,0.15); color: var(--success); border: 1px solid rgba(74,222,128,0.3); }

/* ─── Right Utility Drawer (Pyre Memoria) ────────────────────────────────── */
.right-drawer {
  width: 320px;
  background: rgba(10, 14, 23, 0.95);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 20;
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
}

.right-drawer-header {
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.right-drawer-header h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

#closeRightDrawerBtn {
  background: none;
  border: none;
  color: var(--text2);
  font-size: 1.5rem;
  cursor: pointer;
}
#closeRightDrawerBtn:hover { color: var(--text); }

.right-drawer-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.drawer-tab {
  flex: 1;
  padding: 0.8rem 0;
  background: none;
  border: none;
  color: var(--text2);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.drawer-tab:hover { color: var(--text); background: var(--surface-hover); }
.drawer-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: var(--bg);
}

.right-drawer-content {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
}

.drawer-pane {
  display: none;
  flex-direction: column;
  gap: 10px;
  height: 100%;
}
.drawer-pane.active { display: flex; }

.pane-help {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}

.drawer-pane textarea {
  flex: 1;
  min-height: 150px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.8rem;
  color: var(--text);
  font-family: inherit;
  resize: vertical;
  font-size: 0.9rem;
}
.drawer-pane textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.btn-drawer-save {
  padding: 0.6rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s;
  margin-top: 5px;
}
.btn-drawer-save:hover {
  background: var(--accent);
  color: #fff;
}

/* Regex inputs */
.regex-inputs {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface);
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.regex-inputs input {
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.5rem;
  border-radius: 6px;
}

/* Users table */
.users-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.users-table th {
  padding: 0.5rem 0.7rem;
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.users-table td {
  padding: 0.6rem 0.7rem;
  border-bottom: 1px solid var(--border);
  color: var(--text2);
}

.badge {
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 600;
}

.badge-admin { background: rgba(255,214,0,0.15); color: var(--accent); }
.badge-user { background: var(--surface); color: var(--muted); }

.btn-sm {
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 0.75rem;
  cursor: pointer;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--error);
  transition: background 0.15s;
}

.btn-sm:hover { background: rgba(248,113,113,0.1); }

/* ─── Overlay ─────────────────────────────────────────────────────────── */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 50;
  backdrop-filter: blur(2px);
}

.overlay.show { display: block; }

/* ─── Lightbox ───────────────────────────────────────────────────────── */
.lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 200;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}

.lightbox.open { display: flex; }

.lightbox img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.8);
  cursor: auto;
}

/* ─── Toast ──────────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 2rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.toast {
  padding: 0.7rem 1.2rem;
  background: rgba(13, 17, 30, 0.95);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.88rem;
  color: var(--text);
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  animation: toastIn 0.3s ease;
  backdrop-filter: blur(10px);
}

.toast.error { border-color: rgba(248,113,113,0.4); color: var(--error); }
.toast.success { border-color: rgba(74,222,128,0.4); color: var(--success); }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ─── Loading spinner ────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Mobile ─────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    transform: translateX(-100%);
    z-index: 50;
  }

  .sidebar.open { transform: translateX(0); }

  .hamburger { display: flex; }

  .settings-panel { width: 100%; }

  .model-browser-header,
  .model-browser-list { padding-left: 1rem; padding-right: 1rem; }
  .model-search { margin-left: 1rem; margin-right: 1rem; }
  .model-browser-status { padding-left: 1rem; padding-right: 1rem; }
  .model-browser-sheet { max-height: 88vh; }

  .img-gallery { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }

  .model-selector select { max-width: 130px; }

  .topbar-selectors { gap: 4px !important; min-width: 0; }
  .topbar-selectors .model-selector { padding: 0.3rem 0.4rem; }
  .topbar-selectors .model-selector select { max-width: 82px; }

  .topbar-title { font-size: 0.85rem; }

  .chat-area, .img-gen-area { padding: 1rem; }
  .input-area { padding: 0.8rem 1rem 1rem; }
}

/* Characters UI */
.characters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 1.5rem;
    padding: 2rem;
    overflow-y: auto;
}
.character-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 1.5rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}
.character-card:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}
.character-header {
    display: flex;
    align-items: center;
    gap: 1rem;
}
.character-avatar {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    object-fit: cover;
    background: var(--bg-secondary);
}
.character-info h3 { margin: 0; font-size: 1.2rem; }
.character-info p { margin: 0.2rem 0 0; font-size: 0.85rem; opacity: 0.7; }
.character-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: auto;
}
.btn-small {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
    border-radius: 4px;
    border: none;
    cursor: pointer;
    background: var(--bg-tertiary);
    color: var(--text-primary);
}
.btn-small:hover { background: rgba(255,255,255,0.2); }
.btn-small.danger:hover { background: #ff4444; }

.large-modal { max-width: 800px; width: 90%; }
.modal-actions {
    display: flex;
    justify-content: space-between;
    margin-top: 2rem;
}
.btn.secondary { background: var(--bg-tertiary); color: var(--text-primary); }

/* Lorebook */
.lorebook-list {
    margin-top: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-height: 400px;
    overflow-y: auto;
}
.lorebook-entry {
    background: var(--bg-secondary);
    padding: 1rem;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.1);
}
.lorebook-entry-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.5rem;
}
.lb-keyword { color: var(--accent-color); font-weight: 500; }
.lb-actions button { background: none; border: none; color: inherit; cursor: pointer; opacity: 0.6; }
.lb-actions button:hover { opacity: 1; }
.lb-content { font-size: 0.9rem; opacity: 0.9; margin: 0; }

.char-select-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 400px;
    overflow-y: auto;
    margin-top: 1rem;
}
.char-select-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.8rem;
    background: var(--bg-secondary);
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
}
.char-select-item:hover { background: var(--bg-tertiary); }
.char-select-item img { width: 40px; height: 40px; border-radius: 50%; }

.badge {
    background: var(--accent-color);
    color: white;
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
}
.hidden { display: none !important; }


/* Modals Overlay & Content */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 1000;
  backdrop-filter: blur(4px);
  align-items: center;
  justify-content: center;
}
/* Modals styling for Emochi */
.modal-content {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 24px;
  width: 90%;
  max-width: 500px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  overflow: hidden;
  position: relative;
  max-height: 90vh;
}
.modal-header {
  padding: 1.2rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h3 {
  font-size: 1.2rem;
  margin: 0;
}
.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 1.5rem;
  cursor: pointer;
}
.modal-close:hover {
  color: var(--text);
}
.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
}
.form-group {
  margin-bottom: 1rem;
}
.form-group label {
  display: block;
  font-size: 0.85rem;
  color: var(--text2);
  margin-bottom: 0.4rem;
}
@keyframes modalIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ─── Character Mode ─────────────────────────────────────────────────── */
.mode-btn.active.char-mode {
  background: linear-gradient(135deg, rgba(255,214,0,0.15), rgba(255,214,0,0.15));
  color: var(--cyan);
}

/* Character View */
.char-view-area {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
}

.char-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 1.5rem;
  max-width: 1100px;
  margin-left: auto;
  margin-right: auto;
}

.char-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--cyan), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.char-header-actions {
  display: flex;
  gap: 8px;
}

.btn-char-action {
  padding: 0.55rem 1rem;
  border-radius: 10px;
  border: none;
  font-family: 'Inter', sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}

.btn-char-create {
  background: linear-gradient(135deg, var(--cyan), var(--accent));
  color: #fff;
  box-shadow: 0 4px 12px rgba(255,214,0,0.3);
}

.btn-char-create:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(255,214,0,0.4);
}

.btn-char-import {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text2);
}

.btn-char-import:hover {
  background: var(--surface-hover);
  color: var(--text);
}

/* Character Grid */
.char-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 1rem;
  max-width: 1100px;
  margin: 0 auto;
}

.char-card {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  transition: transform 0.25s, box-shadow 0.25s, border-color 0.25s;
  animation: msgIn 0.3s ease;
  cursor: pointer;
}

.char-card:hover {
  transform: translateY(-6px);
  box-shadow: 0 16px 40px rgba(0,0,0,0.4);
  border-color: var(--border-hover);
}

.char-card-avatar {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  display: block;
  background: linear-gradient(135deg, rgba(255,214,0,0.15), rgba(255,214,0,0.12));
}

.char-card-avatar-placeholder {
  width: 100%;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 3.5rem;
  background: linear-gradient(135deg, rgba(255,214,0,0.1), rgba(255,214,0,0.1));
  color: var(--muted);
}

.char-card-body {
  padding: 0.9rem;
}

.char-card-name {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.char-card-desc {
  font-size: 0.78rem;
  color: var(--muted);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  margin-bottom: 8px;
  line-height: 1.5;
}

.char-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 10px;
}

.char-tag {
  padding: 2px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 99px;
  font-size: 0.68rem;
  color: var(--muted);
}

.char-card-actions {
  display: flex;
  gap: 4px;
}

.char-action-btn {
  flex: 1;
  padding: 0.4rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--muted);
  font-family: 'Inter', sans-serif;
  font-size: 0.72rem;
  cursor: pointer;
  transition: all 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
}

.char-action-btn:hover { background: var(--surface-hover); color: var(--text); }
.char-action-btn.primary { border-color: rgba(255,214,0,0.25); color: var(--cyan); }
.char-action-btn.primary:hover { background: rgba(255,214,0,0.08); }
.char-action-btn.danger:hover { background: rgba(248,113,113,0.1); color: var(--error); }

.char-empty {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--muted);
}

.char-empty-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
  opacity: 0.3;
}

/* ─── Character Editor Panel ─────────────────────────────────────────── */
.char-editor {
  position: fixed;
  top: 0; right: 0;
  width: 520px;
  height: 100vh;
  background: rgba(8, 11, 20, 0.97);
  border-left: 1px solid var(--border);
  backdrop-filter: blur(20px);
  z-index: 100;
  transform: translateX(100%);
  transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  box-shadow: -20px 0 60px rgba(0,0,0,0.5);
}

.char-editor.open { transform: translateX(0); }

.char-editor-header {
  padding: 1.2rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}

.char-editor-header h2 { flex: 1; font-size: 1.05rem; font-weight: 700; }

.char-editor-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.char-editor-body .setting-row { margin-bottom: 0.8rem; }

.char-editor-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
}

.char-editor-footer .btn-save { flex: 1; }

/* ─── Lorebook Section ───────────────────────────────────────────────── */
.lore-section {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
  margin-top: 0.5rem;
}

.lore-section-title {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.8rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.lore-section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.lore-entries { display: flex; flex-direction: column; gap: 8px; margin-bottom: 1rem; }

.lore-entry {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem;
  transition: background 0.15s;
}

.lore-entry:hover { background: var(--surface-hover); }

.lore-entry-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.lore-keywords {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  flex: 1;
}

.lore-keyword {
  padding: 1px 7px;
  background: rgba(255,214,0,0.1);
  border: 1px solid rgba(255,214,0,0.2);
  border-radius: 99px;
  font-size: 0.7rem;
  color: var(--cyan);
}

.lore-priority {
  font-size: 0.68rem;
  color: var(--muted2);
  padding: 1px 6px;
  background: var(--surface);
  border-radius: 4px;
}

.lore-edit-btn, .lore-delete-btn {
  background: none;
  border: none;
  color: var(--muted2);
  cursor: pointer;
  font-size: 12px;
  padding: 2px 4px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}

.lore-edit-btn:hover { color: var(--cyan); background: rgba(255,214,0,0.1); }
.lore-delete-btn:hover { color: var(--error); background: rgba(248,113,113,0.1); }

.lore-content-preview {
  font-size: 0.78rem;
  color: var(--muted);
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  line-height: 1.5;
}

.lore-add-form {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lore-add-row {
  display: flex;
  gap: 6px;
}

.lore-add-row input,
.lore-add-row textarea {
  flex: 1;
  padding: 0.5rem 0.7rem;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 0.82rem;
  outline: none;
  transition: border-color 0.15s;
}

.lore-add-row input:focus,
.lore-add-row textarea:focus { border-color: var(--cyan); }

.lore-add-row textarea { min-height: 60px; resize: vertical; }

.btn-lore-add {
  padding: 0.5rem 1rem;
  background: rgba(255,214,0,0.12);
  border: 1px solid rgba(255,214,0,0.25);
  border-radius: 8px;
  color: var(--cyan);
  font-family: 'Inter', sans-serif;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  align-self: flex-end;
}

.btn-lore-add:hover { background: rgba(255,214,0,0.2); }

/* ─── Mobile overrides for characters ────────────────────────────────── */
@media (max-width: 768px) {
  .char-editor { width: 100%; }
  .char-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
  .char-header { padding: 0 0.5rem; }
  .modal-content { width: 96%; max-height: 92vh; }
  #personasModal .modal-body { flex-direction: column; }
  #personasModal .modal-body > div:first-child { border-right: 0 !important; border-bottom: 1px solid var(--border); padding: 0 0 1rem !important; }
}

/* ─── OpenRouter Model Browser ─────────────────────────────────────────── */
.model-browser {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: none;
  align-items: flex-end;
  justify-content: center;
}

.model-browser.open { display: flex; }

.model-browser-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(6px);
}

.model-browser-sheet {
  position: relative;
  width: min(100%, 760px);
  max-height: min(82vh, 760px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #10121f;
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: 24px 24px 0 0;
  box-shadow: 0 -20px 70px rgba(0, 0, 0, 0.55);
  animation: modelBrowserIn 0.25s ease-out;
}

.model-browser-handle {
  width: 46px;
  height: 5px;
  margin: 10px auto 0;
  border-radius: 99px;
  background: var(--muted2);
}

.model-browser-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 1rem 1.5rem 0.8rem;
}

.model-browser-header h2 {
  font-size: 1.15rem;
  line-height: 1.3;
}

.model-browser-header p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
}

.model-browser-actions {
  display: flex;
  gap: 6px;
}

.model-browser-icon {
  width: 34px;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  color: var(--text2);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
}

.model-browser-icon:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.model-search {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 1.5rem 0.7rem;
  padding: 0.75rem 1rem;
  background: #191c2d;
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text2);
}

.model-search:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 214, 0, 0.1);
}

.model-search input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
}

.model-search input::placeholder { color: var(--muted); }

.model-browser-status {
  padding: 0 1.5rem 0.7rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.model-browser-status.error { color: var(--error); }

.model-browser-list {
  min-height: 150px;
  overflow-y: auto;
  padding: 0 1.5rem 1.5rem;
}

.model-option {
  width: 100%;
  margin-bottom: 7px;
  padding: 0.85rem 1rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255,255,255,0.025);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}

.model-option:hover {
  background: var(--surface-hover);
  border-color: var(--accent);
  transform: translateY(-1px);
}

.model-option-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.model-option-id {
  min-width: 0;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.84rem;
}

.model-option-name {
  margin-top: 3px;
  color: var(--text2);
  font-size: 0.76rem;
}

.model-option-meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.7rem;
}

.model-free-badge {
  flex: 0 0 auto;
  padding: 2px 7px;
  border: 1px solid rgba(34,197,94,0.35);
  border-radius: 99px;
  color: var(--success);
  font-size: 0.67rem;
  font-weight: 600;
}

.model-browser-empty {
  padding: 2rem 0;
  color: var(--muted);
  text-align: center;
  font-size: 0.85rem;
}

@keyframes modelBrowserIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

#importFileInput { display: none; }


/* Message Action Buttons */
.message-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  opacity: 0.8;
  flex-wrap: wrap;
}
.msg-action-btn {
  background: var(--surface);
  color: var(--text-light);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s ease;
}
.msg-action-btn:hover {
  background: var(--surface-light);
  color: var(--text);
  border-color: var(--primary);
}
.msg-action-btn svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

/* Mobile Optimization */
@media (max-width: 768px) {
  .app {
    flex-direction: column;
  }
  .sidebar {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 1000;
    transform: translateX(-100%);
    box-shadow: 10px 0 30px rgba(0,0,0,0.5);
    width: 280px;
    max-width: 85vw;
  }
  .sidebar.mobile-open {
    transform: translateX(0);
  }
  .hamburger {
    display: block !important;
  }
  .main {
    width: 100%;
  }
  .topbar {
    padding: 0.8rem;
    gap: 8px;
  }
  .topbar-title {
    font-size: 0.9rem;
  }
  .model-selector {
    padding: 0.3rem 0.5rem;
  }
  .model-selector select {
    max-width: 100px;
    font-size: 0.75rem;
  }
  .chat-area {
    padding: 1rem;
  }
  .right-drawer {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    z-index: 1000;
    box-shadow: -10px 0 30px rgba(0,0,0,0.5);
    width: 300px;
    max-width: 85vw;
  }
  .bottom-input-container {
    padding: 10px;
  }
  .msg-bubble {
    font-size: 0.9rem;
    padding: 0.7rem 0.9rem;
  }
}

/* Message Dropdown Actions */
.msg-container {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
}
.msg.user .msg-container {
  flex-direction: row-reverse;
}
.msg-dropdown {
  position: relative;
  display: inline-block;
  opacity: 0.5;
  transition: opacity 0.2s;
  margin-top: 5px;
}
.msg:hover .msg-dropdown {
  opacity: 1;
}
.msg-dropdown-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 4px;
}
.msg-dropdown-btn:hover {
  background: var(--surface-hover);
  color: var(--text);
}
.msg-dropdown-content {
  display: none;
  position: absolute;
  right: 0;
  top: 100%;
  background: var(--surface);
  min-width: 130px;
  box-shadow: 0 8px 16px rgba(0,0,0,0.5);
  border: 1px solid var(--border);
  border-radius: 8px;
  z-index: 100;
  overflow: hidden;
}
.msg.user .msg-dropdown-content {
  right: auto;
  left: 0;
}
.msg-dropdown-content.show {
  display: block;
}
.msg-dropdown-content button {
  width: 100%;
  text-align: left;
  padding: 10px 14px;
  background: none;
  border: none;
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}
.msg-dropdown-content button:hover {
  background: var(--surface-hover);
}
.msg-dropdown-content button.danger:hover {
  background: rgba(248,113,113,0.1);
  color: var(--error);
}
