/* ════════════════════════════════════════════════════════════════════════════
   BananaWeb — Atmospheric Dark/Light Dashboard
   Fonts: Space Grotesk (UI) + JetBrains Mono (data/code)
   ════════════════════════════════════════════════════════════════════════════ */

/* ─── Google Fonts already loaded via <link> ─────────────────────────────── */

/* ─── CSS Variables ──────────────────────────────────────────────────────── */
:root {
  --font-ui: 'Space Grotesk', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  --sidebar-w: 280px;
  --radius: 10px;
  --radius-lg: 16px;
  --transition: 0.22s ease;
}

/* ─── Dark theme ─────────────────────────────────────────────────────────── */
[data-theme="dark"] {
  --bg-base:       #0d1117;
  --bg-sidebar:    #111820;
  --bg-main:       #0d1117;
  --bg-surface:    #161e29;
  --bg-input:      #1a2233;
  --bg-hover:      #1e2d42;
  --bg-active:     #1a3a5c;
  --bg-card:       #131c28;
  --bg-message-u:  #1a2e44;
  --bg-message-a:  #161e29;
  --bg-code:       #0a0f17;

  --border:        rgba(255,255,255,0.07);
  --border-strong: rgba(255,255,255,0.14);

  --text-primary:  #e8f0f8;
  --text-secondary:#8ba4be;
  --text-muted:    #4a6075;
  --text-accent:   #f5a623;   /* amber — no purple/blue */
  --text-accent2:  #e07b00;

  --accent:        #f5a623;
  --accent-hover:  #ffba47;
  --accent-dim:    rgba(245,166,35,0.15);
  --accent-glow:   rgba(245,166,35,0.25);

  --danger:        #e05555;
  --success:       #3dba7a;

  --shadow-sm:     0 2px 8px rgba(0,0,0,0.4);
  --shadow-md:     0 4px 20px rgba(0,0,0,0.55);
  --shadow-lg:     0 8px 40px rgba(0,0,0,0.7);

  /* Noise / pattern overlay opacity */
  --noise-opacity: 0.025;
  --grid-opacity:  0.03;
}

/* ─── Light theme ────────────────────────────────────────────────────────── */
[data-theme="light"] {
  --bg-base:       #f5f0e8;
  --bg-sidebar:    #ede7d8;
  --bg-main:       #f5f0e8;
  --bg-surface:    #fff9ef;
  --bg-input:      #fdf7ed;
  --bg-hover:      #ede2c8;
  --bg-active:     #e3d2a8;
  --bg-card:       #faf4e8;
  --bg-message-u:  #e9dfc8;
  --bg-message-a:  #fff9ef;
  --bg-code:       #f0ead8;

  --border:        rgba(0,0,0,0.08);
  --border-strong: rgba(0,0,0,0.15);

  --text-primary:  #1c1408;
  --text-secondary:#6b5c3e;
  --text-muted:    #a89070;
  --text-accent:   #b35c00;
  --text-accent2:  #8a4000;

  --accent:        #b35c00;
  --accent-hover:  #d46c00;
  --accent-dim:    rgba(179,92,0,0.12);
  --accent-glow:   rgba(179,92,0,0.2);

  --danger:        #c0392b;
  --success:       #27ae60;

  --shadow-sm:     0 2px 8px rgba(0,0,0,0.1);
  --shadow-md:     0 4px 20px rgba(0,0,0,0.15);
  --shadow-lg:     0 8px 40px rgba(0,0,0,0.2);

  --noise-opacity: 0.04;
  --grid-opacity:  0.05;
}

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

html, body {
  height: 100%;
  /* 100dvh = dynamic viewport height, excludes browser chrome on mobile */
  height: 100dvh;
  min-height: 100svh;
  overflow: hidden;
  font-family: var(--font-ui);
  font-size: 15px;
  background: var(--bg-base);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

html {
  min-height: -webkit-fill-available;
}

/* Atmospheric background — multi-layer gradient + noise texture */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(ellipse 80% 60% at 75% 10%, color-mix(in srgb, var(--accent) 8%, transparent) 0%, transparent 55%),
    radial-gradient(ellipse 60% 40% at 15% 90%, color-mix(in srgb, var(--accent) 5%, transparent) 0%, transparent 55%),
    radial-gradient(ellipse 100% 80% at 50% 50%, var(--bg-base) 0%, transparent 100%);
}

/* Subtle grid pattern */
body::after {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px);
  background-size: 40px 40px;
  opacity: var(--grid-opacity);
}

.hidden { display: none !important; }
.mobile-only { display: none; }

/* ─── Utility ────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  border: none;
  border-radius: var(--radius);
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), box-shadow var(--transition), transform 0.12s;
  white-space: nowrap;
  position: relative;
  overflow: hidden;
}
.btn:active { transform: scale(0.97); }
.btn-icon { width: 16px; height: 16px; flex-shrink: 0; }

.btn-primary {
  background: var(--accent);
  color: #0d1117;
  font-weight: 600;
  box-shadow: 0 0 0 0 var(--accent-glow);
}
.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: 0 0 16px var(--accent-glow);
}

.btn-accent {
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid color-mix(in srgb, var(--accent) 30%, transparent);
}
.btn-accent:hover {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-full { width: 100%; justify-content: center; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0;
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }

.icon-btn-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.icon-btn-sm svg { width: 15px; height: 15px; }
.icon-btn-sm:hover { background: var(--bg-hover); color: var(--text-primary); }

.select-field {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 13px;
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%238ba4be' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}
.select-field:focus { border-color: var(--accent); }

/* ─── Theme icon toggle ──────────────────────────────────────────────────── */
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="dark"] .icon-sun  { display: block; }
[data-theme="light"] .icon-sun  { display: none; }
[data-theme="light"] .icon-moon { display: block; }
.icon { display: block; }

/* ─── Login overlay ──────────────────────────────────────────────────────── */
.login-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  background: var(--bg-base);
  animation: fadeIn 0.4s ease;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.login-box {
  width: 100%;
  max-width: 380px;
  padding: 48px 40px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  text-align: center;
  position: relative;
  animation: slideUp 0.4s ease;
}
.login-box::before {
  content: '';
  position: absolute;
  inset: -1px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 25%, transparent), transparent 60%);
  z-index: -1;
}

.login-logo {
  font-size: 52px;
  margin-bottom: 12px;
  filter: drop-shadow(0 0 20px var(--accent-glow));
  animation: float 3s ease-in-out infinite;
}
.login-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
  letter-spacing: -0.5px;
}
.login-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 32px;
}

.input-group { margin-bottom: 14px; }
.input-group input {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 15px;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.input-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.input-group input::placeholder { color: var(--text-muted); }

.login-error {
  margin-top: 10px;
  font-size: 13px;
  color: var(--danger);
  font-family: var(--font-mono);
}

/* ─── App layout ─────────────────────────────────────────────────────────── */
.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  min-height: 100svh;
  max-height: 100dvh;
  overflow: hidden;
  position: relative;
  z-index: 1;
  /* Safe area insets: notch / Dynamic Island / Home Indicator */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* ─── Sidebar ────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  overflow: hidden;
  position: relative;
  z-index: 10;
  animation: slideRight 0.4s ease;
}

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

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
}
.logo-icon { font-size: 22px; }
.logo-text {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.3px;
}

.sidebar-actions { display: flex; gap: 4px; }

.new-session-btn {
  margin: 12px 12px 8px;
  font-size: 13px;
  padding: 8px 14px;
}

.sidebar-section {
  padding: 10px 12px 8px;
  flex-shrink: 0;
}
.section-label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
  font-family: var(--font-mono);
}

.sessions-section {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.sessions-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding-right: 2px;
}
.sessions-list::-webkit-scrollbar { width: 4px; }
.sessions-list::-webkit-scrollbar-track { background: transparent; }
.sessions-list::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

.sessions-empty {
  font-size: 12px;
  color: var(--text-muted);
  padding: 12px 4px;
  text-align: center;
}

.session-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  transition: background var(--transition);
  position: relative;
  group: true;
}
.session-item:hover { background: var(--bg-hover); }
.session-item.active {
  background: var(--bg-active);
  border-left: 2px solid var(--accent);
}
.session-item-icon {
  font-size: 14px;
  flex-shrink: 0;
  opacity: 0.7;
}
.session-item-text {
  flex: 1;
  min-width: 0;
}
.session-item-title {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.session-item-date {
  font-size: 10px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  margin-top: 1px;
}
.session-item-del {
  opacity: 0;
  width: 22px;
  height: 22px;
  border-radius: 5px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity var(--transition), background var(--transition), color var(--transition);
  flex-shrink: 0;
}
.session-item-del svg { width: 12px; height: 12px; }
.session-item:hover .session-item-del { opacity: 1; }
.session-item-del:hover { background: var(--danger); color: #fff; }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ─── Main area ──────────────────────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: hidden;
  animation: fadeIn 0.5s ease 0.1s both;
}

/* ─── Chat header ────────────────────────────────────────────────────────── */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
  min-height: 56px;
  gap: 12px;
}
.chat-header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}
.chat-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.session-title-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}
.session-title-display {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 380px;
}
.chat-placeholder-title {
  font-size: 14px;
  color: var(--text-muted);
}

.model-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 3px 9px;
  background: var(--accent-dim);
  color: var(--text-accent);
  border-radius: 20px;
  border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
  white-space: nowrap;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ─── Chat messages ──────────────────────────────────────────────────────── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar { width: 5px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 4px; }

.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px;
  gap: 12px;
}
.empty-icon {
  font-size: 56px;
  filter: drop-shadow(0 0 24px var(--accent-glow));
  animation: float 4s ease-in-out infinite;
}
.empty-title {
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
}
.empty-hint {
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.6;
}

/* ─── Message bubbles ────────────────────────────────────────────────────── */
.message {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: 780px;
  animation: msgIn 0.3s ease;
}
.message.user {
  align-self: flex-end;
  align-items: flex-end;
}
.message.assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.message-meta-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 2px;
}

.message-meta {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  padding: 0 4px;
  flex: 1;
}

.regen-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 5px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s, color 0.15s;
  flex-shrink: 0;
  padding: 2px;
}
.regen-btn svg { width: 13px; height: 13px; }
.regen-btn:hover {
  background: var(--bg-hover);
  color: var(--text-secondary);
}
/* Show on hover (desktop) */
.message:hover .regen-btn { opacity: 1; }

/* Always visible on touch devices (no hover) */
@media (hover: none) {
  .regen-btn { opacity: 0.45; }
  .regen-btn:active { opacity: 1; background: var(--bg-hover); }
}

.regen-loading {
  color: var(--text-muted);
  font-style: italic;
  animation: pulse 1.4s ease-in-out infinite;
}

.message-bubble {
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.65;
  color: var(--text-primary);
  word-break: break-word;
  position: relative;
}
.message.user .message-bubble {
  background: var(--bg-message-u);
  border-bottom-right-radius: 4px;
  border: 1px solid var(--border);
}
.message.assistant .message-bubble {
  background: var(--bg-message-a);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border);
}

.message-bubble p { margin-bottom: 8px; }
.message-bubble p:last-child { margin-bottom: 0; }
.message-bubble code {
  font-family: var(--font-mono);
  font-size: 12px;
  background: var(--bg-code);
  padding: 1px 5px;
  border-radius: 4px;
}

/* Uploaded images in user message */
.message-images-input {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}
.message-images-input img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}

/* Generated images */
.message-images-output {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.gen-image-wrap {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow-md);
  cursor: zoom-in;
  transition: transform 0.2s, box-shadow 0.2s;
}
.gen-image-wrap:hover { transform: scale(1.015); box-shadow: var(--shadow-lg); }
.gen-image-wrap img {
  display: block;
  max-width: 480px;
  max-height: 480px;
  width: auto;
  height: auto;
  border-radius: 12px;
}

/* ─── Error bubble ───────────────────────────────────────────────────────── */
.message-error {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.error-text {
  color: var(--danger);
  font-size: 13.5px;
}
.retry-btn {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent);
  border-radius: 20px;
  background: var(--accent-dim);
  color: var(--accent);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), box-shadow var(--transition);
}
.retry-btn svg { width: 13px; height: 13px; flex-shrink: 0; }
.retry-btn:hover {
  background: color-mix(in srgb, var(--accent) 22%, transparent);
  box-shadow: 0 0 10px var(--accent-glow);
}

/* ─── Typing / loading bubble ────────────────────────────────────────────── */
.message-loading .message-bubble {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-secondary);
  font-size: 13px;
}
.loading-dots {
  display: flex;
  gap: 4px;
}
.loading-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  animation: dot-bounce 1.2s ease-in-out infinite;
}
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }

/* ─── Input area ─────────────────────────────────────────────────────────── */
.input-area {
  padding: 8px 20px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
  position: relative;
}

.image-preview-strip {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.preview-thumb {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.preview-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.preview-thumb-del {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0,0,0,0.7);
  color: #fff;
  border: none;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: background 0.15s;
}
.preview-thumb-del:hover { background: var(--danger); }

.drop-overlay {
  position: absolute;
  inset: 0;
  background: var(--accent-dim);
  border: 2px dashed var(--accent);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 5;
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  backdrop-filter: blur(2px);
}
.drop-text { display: flex; flex-direction: column; align-items: center; }

.input-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.textarea-wrapper {
  flex: 1;
  min-width: 0;
}

.textarea-wrapper textarea {
  width: 100%;
  padding: 11px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  outline: none;
  overflow-y: auto;
  max-height: 160px;
  min-height: 44px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.textarea-wrapper textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}
.textarea-wrapper textarea::placeholder { color: var(--text-muted); }
.textarea-wrapper textarea:disabled { opacity: 0.5; cursor: not-allowed; }

.send-btn {
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  border: none;
  background: var(--accent);
  color: #0d1117;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition), box-shadow var(--transition), transform 0.12s;
}
.send-btn svg { width: 18px; height: 18px; }
.send-btn:hover:not(:disabled) {
  background: var(--accent-hover);
  box-shadow: 0 0 16px var(--accent-glow);
}
.send-btn:active:not(:disabled) { transform: scale(0.93); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

.input-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 7px;
  font-family: var(--font-mono);
  text-align: center;
}

/* ─── Lightbox ───────────────────────────────────────────────────────────── */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}
.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.88);
  backdrop-filter: blur(6px);
}
.lightbox-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 16px;
  max-width: 95vw;
  max-height: 95vh;
}
.lightbox-content img {
  max-width: 100%;
  max-height: 82vh;
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  object-fit: contain;
}
.lightbox-close {
  position: absolute;
  top: 0;
  right: 0;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.15);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
  transition: background 0.15s;
}
.lightbox-close:hover { background: rgba(255,255,255,0.25); }
.lightbox-download {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 18px;
  background: var(--accent);
  color: #0d1117;
  border-radius: var(--radius);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  transition: background var(--transition);
}
.lightbox-download svg { width: 15px; height: 15px; }
.lightbox-download:hover { background: var(--accent-hover); }

/* ─── Modal ──────────────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.2s ease;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
}
.modal-box {
  position: relative;
  z-index: 1;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 28px 32px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.25s ease;
}
.modal-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
}
.modal-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 14px;
  outline: none;
  margin-bottom: 20px;
  transition: border-color var(--transition);
}
.modal-input:focus { border-color: var(--accent); }
.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ─── Gallery modal ─────────────────────────────────────────────────────── */
.gallery-modal {
  position: fixed;
  inset: 0;
  z-index: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.gallery-modal.hidden { display: none; }

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

.gallery-box {
  position: relative;
  z-index: 1;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  width: min(900px, 100%);
  max-height: calc(100dvh - 32px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 80px rgba(0,0,0,0.5);
  animation: modalIn 0.2s cubic-bezier(0.22,1,0.36,1);
}

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

.gallery-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 22px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.gallery-title {
  font-family: var(--font-ui);
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  flex: 1;
}
.gallery-count {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
}
.gallery-header-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 8px;
  border: none;
  background: #2563eb;
  color: #fff;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, box-shadow 0.15s;
  white-space: nowrap;
  flex-shrink: 0;
}
.gallery-header-btn svg { width: 14px; height: 14px; flex-shrink: 0; }
.gallery-header-btn:hover {
  background: #1d4ed8;
  box-shadow: 0 0 12px rgba(37,99,235,0.45);
}

.gallery-close {
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  transition: background var(--transition), color var(--transition);
}
.gallery-close:hover { background: var(--bg-hover); color: var(--text-primary); }

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 8px;
  padding: 14px 16px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border-strong) transparent;
}

@media (max-width: 480px) {
  .gallery-modal { padding: 0; align-items: flex-end; }
  .gallery-box {
    border-radius: 18px 18px 0 0;
    width: 100%;
    max-height: 90dvh;
  }
  .gallery-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    padding: 10px 12px;
  }
}

.gallery-loading, .gallery-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 48px 0;
  color: var(--text-muted);
  font-size: 14px;
}

.gallery-cell {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-input);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
  /* Reliable square via padding-bottom trick */
  height: 0;
  padding-bottom: 100%;
}
.gallery-cell:hover { border-color: var(--border-strong); transform: scale(1.015); }

.gallery-cell img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.gallery-cell-actions {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  background: linear-gradient(transparent, rgba(0,0,0,0.65));
  opacity: 0;
  transition: opacity 0.15s;
}
.gallery-cell:hover .gallery-cell-actions { opacity: 1; }

.gallery-dl-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: rgba(255,255,255,0.15);
  color: #fff;
  text-decoration: none;
  transition: background 0.15s;
}
.gallery-dl-btn:hover { background: rgba(255,255,255,0.28); }
.gallery-dl-btn svg { width: 14px; height: 14px; }

.gallery-cell-time {
  font-family: var(--font-mono);
  font-size: 10px;
  color: rgba(255,255,255,0.7);
}

/* ─── Model description ──────────────────────────────────────────────────── */
.model-description {
  margin-top: 7px;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 11.5px;
  color: var(--text-secondary);
  line-height: 1.5;
  animation: fadeIn 0.2s ease;
}

/* ─── Input params row ───────────────────────────────────────────────────── */
.input-params-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
  margin-bottom: 8px;
}

/* Image size segmented control */
.img-size-group {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}
.param-label {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-ui);
  white-space: nowrap;
}
.size-btns {
  display: flex;
  gap: 1px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 2px;
}
.size-btn {
  padding: 2px 8px;
  border-radius: 5px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  letter-spacing: 0.02em;
}
.size-btn:hover { color: var(--text-primary); }
.size-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
}

/* ─── AR trigger + panel ─────────────────────────────────────────────────── */
.ar-trigger-wrap {
  position: relative;
  display: inline-flex;
}

.ar-trigger {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px 4px 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text-secondary);
  font-family: var(--font-ui);
  font-size: 13px;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
  white-space: nowrap;
  user-select: none;
}
.ar-trigger:not(:disabled):hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
  color: var(--text-primary);
}
.ar-trigger.open {
  border-color: color-mix(in srgb, var(--accent) 50%, transparent);
  color: var(--text-primary);
}

.ar-trigger-text { color: var(--text-muted); font-size: 11px; }

.ar-trigger-value {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--accent);
  font-size: 12px;
}

.ar-chevron {
  color: var(--text-muted);
  transition: transform 0.2s ease;
}
.ar-trigger.open .ar-chevron { transform: rotate(180deg); }

/* Panel */
.ar-panel {
  display: none;
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  min-width: 340px;
  background: var(--bg-card);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 -12px 40px rgba(0,0,0,0.3), 0 0 0 1px rgba(255,255,255,0.04);
  z-index: 200;
  flex-direction: column;
  gap: 10px;
}
.ar-panel.open {
  display: flex;
  animation: arPanelIn 0.16s cubic-bezier(0.22,1,0.36,1);
}

@keyframes arPanelIn {
  from { opacity: 0; transform: translateY(6px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.ar-panel-divider {
  height: 1px;
  background: var(--border);
  margin: 2px 0;
  border-radius: 1px;
}

.ar-panel-section { display: flex; flex-direction: column; gap: 8px; }

.ar-section-title {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.ar-opts-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: flex-end;
}

/* Auto option spans a full row */
.ar-opt[data-ar=""] {
  flex-direction: row;
  padding: 6px 14px;
  border-radius: 8px;
  width: 100%;
  justify-content: center;
  gap: 8px;
}

.ar-opt {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.ar-opt:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-strong);
}
.ar-opt.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
}

.ar-opt-label {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  line-height: 1;
}

/* Rectangle preview */
.ar-rect-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 44px;
  flex-shrink: 0;
}
.ar-opt[data-ar=""] .ar-rect-wrap { width: auto; height: auto; }

.ar-rect {
  display: block;
  background: currentColor;
  opacity: 0.45;
  border-radius: 2px;
  transition: opacity 0.15s;
}
.ar-opt:hover .ar-rect, .ar-opt.active .ar-rect { opacity: 0.7; }

.ar-rect-auto {
  width: 26px;
  height: 20px;
  background: transparent;
  border: 2px dashed currentColor;
  border-radius: 3px;
  opacity: 0.7;
}

/* ─── Settings section ───────────────────────────────────────────────────── */
.setting-row {
  margin-bottom: 12px;
}
.setting-row:last-child { margin-bottom: 0; }

.setting-label-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 5px;
}
.setting-name {
  font-size: 12px;
  color: var(--text-secondary);
  display: block;
  margin-bottom: 5px;
}
.setting-label-row .setting-name { margin-bottom: 0; }
.setting-value {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
  font-weight: 600;
  min-width: 20px;
  text-align: right;
}

.range-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 4px;
  border-radius: 4px;
  background: var(--border-strong);
  outline: none;
  cursor: pointer;
}
.range-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 6px var(--accent-glow);
  transition: box-shadow 0.15s;
}
.range-slider::-webkit-slider-thumb:hover { box-shadow: 0 0 12px var(--accent-glow); }
.range-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: none;
}
.range-hints {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 3px;
}

.system-prompt-input {
  width: 100%;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 12px;
  line-height: 1.5;
  resize: vertical;
  min-height: 52px;
  max-height: 120px;
  outline: none;
  transition: border-color var(--transition);
}
.system-prompt-input:focus { border-color: var(--accent); }
.system-prompt-input::placeholder { color: var(--text-muted); }

/* ─── Mobile top bar ─────────────────────────────────────────────────────── */
.mobile-topbar {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
}
.mobile-title {
  font-size: 16px;
  font-weight: 700;
}

/* ─── Animations ─────────────────────────────────────────────────────────── */
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes slideRight {
  from { opacity: 0; transform: translateX(-20px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50%       { transform: translateY(-8px); }
}
@keyframes dot-bounce {
  0%, 80%, 100% { transform: scale(0.7); opacity: 0.4; }
  40%           { transform: scale(1.1); opacity: 1; }
}

/* Staggered reveal for session items */
.session-item { animation: fadeIn 0.25s ease both; }
.session-item:nth-child(1)  { animation-delay: 0.03s; }
.session-item:nth-child(2)  { animation-delay: 0.06s; }
.session-item:nth-child(3)  { animation-delay: 0.09s; }
.session-item:nth-child(4)  { animation-delay: 0.12s; }
.session-item:nth-child(5)  { animation-delay: 0.15s; }
.session-item:nth-child(6)  { animation-delay: 0.18s; }
.session-item:nth-child(7)  { animation-delay: 0.21s; }
.session-item:nth-child(8)  { animation-delay: 0.24s; }

/* ─── Scrollbar global ───────────────────────────────────────────────────── */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }

/* ─── Pulse animation (used by regen-loading) ────────────────────────────── */
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.45; }
}

/* ─── Page navigation (sidebar tabs) ────────────────────────────────────── */
.page-nav {
  display: flex;
  gap: 4px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.page-nav-link {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 6px 8px;
  border-radius: 7px;
  text-decoration: none;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  transition: background var(--transition), color var(--transition);
}
.page-nav-link:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}
.page-nav-link.active {
  background: var(--accent-dim);
  color: var(--accent);
  font-weight: 600;
}

/* ─── Mobile responsive ──────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .mobile-only { display: flex; }

  .page-nav {
    gap: 3px;
    padding: 8px 8px;
  }
  .page-nav-link {
    gap: 3px;
    padding: 6px 5px;
    font-size: 12px;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(var(--sidebar-w), 88vw);
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-lg);
    /* Prevent backdrop-filter bleed from overlay */
    isolation: isolate;
    will-change: transform;
    /* Safe areas for notch and Home Indicator */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 199;
    display: none;
  }
  .sidebar-overlay.visible { display: block; animation: fadeIn 0.2s ease; }

  .mobile-topbar { display: flex; }

  .main { overflow: hidden; }

  .chat-header { padding: 10px 14px; }
  .session-title-display { max-width: 180px; font-size: 13px; }
  .model-badge { display: none; }

  .chat-messages { padding: 16px 14px; }

  .input-area { padding: 6px 14px 14px; }
  .input-hint { display: none; }

  .gen-image-wrap img { max-width: 280px; max-height: 280px; }

  .login-box { margin: 16px; padding: 36px 24px; }
}

@media (max-width: 480px) {
  .gen-image-wrap img { max-width: 240px; max-height: 240px; }
  .message { max-width: 95%; }
}
