/* ═══════════════════════════════════════════════════════════
   🕌 اوای یقین — استایل اصلی
   ═══════════════════════════════════════════════════════════ */

:root {
  --sky-50: #f0f9ff; --sky-100: #e0f2fe; --sky-200: #bae6fd;
  --sky-300: #7dd3fc; --sky-400: #38bdf8; --sky-500: #0ea5e9;
  --sky-600: #0284c7; --sky-700: #0369a1; --sky-800: #075985;
  --sky-900: #0c4a6e;
  
  --bg: #ffffff;
  --bg-alt: #f7f9fc;
  --sidebar: #f9fafb;
  --sidebar-hover: #eef2f7;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --text: #0f172a;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  
  --user-bubble: #f0f4f8;
  --ai-bg: transparent;
  
  --shadow-sm: 0 1px 2px rgba(15,23,42,.04);
  --shadow-md: 0 4px 12px rgba(15,23,42,.08);
  --shadow-lg: 0 12px 32px rgba(15,23,42,.12);
  --shadow-xl: 0 20px 50px rgba(15,23,42,.15);
  
  --input-bg: #ffffff;
  --accent: #0ea5e9;
  --accent-hover: #0284c7;
  --danger: #ef4444;
  --success: #10b981;
  
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-full: 9999px;
  
  --font: "Segoe UI", "Tahoma", "Arial", -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: "SF Mono", "Monaco", "Consolas", "Courier New", monospace;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --bg-alt: #1e293b;
  --sidebar: #0a0f1e;
  --sidebar-hover: #1a2336;
  --border: #1e293b;
  --border-strong: #334155;
  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --user-bubble: #1e293b;
  --input-bg: #1e293b;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,.4);
  --shadow-lg: 0 12px 32px rgba(0,0,0,.5);
  --shadow-xl: 0 20px 50px rgba(0,0,0,.6);
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  overscroll-behavior: none;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body { overflow: hidden; transition: background .25s ease, color .25s ease; }

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

/* ─────────────────────────────────────────────
   Layout
   ───────────────────────────────────────────── */
.app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  position: relative;
  overflow: hidden;
}

/* ─────────────────────────────────────────────
   Sidebar
   ───────────────────────────────────────────── */
.sidebar {
  width: 260px;
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  z-index: 20;
  padding-top: var(--safe-top);
  flex-shrink: 0;
  transition: margin-right .3s cubic-bezier(.4,0,.2,1), width .3s cubic-bezier(.4,0,.2,1);
}
.sidebar.collapsed { width: 0; border: 0; overflow: hidden; }

.sidebar-inner {
  width: 260px;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 12px 10px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background .15s;
}
.brand:hover { background: var(--sidebar-hover); }

.brand-logo {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--sky-400), var(--sky-700));
  display: grid;
  place-items: center;
  box-shadow: 0 2px 8px rgba(14,165,233,.35);
  flex-shrink: 0;
}
.brand-logo svg { width: 20px; height: 20px; color: #fff; }

.brand-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.2px;
}

.new-chat-btn {
  height: 42px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  background: var(--bg);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  transition: .15s;
  margin-bottom: 10px;
  box-shadow: var(--shadow-sm);
}
.new-chat-btn:hover { background: var(--sidebar-hover); transform: translateY(-1px); }
.new-chat-btn:active { transform: translateY(0); }
.new-chat-btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.search-box {
  height: 38px;
  margin: 0 2px 12px;
  border-radius: var(--radius-md);
  background: var(--sidebar-hover);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 8px;
  color: var(--text-secondary);
  transition: .15s;
  border: 1px solid transparent;
}
.search-box:focus-within {
  background: var(--bg);
  border-color: var(--accent);
}
.search-box svg { width: 15px; height: 15px; flex-shrink: 0; }
.search-box input {
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 13px;
  color: var(--text);
}
.search-box input::placeholder { color: var(--text-muted); }

.section-label {
  font-size: 11px;
  color: var(--text-muted);
  padding: 10px 12px 6px;
  font-weight: 700;
  letter-spacing: .3px;
}

.history {
  flex: 1;
  overflow-y: auto;
  padding: 0 2px;
  margin: 0 -2px;
  -webkit-overflow-scrolling: touch;
}
.history::-webkit-scrollbar { width: 5px; }
.history::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; }

.chat-item {
  padding: 9px 11px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 2px 0;
  color: var(--text);
  transition: .12s;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  position: relative;
  min-height: 40px;
}
.chat-item:hover { background: var(--sidebar-hover); }
.chat-item.active {
  background: var(--sky-100);
  color: var(--sky-800);
  font-weight: 600;
}
[data-theme="dark"] .chat-item.active {
  background: #1a2e47;
  color: var(--sky-300);
}

.chat-item .title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 8px;
}
.chat-item .title svg { width: 14px; height: 14px; flex-shrink: 0; opacity: .6; }

.chat-item .del-btn {
  position: absolute;
  left: 6px;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0;
  color: var(--text-muted);
  transition: opacity .15s, color .15s, background .15s;
  padding: 6px;
  border-radius: 6px;
  display: grid;
  place-items: center;
}
.chat-item:hover .del-btn { opacity: 1; }
.chat-item .del-btn:hover { background: rgba(239,68,68,.15); color: var(--danger); }
.chat-item .del-btn svg { width: 14px; height: 14px; }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 8px;
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.side-btn {
  width: 100%;
  height: 42px;
  border-radius: var(--radius-md);
  text-align: right;
  padding: 0 12px;
  font-size: 13.5px;
  color: var(--text);
  transition: .12s;
  display: flex;
  align-items: center;
  gap: 11px;
}
.side-btn:hover { background: var(--sidebar-hover); }
.side-btn svg {
  width: 17px; height: 17px;
  color: var(--text-secondary);
  flex-shrink: 0;
}
.side-btn.admin svg { color: #f59e0b; }
.side-btn.danger svg { color: var(--danger); }

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  margin-top: 4px;
  border: 1px solid transparent;
  min-height: 46px;
}
.user-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--sky-400), var(--sky-700));
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-info .name {
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-info .phone {
  font-size: 10.5px;
  color: var(--text-secondary);
  direction: ltr;
  text-align: right;
}
.admin-badge {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  color: #fff;
  font-size: 9px;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  font-weight: 700;
  white-space: nowrap;
}

/* ─────────────────────────────────────────────
   Main
   ───────────────────────────────────────────── */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}

.top-bar {
  height: calc(56px + var(--safe-top));
  padding: 0 12px;
  padding-top: var(--safe-top);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg);
  z-index: 4;
  border-bottom: 1px solid transparent;
  transition: border-color .2s;
  flex-shrink: 0;
}
.top-bar.scrolled { border-color: var(--border); }

.top-bar-left, .top-bar-right { display: flex; align-items: center; gap: 4px; }

.icon-btn {
  width: 38px; height: 38px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  display: grid;
  place-items: center;
  transition: .12s;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--sidebar-hover); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }

.model-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: .12s;
}
.model-selector:hover { background: var(--sidebar-hover); }
.model-selector .name { font-size: 14.5px; font-weight: 600; }
.model-selector .badge {
  font-size: 10px;
  font-weight: 500;
  background: var(--sky-100);
  color: var(--sky-700);
  padding: 2px 8px;
  border-radius: var(--radius-full);
  border: 1px solid var(--sky-200);
  white-space: nowrap;
}
[data-theme="dark"] .model-selector .badge {
  background: #1a2e47;
  color: var(--sky-300);
  border-color: #2a4a6b;
}
.model-selector .chev { width: 12px; height: 12px; opacity: .5; }

.mobile-only { display: none; }

/* ─────────────────────────────────────────────
   Content / Messages
   ───────────────────────────────────────────── */
.content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
  position: relative;
  overscroll-behavior: contain;
}
.content::-webkit-scrollbar { width: 8px; }
.content::-webkit-scrollbar-track { background: transparent; }
.content::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 4px;
  border: 2px solid var(--bg);
}

.wrap {
  max-width: 768px;
  margin: 0 auto;
  padding: 0 20px 220px;
}

/* ── Welcome Screen ── */
.welcome {
  text-align: center;
  padding-top: 8vh;
  animation: fadeUp .5s ease;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}

.welcome-logo {
  width: 100px; height: 100px;
  margin: 0 auto 22px;
  display: grid;
  place-items: center;
  filter: drop-shadow(0 10px 24px rgba(14,165,233,.3));
}
.welcome-logo svg { width: 100%; height: 100%; }

.welcome h1 {
  font-size: 26px;
  font-weight: 700;
  margin: 0 0 12px;
  color: var(--text);
  letter-spacing: -.5px;
  line-height: 1.4;
}
.welcome p {
  color: var(--text-secondary);
  font-size: 14.5px;
  margin-bottom: 18px;
  line-height: 2;
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
}
.welcome .ayah {
  display: inline-block;
  background: var(--sky-50);
  border: 1px solid var(--sky-100);
  color: var(--sky-700);
  padding: 8px 18px;
  border-radius: var(--radius-full);
  font-size: 12.5px;
  margin-bottom: 32px;
  box-shadow: var(--shadow-sm);
}
[data-theme="dark"] .welcome .ayah {
  background: #1a2e47;
  border-color: #2a4a6b;
  color: var(--sky-300);
}

.suggestion-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  max-width: 620px;
  margin: 0 auto;
}
.suggestion {
  text-align: right;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  background: var(--bg);
  transition: .18s;
  box-shadow: var(--shadow-sm);
  min-height: 76px;
  cursor: pointer;
}
.suggestion:hover {
  background: var(--bg-alt);
  border-color: var(--sky-300);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.suggestion strong {
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
  color: var(--sky-700);
  font-weight: 600;
}
[data-theme="dark"] .suggestion strong { color: var(--sky-300); }
.suggestion strong svg { width: 15px; height: 15px; }
.suggestion span {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.7;
}

/* ── Messages ── */
.message {
  display: flex;
  gap: 14px;
  margin: 22px 0;
  font-size: 15px;
  line-height: 1.9;
  animation: fadeIn .25s ease;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-avatar {
  width: 32px; height: 32px;
  min-width: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  overflow: hidden;
  flex-shrink: 0;
}
.ai .msg-avatar {
  background: linear-gradient(135deg, var(--sky-400), var(--sky-700));
  color: #fff;
  box-shadow: 0 2px 8px rgba(14,165,233,.3);
}
.ai .msg-avatar svg { width: 18px; height: 18px; }
.user .msg-avatar {
  background: var(--sky-100);
  color: var(--sky-700);
  font-size: 12px;
  border: 1px solid var(--sky-200);
}
[data-theme="dark"] .user .msg-avatar {
  background: #1a2e47;
  color: var(--sky-300);
  border-color: #2a4a6b;
}

.msg-body {
  flex: 1;
  min-width: 0;
  max-width: calc(100% - 46px);
  padding-top: 4px;
}

.user .msg-body {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.msg-bubble {
  max-width: 100%;
  word-wrap: break-word;
}
.user .msg-bubble {
  background: var(--user-bubble);
  border-radius: 18px 18px 4px 18px;
  padding: 10px 16px;
  color: var(--text);
}
.ai .msg-bubble {
  color: var(--text);
  line-height: 2;
}

.msg-text {
  white-space: pre-wrap;
  word-break: break-word;
}
.user .msg-text { white-space: normal; }

/* ── Markdown in AI messages ── */
.ai .msg-text h1,
.ai .msg-text h2,
.ai .msg-text h3,
.ai .msg-text h4 {
  margin: 16px 0 8px;
  color: var(--sky-700);
  font-weight: 700;
  line-height: 1.4;
}
[data-theme="dark"] .ai .msg-text h1,
[data-theme="dark"] .ai .msg-text h2,
[data-theme="dark"] .ai .msg-text h3,
[data-theme="dark"] .ai .msg-text h4 { color: var(--sky-300); }
.ai .msg-text h1 { font-size: 20px; }
.ai .msg-text h2 { font-size: 18px; }
.ai .msg-text h3 { font-size: 16px; }
.ai .msg-text h4 { font-size: 15px; }
.ai .msg-text p { margin: 8px 0; }
.ai .msg-text ul,
.ai .msg-text ol { margin: 8px 22px 8px 0; padding-right: 0; }
.ai .msg-text li { margin: 4px 0; }
.ai .msg-text strong { font-weight: 700; color: var(--text); }
.ai .msg-text em { font-style: italic; }

.ai .msg-text code {
  background: var(--sky-50);
  padding: 2px 7px;
  border-radius: 6px;
  font-size: 13px;
  font-family: var(--mono);
  color: #be185d;
  border: 1px solid var(--sky-100);
}
[data-theme="dark"] .ai .msg-text code {
  background: #1a2e47;
  color: #f472b6;
  border-color: #2a4a6b;
}
.ai .msg-text pre {
  background: #0f172a;
  color: #e2e8f0;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  overflow-x: auto;
  margin: 12px 0;
  direction: ltr;
  text-align: left;
  font-size: 13px;
  line-height: 1.6;
}
.ai .msg-text pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  border: 0;
  font-size: inherit;
}
.ai .msg-text blockquote {
  border-right: 3px solid var(--sky-400);
  padding: 8px 14px;
  background: var(--sky-50);
  margin: 10px 0;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  color: var(--sky-800);
  font-style: italic;
}
[data-theme="dark"] .ai .msg-text blockquote {
  background: #1a2e47;
  color: var(--sky-300);
}
.ai .msg-text a { color: var(--accent); text-decoration: underline; }
.ai .msg-text hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
.ai .msg-text table {
  border-collapse: collapse;
  width: 100%;
  margin: 12px 0;
  font-size: 13px;
  border-radius: var(--radius-md);
  overflow: hidden;
}
.ai .msg-text th,
.ai .msg-text td {
  border: 1px solid var(--border);
  padding: 8px 12px;
  text-align: right;
}
.ai .msg-text th {
  background: var(--sky-50);
  font-weight: 600;
}
[data-theme="dark"] .ai .msg-text th { background: #1a2e47; }

/* ── Image in message ── */
.msg-image {
  max-width: 280px;
  max-height: 280px;
  border-radius: var(--radius-md);
  margin-top: 8px;
  display: block;
  cursor: pointer;
  transition: transform .2s;
  border: 1px solid var(--border);
}
.msg-image:hover { transform: scale(1.02); }

/* ── Message actions ── */
.msg-actions {
  display: flex;
  gap: 2px;
  margin-top: 8px;
  opacity: 0;
  transition: opacity .2s;
  flex-wrap: wrap;
}
.message:hover .msg-actions { opacity: 1; }
.msg-actions button {
  font-size: 14px;
  color: var(--text-muted);
  padding: 6px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  min-width: 30px;
  min-height: 30px;
  transition: .12s;
}
.msg-actions button:hover {
  background: var(--sidebar-hover);
  color: var(--accent);
}
.msg-actions button svg { width: 15px; height: 15px; }
.msg-actions button.active { color: var(--accent); background: var(--sky-50); }

/* ── Typing indicator ── */
.typing-indicator {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 8px 0;
}
.typing-indicator span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.3s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: .18s; }
.typing-indicator span:nth-child(3) { animation-delay: .36s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* ── Cursor while streaming ── */
.streaming-cursor {
  display: inline-block;
  width: 8px;
  height: 18px;
  background: var(--accent);
  margin-right: 2px;
  vertical-align: middle;
  animation: blink 1s infinite;
  border-radius: 2px;
}
@keyframes blink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

/* ─────────────────────────────────────────────
   Composer
   ───────────────────────────────────────────── */
.composer-area {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 16px 20px calc(12px + var(--safe-bottom));
  background: linear-gradient(transparent, var(--bg) 30%);
  pointer-events: none;
  z-index: 6;
}

.composer {
  max-width: 768px;
  margin: auto;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xl);
  background: var(--input-bg);
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: flex-end;
  padding: 6px 6px 6px 14px;
  gap: 4px;
  pointer-events: auto;
  transition: border-color .2s, box-shadow .2s;
  position: relative;
}
.composer:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(14,165,233,.1), var(--shadow-md);
}

.composer textarea {
  flex: 1;
  min-height: 28px;
  max-height: 180px;
  resize: none;
  border: 0;
  outline: 0;
  padding: 8px 2px;
  background: transparent;
  line-height: 1.6;
  font-size: 15.5px;
  color: var(--text);
  font-family: inherit;
}
.composer textarea::placeholder { color: var(--text-muted); }

.composer-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  color: var(--text-secondary);
  font-size: 20px;
  display: grid;
  place-items: center;
  transition: .12s;
  flex-shrink: 0;
}
.composer-btn:hover { background: var(--sidebar-hover); color: var(--accent); }
.composer-btn svg { width: 20px; height: 20px; }
.composer-btn.recording {
  background: #fef2f2;
  color: var(--danger);
  animation: pulseRing 1.5s infinite;
}
@keyframes pulseRing {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,.5); }
  50% { box-shadow: 0 0 0 10px rgba(239,68,68,0); }
}
.composer-btn.has-image { background: var(--sky-100); color: var(--accent); }

.send-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  transition: .15s;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(14,165,233,.35);
}
.send-btn:hover:not(:disabled) { background: var(--accent-hover); transform: scale(1.05); }
.send-btn:disabled {
  background: var(--border-strong);
  color: var(--text-muted);
  cursor: not-allowed;
  box-shadow: none;
}
.send-btn svg { width: 16px; height: 16px; }
.send-btn.stop {
  background: var(--danger);
  box-shadow: 0 2px 8px rgba(239,68,68,.35);
}
.send-btn.stop:hover { background: #dc2626; }

/* ── Image preview ── */
.image-preview {
  position: absolute;
  bottom: 100%;
  margin-bottom: 10px;
  right: 14px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 6px;
  display: none;
  box-shadow: var(--shadow-lg);
}
.image-preview.show { display: block; }
.image-preview img {
  max-width: 90px;
  max-height: 90px;
  border-radius: var(--radius-sm);
  display: block;
}
.image-preview .remove-img {
  position: absolute;
  top: -8px;
  right: -8px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-md);
}
.image-preview .remove-img svg { width: 12px; height: 12px; }

/* ── Footer note ── */
.composer-note {
  text-align: center;
  color: var(--text-muted);
  font-size: 10.5px;
  margin-top: 8px;
  pointer-events: auto;
  line-height: 1.7;
  opacity: .85;
  padding: 0 8px;
}
.composer-note strong { color: var(--sky-600); }

/* ─────────────────────────────────────────────
   Scroll to bottom
   ───────────────────────────────────────────── */
.scroll-bottom {
  position: absolute;
  bottom: 150px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  display: grid;
  place-items: center;
  box-shadow: var(--shadow-md);
  z-index: 5;
  transition: .2s;
  opacity: 0;
  pointer-events: none;
}
.scroll-bottom.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}
.scroll-bottom:hover { background: var(--bg-alt); }
.scroll-bottom svg { width: 16px; height: 16px; }

/* ─────────────────────────────────────────────
   Login Screen
   ───────────────────────────────────────────── */
.login-screen {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #0c4a6e, #0369a1, #0ea5e9);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
  transition: opacity .4s, transform .4s;
}
.login-screen.hide {
  opacity: 0;
  pointer-events: none;
  transform: scale(1.03);
}

.login-card {
  background: #fff;
  border-radius: var(--radius-xl);
  padding: 36px 28px;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow-xl);
  animation: slideUp .5s cubic-bezier(.4,0,.2,1);
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: translateY(0); }
}

.login-logo {
  width: 84px;
  height: 84px;
  margin: 0 auto 20px;
  display: grid;
  place-items: center;
  filter: drop-shadow(0 8px 18px rgba(14,165,233,.35));
}
.login-logo svg { width: 100%; height: 100%; }

.login-card h1 {
  text-align: center;
  font-size: 22px;
  color: #0c4a6e;
  margin-bottom: 8px;
  font-weight: 700;
}
.login-card .sub {
  text-align: center;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 26px;
  line-height: 1.8;
}

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12.5px;
  color: #475569;
  margin-bottom: 6px;
  font-weight: 600;
}
.field input {
  width: 100%;
  height: 50px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0 16px;
  font-size: 15px;
  background: var(--bg-alt);
  transition: .15s;
  color: #0c2d48;
  outline: none;
}
.field input:focus {
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 4px rgba(14,165,233,.1);
}
.field input::placeholder { color: var(--text-muted); }

.login-btn {
  width: 100%;
  height: 52px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--sky-400), var(--sky-700));
  color: #fff;
  font-size: 15.5px;
  font-weight: 700;
  margin-top: 8px;
  transition: .2s;
  box-shadow: 0 8px 20px rgba(14,165,233,.35);
  letter-spacing: .2px;
}
.login-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(14,165,233,.45);
}
.login-btn:disabled { opacity: .6; cursor: not-allowed; }

.login-error {
  background: #fef2f2;
  color: #dc2626;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-size: 13px;
  margin-bottom: 14px;
  border: 1px solid #fecaca;
  display: none;
  line-height: 1.7;
}
.login-error.show { display: block; }

.login-footer {
  text-align: center;
  margin-top: 18px;
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.9;
}
.login-footer strong { color: var(--sky-700); }

/* ─────────────────────────────────────────────
   Modal
   ───────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn .2s ease;
}
.modal-overlay.show { display: flex; }

.modal {
  background: var(--bg);
  border-radius: var(--radius-lg);
  padding: 22px;
  max-width: 440px;
  width: 100%;
  box-shadow: var(--shadow-xl);
  animation: scaleIn .22s ease;
  max-height: 85vh;
  overflow-y: auto;
}
@keyframes scaleIn {
  from { opacity: 0; transform: scale(.95); }
  to { opacity: 1; transform: scale(1); }
}

.modal h3 {
  font-size: 17px;
  margin-bottom: 14px;
  color: var(--sky-800);
  display: flex;
  align-items: center;
  gap: 8px;
}
[data-theme="dark"] .modal h3 { color: var(--sky-300); }
.modal h3 svg { width: 20px; height: 20px; }

.modal-btns {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}
.modal-btns button {
  padding: 10px 20px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  font-weight: 600;
  transition: .12s;
  min-height: 42px;
}
.btn-secondary { background: var(--sidebar-hover); color: var(--text); }
.btn-secondary:hover { background: var(--border); }
.btn-primary {
  background: linear-gradient(135deg, var(--sky-400), var(--sky-700));
  color: #fff;
  box-shadow: 0 4px 12px rgba(14,165,233,.3);
}
.btn-primary:hover { box-shadow: 0 6px 18px rgba(14,165,233,.4); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }

/* ─────────────────────────────────────────────
   Toast
   ───────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--sky-900);
  color: #fff;
  padding: 12px 22px;
  border-radius: var(--radius-md);
  font-size: 13.5px;
  box-shadow: var(--shadow-xl);
  z-index: 2000;
  transition: transform .3s;
  pointer-events: none;
  max-width: 90%;
  text-align: center;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

/* ─────────────────────────────────────────────
   Backdrop (mobile)
   ───────────────────────────────────────────── */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(2px);
  z-index: 15;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
}
.backdrop.show { opacity: 1; pointer-events: auto; }

/* ─────────────────────────────────────────────
   Image Lightbox
   ───────────────────────────────────────────── */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.9);
  z-index: 3000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  cursor: zoom-out;
}
.lightbox.show { display: flex; }
.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xl);
}
.lightbox .close-lightbox {
  position: absolute;
  top: 20px;
  left: 20px;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255,255,255,.15);
  color: #fff;
  display: grid;
  place-items: center;
  backdrop-filter: blur(10px);
}
.lightbox .close-lightbox svg { width: 20px; height: 20px; }

/* ─────────────────────────────────────────────
   Responsive
   ───────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    transform: translateX(100%);
    width: 280px;
    padding-top: 0;
    box-shadow: -10px 0 40px rgba(0,0,0,.2);
    transition: transform .3s cubic-bezier(.4,0,.2,1);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar.collapsed { width: 280px; transform: translateX(100%); }
  .sidebar-inner { width: 280px; }
  
  .mobile-only { display: grid; }
  #collapseBtn { display: none; }
  
  .wrap { padding: 0 14px 200px; }
  .welcome { padding-top: 5vh; }
  .welcome h1 { font-size: 21px; }
  .welcome-logo { width: 80px; height: 80px; }
  .suggestion-grid { grid-template-columns: 1fr; }
  
  .message { font-size: 14.5px; gap: 11px; margin: 20px 0; }
  .msg-avatar { width: 30px; height: 30px; min-width: 30px; }
  .msg-body { max-width: calc(100% - 42px); }
  .msg-actions { opacity: 1; }
  
  .composer-area { padding: 12px 12px calc(10px + var(--safe-bottom)); }
  .composer { padding: 5px 5px 5px 10px; border-radius: var(--radius-xl); }
  .composer-btn { width: 38px; height: 38px; }
  .send-btn { width: 36px; height: 36px; }
  
  .scroll-bottom { bottom: 130px; width: 38px; height: 38px; }
  
  .login-card { padding: 28px 22px; border-radius: var(--radius-lg); }
  .login-card h1 { font-size: 20px; }
  .login-logo { width: 68px; height: 68px; }
}

@media (max-width: 480px) {
  .top-bar { height: calc(54px + var(--safe-top)); }
  .model-selector .badge { display: none; }
  .model-selector .name { font-size: 14px; }
  .wrap { padding: 0 12px 200px; }
  .welcome h1 { font-size: 19px; }
  .message { font-size: 14px; }
}
