/* ============================================
   ESN GPT — Complete Stylesheet
   Dark/Light theme, responsive, animated
   ============================================ */

/* ── CSS Variables ── */
:root {
  --bg-primary: #0a0a0a;
  --bg-secondary: #111111;
  --bg-tertiary: #1a1a1a;
  --bg-hover: #222222;
  --bg-active: #2a2a2a;
  --bg-input: #1e1e1e;
  --bg-message-user: #10a37f;
  --bg-message-ai: #1e1e1e;
  --bg-card: #161616;
  --bg-modal: #161616;
  --bg-dropdown: #1a1a1a;

  --text-primary: #ececec;
  --text-secondary: #8e8ea0;
  --text-muted: #565869;
  --text-accent: #10a37f;
  --text-on-accent: #ffffff;

  --border-color: #2a2a2a;
  --border-hover: #3a3a3a;
  --border-focus: #10a37f;

  --accent: #10a37f;
  --accent-hover: #0d8f6e;
  --accent-light: rgba(16, 163, 127, 0.15);
  --accent-glow: rgba(16, 163, 127, 0.3);

  --danger: #ef4444;
  --danger-hover: #dc2626;
  --warning: #f59e0b;
  --success: #10a37f;

  --sidebar-width: 260px;
  --topbar-height: 56px;
  --input-area-height: auto;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;
  --radius-full: 9999px;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.5);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.6);
  --shadow-glow: 0 0 20px rgba(16,163,127,0.2);

  --font-display: 'Syne', sans-serif;
  --font-body: 'Plus Jakarta Sans', sans-serif;

  --transition: 0.2s ease;
  --transition-slow: 0.35s ease;

  --font-size-base: 15px;
}

/* Light Theme */
[data-theme="light"] {
  --bg-primary: #f7f7f8;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f0f0f0;
  --bg-hover: #e8e8e8;
  --bg-active: #e0e0e0;
  --bg-input: #ffffff;
  --bg-message-user: #10a37f;
  --bg-message-ai: #ffffff;
  --bg-card: #ffffff;
  --bg-modal: #ffffff;
  --bg-dropdown: #ffffff;

  --text-primary: #0d0d0d;
  --text-secondary: #6e6e80;
  --text-muted: #acacbe;
  --text-accent: #0d8f6e;

  --border-color: #e5e5e5;
  --border-hover: #d0d0d0;

  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
}

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

html { font-size: var(--font-size-base); scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
}

.hidden { display: none !important; }

button { cursor: pointer; border: none; background: none; font-family: inherit; }
input, textarea, select { font-family: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }

/* ── Splash Screen ── */
.splash-screen {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--bg-primary);
  display: flex; align-items: center; justify-content: center;
  flex-direction: column;
  animation: splashFadeOut 0.5s ease 2.2s forwards;
}

.splash-content {
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  animation: splashIn 0.6s ease forwards;
}

.splash-logo {
  animation: splashPulse 1.5s ease infinite;
}

.splash-title {
  font-family: var(--font-display);
  font-size: 2.4rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}

.splash-subtitle {
  font-size: 0.95rem;
  color: var(--text-secondary);
}

.splash-loader {
  display: flex; gap: 8px; margin-top: 8px;
}

.splash-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: splashDot 1.2s ease infinite;
}
.splash-dot:nth-child(2) { animation-delay: 0.2s; }
.splash-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes splashIn {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes splashFadeOut {
  to { opacity: 0; pointer-events: none; }
}
@keyframes splashPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}
@keyframes splashDot {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ── Install Banner ── */
.install-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 1000;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 10px 16px;
  animation: slideDown 0.3s ease;
}

.install-banner-content {
  display: flex; align-items: center; gap: 12px;
  max-width: 600px; margin: 0 auto;
}

.install-text {
  flex: 1; display: flex; flex-direction: column;
}
.install-text strong { font-size: 0.9rem; color: var(--text-primary); }
.install-text span { font-size: 0.78rem; color: var(--text-secondary); }

.install-confirm-btn {
  background: var(--accent); color: white;
  padding: 7px 18px; border-radius: var(--radius-full);
  font-size: 0.85rem; font-weight: 600;
  transition: background var(--transition);
}
.install-confirm-btn:hover { background: var(--accent-hover); }

.install-dismiss-btn {
  color: var(--text-secondary); font-size: 1rem; padding: 4px 8px;
  transition: color var(--transition);
}
.install-dismiss-btn:hover { color: var(--text-primary); }

@keyframes slideDown {
  from { transform: translateY(-100%); }
  to { transform: translateY(0); }
}

/* ── App Layout ── */
.app {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  transition: transform var(--transition-slow), width var(--transition-slow);
  z-index: 100;
  overflow: hidden;
}

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

.logo-area {
  display: flex; align-items: center; gap: 10px;
}

.logo-text {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.new-chat-btn {
  width: 32px; height: 32px;
  border-radius: var(--radius-md);
  background: var(--bg-hover);
  color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
  border: 1px solid var(--border-color);
}
.new-chat-btn:hover {
  background: var(--accent-light);
  color: var(--accent);
  border-color: var(--accent);
}

/* Sidebar Search */
.sidebar-search {
  display: flex; align-items: center; gap: 8px;
  margin: 10px 10px 6px;
  padding: 8px 10px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  flex-shrink: 0;
}
.sidebar-search svg { color: var(--text-muted); flex-shrink: 0; }
.sidebar-search input {
  flex: 1; background: none; border: none; outline: none;
  color: var(--text-primary); font-size: 0.82rem;
}
.sidebar-search input::placeholder { color: var(--text-muted); }

/* Conversations */
.conversations-container {
  flex: 1; overflow-y: auto; padding: 4px 6px;
}

.conversations-section { margin-bottom: 4px; }

.section-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 8px 8px 4px;
}

.conversations-list { list-style: none; }

.conversation-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition);
  position: relative;
  group: true;
}
.conversation-item:hover { background: var(--bg-hover); }
.conversation-item.active { background: var(--bg-active); }

.conversation-item .conv-icon {
  color: var(--text-muted); flex-shrink: 0;
}

.conversation-item .conv-title {
  flex: 1;
  font-size: 0.83rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-item .conv-actions {
  display: none; gap: 2px;
}
.conversation-item:hover .conv-actions { display: flex; }

.conv-action-btn {
  width: 24px; height: 24px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.conv-action-btn:hover { background: var(--bg-active); color: var(--text-primary); }
.conv-action-btn.danger:hover { color: var(--danger); }

/* Sidebar Footer */
.sidebar-footer {
  border-top: 1px solid var(--border-color);
  padding: 8px;
  flex-shrink: 0;
}

.sidebar-footer-btn {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 9px 10px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 0.83rem;
  transition: all var(--transition);
}
.sidebar-footer-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.user-profile {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition);
  margin-top: 2px;
}
.user-profile:hover { background: var(--bg-hover); }

.user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; font-weight: 700;
  flex-shrink: 0;
}

.user-info {
  flex: 1; display: flex; flex-direction: column;
}
.user-name { font-size: 0.83rem; font-weight: 600; color: var(--text-primary); }
.user-plan { font-size: 0.72rem; color: var(--text-muted); }

.user-menu-btn { color: var(--text-muted); padding: 2px; }

/* ── Sidebar Overlay (mobile) ── */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 99;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(2px);
}

/* ── Main Content ── */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: var(--bg-primary);
  min-width: 0;
}

/* ── Topbar ── */
.topbar {
  height: var(--topbar-height);
  display: flex; align-items: center; gap: 10px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-primary);
  flex-shrink: 0;
  z-index: 10;
}

.topbar-btn {
  width: 36px; height: 36px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}
.topbar-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

/* Model Selector */
.model-selector-wrapper { position: relative; }

.model-selector-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 7px 12px;
  border-radius: var(--radius-md);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 0.88rem;
  font-weight: 600;
  font-family: var(--font-display);
  transition: all var(--transition);
  white-space: nowrap;
}
.model-selector-btn:hover { border-color: var(--border-hover); background: var(--bg-hover); }

.model-dropdown {
  position: absolute; top: calc(100% + 6px); left: 0;
  min-width: 260px;
  background: var(--bg-dropdown);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  overflow: hidden;
  animation: dropdownIn 0.15s ease;
}

.model-dropdown-header {
  padding: 10px 14px 6px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.model-option {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  cursor: pointer;
  transition: background var(--transition);
}
.model-option:hover { background: var(--bg-hover); }
.model-option.active { background: var(--accent-light); }

.model-option-info { display: flex; flex-direction: column; gap: 2px; }
.model-name { font-size: 0.88rem; font-weight: 600; color: var(--text-primary); }
.model-desc { font-size: 0.75rem; color: var(--text-secondary); }

.model-badge {
  font-size: 0.68rem; font-weight: 700;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.model-badge.new { background: var(--accent-light); color: var(--accent); }

/* Topbar Actions */
.topbar-actions {
  margin-left: auto;
  display: flex; align-items: center; gap: 4px;
}

/* Language Selector */
.lang-selector-wrapper { position: relative; }

.lang-btn {
  display: flex; align-items: center; gap: 5px;
  width: auto; padding: 0 10px;
  font-size: 0.8rem; font-weight: 600;
}

.lang-dropdown {
  position: absolute; top: calc(100% + 6px); right: 0;
  width: 220px; max-height: 320px; overflow-y: auto;
  background: var(--bg-dropdown);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  z-index: 200;
  animation: dropdownIn 0.15s ease;
}

.lang-search {
  position: sticky; top: 0;
  padding: 8px;
  background: var(--bg-dropdown);
  border-bottom: 1px solid var(--border-color);
}

.lang-search input {
  width: 100%; padding: 6px 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.82rem;
  outline: none;
}

.lang-option {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background var(--transition);
  font-size: 0.83rem;
}
.lang-option:hover { background: var(--bg-hover); }
.lang-option.active { background: var(--accent-light); color: var(--accent); }
.lang-flag { font-size: 1.1rem; }
.lang-name { flex: 1; color: var(--text-primary); }
.lang-code { font-size: 0.72rem; color: var(--text-muted); font-weight: 600; }

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

/* ── Chat Area ── */
.chat-area {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ── Welcome Screen ── */
.welcome-screen {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 40px 20px;
  gap: 16px;
  animation: fadeInUp 0.5s ease;
}

.welcome-logo {
  animation: welcomePulse 3s ease infinite;
}

@keyframes welcomePulse {
  0%, 100% { transform: scale(1); filter: drop-shadow(0 0 0px rgba(16,163,127,0)); }
  50% { transform: scale(1.03); filter: drop-shadow(0 0 12px rgba(16,163,127,0.4)); }
}

.welcome-title {
  font-family: var(--font-display);
  font-size: 1.9rem;
  font-weight: 800;
  color: var(--text-primary);
  text-align: center;
  letter-spacing: -0.5px;
}

.welcome-subtitle {
  font-size: 0.95rem;
  color: var(--text-secondary);
  text-align: center;
}

/* Suggestion Grid */
.suggestion-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  max-width: 720px;
  width: 100%;
  margin-top: 8px;
}

.suggestion-card {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  text-align: left;
  transition: all var(--transition);
  cursor: pointer;
}
.suggestion-card:hover {
  border-color: var(--accent);
  background: var(--accent-light);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.suggestion-icon { font-size: 1.3rem; flex-shrink: 0; margin-top: 1px; }

.suggestion-text {
  display: flex; flex-direction: column; gap: 2px;
}
.suggestion-text strong {
  font-size: 0.83rem; font-weight: 600; color: var(--text-primary);
}
.suggestion-text span {
  font-size: 0.77rem; color: var(--text-secondary);
}

/* ── Messages Container ── */
.messages-container {
  flex: 1;
  padding: 20px 0 10px;
  display: flex;
  flex-direction: column;
  gap: 0;
}

/* ── Message ── */
.message {
  display: flex;
  padding: 16px 0;
  animation: messageIn 0.3s ease;
  position: relative;
}

.message:hover .message-actions { opacity: 1; }

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

.message-inner {
  max-width: 760px;
  width: 100%;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

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

.message.user .message-avatar {
  background: var(--accent);
  color: white;
}

.message.assistant .message-avatar {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--accent);
}

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

.message-sender {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 4px;
  font-family: var(--font-display);
}

.message-content {
  font-size: 0.93rem;
  line-height: 1.75;
  color: var(--text-primary);
}

/* Markdown Styles */
.message-content h1, .message-content h2, .message-content h3,
.message-content h4, .message-content h5, .message-content h6 {
  font-family: var(--font-display);
  font-weight: 700;
  margin: 1.2em 0 0.5em;
  color: var(--text-primary);
  line-height: 1.3;
}
.message-content h1 { font-size: 1.5rem; }
.message-content h2 { font-size: 1.25rem; }
.message-content h3 { font-size: 1.1rem; }

.message-content p { margin-bottom: 0.8em; }
.message-content p:last-child { margin-bottom: 0; }

.message-content ul, .message-content ol {
  padding-left: 1.5em; margin-bottom: 0.8em;
}
.message-content li { margin-bottom: 0.3em; }

.message-content strong { font-weight: 700; color: var(--text-primary); }
.message-content em { font-style: italic; }

.message-content blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 14px;
  margin: 0.8em 0;
  color: var(--text-secondary);
  font-style: italic;
}

.message-content table {
  width: 100%; border-collapse: collapse; margin: 0.8em 0;
  font-size: 0.88rem;
}
.message-content th, .message-content td {
  padding: 8px 12px;
  border: 1px solid var(--border-color);
  text-align: left;
}
.message-content th {
  background: var(--bg-tertiary);
  font-weight: 700;
  color: var(--text-primary);
}
.message-content tr:nth-child(even) { background: var(--bg-tertiary); }

.message-content a { color: var(--accent); }

/* Code Blocks */
.message-content pre {
  position: relative;
  margin: 0.8em 0;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-color);
}

.code-block-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px;
  background: #1a1a2e;
  border-bottom: 1px solid var(--border-color);
}

.code-lang {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.copy-code-btn {
  display: flex; align-items: center; gap: 5px;
  font-size: 0.75rem;
  color: var(--text-secondary);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}
.copy-code-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.copy-code-btn.copied { color: var(--accent); }

.message-content pre code {
  display: block;
  padding: 14px;
  font-size: 0.85rem;
  line-height: 1.6;
  overflow-x: auto;
  background: #0d1117;
}

.message-content code:not(pre code) {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.85em;
  color: #e06c75;
}

/* Message Actions */
.message-actions {
  display: flex; gap: 4px;
  margin-top: 8px;
  opacity: 0;
  transition: opacity var(--transition);
}

.message-action-btn {
  display: flex; align-items: center; gap: 5px;
  padding: 5px 9px;
  border-radius: var(--radius-md);
  font-size: 0.75rem;
  color: var(--text-muted);
  transition: all var(--transition);
}
.message-action-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.message-action-btn.active { color: var(--accent); }

/* Typing Indicator */
.typing-indicator {
  display: flex; align-items: center; gap: 5px;
  padding: 10px 0;
}
.typing-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.2s ease infinite;
}
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

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

/* ── Input Area ── */
.input-area {
  padding: 12px 16px 16px;
  background: var(--bg-primary);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
}

.image-preview-area {
  margin-bottom: 8px;
}

.image-previews {
  display: flex; gap: 8px; flex-wrap: wrap;
}

.image-preview-item {
  position: relative;
  width: 64px; height: 64px;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid var(--border-color);
}
.image-preview-item img {
  width: 100%; height: 100%; object-fit: cover;
}
.image-preview-remove {
  position: absolute; top: 2px; right: 2px;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: rgba(0,0,0,0.7);
  color: white;
  font-size: 0.7rem;
  display: flex; align-items: center; justify-content: center;
}

.input-box {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 10px 12px;
  transition: border-color var(--transition), box-shadow var(--transition);
  max-width: 760px;
  margin: 0 auto;
}
.input-box:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.input-tools-left, .input-tools-right {
  display: flex; align-items: center; gap: 4px;
  flex-shrink: 0;
}

.input-tool-btn {
  width: 34px; height: 34px;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
  cursor: pointer;
}
.input-tool-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.voice-btn.recording {
  color: var(--danger);
  animation: recordPulse 1s ease infinite;
}
@keyframes recordPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.message-input {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 0.93rem;
  line-height: 1.6;
  resize: none;
  max-height: 200px;
  overflow-y: auto;
  padding: 2px 0;
}
.message-input::placeholder { color: var(--text-muted); }

.send-btn {
  width: 34px; height: 34px;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: white;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}
.send-btn:hover:not(:disabled) {
  background: var(--accent-hover);
  transform: scale(1.05);
}
.send-btn:disabled {
  background: var(--bg-hover);
  color: var(--text-muted);
  cursor: not-allowed;
}

.input-footer {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 760px; margin: 6px auto 0;
  padding: 0 4px;
}

.char-count {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.input-disclaimer {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-align: center;
}

/* ── Context Menu ── */
.context-menu {
  position: fixed; z-index: 500;
  background: var(--bg-dropdown);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 4px;
  min-width: 160px;
  animation: dropdownIn 0.15s ease;
}

.context-menu-item {
  display: flex; align-items: center; gap: 9px;
  width: 100%; padding: 8px 12px;
  border-radius: var(--radius-md);
  font-size: 0.83rem;
  color: var(--text-primary);
  transition: background var(--transition);
}
.context-menu-item:hover { background: var(--bg-hover); }
.context-menu-item.danger { color: var(--danger); }
.context-menu-item.danger:hover { background: rgba(239,68,68,0.1); }

.context-menu-divider {
  height: 1px; background: var(--border-color); margin: 4px 0;
}

/* ── Modals ── */
.modal-overlay {
  position: fixed; inset: 0; z-index: 800;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

.modal {
  background: var(--bg-modal);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 24px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  animation: modalIn 0.25s ease;
}

.settings-modal {
  max-width: 520px;
  padding: 0;
  overflow: hidden;
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px 0;
}

.modal-title {
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 16px;
}

.modal-header .modal-title { margin-bottom: 0; }

.modal-close-btn {
  color: var(--text-muted); font-size: 1rem;
  width: 28px; height: 28px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.modal-close-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.modal-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
  transition: border-color var(--transition);
  margin-bottom: 16px;
}
.modal-input:focus { border-color: var(--border-focus); }

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

.modal-btn {
  padding: 9px 20px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  font-weight: 600;
  transition: all var(--transition);
}
.modal-btn.primary {
  background: var(--accent); color: white;
}
.modal-btn.primary:hover { background: var(--accent-hover); }
.modal-btn.secondary {
  background: var(--bg-hover); color: var(--text-primary);
  border: 1px solid var(--border-color);
}
.modal-btn.secondary:hover { background: var(--bg-active); }
.modal-btn.full-width { width: 100%; justify-content: center; }

/* Settings Tabs */
.settings-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  padding: 0 24px;
  margin-top: 16px;
  gap: 4px;
}

.settings-tab {
  padding: 10px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  border-bottom: 2px solid transparent;
  transition: all var(--transition);
  margin-bottom: -1px;
}
.settings-tab:hover { color: var(--text-primary); }
.settings-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.settings-content { padding: 20px 24px 24px; }

.settings-panel { display: none; }
.settings-panel.active { display: block; }

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

.settings-label {
  display: block;
  font-size: 0.83rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.settings-select, .settings-input {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.88rem;
  outline: none;
  transition: border-color var(--transition);
  appearance: none;
}
.settings-select:focus, .settings-input:focus { border-color: var(--border-focus); }

.toggle-group {
  display: flex; align-items: center; justify-content: space-between;
}

.toggle-switch {
  position: relative; display: inline-block;
  width: 42px; height: 24px; cursor: pointer;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0;
  background: var(--bg-hover);
  border-radius: var(--radius-full);
  transition: background var(--transition);
  border: 1px solid var(--border-color);
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  left: 2px; top: 2px;
  background: var(--text-muted);
  border-radius: 50%;
  transition: transform var(--transition), background var(--transition);
}
.toggle-switch input:checked + .toggle-slider { background: var(--accent-light); border-color: var(--accent); }
.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(18px);
  background: var(--accent);
}

/* Theme Options */
.theme-options {
  display: flex; gap: 10px;
}
.theme-option {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 10px;
  border-radius: var(--radius-md);
  border: 2px solid var(--border-color);
  transition: all var(--transition);
  cursor: pointer;
  font-size: 0.8rem; color: var(--text-secondary);
}
.theme-option:hover { border-color: var(--border-hover); }
.theme-option.active { border-color: var(--accent); color: var(--accent); }

.theme-preview {
  width: 48px; height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}
.dark-preview { background: linear-gradient(135deg, #0a0a0a 50%, #1a1a1a 50%); }
.light-preview { background: linear-gradient(135deg, #f7f7f8 50%, #ffffff 50%); }
.system-preview { background: linear-gradient(135deg, #0a0a0a 50%, #f7f7f8 50%); }

/* Font Size Options */
.font-size-options { display: flex; gap: 8px; }
.font-size-btn {
  padding: 7px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  font-size: 0.83rem;
  color: var(--text-secondary);
  transition: all var(--transition);
}
.font-size-btn:hover { border-color: var(--border-hover); color: var(--text-primary); }
.font-size-btn.active { border-color: var(--accent); color: var(--accent); background: var(--accent-light); }

/* API Key */
.api-key-info {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 16px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-lg);
  margin-bottom: 18px;
  text-align: center;
}
.api-key-info p { font-size: 0.85rem; color: var(--text-secondary); }

.api-key-input-wrapper { position: relative; }
.api-key-input-wrapper .settings-input { padding-right: 44px; }
.api-key-toggle {
  position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); padding: 4px;
  transition: color var(--transition);
}
.api-key-toggle:hover { color: var(--text-primary); }

.api-key-note {
  font-size: 0.75rem; color: var(--text-muted);
  text-align: center; margin-top: 10px;
}

/* About */
.about-content {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  text-align: center;
}
.about-content h2 {
  font-family: var(--font-display);
  font-size: 1.4rem; font-weight: 800;
  color: var(--text-primary);
}
.about-version { font-size: 0.8rem; color: var(--text-muted); }
.about-desc { font-size: 0.85rem; color: var(--text-secondary); line-height: 1.6; max-width: 340px; }
.about-features {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 6px; margin-top: 8px; width: 100%;
}
.about-feature {
  font-size: 0.8rem; color: var(--text-secondary);
  padding: 6px 10px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  text-align: left;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ── Toast ── */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 10px 20px;
  border-radius: var(--radius-full);
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 9000;
  animation: toastIn 0.3s ease;
  white-space: nowrap;
}
.toast.success { border-color: var(--accent); color: var(--accent); }
.toast.error { border-color: var(--danger); color: var(--danger); }

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

/* ── Animations ── */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Font Size Variants ── */
body.font-sm { --font-size-base: 13px; }
body.font-md { --font-size-base: 15px; }
body.font-lg { --font-size-base: 17px; }

/* ── Compact Mode ── */
body.compact .message { padding: 8px 0; }
body.compact .message-inner { padding: 0 16px; }
body.compact .suggestion-grid { gap: 6px; }

/* ── Sidebar Collapsed ── */
.sidebar.collapsed {
  width: 0;
  min-width: 0;
  border-right: none;
}

/* ── Responsive ── */
@media (max-width: 900px) {
  .suggestion-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  :root { --sidebar-width: 280px; }

  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
    z-index: 200;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.mobile-open {
    transform: translateX(0);
  }
  .sidebar-overlay.active { display: block; }

  .suggestion-grid { grid-template-columns: 1fr 1fr; }
  .welcome-title { font-size: 1.4rem; }

  .model-selector-btn span { max-width: 120px; overflow: hidden; text-overflow: ellipsis; }

  .message-inner { padding: 0 14px; }
}

@media (max-width: 480px) {
  .suggestion-grid { grid-template-columns: 1fr; }
  .topbar-actions .topbar-btn:not(.lang-btn) { display: none; }
  .input-footer .input-disclaimer { display: none; }
}