/* ══════════════════════════════════════════════
   Prefrontal — ChatGPT-Style UI
   Copyright (C) 2026 sidx1-scratch

   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <https://www.gnu.org/licenses/>.
   ══════════════════════════════════════════════ */

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

:root {
  --hue: 220;
  --sidebar-bg:     hsla(var(--hue), 20%, 9%, 0.65);
  --main-bg:        #0b0d11; 
  --surface:        hsla(var(--hue), 20%, 20%, 0.5);
  --surface-hover:  hsla(var(--hue), 25%, 30%, 0.6);
  --input-bg:       hsla(var(--hue), 20%, 15%, 0.5);
  --border:         hsla(var(--hue), 10%, 100%, 0.08);
  --text-primary:   #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted:     #64748b;
  --accent:         #10a37f;
  --accent-hover:   #0d8a6b;
  --user-bubble:    linear-gradient(135deg, #6366f1, #a855f7);
  --danger:         #ef4444;
  --radius-sm:      8px;
  --radius-md:      12px;
  --radius-lg:      20px;
  --radius-pill:    999px;
  --sidebar-w:      270px;
  --topbar-h:       60px;
  --transition:     0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --font:           -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';
  --font-mono:      'Fira Code', 'Cascadia Code', 'Consolas', 'Courier New', monospace;
  --shadow:         0 0 0 1px hsla(var(--hue),10%,100%,0.05), 0 8px 32px hsla(0,0%,0%,0.4);
}

[data-theme="light"] {
  --hue: 210;
  --sidebar-bg:     hsla(var(--hue), 20%, 95%, 0.7);
  --main-bg:        #f8fafc;
  --surface:        hsla(var(--hue), 20%, 100%, 0.5);
  --surface-hover:  hsla(var(--hue), 25%, 90%, 0.6);
  --input-bg:       hsla(var(--hue), 20%, 100%, 0.6);
  --border:         hsla(var(--hue), 10%, 0%, 0.08);
  --text-primary:   #0f172a;
  --text-secondary: #475569;
  --text-muted:     #94a3b8;
  --user-bubble:    linear-gradient(135deg, #3b82f6, #8b5cf6);
  --shadow:         0 0 0 1px hsla(var(--hue),10%,0%,0.05), 0 8px 32px hsla(0,0%,0%,0.08);
}
[data-theme="midnight"] {
  --hue: 240;
  --sidebar-bg:     hsla(var(--hue), 40%, 6%, 0.6);
  --main-bg:        #020617;
  --surface:        hsla(var(--hue), 30%, 15%, 0.5);
  --surface-hover:  hsla(var(--hue), 35%, 20%, 0.6);
  --input-bg:       hsla(var(--hue), 30%, 12%, 0.5);
  --accent:         #6366f1;
  --accent-hover:   #4f46e5;
}
[data-theme="emerald"] {
  --accent:         #10b981;
  --accent-hover:   #059669;
}

html, body {
  height: 100%;
  /* Use dvh (dynamic viewport height) on browsers that support it — critical for iOS Safari */
  height: 100dvh;
  font-family: var(--font);
  font-size: 15px;
  background: var(--main-bg);
  color: var(--text-primary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  /* Prevent elastic bounce on iOS body */
  overscroll-behavior: none;
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.2); }
[data-theme="light"] ::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.12); }
[data-theme="light"] ::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,0.2); }

/* ── AMBIENT BACKGROUND ── */
.ambient-bg {
  position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: -1;
  background: var(--main-bg);
}
.orb {
  position: absolute; border-radius: 50%; filter: blur(90px); opacity: 0.5;
  animation: float 20s infinite ease-in-out alternate;
}
.orb-1 { width: 400px; height: 400px; background: rgba(99, 102, 241, 0.4); top: -100px; left: -100px; animation-delay: 0s; }
.orb-2 { width: 500px; height: 500px; background: rgba(168, 85, 247, 0.3); bottom: -150px; right: 10%; animation-delay: -5s; }
.orb-3 { width: 300px; height: 300px; background: rgba(16, 185, 129, 0.2); top: 30%; left: 40%; animation-delay: -10s; }
[data-theme="emerald"] .orb-1 { background: rgba(16, 185, 129, 0.4); }
[data-theme="light"] .orb-1 { background: rgba(99, 102, 241, 0.2); }
[data-theme="light"] .orb-2 { background: rgba(168, 85, 247, 0.15); }
@keyframes float {
  0% { transform: translateY(0) scale(1); }
  100% { transform: translateY(40px) scale(1.1); }
}

/* Touch-action: manipulation removes 300ms tap delay on mobile/iOS for all interactive elements */
button, a, label, [role="button"] { touch-action: manipulation; }

/* ── LAYOUT ── */
body { display: flex; position: relative; background: transparent; z-index: 0; font-weight: 400; }

.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100%;
  height: 100dvh;
  background: var(--sidebar-bg);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  display: flex;
  flex-direction: column;
  transition: transform var(--transition), margin-left var(--transition);
  overflow: hidden;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  z-index: 10;
  /* iOS safe area: respect notch on left side */
  padding-left: env(safe-area-inset-left, 0px);
}
.sidebar.collapsed {
  margin-left: calc(-1 * var(--sidebar-w));
  transform: translateX(0);
}

.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  height: 100dvh;
  min-width: 0;
  background: transparent;
  /* iOS safe area: respect notch on right side */
  padding-right: env(safe-area-inset-right, 0px);
}

/* ── SIDEBAR HEADER ── */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 12px 8px;
}
.logo { display: flex; align-items: center; gap: 9px; }
.logo-icon { width: 28px; height: 28px; flex-shrink: 0; }
.logo-text {
  font-size: 15px; font-weight: 600;
  color: var(--text-primary); letter-spacing: -0.2px;
}

/* New chat button */
#newChatBtn {
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  background: transparent; border: none; color: var(--text-secondary);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background var(--transition), color var(--transition);
}
#newChatBtn:hover { background: var(--surface); color: var(--text-primary); }
#newChatBtn svg { width: 18px; height: 18px; }

/* ── SIDEBAR SEARCH ── */
.sidebar-search { padding: 4px 12px 8px; position: relative; }
.search-icon {
  position: absolute; left: 22px; top: 50%; transform: translateY(-50%);
  width: 14px; height: 14px; color: var(--text-muted); pointer-events: none;
}
#searchChats {
  width: 100%; padding: 7px 10px 7px 32px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-primary);
  font-size: 13px; font-family: var(--font); outline: none;
  transition: border-color var(--transition);
}
#searchChats::placeholder { color: var(--text-muted); }
#searchChats:focus { border-color: var(--accent); }

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

/* ── CHAT LIST ── */
.chat-list { flex: 1; overflow-y: auto; padding: 2px 8px;
  /* iOS momentum scrolling */
  -webkit-overflow-scrolling: touch;
}

.chat-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 8px; border-radius: var(--radius-sm);
  cursor: pointer; transition: background var(--transition);
  position: relative;
}
.chat-item:hover { background: var(--surface); }
.chat-item.active { background: var(--surface); }
.chat-item-icon { font-size: 14px; flex-shrink: 0; line-height: 1; }
.chat-item-info { flex: 1; min-width: 0; }
.chat-item-title {
  font-size: 13.5px; font-weight: 400; color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-item-date { font-size: 11px; color: var(--text-muted); margin-top: 1px; }
.chat-item-actions { display: none; gap: 2px; align-items: center; }
.chat-item:hover .chat-item-actions { display: flex; }
.chat-item-action-btn {
  width: 22px; height: 22px; border-radius: 4px; border: none;
  background: transparent; color: var(--text-secondary); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; transition: background var(--transition), color var(--transition);
}
.chat-item-action-btn:hover { background: var(--surface-hover); color: var(--text-primary); }
.chat-item-action-btn.del:hover { color: var(--danger); }

/* ── SIDEBAR FOOTER ACTIONS ── */
.sidebar-footer-actions {
  padding: 8px 8px 4px;
  border-top: 1px solid var(--border);
  display: flex; gap: 4px;
}
.sidebar-footer-btn {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 7px 8px; border-radius: var(--radius-sm); border: none;
  background: transparent; color: var(--text-secondary);
  font-size: 12px; font-weight: 500; font-family: var(--font);
  cursor: pointer; transition: background var(--transition), color var(--transition);
}
.sidebar-footer-btn svg { width: 13px; height: 13px; flex-shrink: 0; }
.sidebar-footer-btn:hover { background: var(--surface); color: var(--text-primary); }
.sidebar-footer-btn.danger:hover { color: var(--danger); }

/* ── PROFILE CARD (sidebar bottom) ── */
.profile-card {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px 12px;
  border-top: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
  border-radius: 0 0 0 0;
}
.profile-card:hover { background: var(--surface); }
.profile-avatar {
  width: 32px; height: 32px; flex-shrink: 0;
  background: var(--surface); border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; border: 1px solid var(--border);
}
.profile-info { flex: 1; min-width: 0; }
.profile-name {
  font-size: 13px; font-weight: 600; color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.profile-id {
  font-size: 10.5px; color: var(--text-muted);
  font-family: var(--font-mono);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.profile-edit-btn {
  width: 26px; height: 26px; flex-shrink: 0; border-radius: 5px; border: none;
  background: transparent; color: var(--text-muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--transition), color var(--transition);
}
.profile-edit-btn:hover { background: var(--surface-hover); color: var(--text-primary); }
.profile-edit-btn svg { width: 15px; height: 15px; }

/* ── SETUP MODAL ── */
.setup-modal {
  width: 460px;
  /* Critical: constrain height so it never overflows the viewport */
  max-height: min(92vh, 92dvh);
  animation: setupIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
@keyframes setupIn { from{opacity:0;transform:translateY(40px) scale(0.95)} to{opacity:1;transform:translateY(0) scale(1)} }
.setup-header {
  padding: 20px 24px 16px;
  display: flex; flex-direction: column; align-items: center; text-align: center;
  border-bottom: 1px solid var(--border);
  gap: 10px;
  flex-shrink: 0;
}
.setup-logo { width: 40px; height: 40px; }
.setup-header h2 { font-size: 20px; font-weight: 700; }
.setup-header p { font-size: 13px; color: var(--text-secondary); line-height: 1.5; }
/* Body scrolls — footer stays at bottom */
.setup-body {
  padding: 18px 24px;
  display: flex; flex-direction: column; gap: 18px;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  /* iOS momentum */
  -webkit-overflow-scrolling: touch;
}
.setup-footer {
  padding: 14px 24px 16px;
  /* iOS: add bottom safe area for devices with home indicator */
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.setup-field { display: flex; flex-direction: column; gap: 7px; }
.setup-label {
  font-size: 13.5px; font-weight: 600; color: var(--text-primary);
  display: flex; align-items: center; gap: 8px;
}
.setup-badge {
  font-size: 10px; font-weight: 500; padding: 2px 7px;
  background: rgba(16,163,127,0.15); color: var(--accent);
  border-radius: var(--radius-pill); border: 1px solid rgba(16,163,127,0.25);
  font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.05em;
}
.setup-hint { font-size: 12px; color: var(--text-muted); line-height: 1.4; }
.setup-input {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-primary);
  /* 16px minimum to prevent iOS Safari auto-zoom on tap */
  font-size: 16px; font-family: var(--font); padding: 10px 13px; outline: none;
  transition: border-color var(--transition);
}
.setup-input:focus { border-color: var(--accent); }
.setup-input::placeholder { color: var(--text-muted); }

/* ── AVATAR GRID ── */
.avatar-grid {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px;
}
.avatar-btn {
  width: 100%; aspect-ratio: 1; border-radius: var(--radius-sm);
  border: 2px solid transparent; background: var(--surface);
  font-size: 22px; cursor: pointer; transition: all var(--transition);
  display: flex; align-items: center; justify-content: center;
}
.avatar-btn:hover { border-color: var(--accent); background: rgba(16,163,127,0.1); transform: scale(1.08); }
.avatar-btn.selected { border-color: var(--accent); background: rgba(16,163,127,0.15); }

/* ── DEVICE ID BOX ── */
.device-id-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 9px 12px;
  font-size: 12px; font-family: var(--font-mono); color: var(--text-secondary);
  word-break: break-all; line-height: 1.5;
  transition: border-color var(--transition);
}
.device-id-box:hover { border-color: rgba(255,255,255,0.2); }

/* ── PROFILE MODAL ── */
.profile-modal { width: 480px; }
.profile-preview {
  display: flex; align-items: center; gap: 14px;
  padding: 16px; background: var(--surface); border-radius: var(--radius-md);
  border: 1px solid var(--border);
}
.profile-preview-avatar {
  width: 48px; height: 48px; border-radius: 12px;
  background: var(--surface-hover); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 26px; flex-shrink: 0;
}
.profile-preview-name { font-size: 16px; font-weight: 700; color: var(--text-primary); margin-bottom: 3px; }
.profile-preview-meta { font-size: 12px; color: var(--text-muted); font-family: var(--font-mono); }

/* ── TOPBAR ── */
.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 8px;
  padding: 0 16px;
  background: hsla(var(--hue, 220), 20%, 8%, 0.5);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  z-index: 5;
}
[data-theme="light"] .topbar { background: hsla(var(--hue,210),20%,95%,0.6); }
[data-theme="midnight"] .topbar { background: hsla(var(--hue,240),40%,6%,0.5); }
.topbar-title {
  flex: 1; font-size: 14px; font-weight: 500; color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.topbar-actions { display: flex; align-items: center; gap: 4px; }

.model-badge {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: var(--radius-pill);
  background: var(--surface); border: 1px solid var(--border);
  font-size: 12px; font-weight: 500; color: var(--text-secondary);
  font-family: var(--font-mono); cursor: default;
}
.model-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: #22c55e; box-shadow: 0 0 5px #22c55e66;
  animation: pulse 2.5s ease-in-out infinite;
}
.model-dot.offline { background: var(--danger); box-shadow: 0 0 5px #ef444466; animation: none; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.4} }

/* ── ICON BUTTONS ── */
.btn-icon {
  width: 34px; height: 34px; border-radius: var(--radius-sm); border: none;
  background: transparent; color: var(--text-secondary); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--transition), color var(--transition);
}
.btn-icon svg { width: 17px; height: 17px; }
.btn-icon:hover { background: var(--surface); color: var(--text-primary); }

/* ── BUTTONS ── */
.btn-primary {
  padding: 9px 20px; border-radius: var(--radius-sm); border: none;
  background: var(--accent); color: #fff; font-size: 14.5px; font-weight: 600;
  font-family: var(--font); cursor: pointer; transition: all var(--transition);
  box-shadow: 0 2px 10px rgba(16,163,127,0.3);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(16,163,127,0.4); }
.btn-secondary {
  padding: 8px 16px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-primary); font-size: 13.5px; font-weight: 500;
  font-family: var(--font); cursor: pointer;
  transition: all var(--transition);
}
.btn-secondary:hover { background: var(--surface-hover); border-color: rgba(255,255,255,0.25); transform: translateY(-1px); }
.btn-danger {
  padding: 9px 20px; border-radius: var(--radius-sm); border: none;
  background: var(--danger); color: #fff; font-size: 14.5px; font-weight: 600;
  font-family: var(--font); cursor: pointer; transition: all var(--transition);
  box-shadow: 0 2px 10px rgba(239,68,68,0.3);
}
.btn-danger:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(239,68,68,0.4); }

/* ── CHAT AREA ── */
.chat-area {
  flex: 1; overflow-y: auto;
  position: relative;
  /* iOS momentum scrolling */
  -webkit-overflow-scrolling: touch;
}

.messages-wrapper {
  max-width: 760px; margin: 0 auto;
  padding: 28px 20px 20px;
  display: flex; flex-direction: column;
}

/* ── WELCOME SCREEN (ChatGPT style) ── */
.welcome-screen {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 40px 24px;
  animation: fadeIn 0.4s ease;
}
@keyframes fadeIn { from{opacity:0;transform:translateY(10px)} to{opacity:1;transform:translateY(0)} }

.welcome-logo {
  width: 52px; height: 52px; margin-bottom: 20px;
  background: var(--accent);
  border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 20px rgba(16,163,127,0.3);
}
.welcome-logo svg { width: 30px; height: 30px; color: #fff; }

.welcome-title {
  font-size: 28px; font-weight: 700; color: var(--text-primary);
  margin-bottom: 6px; letter-spacing: -0.5px;
}
.welcome-subtitle {
  font-size: 14px; color: var(--text-secondary);
  margin-bottom: 32px; text-align: center;
}
.welcome-subtitle strong { color: var(--text-primary); font-weight: 500; }

.welcome-chips {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  max-width: 620px; width: 100%;
}
.chip {
  padding: 13px 16px; border-radius: var(--radius-md);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-primary); font-size: 13.5px; font-family: var(--font);
  cursor: pointer; text-align: left; line-height: 1.4;
  transition: background var(--transition), border-color var(--transition);
}
.chip:hover { background: var(--surface-hover); border-color: rgba(255,255,255,0.15); }

/* ── MESSAGES (ChatGPT style) ── */
.message {
  display: flex; gap: 14px;
  padding: 18px 0;
  animation: msgIn 0.2s ease;
  border-bottom: 1px solid var(--border);
}
.message:last-child { border-bottom: none; }
@keyframes msgIn { from{opacity:0;transform:translateY(6px)} to{opacity:1;transform:translateY(0)} }

/* User messages — right aligned, bubble style */
.message.user {
  flex-direction: row-reverse;
  border-bottom: none;
  padding-bottom: 4px;
}
.message.user .msg-bubble {
  background: var(--user-bubble);
  border-radius: var(--radius-lg) var(--radius-lg) 4px var(--radius-lg);
  padding: 11px 15px;
  max-width: 75%;
  border: 1px solid var(--border);
}
.message.user .msg-content { font-size: 14.5px; line-height: 1.65; }
.message.user .msg-meta { display: none; }

/* Assistant messages — full width, flat */
.message.assistant .msg-bubble {
  flex: 1; min-width: 0;
  background: transparent;
  padding: 0;
}
.message.assistant .msg-content { font-size: 14.5px; line-height: 1.75; }

/* Avatars */
.msg-avatar {
  width: 30px; height: 30px; flex-shrink: 0;
  border-radius: 50%; margin-top: 2px;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
}
.message.user .msg-avatar {
  background: #5436da;
  width: 28px; height: 28px; margin-top: 4px;
}
.message.assistant .msg-avatar {
  background: var(--accent);
  width: 28px; height: 28px; margin-top: 2px;
}

/* Markdown content */
.msg-content p { margin: 0 0 12px; }
.msg-content p:last-child { margin-bottom: 0; }
.msg-content ul, .msg-content ol { padding-left: 22px; margin: 8px 0; }
.msg-content li { margin: 4px 0; line-height: 1.65; }
.msg-content strong { font-weight: 600; }
.msg-content em { font-style: italic; }
.msg-content a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.msg-content h1,.msg-content h2,.msg-content h3 { font-weight: 600; margin: 16px 0 6px; line-height: 1.3; }
.msg-content h1 { font-size: 1.25em; }
.msg-content h2 { font-size: 1.1em; }
.msg-content h3 { font-size: 1em; }
.msg-content blockquote {
  border-left: 3px solid var(--surface-hover); padding-left: 14px;
  color: var(--text-secondary); margin: 12px 0;
}
.msg-content hr { border: none; border-top: 1px solid var(--border); margin: 14px 0; }
.msg-content table { border-collapse: collapse; width: 100%; margin: 12px 0; font-size: 14px; }
.msg-content th, .msg-content td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.msg-content th { background: var(--surface); font-weight: 600; }

/* Code blocks */
.msg-content pre {
  background: #0d0d0d !important;
  border-radius: var(--radius-md);
  margin: 14px 0;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.08);
}
[data-theme="light"] .msg-content pre { background: #f7f7f7 !important; border-color: rgba(0,0,0,0.1); }
.msg-content pre code {
  font-family: var(--font-mono) !important;
  font-size: 13px !important;
  padding: 14px 16px !important;
  display: block; overflow-x: auto;
  background: transparent !important;
  line-height: 1.6;
}
.code-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px;
  background: rgba(255,255,255,0.05);
  border-bottom: 1px solid rgba(255,255,255,0.07);
}
[data-theme="light"] .code-header { background: rgba(0,0,0,0.04); border-bottom-color: rgba(0,0,0,0.07); }
.code-lang {
  font-size: 11.5px; color: #999; font-family: var(--font-mono);
  text-transform: lowercase; letter-spacing: 0.02em;
}
.copy-code-btn {
  display: flex; align-items: center; gap: 5px;
  background: none; border: none; color: #999; cursor: pointer;
  font-size: 12px; font-family: var(--font);
  padding: 2px 6px; border-radius: 4px;
  transition: color var(--transition), background var(--transition);
}
.copy-code-btn:hover { color: var(--text-primary); background: rgba(255,255,255,0.07); }
.copy-code-btn.copied { color: #22c55e; }
.msg-content code:not(pre code) {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px; padding: 1px 6px;
  font-family: var(--font-mono); font-size: 13px;
  color: var(--text-primary);
}

/* Web search sources (prompt-driven DuckDuckGo citations) */
.msg-sources {
  margin-top: 12px; padding-top: 10px;
  border-top: 1px dashed var(--border);
}
.msg-sources-label {
  display: block; font-size: 11px; font-weight: 600;
  color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.msg-source-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.msg-source-chip {
  display: inline-block; max-width: 220px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 12px; line-height: 1.4;
  padding: 4px 10px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--accent) !important; text-decoration: none !important;
  transition: background var(--transition), border-color var(--transition);
}
.msg-source-chip:hover { background: var(--surface-hover, var(--surface)); border-color: var(--accent); }

/* Msg meta & actions */
.msg-meta {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 8px;
}
.msg-time { font-size: 11.5px; color: var(--text-muted); }
.msg-actions { display: flex; gap: 2px; opacity: 0; transition: opacity var(--transition); }
.message:hover .msg-actions { opacity: 1; }
.msg-action-btn {
  width: 28px; height: 28px; border-radius: 6px; border: none;
  background: transparent; color: var(--text-muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--transition), color var(--transition);
}
.msg-action-btn:hover { background: var(--surface); color: var(--text-primary); }
.msg-action-btn svg { width: 14px; height: 14px; }

/* Typing cursor */
.typing-cursor {
  display: inline-block; width: 2px; height: 1.1em;
  background: var(--text-primary); margin-left: 1px;
  vertical-align: text-bottom; animation: blink 0.9s step-end infinite;
}
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }

/* Thinking dots */
.thinking-dots { display: flex; gap: 4px; align-items: center; padding: 6px 0; }
.thinking-dots span {
  width: 6px; height: 6px; border-radius: 50%; background: var(--text-muted);
  animation: dotBounce 1.2s ease-in-out infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.15s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes dotBounce { 0%,100%{transform:translateY(0);opacity:0.35} 50%{transform:translateY(-4px);opacity:1} }

/* Web search in progress (prompt-driven DuckDuckGo search) */
.search-status {
  display: flex; align-items: center; gap: 8px;
  font-size: 13.5px; color: var(--text-muted); padding: 6px 0;
  animation: searchPulse 1.6s ease-in-out infinite;
}
@keyframes searchPulse { 0%,100%{opacity:0.6} 50%{opacity:1} }

/* Stop button */
.stop-btn-wrapper { display: flex; justify-content: center; padding: 8px 0 4px; }
.stop-btn {
  display: none; align-items: center; gap: 7px;
  padding: 7px 16px; border-radius: var(--radius-pill);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-secondary); font-size: 13px; font-weight: 500;
  font-family: var(--font); cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.stop-btn.visible { display: flex; }
.stop-btn:hover { background: var(--surface-hover); color: var(--text-primary); }
.stop-btn svg { width: 13px; height: 13px; }

/* Permission prompt rendered inline inside a chat `/agent` reply */
.msg-perm {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-top: 8px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); font-size: 13px; color: var(--text-secondary);
}
.msg-perm .btn-primary, .msg-perm .btn-secondary { padding: 4px 12px; font-size: 12px; }

/* Interactive multiple-choice block rendered for the planner's ask_user tool */
.ask-box {
  margin-top: 10px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); display: flex; flex-direction: column; gap: 8px;
}
.ask-question { font-size: 13.5px; font-weight: 600; color: var(--text-primary); }
.ask-options { display: flex; flex-direction: column; gap: 6px; }
.ask-option {
  display: flex; align-items: center; gap: 8px; text-align: left;
  padding: 7px 10px; border-radius: var(--radius);
  border: 1px solid var(--border); background: transparent;
  color: var(--text-secondary); font-size: 13px; cursor: pointer;
  transition: border-color var(--transition), background var(--transition), color var(--transition);
}
.ask-option:hover { border-color: var(--accent); color: var(--text-primary); }
.ask-option.selected { border-color: var(--accent); background: rgba(16,163,127,0.12); color: var(--accent); }
.ask-opt-idx {
  flex-shrink: 0; width: 20px; height: 20px; display: inline-flex; align-items: center;
  justify-content: center; font-size: 11px; font-weight: 700;
  border-radius: 50%; background: var(--surface-hover); color: var(--text-secondary);
}
.ask-option.selected .ask-opt-idx { background: var(--accent); color: #fff; }
.ask-input {
  width: 100%; padding: 8px 10px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface-hover);
  color: var(--text-primary); font-size: 13px; font-family: var(--font);
}
.ask-answer { font-size: 13px; color: var(--text-primary); }
.ask-done { opacity: 0.95; }

/* ── STATUS BAR ── */
.status-bar {
  padding: 3px 18px;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--main-bg); border-top: 1px solid var(--border);
  min-height: 26px;
}
.status-indicator { display: flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--text-muted); }
.status-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--text-muted); transition: background 0.3s; }
.status-dot.online { background: #22c55e; }
.status-dot.error { background: var(--danger); }
.status-dot.loading { background: var(--accent); animation: pulse 1s infinite; }
.token-counter { font-size: 11px; color: var(--text-muted); font-family: var(--font-mono); }

/* ── INPUT AREA (ChatGPT style) ── */
.input-area {
  padding: 10px 16px;
  /* iOS: respect home indicator at the bottom */
  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));
  background: var(--main-bg);
  flex-shrink: 0;
}
.input-wrapper {
  max-width: 760px; margin: 0 auto;
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 10px 10px 10px 14px;
  transition: border-color var(--transition), box-shadow var(--transition);
  box-shadow: 0 2px 12px rgba(0,0,0,0.25);
}
.input-wrapper:focus-within {
  border-color: rgba(255,255,255,0.18);
  box-shadow: 0 2px 16px rgba(0,0,0,0.35);
}
[data-theme="light"] .input-wrapper { box-shadow: 0 2px 12px rgba(0,0,0,0.08); }
[data-theme="light"] .input-wrapper:focus-within { border-color: rgba(0,0,0,0.2); }

.input-tools { display: flex; align-items: flex-end; padding-bottom: 1px; }
.tool-btn {
  width: 30px; height: 30px; border-radius: var(--radius-sm); border: none;
  background: transparent; color: var(--text-muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: color var(--transition);
}
.tool-btn:hover:not(:disabled) { color: var(--text-primary); }
.tool-btn:disabled { opacity: 0.3; cursor: default; }
.tool-btn svg { width: 16px; height: 16px; }

.textarea-container { flex: 1; }
#userInput {
  width: 100%; background: transparent; border: none; outline: none;
  color: var(--text-primary); font-size: 15px; font-family: var(--font);
  line-height: 1.55; resize: none; max-height: 200px; overflow-y: auto;
  padding: 3px 0;
  /* On iOS, font-size must be >= 16px to prevent auto-zoom when focused.
     We use a CSS trick: 15px display but 16px for inputs specifically. */
  font-size: 16px;
}
#userInput::placeholder { color: var(--text-muted); }
.char-count { font-size: 10px; color: var(--text-muted); text-align: right; margin-top: 2px; display: none; }

.send-btn {
  width: 34px; height: 34px; flex-shrink: 0;
  border-radius: var(--radius-sm); border: none;
  background: var(--accent); color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--transition), opacity var(--transition);
}
.send-btn:hover:not(:disabled) { background: var(--accent-hover); }
.send-btn:disabled { opacity: 0.3; cursor: default; }
.send-btn svg { width: 16px; height: 16px; }

.input-footer-text {
  max-width: 760px; margin: 7px auto 0;
  font-size: 11.5px; color: var(--text-muted); text-align: center;
}

/* ── MODAL ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; opacity: 0; pointer-events: none;
  transition: opacity var(--transition);
  /* iOS: overflow scroll for modal overlays on older Safari */
  -webkit-overflow-scrolling: touch;
  padding: env(safe-area-inset-top, 12px) env(safe-area-inset-right, 12px)
           env(safe-area-inset-bottom, 12px) env(safe-area-inset-left, 12px);
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: #2a2a2a;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 520px; max-width: calc(100vw - 24px); max-height: min(90vh, 90dvh);
  display: flex; flex-direction: column;
  box-shadow: var(--shadow);
  transform: translateY(16px) scale(0.98);
  transition: transform var(--transition);
  overflow: hidden;
}
[data-theme="light"] .modal { background: #fff; }
.modal-overlay.open .modal { transform: translateY(0) scale(1); }
.confirm-modal { width: 400px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h2 { font-size: 16px; font-weight: 600; }
.modal-body {
  flex: 1; overflow-y: auto; padding: 18px;
  display: flex; flex-direction: column; gap: 18px;
  /* iOS momentum scrolling inside modals */
  -webkit-overflow-scrolling: touch;
  min-height: 0;
}
.modal-footer {
  padding: 14px 18px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
  flex-shrink: 0;
}

.setting-group { display: flex; flex-direction: column; gap: 6px; }
.setting-label { font-size: 13.5px; font-weight: 600; color: var(--text-primary); }
.setting-hint { font-size: 12px; color: var(--text-muted); line-height: 1.5; }
.setting-hint code { font-family: var(--font-mono); font-size: 11px; background: var(--surface); padding: 1px 5px; border-radius: 3px; }
.setting-input {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-primary);
  /* 16px minimum to prevent iOS Safari from auto-zooming on focus */
  font-size: 16px; font-family: var(--font);
  padding: 8px 11px; outline: none;
  transition: border-color var(--transition);
}
.setting-input:focus { border-color: var(--accent); }
.setting-input::placeholder { color: var(--text-muted); }
.setting-textarea { resize: vertical; min-height: 80px; line-height: 1.5; font-size: 14px; }

/* ── SERVER TYPE BADGE & QUICK BUTTONS ── */
.server-type-badge {
  display: inline-block; font-size: 9px; font-weight: 700;
  padding: 1px 7px; border-radius: var(--radius-pill);
  background: rgba(16,163,127,0.15); color: var(--accent);
  border: 1px solid rgba(16,163,127,0.25);
  margin-left: 6px; vertical-align: middle;
  font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.06em;
}
.server-quick-btns {
  display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px;
}
.server-quick-btn {
  padding: 4px 10px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-secondary); font-size: 11.5px; font-family: var(--font);
  cursor: pointer; transition: all var(--transition);
}
.server-quick-btn:hover { border-color: var(--accent); color: var(--text-primary); background: rgba(16,163,127,0.08); }
.model-select-row { display: flex; gap: 8px; }
.model-select-row .setting-input { flex: 1; }
.model-list { display: flex; flex-wrap: wrap; gap: 6px; }
.model-chip {
  padding: 5px 10px; border-radius: var(--radius-pill);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-secondary); font-size: 12px; font-family: var(--font-mono);
  cursor: pointer; transition: all var(--transition);
}
.model-chip:hover { border-color: var(--accent); color: var(--text-primary); }
.model-chip.selected { border-color: var(--accent); background: rgba(16,163,127,0.1); color: var(--accent); }

.setting-slider { width: 100%; accent-color: var(--accent); cursor: pointer; }
.theme-options { display: flex; gap: 8px; flex-wrap: wrap; }
.theme-btn {
  padding: 6px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-secondary); font-size: 13px; font-family: var(--font);
  cursor: pointer; transition: all var(--transition);
}
.theme-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(16,163,127,0.1); }
.theme-btn:hover:not(.active) { background: var(--surface-hover); color: var(--text-primary); }
.shortcut-options { display: flex; gap: 8px; }
.shortcut-btn {
  padding: 6px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-secondary); font-size: 13px; font-family: var(--font);
  cursor: pointer; transition: all var(--transition);
}
.shortcut-btn.active { border-color: var(--accent); color: var(--accent); background: rgba(16,163,127,0.1); }
.shortcut-btn:hover:not(.active) { background: var(--surface-hover); color: var(--text-primary); }

.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.toggle { position: relative; width: 42px; height: 22px; flex-shrink: 0; cursor: pointer; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0; border-radius: var(--radius-pill);
  background: var(--surface); border: 1px solid var(--border);
  transition: all var(--transition);
}
.toggle-slider::before {
  content: ''; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px;
  border-radius: 50%; background: var(--text-muted); transition: all var(--transition);
}
.toggle input:checked + .toggle-slider { background: var(--accent); border-color: transparent; }
.toggle input:checked + .toggle-slider::before { transform: translateX(20px); background: #fff; }

/* ── TOAST ── */
.toast-container {
  position: fixed; bottom: 20px; right: 20px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  display: flex; align-items: center; gap: 9px;
  padding: 11px 16px; border-radius: var(--radius-md);
  background: #3a3a3a; border: 1px solid var(--border);
  box-shadow: var(--shadow); font-size: 13.5px; color: var(--text-primary);
  animation: toastIn 0.25s ease; max-width: 300px;
}
[data-theme="light"] .toast { background: #fff; }
.toast.success { border-color: rgba(34,197,94,0.3); }
.toast.error   { border-color: rgba(239,68,68,0.3); }
.toast.info    { border-color: rgba(16,163,127,0.3); }
.toast-icon { font-size: 15px; flex-shrink: 0; }
@keyframes toastIn  { from{opacity:0;transform:translateX(16px)} to{opacity:1;transform:translateX(0)} }
@keyframes toastOut { to{opacity:0;transform:translateX(16px)} }

/* ── EMPTY STATE ── */
.empty-chat-list {
  padding: 20px 14px; text-align: center;
  color: var(--text-muted); font-size: 12.5px; line-height: 1.6;
}
.empty-chat-list svg { width: 30px; height: 30px; margin-bottom: 8px; opacity: 0.4; display: block; margin-inline: auto; }

/* ── PERSONALITY PRESETS ── */
.personality-preset-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.personality-preset-btn {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 10px 8px; border-radius: var(--radius-md);
  border: 2px solid var(--border); background: var(--surface);
  cursor: pointer; transition: all var(--transition);
  text-align: center; font-family: var(--font);
}
.personality-preset-btn:hover { border-color: var(--accent); background: rgba(16,163,127,0.08); transform: translateY(-1px); }
.personality-preset-btn.active { border-color: var(--accent); background: rgba(16,163,127,0.12); box-shadow: 0 0 0 3px rgba(16,163,127,0.15); }
.preset-icon { font-size: 20px; line-height: 1; }
.preset-name { font-size: 12px; font-weight: 700; color: var(--text-primary); }
.preset-desc { font-size: 10px; color: var(--text-muted); line-height: 1.3; }

/* ── TEMPERATURE LABELS ── */
.temp-labels {
  display: flex; justify-content: space-between;
  font-size: 10.5px; color: var(--text-muted);
  margin-top: 3px; padding: 0 2px;
}
.temp-badge {
  display: inline-block; font-size: 10px; font-weight: 600;
  padding: 1px 7px; border-radius: var(--radius-pill);
  background: rgba(16,163,127,0.15); color: var(--accent);
  border: 1px solid rgba(16,163,127,0.25);
  margin-left: 6px; vertical-align: middle;
  font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.05em;
}

/* ── WELCOME PERSONALITY BAR ── */
.welcome-personality-bar {
  display: flex; gap: 8px; justify-content: center;
  margin-bottom: 24px; flex-wrap: wrap;
}
.personality-pill {
  padding: 5px 14px; border-radius: var(--radius-pill);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-secondary); font-size: 13px; font-weight: 500;
  font-family: var(--font); cursor: pointer;
  transition: all var(--transition);
}
.personality-pill:hover { border-color: var(--accent); color: var(--text-primary); background: rgba(16,163,127,0.08); }
.personality-pill.active { border-color: var(--accent); color: var(--accent); background: rgba(16,163,127,0.12); }

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed; height: 100vh; left: 0; top: 0; z-index: 200;
    transform: translateX(0); transition: transform var(--transition);
    margin-left: 0;
  }
  .sidebar.collapsed { transform: translateX(-100%); }
  .welcome-chips { grid-template-columns: 1fr; }
  .chip { font-size: 13px; }
  .message.user .msg-bubble { max-width: 90%; }
  .modal { width: 96vw; }
  .personality-preset-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ══════════════════════════════════════════════
   IMAGE GENERATION CARDS
   ══════════════════════════════════════════════ */

/* Loading state while image is being generated */
.img-gen-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-secondary);
  font-size: 14px;
  padding: 12px 0;
}

.img-gen-spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid hsla(260, 80%, 70%, 0.25);
  border-top-color: #7c3aed;
  border-radius: 50%;
  animation: imgSpin 0.75s linear infinite;
  flex-shrink: 0;
}

@keyframes imgSpin {
  to { transform: rotate(360deg); }
}

/* Card container */
.img-gen-card {
  margin-top: 12px;
  border-radius: var(--radius-md);
  overflow: hidden;
  background: hsla(260, 30%, 10%, 0.5);
  border: 1px solid hsla(260, 40%, 60%, 0.18);
  box-shadow: 0 4px 24px hsla(260, 60%, 10%, 0.35);
  max-width: 520px;
  transition: box-shadow var(--transition), transform var(--transition);
}

.img-gen-card:hover {
  box-shadow: 0 8px 40px hsla(260, 60%, 30%, 0.3);
  transform: translateY(-2px);
}

/* Image frame with hover overlay */
.img-gen-frame {
  position: relative;
  overflow: hidden;
  background: #0a0a12;
  line-height: 0;
}

.img-gen-img {
  width: 100%;
  height: auto;
  display: block;
  transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1), filter 0.4s;
  cursor: zoom-in;
}

.img-gen-frame:hover .img-gen-img {
  transform: scale(1.02);
  filter: brightness(0.72);
}

/* Hover action overlay */
.img-gen-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  opacity: 0;
  transition: opacity 0.25s ease;
  pointer-events: none;
}

.img-gen-frame:hover .img-gen-overlay {
  opacity: 1;
  pointer-events: auto;
}

/* Download & Copy buttons */
.img-dl-btn,
.img-copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-pill);
  border: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.01em;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.img-dl-btn {
  background: linear-gradient(135deg, #7c3aed, #4f46e5);
  color: #fff;
  box-shadow: 0 4px 20px hsla(260, 70%, 40%, 0.45);
}

.img-dl-btn:hover {
  transform: scale(1.06);
  box-shadow: 0 6px 28px hsla(260, 70%, 40%, 0.65);
}

.img-copy-btn {
  background: hsla(0, 0%, 100%, 0.15);
  color: #fff;
  box-shadow: 0 2px 10px hsla(0, 0%, 0%, 0.3);
}

.img-copy-btn:hover {
  background: hsla(0, 0%, 100%, 0.25);
  transform: scale(1.06);
}

/* Meta row below the image */
.img-gen-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-top: 1px solid hsla(260, 40%, 60%, 0.12);
  gap: 8px;
}

.img-gen-badge {
  font-size: 11.5px;
  font-weight: 600;
  color: #a78bfa;
  letter-spacing: 0.02em;
}

.img-gen-size {
  font-size: 11px;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* Light theme overrides */
[data-theme="light"] .img-gen-card {
  background: hsla(260, 20%, 96%, 0.8);
  border-color: hsla(260, 40%, 60%, 0.22);
}

[data-theme="light"] .img-gen-meta {
  border-top-color: hsla(260, 20%, 0%, 0.08);
}

[data-theme="light"] .img-gen-frame {
  background: #f0eeff;
}

[data-theme="light"] .img-gen-badge {
  color: #6d28d9;
}

/* ── File Attachment Preview Bar ──────────────────────────────── */
.attach-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px 12px 0;
}

.attach-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 6px;
  background: hsla(var(--hue), 20%, 30%, 0.5);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: 12px;
  color: var(--text-secondary);
  max-width: 180px;
}

.attach-thumb {
  width: 28px;
  height: 28px;
  object-fit: cover;
  border-radius: 4px;
  flex-shrink: 0;
}

.attach-file-icon {
  font-size: 18px;
  flex-shrink: 0;
}

.attach-chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.attach-chip-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  padding: 0 2px;
  flex-shrink: 0;
  line-height: 1;
  transition: color var(--transition);
}

.attach-chip-remove:hover {
  color: var(--danger);
}

/* ── User Message Attachments ─────────────────────────────────── */
.msg-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}

.msg-attach-img {
  max-width: 240px;
  max-height: 200px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  cursor: zoom-in;
  transition: opacity var(--transition);
}
.msg-attach-img:hover { opacity: 0.9; }

.msg-attach-file {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: hsla(var(--hue), 20%, 20%, 0.4);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-secondary);
}

/* ── Drag-over highlight ──────────────────────────────────────── */
.chat-area.dragover {
  outline: 2px dashed var(--accent);
  outline-offset: -4px;
  background: hsla(160, 60%, 40%, 0.05);
}

/* ── Lightbox ─────────────────────────────────────────────────── */
.lightbox-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.18s ease;
}

.lightbox-content {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
}

.lightbox-content img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: var(--radius-md);
  object-fit: contain;
  box-shadow: 0 24px 80px rgba(0,0,0,0.6);
}

.lightbox-close {
  position: absolute;
  top: -14px;
  right: -14px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
}
.lightbox-close:hover { background: var(--danger); color: #fff; }

@keyframes fadeIn {
  from { opacity: 0; } to { opacity: 1; }
}

/* ── Accent color alias (used by server key status) ──────────── */
:root { --accent-color: var(--accent); }

/* ── PREFRONTAL AGENT PANEL ─────────────────────────────────────── */
.agent-modal { width: 760px; max-width: calc(100vw - 24px); }
.agent-status-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.agent-status-pill {
  padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--surface); color: var(--text-muted); border: 1px solid var(--border);
}
.agent-status-pill.online { color: #10a37f; border-color: rgba(16, 163, 127, 0.5); }
.agent-name { font-size: 13px; font-weight: 600; }
.agent-workspace { font-size: 12px; color: var(--text-muted); font-family: var(--font-mono); }

.agent-token-box { display: flex; gap: 8px; align-items: stretch; }
.agent-token-box code {
  flex: 1; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 11px;
  font-family: var(--font-mono); font-size: 13px; word-break: break-all; user-select: all;
}
.agent-token-box .btn-secondary { flex-shrink: 0; }

.agent-command-row { display: flex; gap: 8px; align-items: stretch; }
.agent-command-row textarea {
  flex: 1; resize: vertical; min-height: 44px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text-primary);
  font-family: var(--font-mono); font-size: 13px; line-height: 1.5;
  padding: 8px 11px; outline: none;
  transition: border-color var(--transition);
}
.agent-command-row textarea:focus { border-color: var(--accent); }
.agent-command-row textarea::placeholder { color: var(--text-muted); }
.agent-command-row .send-btn { align-self: stretch; }

.agent-log {
  background: #161616; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; font-family: var(--font-mono); font-size: 12.5px; line-height: 1.55;
  max-height: 320px; min-height: 80px; overflow-y: auto;
  white-space: pre-wrap; word-break: break-word;
  -webkit-overflow-scrolling: touch;
}
[data-theme="light"] .agent-log { background: #f2f2f2; }
.agent-log .log-cmd  { color: #10a37f; font-weight: 600; }
.agent-log .log-out  { color: #d4d4d4; }
.agent-log .log-err  { color: #ef6e6e; }
.agent-log .log-warn { color: #ffb74d; }
.agent-log .log-msg  { color: #9ecbff; }
.agent-log .log-ok   { color: #7ee2a8; }
.agent-log .log-muted{ color: #8a8a8a; }
[data-theme="light"] .agent-log .log-out { color: #333; }

.agent-perm-banner {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border: 1px solid rgba(255, 183, 77, 0.5);
  background: rgba(255, 183, 77, 0.08); border-radius: var(--radius-sm);
}
.agent-perm-banner span { flex: 1; font-size: 13px; line-height: 1.45; }
.agent-perm-banner .btn-primary, .agent-perm-banner .btn-secondary { flex-shrink: 0; }

.agent-footer { justify-content: space-between; }
.btn-secondary.danger { color: #ef6e6e; border-color: rgba(239, 110, 110, 0.4); }
.btn-secondary.danger:hover { background: rgba(239, 110, 110, 0.12); }

