/* =========================================================
   Nexora AI — Dark + Light premium theme
   ========================================================= */

:root {
  /* Dark theme (default) */
  --bg-0: #050505;
  --bg-1: #0a0a0a;
  --bg-2: #111111;
  --bg-3: #181818;
  --bg-4: #222222;
  --bg-overlay: rgba(10, 10, 10, 0.85);
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text-0: #ffffff;
  --text-1: #e6e6e6;
  --text-2: #a1a1a1;
  --text-3: #6b6b6b;
  --accent: #4f8cff;
  --accent-2: #7c5cff;
  --accent-soft: rgba(79, 140, 255, 0.12);
  --accent-glow: rgba(79, 140, 255, 0.35);
  --danger: #ff5c5c;
  --success: #2ecc71;
  --code-bg: #0d0d0d;
  --code-color: #ffb86c;
  --shadow-1: 0 4px 20px rgba(0, 0, 0, 0.4);
  --shadow-2: 0 10px 40px rgba(0, 0, 0, 0.6);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --base-font-size: 15px;
}

[data-theme="light"] {
  --bg-0: #ffffff;
  --bg-1: #f7f7f8;
  --bg-2: #f0f0f3;
  --bg-3: #e6e6ea;
  --bg-4: #d8d8de;
  --bg-overlay: rgba(255, 255, 255, 0.85);
  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.18);
  --text-0: #0a0a0a;
  --text-1: #1a1a1a;
  --text-2: #5e5e63;
  --text-3: #8a8a90;
  --accent: #2563eb;
  --accent-2: #6d4dff;
  --accent-soft: rgba(37, 99, 235, 0.10);
  --accent-glow: rgba(37, 99, 235, 0.25);
  --code-bg: #f4f4f6;
  --code-color: #c2410c;
  --shadow-1: 0 4px 18px rgba(0, 0, 0, 0.08);
  --shadow-2: 0 10px 40px rgba(0, 0, 0, 0.12);
}

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

html, body {
  height: 100%;
  background: var(--bg-0);
  color: var(--text-1);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: var(--base-font-size);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
  transition: background 0.25s ease, color 0.25s ease;
}

button {
  font-family: inherit;
  border: none;
  background: none;
  color: inherit;
  cursor: pointer;
}

textarea, input, select {
  font-family: inherit;
  color: inherit;
  background: none;
  border: none;
  outline: none;
}

img { display: block; max-width: 100%; }

.muted { color: var(--text-2); }

.hidden { display: none !important; }
[hidden] { display: none !important; }

/* =========================================================
   Splash
   ========================================================= */
.splash {
  position: fixed;
  inset: 0;
  background: var(--bg-0);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  z-index: 9999;
  transition: opacity 0.5s ease, visibility 0.5s ease;
}
.splash.fade-out { opacity: 0; visibility: hidden; }
.splash-logo img { width: 90px; height: 90px; filter: drop-shadow(0 0 20px var(--accent-glow)); }
.splash-name {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: 0.4em;
  color: var(--text-0);
  text-shadow: 0 0 20px var(--accent-glow);
}
.splash-loader { display: flex; gap: 6px; }
.splash-loader span {
  width: 6px; height: 6px;
  background: var(--text-2);
  border-radius: 50%;
  animation: bounce 1.2s infinite ease-in-out;
}
.splash-loader span:nth-child(2) { animation-delay: 0.15s; }
.splash-loader span:nth-child(3) { animation-delay: 0.3s; }
@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* =========================================================
   Layout
   ========================================================= */
.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  height: 100vh;
  background: var(--bg-0);
}

/* =========================================================
   Sidebar
   ========================================================= */
.sidebar {
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: relative;
  z-index: 50;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-logo {
  width: 32px;
  height: 32px;
  filter: drop-shadow(0 0 6px var(--accent-glow));
}
.brand-name {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text-0);
}

.icon-btn {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text-1);
  transition: background var(--transition), transform var(--transition);
}
.icon-btn:hover { background: var(--bg-3); }
.icon-btn:active { transform: scale(0.95); }
.icon-btn svg { width: 18px; height: 18px; }

.new-chat-btn {
  margin: 14px 14px 8px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-0);
  font-weight: 500;
  font-size: 14px;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
}
.new-chat-btn:hover { background: var(--bg-4); border-color: var(--border-strong); }
.new-chat-btn:active { transform: scale(0.98); }
.new-chat-btn svg { width: 16px; height: 16px; }

.search-wrap {
  position: relative;
  margin: 0 14px 10px;
}
.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  color: var(--text-3);
  pointer-events: none;
}
.search-input {
  width: 100%;
  padding: 8px 10px 8px 32px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 13px;
  color: var(--text-1);
  transition: border-color var(--transition), background var(--transition);
}
.search-input::placeholder { color: var(--text-3); }
.search-input:focus { border-color: var(--accent); background: var(--bg-1); }

.sidebar-section {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 16px;
}
.sidebar-label {
  padding: 12px 12px 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
}
.history-list { display: flex; flex-direction: column; gap: 1px; }
.history-empty {
  padding: 14px 12px;
  font-size: 12px;
  color: var(--text-3);
  text-align: center;
}
.history-item {
  position: relative;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 13px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background var(--transition), color var(--transition);
}
.history-item .h-title {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-item:hover { background: var(--bg-3); color: var(--text-0); }
.history-item.active { background: var(--accent-soft); color: var(--text-0); }
.history-item .h-del,
.history-item .h-pin {
  width: 22px; height: 22px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 4px;
  opacity: 0;
  font-size: 16px;
  color: var(--text-2);
  transition: opacity var(--transition), background var(--transition), color var(--transition);
  flex: 0 0 22px;
}
.history-item:hover .h-del,
.history-item:hover .h-pin { opacity: 0.7; }
.history-item .h-del:hover { opacity: 1; background: var(--bg-4); color: var(--danger); }
.history-item .h-pin:hover { opacity: 1; background: var(--bg-4); color: var(--accent); }
.history-item .h-pin svg { width: 12px; height: 12px; }
.history-item .h-icon { width: 14px; height: 14px; opacity: 0.6; flex: 0 0 14px; }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding: 8px;
}
.footer-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: 13px;
  transition: background var(--transition), color var(--transition);
  margin-bottom: 4px;
}
.footer-btn:hover { background: var(--bg-3); color: var(--text-0); }
.footer-btn svg { width: 16px; height: 16px; }

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition);
}
.user-card:hover { background: var(--bg-3); }
.avatar {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: white;
  font-weight: 600;
  font-size: 14px;
  flex: 0 0 32px;
}
.user-info { line-height: 1.2; flex: 1; min-width: 0; }
.user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-0);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-plan { font-size: 11px; color: var(--text-3); }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 40;
  backdrop-filter: blur(2px);
}

/* =========================================================
   Main
   ========================================================= */
.main {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--bg-0);
  position: relative;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-overlay);
  backdrop-filter: blur(12px);
  position: relative;
  z-index: 20;
}
.topbar-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar-right { display: flex; align-items: center; gap: 4px; }

.model-selector { position: relative; }
.model-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px 7px 12px;
  border-radius: var(--radius-md);
  color: var(--text-0);
  font-size: 14px;
  font-weight: 500;
  transition: background var(--transition);
}
.model-btn:hover { background: var(--bg-2); }
.model-icon { color: var(--accent); font-size: 16px; }
.model-name {
  font-weight: 600;
  max-width: 200px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.model-tag {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 6px;
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.model-btn svg { width: 14px; height: 14px; opacity: 0.6; }

.model-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  width: 300px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-2);
  padding: 6px;
  z-index: 30;
  max-height: 70vh;
  overflow-y: auto;
  display: none;
  animation: fadeSlide 0.15s ease;
}
.model-menu.open { display: block; }
@keyframes fadeSlide {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}
.model-section-title {
  padding: 10px 10px 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
}
.model-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  text-align: left;
  transition: background var(--transition);
}
.model-option:hover { background: var(--bg-3); }
.model-option span:first-child {
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 16px;
  flex: 0 0 28px;
}
.model-option strong { display: block; color: var(--text-0); font-size: 13px; font-weight: 600; }
.model-option small { display: block; color: var(--text-3); font-size: 11px; }

/* =========================================================
   Messages
   ========================================================= */
.messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0 0 16px;
  scroll-behavior: smooth;
}
.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 4px; }
.messages::-webkit-scrollbar-thumb:hover { background: var(--bg-4); }

.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 40px 20px;
  text-align: center;
}
.welcome-logo {
  position: relative;
  margin-bottom: 22px;
}
.welcome-logo img {
  width: 90px; height: 90px;
  filter: drop-shadow(0 0 30px var(--accent-glow));
  position: relative;
  z-index: 2;
}
.welcome-logo .glow {
  position: absolute;
  inset: -30px;
  background: radial-gradient(circle, var(--accent-glow) 0%, transparent 70%);
  z-index: 1;
  animation: pulse 3s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.6; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.1); }
}
.welcome-title {
  font-size: 38px;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--text-0);
  margin-bottom: 8px;
  background: linear-gradient(135deg, var(--text-0) 0%, var(--text-2) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.welcome-subtitle {
  color: var(--text-2);
  font-size: 16px;
  margin-bottom: 36px;
  max-width: 480px;
}
.suggestions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  max-width: 620px;
  width: 100%;
}
.suggestion {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-1);
  text-align: left;
  font-size: 13px;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
}
.suggestion:hover {
  background: var(--bg-3);
  border-color: var(--border-strong);
  transform: translateY(-1px);
}
.sug-icon { font-size: 18px; }
.sug-text { flex: 1; }

.messages-list { padding: 20px 0; }
.msg {
  display: flex;
  gap: 14px;
  padding: 18px 24px;
  max-width: 820px;
  margin: 0 auto;
  animation: msgIn 0.3s ease;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.msg.user { flex-direction: row-reverse; }
.msg-avatar {
  width: 32px; height: 32px;
  flex: 0 0 32px;
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-3);
  border: 1px solid var(--border);
  overflow: hidden;
}
.msg-avatar img { width: 100%; height: 100%; object-fit: cover; }
.msg.user .msg-avatar {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  font-weight: 600;
  font-size: 13px;
  border: none;
}
.msg-body { flex: 1; min-width: 0; }
.msg.user .msg-body { text-align: right; }
.msg-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  margin-bottom: 4px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.msg.user .msg-name { justify-content: flex-end; }
.msg-tag {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-3);
  background: var(--bg-3);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'JetBrains Mono', monospace;
}
.msg-content {
  display: inline-block;
  text-align: left;
  color: var(--text-0);
  font-size: 15px;
  line-height: 1.65;
  word-wrap: break-word;
  overflow-wrap: break-word;
  max-width: 100%;
}
.msg.user .msg-content {
  background: var(--bg-2);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: var(--radius-md);
}
.msg.assistant .msg-content { color: var(--text-1); }

.msg-content p { margin: 0 0 10px; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content code {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.88em;
  background: var(--code-bg);
  border: 1px solid var(--border);
  padding: 1px 6px;
  border-radius: 4px;
  color: var(--code-color);
}
.msg-content pre {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  overflow-x: auto;
  margin: 10px 0;
  position: relative;
}
.msg-content pre code {
  background: none;
  border: none;
  padding: 0;
  color: var(--text-1);
  font-size: 13px;
  line-height: 1.55;
}
.code-wrap { position: relative; margin: 10px 0; }
.code-lang {
  position: absolute;
  top: 6px; left: 10px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
  font-family: 'JetBrains Mono', monospace;
  background: var(--bg-2);
  padding: 2px 6px;
  border-radius: 4px;
}
.code-copy {
  position: absolute;
  top: 6px; right: 8px;
  font-size: 11px;
  color: var(--text-2);
  background: var(--bg-2);
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 4px;
  transition: background var(--transition), color var(--transition);
}
.code-copy:hover { background: var(--bg-3); color: var(--text-0); }

.msg-content ul, .msg-content ol { margin: 8px 0 8px 22px; }
.msg-content li { margin: 4px 0; }
.msg-content h1, .msg-content h2, .msg-content h3 {
  margin: 14px 0 8px;
  color: var(--text-0);
  font-weight: 600;
}
.msg-content h1 { font-size: 20px; }
.msg-content h2 { font-size: 18px; }
.msg-content h3 { font-size: 16px; }
.msg-content blockquote {
  border-left: 3px solid var(--accent);
  padding-left: 12px;
  color: var(--text-2);
  margin: 10px 0;
}
.msg-content a { color: var(--accent); text-decoration: none; }
.msg-content a:hover { text-decoration: underline; }

.msg-image {
  margin-top: 10px;
  border-radius: var(--radius-md);
  overflow: hidden;
  max-width: 420px;
  border: 1px solid var(--border);
  cursor: zoom-in;
  position: relative;
}
.msg-image img { width: 100%; display: block; }
.msg-image-tools {
  position: absolute;
  top: 8px; right: 8px;
  display: flex; gap: 4px;
  opacity: 0;
  transition: opacity var(--transition);
}
.msg-image:hover .msg-image-tools { opacity: 1; }
.msg-image-tool {
  width: 30px; height: 30px;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  border-radius: 6px;
  color: white;
  display: inline-flex; align-items: center; justify-content: center;
}
.msg-image-tool svg { width: 14px; height: 14px; }

.msg-actions {
  display: flex;
  gap: 2px;
  margin-top: 6px;
  opacity: 0;
  transition: opacity var(--transition);
}
.msg:hover .msg-actions { opacity: 1; }
.msg-action {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 11px;
  color: var(--text-3);
  transition: background var(--transition), color var(--transition);
}
.msg-action:hover { background: var(--bg-3); color: var(--text-1); }
.msg-action svg { width: 12px; height: 12px; }

.attachments-preview {
  display: flex; gap: 8px; flex-wrap: wrap;
  margin-top: 8px;
}
.attachment-thumb {
  width: 80px; height: 80px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--border);
  cursor: zoom-in;
}

/* Streaming cursor */
.cursor-blink {
  display: inline-block;
  width: 8px; height: 16px;
  background: var(--accent);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink 1s step-end infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* Typing indicator */
.typing { display: inline-flex; gap: 4px; padding: 8px 0; }
.typing span {
  width: 7px; height: 7px;
  background: var(--text-3);
  border-radius: 50%;
  animation: typingBounce 1.4s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: scale(0.6); opacity: 0.4; }
  30% { transform: scale(1); opacity: 1; }
}

/* =========================================================
   Edit bar
   ========================================================= */
.edit-bar {
  max-width: 820px;
  margin: 0 auto 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 12px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: var(--radius-md);
  font-size: 12px;
  color: var(--accent);
}
.edit-bar button {
  color: var(--text-2);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  transition: background var(--transition), color var(--transition);
}
.edit-bar button:hover { background: var(--bg-3); color: var(--text-0); }

/* =========================================================
   Composer
   ========================================================= */
.composer {
  padding: 0 16px 14px;
  background: linear-gradient(to top, var(--bg-0) 70%, transparent);
}
.composer-inner {
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 6px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 8px 8px 8px 12px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.composer-inner:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.prompt-input {
  flex: 1;
  resize: none;
  font-size: 15px;
  line-height: 1.5;
  padding: 8px 4px;
  max-height: 200px;
  color: var(--text-0);
}
.prompt-input::placeholder { color: var(--text-3); }

.send-btn, .stop-btn {
  width: 36px; height: 36px;
  background: var(--accent);
  color: white;
  border-radius: var(--radius-md);
  flex: 0 0 36px;
  transition: background var(--transition), transform var(--transition);
}
.send-btn:hover { background: var(--accent-2); }
.send-btn:active { transform: scale(0.95); }
.send-btn:disabled, .stop-btn { background: var(--bg-3); color: var(--text-2); }
.stop-btn { background: var(--danger); color: white; }
.stop-btn:hover { background: var(--danger); filter: brightness(0.92); }

.mic-btn.listening { color: var(--danger); animation: pulse 1.5s infinite; }

.composer-foot {
  text-align: center;
  font-size: 11px;
  color: var(--text-3);
  margin-top: 8px;
}

/* Attachments */
.attachments {
  max-width: 820px;
  margin: 0 auto;
  padding: 0 16px 8px;
}
.attachment-list {
  display: flex; gap: 8px; flex-wrap: wrap;
}
.attachment-item {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 6px 6px 6px 8px;
  font-size: 12px;
  color: var(--text-1);
  position: relative;
}
.attachment-item img {
  width: 40px; height: 40px;
  border-radius: 6px;
  object-fit: cover;
}
.attachment-item .remove {
  width: 18px; height: 18px;
  background: var(--bg-4);
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-2);
  margin-left: 4px;
  font-size: 12px;
  transition: background var(--transition), color var(--transition);
}
.attachment-item .remove:hover { background: var(--danger); color: white; }

/* =========================================================
   Lightbox
   ========================================================= */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.lightbox img {
  max-width: 95vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-2);
}
.lightbox-close {
  position: absolute;
  top: 16px; right: 20px;
  width: 40px; height: 40px;
  font-size: 28px;
  color: white;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--transition);
}
.lightbox-close:hover { background: rgba(255, 255, 255, 0.2); }
.lightbox-actions {
  position: absolute;
  bottom: 24px;
  display: flex; gap: 8px;
  background: var(--bg-2);
  padding: 6px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}
.lightbox-actions .icon-btn { color: var(--text-1); }
.lightbox-actions .icon-btn:hover { background: var(--bg-3); }

/* =========================================================
   Modal
   ========================================================= */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(6px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}
.modal-content {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 28px 28px 24px;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow-2);
  animation: modalIn 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}
.modal-wide { max-width: 520px; }
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(10px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px;
}
.modal-head h2 { color: var(--text-0); font-size: 18px; font-weight: 600; }
.modal-x { width: 32px; height: 32px; }
.modal-x svg { width: 16px; height: 16px; }

.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.setting-row:last-of-type { border-bottom: none; }
.setting-label > div { color: var(--text-0); font-size: 14px; font-weight: 500; }
.setting-label > small { color: var(--text-3); font-size: 11px; }

.seg {
  display: inline-flex;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 2px;
}
.seg button {
  padding: 5px 10px;
  font-size: 12px;
  color: var(--text-2);
  border-radius: 8px;
  transition: background var(--transition), color var(--transition);
}
.seg button.active { background: var(--accent); color: white; }
.seg button:hover:not(.active) { color: var(--text-0); }

.select {
  padding: 6px 10px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-0);
  font-size: 13px;
  cursor: pointer;
  min-width: 180px;
}
.select:focus { border-color: var(--accent); }

.switch {
  width: 42px; height: 24px;
  background: var(--bg-3);
  border-radius: 999px;
  position: relative;
  transition: background var(--transition);
  cursor: pointer;
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 18px; height: 18px;
  background: var(--text-1);
  border-radius: 50%;
  transition: transform var(--transition), background var(--transition);
}
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(18px); background: white; }

.primary-btn {
  display: block;
  width: 100%;
  padding: 11px 16px;
  background: var(--accent);
  color: white;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 14px;
  transition: background var(--transition), transform var(--transition);
  margin-top: 8px;
}
.primary-btn:hover { background: var(--accent-2); }
.primary-btn:active { transform: scale(0.98); }

.text-btn {
  color: var(--text-2);
  font-size: 13px;
  padding: 8px;
  transition: color var(--transition);
  width: 100%;
}
.text-btn:hover { color: var(--text-0); }

.modal-actions {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.edit-img-wrap {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-bottom: 14px;
  display: flex;
  justify-content: center;
  max-height: 320px;
}
.edit-img-wrap img { max-width: 100%; max-height: 320px; object-fit: contain; }
.edit-input {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  font-size: 14px;
  color: var(--text-0);
  margin-bottom: 12px;
  resize: vertical;
  min-height: 60px;
}
.edit-input:focus { border-color: var(--accent); }

.shortcut-list {
  display: flex; flex-direction: column; gap: 8px;
}
.shortcut-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-1);
}
.shortcut-row:last-child { border-bottom: none; }
kbd {
  font-family: 'JetBrains Mono', monospace;
  font-size: 11px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  padding: 3px 8px;
  border-radius: 4px;
  color: var(--text-1);
}

/* =========================================================
   Toasts
   ========================================================= */
.toasts {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: calc(100vw - 32px);
}
.toast {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-1);
  min-width: 220px;
  max-width: 360px;
  box-shadow: var(--shadow-1);
  animation: slideIn 0.3s ease, fadeOut 0.3s ease 2.7s forwards;
  pointer-events: auto;
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }
@keyframes slideIn {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes fadeOut {
  to { transform: translateX(20px); opacity: 0; }
}

/* =========================================================
   Mobile
   ========================================================= */
@media (max-width: 768px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    left: 0; top: 0;
    width: 280px;
    transform: translateX(-100%);
    transition: transform var(--transition);
    box-shadow: var(--shadow-2);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.open { display: block; }
  #openSidebar { display: inline-flex !important; }
  .welcome-title { font-size: 28px; }
  .suggestions { grid-template-columns: 1fr; }
  .msg { padding: 14px 12px; }
  .composer { padding: 0 8px 10px; }
  .composer-inner { padding: 6px 6px 6px 10px; }
  .msg-image { max-width: 280px; }
  .model-name { max-width: 120px; }
  .modal-content { padding: 22px 18px; }
  .toasts { top: 8px; right: 8px; }
  .toast { min-width: 180px; }
}
#openSidebar { display: none; }
#closeSidebar { display: none; }
@media (max-width: 768px) {
  #closeSidebar { display: inline-flex; }
}
