/* ============================================================
   AI Chat — OpenRouter | Main Stylesheet
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-primary:    #0a0a0f;
  --bg-secondary:  #111118;
  --bg-card:       #16161f;
  --bg-hover:      #1e1e2a;
  --bg-input:      #1a1a25;
  --border:        rgba(255,255,255,.07);
  --border-focus:  rgba(124,58,237,.5);
  --text-primary:  #f0f0f8;
  --text-secondary:#8b8ba0;
  --text-muted:    #55556a;
  --accent:        #7c3aed;
  --accent-hover:  #6d28d9;
  --accent-light:  rgba(124,58,237,.15);
  --accent-glow:   rgba(124,58,237,.3);
  --blue:          #2563eb;
  --green:         #10b981;
  --red:           #ef4444;
  --amber:         #f59e0b;
  --radius-sm:     8px;
  --radius-md:     12px;
  --radius-lg:     16px;
  --radius-xl:     20px;
  --sidebar-w:     280px;
  --topbar-h:      60px;
  --shadow-sm:     0 2px 8px rgba(0,0,0,.4);
  --shadow-md:     0 4px 20px rgba(0,0,0,.5);
  --shadow-glow:   0 0 30px rgba(124,58,237,.15);
  --transition:    all .2s ease;
}

html {
  height: 100%;
  height: 100dvh;
}

body {
  height: 100%;
  height: 100dvh;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,.1); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,.2); }

/* ══════════════════════════════════════════
   LAYOUT
══════════════════════════════════════════ */
body {
  display: flex;
  height: 100vh;
  height: 100dvh;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  height: 100vh;
  height: 100dvh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  position: relative;
  z-index: 100;
  transition: transform .3s ease;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}
.logo-icon {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, var(--accent), var(--blue));
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  color: white;
  box-shadow: 0 0 16px var(--accent-glow);
}
.logo-text {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -.3px;
  background: linear-gradient(135deg, #c4b5fd, #93c5fd);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

/* ── Credit Card ── */
.credit-card {
  margin: 16px;
  background: linear-gradient(135deg, rgba(124,58,237,.2), rgba(37,99,235,.15));
  border: 1px solid rgba(124,58,237,.3);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
}
.credit-card::before {
  content: '';
  position: absolute;
  top: -30px; right: -30px;
  width: 100px; height: 100px;
  background: radial-gradient(circle, rgba(124,58,237,.25) 0%, transparent 70%);
  pointer-events: none;
}
.credit-label {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 6px;
}
.credit-amount {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -.5px;
  min-height: 30px;
  display: flex;
  align-items: center;
}
.credit-spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.credit-refresh {
  margin-top: 8px;
  display: flex;
  justify-content: flex-end;
}

/* ── Model Section ── */
.model-section {
  padding: 0 16px 12px;
  flex-shrink: 0;
}
.section-label {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  font-weight: 600;
  margin-bottom: 8px;
}
.model-select-wrapper {
  position: relative;
}
.model-select {
  width: 100%;
  appearance: none;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 9px 36px 9px 12px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
}
.model-select:focus { outline: none; border-color: var(--border-focus); box-shadow: 0 0 0 3px var(--accent-light); }
.model-select option { background: #1a1a25; }
.model-select-arrow {
  position: absolute;
  right: 10px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}
.model-info {
  margin-top: 6px;
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.4;
}

/* ── History ── */
.history-section {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.history-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 8px;
}
.history-empty-state {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  padding: 20px 0;
}
.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid transparent;
  color: var(--text-secondary);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.history-item.active { background: var(--accent-light); border-color: rgba(124,58,237,.2); color: var(--text-primary); }
.history-item svg { flex-shrink: 0; color: var(--text-muted); }

/* ── Sidebar Footer ── */
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.btn-sidebar-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  background: none;
  border: none;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
}
.btn-sidebar-footer:hover { background: var(--bg-hover); color: var(--text-primary); }
.admin-link svg { color: var(--amber); }


/* ══════════════════════════════════════════
   MAIN CONTENT
══════════════════════════════════════════ */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg-primary);
}

/* ── Topbar ── */
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  border-bottom: 1px solid var(--border);
  background: rgba(10,10,15,.8);
  backdrop-filter: blur(12px);
  flex-shrink: 0;
}
.topbar-title {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -.2px;
}
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.mobile-menu-btn { display: none; }

/* Credit Badge in topbar */
.credit-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 4px 12px 4px 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}
.credit-dot {
  width: 7px; height: 7px;
  background: var(--green);
  border-radius: 50%;
  box-shadow: 0 0 6px var(--green);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .5; }
}

/* ── Messages Area ── */
.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── Welcome Screen ── */
.welcome-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  animation: fadeInUp .5s ease;
}
.welcome-icon {
  width: 80px; height: 80px;
  background: radial-gradient(circle, rgba(124,58,237,.2) 0%, transparent 70%);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 24px;
  border: 1px solid rgba(124,58,237,.2);
}
.welcome-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -.5px;
  margin-bottom: 8px;
  background: linear-gradient(135deg, var(--text-primary) 30%, var(--text-secondary));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.welcome-subtitle {
  color: var(--text-muted);
  font-size: 15px;
  margin-bottom: 32px;
}
.suggestion-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  max-width: 600px;
}
.chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 100px;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: var(--transition);
}
.chip:hover {
  background: var(--bg-hover);
  border-color: rgba(124,58,237,.3);
  color: var(--text-primary);
  transform: translateY(-1px);
}

/* ── Messages ── */
.message {
  display: flex;
  gap: 12px;
  animation: fadeInUp .3s ease;
  max-width: 100%;
}
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.message.user { flex-direction: row-reverse; }

.message-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  font-weight: 700;
}
.message.user .message-avatar {
  background: linear-gradient(135deg, var(--accent), var(--blue));
  color: white;
}
.message.assistant .message-avatar {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}

.message-content {
  flex: 1;
  max-width: calc(100% - 44px);
}
.message.user .message-content {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.message-bubble {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  line-height: 1.7;
  max-width: 680px;
}
.message.user .message-bubble {
  background: linear-gradient(135deg, var(--accent), var(--blue));
  color: white;
  border-bottom-right-radius: 4px;
}
.message.assistant .message-bubble {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.message-bubble pre {
  background: rgba(0,0,0,.5);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: var(--radius-sm);
  padding: 12px;
  overflow-x: auto;
  margin: 10px 0;
  font-size: 13px;
  line-height: 1.5;
}
.message-bubble code {
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 13px;
  background: rgba(0,0,0,.35);
  padding: 1px 5px;
  border-radius: 4px;
}
.message-bubble pre code { background: none; padding: 0; }
.message-bubble p { margin: 6px 0; }
.message-bubble ul, .message-bubble ol { padding-left: 20px; margin: 6px 0; }
.message-bubble h1,.message-bubble h2,.message-bubble h3 { margin: 12px 0 6px; font-weight: 600; }
.message-bubble strong { font-weight: 600; }
.message-bubble a { color: #a78bfa; }

.message-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-muted);
}
.message.user .message-meta { justify-content: flex-end; }

.message-files {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}
.message.user .message-files { justify-content: flex-end; }

.file-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: var(--radius-sm);
  font-size: 12px;
  cursor: pointer;
  transition: var(--transition);
}
.file-chip:hover { background: rgba(255,255,255,.12); }
.file-chip svg { color: var(--text-muted); flex-shrink: 0; }

.attached-image {
  max-width: 280px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid rgba(255,255,255,.1);
}
.attached-image:hover { opacity: .9; transform: scale(1.01); }

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 14px 16px;
  align-items: center;
}
.typing-dot {
  width: 6px; height: 6px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce .8s infinite;
}
.typing-dot:nth-child(2) { animation-delay: .15s; }
.typing-dot:nth-child(3) { animation-delay: .3s; }
@keyframes bounce {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-6px); }
}

/* ── File Preview Area ── */
.file-preview-area {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 20px 8px;
  flex-shrink: 0;
}
.file-preview-area:empty { display: none; }
.preview-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 12px;
  color: var(--text-secondary);
  max-width: 200px;
}
.preview-item img {
  width: 32px; height: 32px;
  object-fit: cover;
  border-radius: 4px;
}
.preview-item-name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.preview-remove {
  width: 18px; height: 18px;
  background: rgba(239,68,68,.2);
  border: none;
  border-radius: 50%;
  color: var(--red);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: var(--transition);
}
.preview-remove:hover { background: rgba(239,68,68,.35); }

/* ── Input Area ── */
.input-area {
  padding: 12px 20px 20px;
  flex-shrink: 0;
  background: linear-gradient(to top, var(--bg-primary) 80%, transparent);
}
.input-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px 10px 10px 12px;
  transition: var(--transition);
}
.input-wrapper:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-light);
}
.message-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  resize: none;
  min-height: 24px;
  max-height: 200px;
  outline: none;
  line-height: 1.6;
}
.message-input::placeholder { color: var(--text-muted); }
.input-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 4px 0;
}
.input-hint {
  font-size: 11px;
  color: var(--text-muted);
}
.input-hint kbd {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: inherit;
  font-size: 10px;
}
.model-badge {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 2px 8px;
}

/* ══════════════════════════════════════════
   BUTTONS
══════════════════════════════════════════ */
.btn-icon {
  width: 32px; height: 32px;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-attach {
  width: 34px; height: 34px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
}
.btn-attach:hover { color: var(--text-primary); border-color: var(--border-focus); }

.btn-send {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--accent), var(--blue));
  border: none;
  border-radius: 10px;
  color: white;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
  box-shadow: 0 2px 12px var(--accent-glow);
}
.btn-send:hover:not(:disabled) { transform: scale(1.05); box-shadow: 0 4px 16px var(--accent-glow); }
.btn-send:disabled { opacity: .4; cursor: not-allowed; }

.btn-text-small {
  display: flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 11px;
  cursor: pointer;
  transition: var(--transition);
  padding: 2px 4px;
  border-radius: 4px;
}
.btn-text-small:hover { color: var(--text-secondary); }

.btn-primary {
  padding: 10px 20px;
  background: linear-gradient(135deg, var(--accent), var(--blue));
  border: none;
  border-radius: var(--radius-sm);
  color: white;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}
.btn-primary:hover { opacity: .9; transform: translateY(-1px); }

.btn-secondary {
  padding: 10px 20px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: var(--transition);
}
.btn-secondary:hover { background: var(--bg-card); color: var(--text-primary); }

.btn-icon-sm {
  width: 28px; height: 28px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text-muted);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}
.btn-icon-sm:hover { color: var(--text-primary); }

/* ══════════════════════════════════════════
   MODAL
══════════════════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn .2s ease;
}
.modal-overlay.open { display: flex; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  width: 480px;
  max-width: calc(100vw - 40px);
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-md), var(--shadow-glow);
  animation: slideUp .3s ease;
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h2 { font-size: 16px; font-weight: 700; }
.modal-body {
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
}
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px 20px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ── Form Elements ── */
.form-group { display: flex; flex-direction: column; gap: 8px; }
.form-label { font-size: 13px; font-weight: 600; color: var(--text-secondary); }
.form-input, .form-textarea {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  transition: var(--transition);
  width: 100%;
}
.form-input:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-light);
}
.form-textarea { resize: vertical; min-height: 80px; line-height: 1.6; }
.form-hint { font-size: 12px; color: var(--text-muted); }
.input-with-icon { position: relative; display: flex; align-items: center; }
.input-with-icon .form-input { padding-right: 42px; }
.input-with-icon .btn-icon-sm { position: absolute; right: 8px; }
.range-wrapper { display: flex; align-items: center; gap: 12px; }
.range-input {
  flex: 1;
  height: 4px;
  appearance: none;
  background: linear-gradient(to right, var(--accent) 0%, var(--border) 0%);
  border-radius: 2px;
  cursor: pointer;
}
.range-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
  cursor: pointer;
}
.range-value {
  min-width: 32px;
  text-align: right;
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
}

/* ══════════════════════════════════════════
   LIGHTBOX
══════════════════════════════════════════ */
.lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.92);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}
.lightbox.open { display: flex; }
.lightbox img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
}
.lightbox-close {
  position: absolute;
  top: 20px; right: 20px;
  width: 40px; height: 40px;
  background: rgba(255,255,255,.1);
  border: none;
  border-radius: 50%;
  color: white;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}
.lightbox-close:hover { background: rgba(255,255,255,.2); }

/* ══════════════════════════════════════════
   TOASTS
══════════════════════════════════════════ */
.toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 3000;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  color: var(--text-primary);
  animation: slideInRight .3s ease;
  max-width: 320px;
}
.toast.success { border-left: 3px solid var(--green); }
.toast.error { border-left: 3px solid var(--red); }
.toast.info { border-left: 3px solid var(--blue); }
@keyframes slideInRight {
  from { opacity: 0; transform: translateX(30px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ── Streaming cursor ── */
.streaming-cursor {
  display: inline-block;
  width: 2px;
  height: 1em;
  background: var(--text-primary);
  margin-left: 2px;
  vertical-align: text-bottom;
  animation: blink .6s infinite;
}
@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* ── Copy button on code ── */
.code-block-wrapper { position: relative; margin: 10px 0; }
.copy-code-btn {
  position: absolute;
  top: 8px; right: 8px;
  padding: 3px 8px;
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 5px;
  color: var(--text-muted);
  font-size: 11px;
  font-family: inherit;
  cursor: pointer;
  transition: var(--transition);
}
.copy-code-btn:hover { background: rgba(255,255,255,.14); color: var(--text-primary); }

/* ══════════════════════════════════════════
   USER INFO (sidebar bottom)
══════════════════════════════════════════ */
/* ── User dropdown menu ── */
.user-dropdown {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--surface-2, #1a1a2e);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 12px;
  padding: 6px;
  z-index: 200;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
  min-width: 180px;
}
.user-dropdown-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border: none;
  background: transparent;
  color: var(--text-primary, #f0f0f8);
  font-size: 13px;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  transition: background .15s;
}
.user-dropdown-item:hover {
  background: rgba(255,255,255,.07);
}
.user-dropdown-danger {
  color: #f87171;
}
.user-dropdown-danger:hover {
  background: rgba(239,68,68,.12);
}
.user-dropdown-divider {
  height: 1px;
  background: rgba(255,255,255,.08);
  margin: 4px 0;
}

.sidebar-user-info {
  border-top: 1px solid var(--border);
  padding: 10px 12px;
  flex-shrink: 0;
}
.user-info-block {
  display: flex;
  align-items: center;
  gap: 10px;
}
.user-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--blue));
  color: white;
  font-size: 14px;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.user-info-text {
  flex: 1;
  min-width: 0;
}
.user-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.user-client {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ══════════════════════════════════════════
   SIDEBAR OVERLAY (mobile)
══════════════════════════════════════════ */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 99;
}

/* ══════════════════════════════════════════
   RESPONSIVE — TABLET (max 1024px)
══════════════════════════════════════════ */
@media (max-width: 1024px) {
  :root {
    --sidebar-w: 240px;
  }

  .messages-area {
    padding: 20px 16px;
  }

  .message-bubble {
    max-width: 100%;
  }

  .input-area {
    padding: 10px 16px 16px;
  }

  .welcome-title {
    font-size: 24px;
  }

  .welcome-subtitle {
    font-size: 14px;
  }

  .suggestion-chips {
    max-width: 100%;
    padding: 0 8px;
  }

  .chip {
    font-size: 12px;
    padding: 9px 14px;
  }
}

/* ══════════════════════════════════════════
   RESPONSIVE — MOBILE (max 768px)
══════════════════════════════════════════ */
@media (max-width: 768px) {
  html, body {
    font-size: 15px;
    /* Usa dvh per rispettare la barra del browser mobile */
    height: 100dvh;
    overflow: hidden;
    position: fixed;
    width: 100%;
  }

  /* Layout principale: occupa tutto lo schermo disponibile */
  body {
    display: flex;
    flex-direction: row;
  }

  /* Sidebar: slide-in da sinistra, altezza piena */
  .sidebar {
    position: fixed;
    left: 0; top: 0;
    width: 85vw;
    max-width: 300px;
    height: 100%;
    height: 100dvh;
    transform: translateX(-100%);
    z-index: 200;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.open { display: block; }
  .mobile-menu-btn { display: flex; }

  /* Main content: occupa tutto lo schermo */
  .main-content {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  /* Topbar */
  .topbar {
    padding: 0 12px;
    height: 54px;
    flex-shrink: 0;
  }
  .topbar-title {
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .credit-badge {
    font-size: 11px;
    padding: 4px 10px 4px 7px;
  }

  /* Area messaggi: cresce e scorre */
  .messages-area {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px 12px;
    gap: 16px;
    min-height: 0; /* fondamentale per flex su mobile */
  }

  .message-bubble {
    font-size: 14px;
    padding: 10px 14px;
    max-width: 100%;
    word-break: break-word;
  }

  .message-avatar {
    width: 28px;
    height: 28px;
    font-size: 11px;
  }

  .message-content {
    max-width: calc(100% - 40px);
  }

  /* Welcome screen */
  .welcome-screen {
    padding: 20px 16px;
    justify-content: flex-start;
    padding-top: 40px;
  }
  .welcome-icon {
    width: 60px;
    height: 60px;
    margin-bottom: 14px;
  }
  .welcome-icon svg {
    width: 32px;
    height: 32px;
  }
  .welcome-title {
    font-size: 22px;
    margin-bottom: 6px;
  }
  .welcome-subtitle {
    font-size: 13px;
    margin-bottom: 20px;
    padding: 0 8px;
  }
  .suggestion-chips {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    width: 100%;
    padding: 0 4px;
  }
  .chip {
    justify-content: flex-start;
    padding: 12px 16px;
    font-size: 13px;
    border-radius: var(--radius-md);
    border-radius: 12px;
  }

  /* File preview */
  .file-preview-area {
    padding: 0 12px 6px;
    flex-shrink: 0;
  }

  /* Input area: sempre visibile in fondo */
  .input-area {
    flex-shrink: 0;
    padding: 8px 12px 12px;
    background: var(--bg-primary);
  }
  .input-wrapper {
    padding: 8px 8px 8px 12px;
    border-radius: var(--radius-md);
    gap: 6px;
  }
  .message-input {
    font-size: 16px; /* 16px evita zoom su iOS */
    min-height: 22px;
    max-height: 120px;
  }
  .input-footer {
    padding: 4px 2px 0;
  }
  .input-hint {
    display: none;
  }
  .model-badge {
    font-size: 10px;
    padding: 2px 7px;
    max-width: 160px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* Bottoni touch-friendly */
  .btn-send {
    width: 42px;
    height: 42px;
    border-radius: 12px;
  }
  .btn-attach {
    width: 40px;
    height: 40px;
  }
  .btn-icon {
    width: 38px;
    height: 38px;
  }

  /* Toast */
  .toast-container {
    bottom: 80px;
    right: 12px;
    left: 12px;
  }
  .toast {
    max-width: 100%;
  }

  /* Modal */
  .modal {
    width: calc(100vw - 24px);
    max-height: 85dvh;
    border-radius: var(--radius-lg);
  }
  .modal-header {
    padding: 16px 18px 14px;
  }
  .modal-body {
    padding: 18px;
    gap: 16px;
  }
  .modal-footer {
    padding: 14px 18px 16px;
  }

  /* Codice */
  .message-bubble pre {
    font-size: 12px;
    padding: 10px;
    max-width: 100%;
    overflow-x: auto;
  }
  .message-bubble code {
    font-size: 12px;
  }

  /* Immagini allegate */
  .attached-image {
    max-width: min(200px, 60vw);
  }
}

/* ══════════════════════════════════════════
   RESPONSIVE — SMALL MOBILE (max 480px)
══════════════════════════════════════════ */
@media (max-width: 480px) {
  .welcome-title {
    font-size: 20px;
  }
  .welcome-subtitle {
    font-size: 12px;
  }
  .topbar-title {
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
  }
  .message-bubble {
    font-size: 13px;
  }
  .message-input {
    font-size: 16px; /* evita zoom automatico su iOS */
  }
  .credit-badge {
    display: none; /* nasconde il badge credito su schermi molto piccoli */
  }
  .modal {
    width: calc(100vw - 16px);
    max-height: 90vh;
  }
}

/* ══════════════════════════════════════════
   SAFE AREA — iPhone notch / Dynamic Island
   e barra navigazione browser mobile
══════════════════════════════════════════ */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .input-area {
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }
  .topbar {
    padding-top: env(safe-area-inset-top);
  }
  .sidebar {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
  @media (max-width: 768px) {
    .input-area {
      padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }
  }
}
