/* ============================================================
   NEXUSIFY PLAYGROUND — Glassmorphism Dark Theme
   Professional · Responsive · OpenAI-Inspired
   ============================================================ */

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

/* ── Design Tokens ── */
:root {
  /* Background layers */
  --bg:              #09090b;
  --bg-mid:          #0f0f13;
  --bg-card:         rgba(255, 255, 255, 0.035);
  --bg-secondary:    rgba(255, 255, 255, 0.065);
  --bg-hover:        rgba(255, 255, 255, 0.085);
  --bg-active:       rgba(255, 255, 255, 0.11);
  --bg-input:        rgba(255, 255, 255, 0.04);

  /* Borders */
  --border:          rgba(255, 255, 255, 0.08);
  --border-strong:   rgba(255, 255, 255, 0.14);
  --border-focus:    rgba(14, 165, 233, 0.55);

  /* Text */
  --text:            #f1f5f9;
  --text-secondary:  #94a3b8;
  --text-muted:      #64748b;
  --text-dim:        #334155;

  /* Brand accents */
  --blue:            #0ea5e9;
  --blue-dark:       #0284c7;
  --cyan:            #06b6d4;
  --green:           #10b981;
  --purple:          #8b5cf6;
  --red:             #ef4444;

  /* Gradient */
  --grad:            linear-gradient(135deg, #0ea5e9, #06b6d4);
  --grad-text:       linear-gradient(90deg, #0ea5e9, #06b6d4);

  /* Glow effects */
  --glow-blue:       0 0 24px rgba(14, 165, 233, 0.35);
  --glow-sm:         0 0 14px rgba(14, 165, 233, 0.25);
  --shadow-card:     0 4px 24px rgba(0, 0, 0, 0.45), 0 1px 0 rgba(255, 255, 255, 0.05) inset;
  --shadow-dropdown: 0 20px 56px rgba(0, 0, 0, 0.65), 0 1px 0 rgba(255, 255, 255, 0.06) inset;

  /* Glass */
  --glass-blur:      blur(20px);
  --glass-bg:        rgba(12, 12, 16, 0.88);

  /* Layout */
  --radius-sm:       0.375rem;
  --radius:          0.625rem;
  --radius-lg:       0.875rem;
  --radius-xl:       1.125rem;
  --sidebar-w:       268px;
  --header-h:        60px;

  /* Transitions */
  --ease:            cubic-bezier(0.4, 0, 0.2, 1);
  --transition:      all 0.2s var(--ease);
}

/* ── Base ── */
html, body {
  height: 100%;
  height: 100dvh;
  font-family: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
  line-height: 1.5;
}

/* Subtle ambient glow in background */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(14, 165, 233, 0.07) 0%, transparent 65%),
    radial-gradient(ellipse 50% 40% at 95% 95%, rgba(6, 182, 212, 0.05) 0%, transparent 60%);
  pointer-events: none;
  z-index: 0;
}

a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Custom Scrollbar ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.1); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.18); }

::selection { background: rgba(14, 165, 233, 0.3); color: #fff; }
*:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ============================================================
   UTILITIES
   ============================================================ */
.hidden { display: none !important; }
.flex-1 { flex: 1; }
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.8125rem; }
.text-xs { font-size: 0.75rem; }
.desktop-only { display: flex; }
.mobile-only { display: none; }

@media (max-width: 768px) {
  .desktop-only { display: none !important; }
  .mobile-only  { display: flex !important; }
}

/* ============================================================
   LOGO BADGE  (gradient square with sparkle icon)
   ============================================================ */
.logo-badge {
  width: 52px; height: 52px;
  border-radius: var(--radius-lg);
  background: var(--grad);
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--glow-blue), 0 4px 16px rgba(0, 0, 0, 0.35);
  flex-shrink: 0;
  position: relative; overflow: hidden;
}
/* Glint overlay */
.logo-badge::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.16) 0%, transparent 55%);
  border-radius: inherit;
}
.logo-badge svg { position: relative; z-index: 1; }

.logo-badge-sm {
  width: 30px; height: 30px;
  border-radius: 0.5rem;
  box-shadow: var(--glow-sm);
}
.logo-badge-xl {
  width: 64px; height: 64px;
  border-radius: 1.25rem;
  margin-bottom: 1.5rem;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 0.5rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 0.875rem; font-weight: 500;
  font-family: inherit;
  cursor: pointer; transition: var(--transition);
  white-space: nowrap;
  background: transparent; color: var(--text);
  line-height: 1.4;
  letter-spacing: 0.01em;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }

.btn-primary {
  background: var(--blue); color: #fff;
  border-color: var(--blue);
}
.btn-primary:hover:not(:disabled) {
  background: var(--blue-dark);
  box-shadow: var(--glow-sm);
}

.btn-gradient {
  background: var(--grad);
  color: #fff; border: none;
  box-shadow: var(--glow-sm);
  position: relative; overflow: hidden;
}
.btn-gradient::before {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.12), transparent);
  opacity: 0; transition: opacity 0.2s;
}
.btn-gradient:hover:not(:disabled)::before { opacity: 1; }
.btn-gradient:hover:not(:disabled) { box-shadow: var(--glow-blue); }

.btn-outline {
  border-color: var(--border-strong);
  color: var(--text);
  background: var(--bg-card);
  backdrop-filter: var(--glass-blur);
}
.btn-outline:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: rgba(14, 165, 233, 0.35);
}

.btn-ghost { border: none; color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); }

.btn-full { width: 100%; justify-content: center; }
.btn-justify-start { justify-content: flex-start; }
.btn-sm { padding: 0.3rem 0.625rem; font-size: 0.8125rem; }

/* Icon-only button */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px;
  border: none; background: transparent;
  border-radius: var(--radius);
  cursor: pointer; color: var(--text-muted); transition: var(--transition);
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn-sm { width: 26px; height: 26px; border-radius: var(--radius-sm); }

/* ============================================================
   FORM INPUTS
   ============================================================ */
.text-input {
  width: 100%;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.625rem 0.875rem;
  color: var(--text);
  font-size: 0.875rem;
  font-family: inherit;
  transition: var(--transition);
  resize: vertical;
}
.text-input::placeholder { color: var(--text-dim); }
.text-input:focus {
  outline: none;
  border-color: rgba(14, 165, 233, 0.5);
  background: rgba(14, 165, 233, 0.04);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.1);
}
.text-input[type="password"] { letter-spacing: 0.1em; }

.field-label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.375rem;
  letter-spacing: 0.02em;
}
.field-group { display: flex; flex-direction: column; gap: 0.5rem; }
.input-row { display: flex; gap: 0.5rem; align-items: center; }

/* Range slider */
.range-slider {
  -webkit-appearance: none;
  width: 100%; height: 4px;
  background: var(--bg-hover);
  border-radius: 8px; cursor: pointer;
  outline: none;
}
.range-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--blue);
  cursor: pointer;
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.25), 0 2px 8px rgba(14, 165, 233, 0.4);
  transition: box-shadow 0.2s;
}
.range-slider::-webkit-slider-thumb:hover {
  box-shadow: 0 0 0 5px rgba(14, 165, 233, 0.2), 0 2px 12px rgba(14, 165, 233, 0.5);
}
.range-slider::-moz-range-thumb {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--blue); border: none;
  cursor: pointer;
}
.slider-label-row {
  display: flex; justify-content: space-between; align-items: center;
}
.slider-value {
  font-size: 0.8125rem;
  color: var(--blue);
  font-weight: 600;
  min-width: 2.5rem; text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Toggle switch */
.switch { display: inline-flex; align-items: center; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  width: 42px; height: 24px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 99px;
  position: relative;
  transition: all 0.25s var(--ease);
}
.switch input:checked ~ .switch-track {
  background: var(--blue);
  border-color: var(--blue);
  box-shadow: var(--glow-sm);
}
.switch-thumb {
  position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.25s var(--ease);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}
.switch input:checked ~ .switch-track .switch-thumb { transform: translateX(18px); }
.toggle-row {
  display: flex; justify-content: space-between;
  align-items: center; padding: 0.25rem 0;
}

/* ============================================================
   CUSTOM SELECT / DROPDOWN
   ============================================================ */
.custom-select { position: relative; }

.cs-trigger {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 0.5rem 0.875rem;
  min-width: 160px; width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text); font-size: 0.875rem;
  font-family: inherit;
  cursor: pointer; transition: var(--transition);
  white-space: nowrap; overflow: hidden;
  text-align: left;
}
.cs-trigger span { overflow: hidden; text-overflow: ellipsis; }
.cs-trigger:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}
.cs-trigger[aria-expanded="true"] {
  border-color: rgba(14, 165, 233, 0.5);
  background: rgba(14, 165, 233, 0.05);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.08);
}

.cs-arrow {
  flex-shrink: 0; color: var(--text-muted);
  transition: transform 0.25s var(--ease);
}
.cs-trigger[aria-expanded="true"] .cs-arrow { transform: rotate(180deg); }

.cs-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0; min-width: 100%;
  background: var(--glass-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  z-index: 200;
  max-height: 320px;
  overflow-y: auto;
  box-shadow: var(--shadow-dropdown);
  padding: 0.375rem;
  backdrop-filter: var(--glass-blur);
}

.cs-option {
  display: flex; align-items: center; gap: 6px;
  width: 100%;
  padding: 0.5625rem 0.75rem;
  border: none; background: transparent;
  color: var(--text); font-size: 0.875rem;
  font-family: inherit;
  cursor: pointer; border-radius: calc(var(--radius) - 2px);
  text-align: left; transition: background 0.12s;
}
.cs-option:hover { background: var(--bg-hover); }
.cs-option.selected {
  background: rgba(14, 165, 233, 0.12);
  color: var(--blue);
}
.cs-option-sub { font-size: 0.75rem; color: var(--text-muted); margin-left: auto; }

/* ============================================================
   BADGES
   ============================================================ */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 0.15rem 0.5rem;
  font-size: 0.725rem; font-weight: 500;
  border-radius: 99px;
  border: 1px solid;
  white-space: nowrap;
  letter-spacing: 0.02em;
}
.badge-purple {
  border-color: rgba(139, 92, 246, 0.4);
  color: #c4b5fd;
  background: rgba(139, 92, 246, 0.08);
}
.badge-blue {
  border-color: rgba(14, 165, 233, 0.4);
  color: #7dd3fc;
  background: rgba(14, 165, 233, 0.08);
}
.badge-green {
  border-color: rgba(16, 185, 129, 0.4);
  color: #6ee7b7;
  background: rgba(16, 185, 129, 0.08);
}

/* ============================================================
   API KEY SCREEN
   ============================================================ */
.api-key-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex; align-items: center; justify-content: center;
  padding: 1.5rem;
  background: var(--bg);
  position: relative; z-index: 1;
}
.api-key-card {
  width: 100%; max-width: 440px;
  background: var(--glass-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 2.5rem;
  display: flex; flex-direction: column; gap: 2rem;
  box-shadow: var(--shadow-card);
  backdrop-filter: var(--glass-blur);
  position: relative; overflow: hidden;
}
/* Accent top edge line on card */
.api-key-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(14, 165, 233, 0.5), transparent);
}
.api-key-header {
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 0.75rem;
}
.api-key-header h1 {
  font-size: 1.625rem; font-weight: 700;
  letter-spacing: -0.02em;
}
.api-key-form { display: flex; flex-direction: column; gap: 1.125rem; }
.api-key-footnote {
  font-size: 0.75rem; color: var(--text-muted); text-align: center;
}

/* ============================================================
   APP LAYOUT
   ============================================================ */
.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  position: relative; z-index: 1;
}

/* Sidebar backdrop (mobile) */
.sidebar-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(4px);
  z-index: 30;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  height: 100%;
  background: var(--glass-bg);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  transition: transform 0.3s var(--ease);
  backdrop-filter: var(--glass-blur);
}

.sidebar-header {
  padding: 1rem 1rem 0.875rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.sidebar-brand { display: flex; align-items: center; gap: 0.75rem; }
.sidebar-title {
  font-weight: 700; font-size: 1rem;
  letter-spacing: -0.01em;
  background: var(--grad-text);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.sidebar-close-mobile { display: none; }

.sidebar-new-chat { padding: 0.875rem; flex-shrink: 0; }

.conversation-list {
  flex: 1; overflow-y: auto;
  padding: 0 0.625rem 0.625rem;
  display: flex; flex-direction: column; gap: 2px;
}

.sidebar-footer {
  padding: 0.75rem;
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 2px;
  flex-shrink: 0;
}

/* Mobile sidebar */
@media (max-width: 768px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    z-index: 40;
    transform: translateX(-100%);
    width: min(var(--sidebar-w), 85vw);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close-mobile { display: flex; }
}

/* Conversation items (JS renders these) */
.conv-item {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.5625rem 0.75rem;
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
  color: var(--text-muted); font-size: 0.875rem;
  border: 1px solid transparent;
  background: transparent; text-align: left; width: 100%;
}
.conv-item:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--border);
}
.conv-item.active {
  background: rgba(14, 165, 233, 0.08);
  color: var(--text);
  border-color: rgba(14, 165, 233, 0.2);
}
.conv-item svg { flex-shrink: 0; color: var(--text-muted); }
.conv-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-delete {
  opacity: 0; flex-shrink: 0;
  width: 20px; height: 20px;
  border: none; background: transparent;
  color: var(--text-muted); cursor: pointer;
  border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  transition: var(--transition);
}
.conv-item:hover .conv-delete { opacity: 1; }
.conv-delete:hover { background: rgba(239, 68, 68, 0.15); color: var(--red); }

/* ── Main area ── */
.main {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
  height: 100%;
}

/* ── App header ── */
.app-header {
  height: var(--header-h);
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.25rem;
  border-bottom: 1px solid var(--border);
  background: rgba(9, 9, 11, 0.88);
  backdrop-filter: blur(20px);
  gap: 1rem;
  position: relative;
}
/* Subtle accent glow on header bottom */
.app-header::after {
  content: '';
  position: absolute; bottom: -1px; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(14, 165, 233, 0.25), transparent);
}
.header-left {
  display: flex; align-items: center; gap: 0.875rem;
  min-width: 0; flex: 1;
}
.capability-badges { display: flex; align-items: center; gap: 0.375rem; flex-wrap: nowrap; }

/* Tab switcher */
.tab-switcher {
  display: flex; align-items: center; gap: 2px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 3px; flex-shrink: 0;
}
.tab-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 0.375rem 0.875rem;
  border: none; background: transparent;
  color: var(--text-muted); font-size: 0.8125rem; font-weight: 500;
  font-family: inherit;
  border-radius: calc(var(--radius) - 2px);
  cursor: pointer; transition: var(--transition);
  white-space: nowrap;
}
.tab-btn.active {
  background: var(--bg-hover);
  color: var(--text);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
}
.tab-btn:hover:not(.active) { color: var(--text); }

/* Tab sections */
.tab-section {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
  align-items: stretch;
}

/* Mobile header — 2-row layout */
@media (max-width: 768px) {
  .app-header {
    height: auto;
    flex-direction: column;
    align-items: stretch;
    padding: 0.625rem 0.875rem;
    gap: 0.5rem;
  }
  .header-left { width: 100%; }
  .header-left .custom-select { flex: 1; }
  .header-left .cs-trigger { min-width: 0; width: 100%; }
  .tab-switcher { width: 100%; }
  .tab-btn { flex: 1; justify-content: center; }
}

/* ============================================================
   CHAT TAB
   ============================================================ */
.messages-scroll {
  flex: 1; overflow-y: auto;
  padding: 1.5rem 1rem;
  display: flex; flex-direction: column;
  min-height: 0;
}

/* Welcome screen */
.welcome-screen {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; text-align: center;
  flex: 1;
  padding: 2.5rem 1.5rem;
}
.welcome-screen h2 {
  font-size: 1.75rem; font-weight: 700;
  margin-bottom: 0.5rem;
  letter-spacing: -0.02em;
}

.suggestions-grid {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem; width: 100%; max-width: 520px; margin-top: 2rem;
}
.suggestion-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 0.4rem;
  padding: 1.125rem;
  background: var(--glass-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer; text-align: left;
  transition: var(--transition);
  color: var(--text);
  backdrop-filter: var(--glass-blur);
}
.suggestion-card:hover {
  background: var(--bg-hover);
  border-color: rgba(14, 165, 233, 0.3);
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(14, 165, 233, 0.1);
}
.suggestion-icon { color: var(--blue); }
.suggestion-title { font-size: 0.875rem; font-weight: 600; }
.suggestion-desc { font-size: 0.75rem; color: var(--text-muted); }

@media (max-width: 480px) {
  .suggestions-grid { grid-template-columns: 1fr 1fr; gap: 0.5rem; }
  .suggestion-card { padding: 0.875rem; }
  .welcome-screen h2 { font-size: 1.375rem; }
  .logo-badge-xl { width: 52px; height: 52px; margin-bottom: 1rem; }
}

/* Messages list */
.messages-list {
  max-width: 800px; width: 100%; margin: 0 auto;
  display: flex; flex-direction: column; gap: 1.75rem;
}
.messages-scroll .messages-list:not(:empty) { padding-bottom: 0.5rem; }

/* Message rows */
.message-row {
  display: flex; gap: 0.875rem;
  max-width: 800px; width: 100%; margin: 0 auto;
}
.user-row { justify-content: flex-end; }
.assistant-row { justify-content: flex-start; align-items: flex-start; }

/* Assistant avatar */
.assistant-avatar {
  width: 32px; height: 32px;
  background: var(--grad);
  border-radius: 0.625rem;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; margin-top: 2px;
  box-shadow: var(--glow-sm);
  position: relative; overflow: hidden;
}
.assistant-avatar::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.14), transparent);
}
.assistant-avatar svg { position: relative; z-index: 1; }

/* Assistant message body */
.assistant-body { flex: 1; min-width: 0; }
.assistant-meta {
  display: flex; align-items: center; gap: 0.5rem;
  margin-bottom: 0.625rem; flex-wrap: wrap;
}
.assistant-model {
  font-size: 0.8125rem; font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}
.assistant-time { font-size: 0.75rem; color: var(--text-dim); }
.token-badge {
  font-size: 0.7rem; padding: 0.075rem 0.4rem;
  border: 1px solid var(--border);
  border-radius: 99px;
  color: var(--text-muted);
  background: var(--bg-card);
}

/* Reasoning / thinking block */
.reasoning-details {
  background: rgba(14, 165, 233, 0.04);
  border: 1px solid rgba(14, 165, 233, 0.15);
  border-radius: var(--radius);
  overflow: hidden; margin-bottom: 0.875rem;
}
.reasoning-summary {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.625rem 0.875rem;
  cursor: pointer; font-size: 0.875rem; font-weight: 500;
  list-style: none; user-select: none;
  transition: background 0.15s;
  color: var(--text-secondary);
}
.reasoning-summary:hover { background: rgba(14, 165, 233, 0.04); }
.reasoning-summary svg { color: var(--blue); }
.reasoning-time { font-size: 0.75rem; color: var(--text-muted); margin-left: auto; }
.reasoning-body {
  padding: 0.875rem;
  border-top: 1px solid rgba(14, 165, 233, 0.12);
  font-size: 0.875rem; color: var(--text-muted);
  background: rgba(0, 0, 0, 0.2);
}

/* Message actions (revealed on hover) */
.message-actions {
  display: flex; align-items: center; gap: 2px; margin-top: 0.625rem;
  opacity: 0; transition: opacity 0.2s;
}
.message-row:hover .message-actions,
.assistant-row:hover .message-actions { opacity: 1; }

/* User message bubble */
.user-bubble {
  max-width: 72%;
  background: var(--bg-secondary);
  border: 1px solid var(--border-strong);
  border-radius: 1.25rem 1.25rem 0.375rem 1.25rem;
  padding: 0.875rem 1.125rem;
}
.user-content {
  font-size: 0.9375rem; white-space: pre-wrap; word-break: break-word;
  line-height: 1.65;
}
.user-images { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 0.625rem; }
.user-images img { width: 84px; height: 84px; object-fit: cover; border-radius: 0.625rem; }
.user-meta {
  display: flex; justify-content: flex-end; align-items: center;
  gap: 0.25rem; margin-top: 0.375rem;
}
.user-time { font-size: 0.6875rem; color: var(--text-dim); }

/* Loading dots */
.loading-bubble {
  background: var(--glass-bg);
  border: 1px solid var(--border);
  border-radius: 1rem;
  padding: 1rem 1.25rem;
  display: flex; align-items: center; gap: 5px;
  backdrop-filter: var(--glass-blur);
}
.typing-dot {
  width: 5px; height: 5px;
  background: var(--blue);
  border-radius: 50%; display: inline-block;
  animation: typing 1.4s infinite ease-in-out both;
}
.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }
@keyframes typing {
  0%, 80%, 100% { transform: scale(0); opacity: 0.3; }
  40%           { transform: scale(1); opacity: 1; }
}

/* Spinner */
.spinner {
  animation: spin 0.8s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Input area ── */
.input-area {
  flex-shrink: 0;
  padding: 1rem 1.25rem;
  padding-bottom: max(1.25rem, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: rgba(9, 9, 11, 0.75);
  backdrop-filter: blur(20px);
  width: 100%;
}
/* Inner content is max-width centered */
.input-area > * {
  max-width: 800px;
  margin-left: auto; margin-right: auto; display: block;
}
.input-area .input-box { display: flex; }

@media (max-width: 768px) {
  .input-area {
    padding: 0.75rem 0.875rem;
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  }
  .messages-scroll { padding: 1rem 0.75rem; }
}

/* Uploaded image previews */
.uploaded-images {
  display: flex; flex-wrap: wrap; gap: 0.5rem;
  margin-bottom: 0.625rem;
}
.uploaded-thumb { position: relative; display: inline-block; }
.uploaded-thumb img {
  width: 68px; height: 68px;
  object-fit: cover; border-radius: 0.625rem;
  border: 1px solid var(--border);
}
.uploaded-thumb-remove {
  position: absolute; top: -5px; right: -5px;
  width: 20px; height: 20px;
  background: var(--bg-mid);
  border: 1px solid var(--border);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text-muted);
  font-size: 10px; line-height: 1;
  transition: var(--transition);
}
.uploaded-thumb-remove:hover { background: var(--red); color: #fff; border-color: var(--red); }

/* Glass input box */
.input-box {
  display: flex; align-items: flex-end; gap: 0.625rem;
  background: var(--glass-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 0.625rem;
  transition: var(--transition);
  backdrop-filter: var(--glass-blur);
  box-shadow: var(--shadow-card);
}
.input-box:focus-within {
  border-color: rgba(14, 165, 233, 0.4);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.08), var(--shadow-card);
}

.upload-btn { color: var(--text-muted); }
.upload-btn:hover { color: var(--blue); }

.chat-textarea {
  flex: 1;
  background: transparent;
  border: none; outline: none;
  resize: none;
  color: var(--text); font-size: 0.9375rem;
  font-family: inherit;
  line-height: 1.55;
  min-height: 24px; max-height: 180px;
  padding: 0.375rem 0;
}
.chat-textarea::placeholder { color: var(--text-dim); }

.send-btn {
  width: 38px; height: 38px; border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  border: none; cursor: pointer;
  background: var(--bg-hover);
  color: var(--text-muted);
  transition: var(--transition);
}
.send-btn.ready {
  background: var(--grad);
  color: #fff;
  box-shadow: var(--glow-sm);
}
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.send-btn.ready:hover { box-shadow: var(--glow-blue); transform: scale(1.05); }

.input-footnote {
  font-size: 0.6875rem; color: var(--text-dim);
  text-align: center; margin-top: 0.625rem;
}

/* ============================================================
   PROSE  (markdown content)
   ============================================================ */
.prose { font-size: 0.9375rem; line-height: 1.75; word-break: break-word; color: var(--text); }
.prose p { margin-bottom: 0.875rem; }
.prose p:last-child { margin-bottom: 0; }
.prose h1, .prose h2, .prose h3, .prose h4 {
  font-weight: 700; margin: 1.25rem 0 0.625rem; color: #fff;
  letter-spacing: -0.02em;
}
.prose h1 { font-size: 1.5rem; }
.prose h2 { font-size: 1.25rem; }
.prose h3 { font-size: 1.0625rem; }
.prose ul, .prose ol { padding-left: 1.5rem; margin-bottom: 0.875rem; }
.prose li { margin-bottom: 0.3rem; }
.prose a { color: var(--blue); }
.prose a:hover { text-decoration: underline; }
.prose strong { font-weight: 700; color: #fff; }
.prose em { font-style: italic; }
.prose blockquote {
  border-left: 3px solid var(--blue);
  padding: 0.5rem 1rem; margin: 1rem 0;
  color: var(--text-muted); font-style: italic;
  background: rgba(14, 165, 233, 0.04);
  border-radius: 0 var(--radius) var(--radius) 0;
}
.prose hr { border: none; border-top: 1px solid var(--border); margin: 1.25rem 0; }
.prose table { border-collapse: collapse; width: 100%; margin-bottom: 0.875rem; }
.prose th, .prose td { border: 1px solid var(--border); padding: 0.5rem 0.875rem; text-align: left; }
.prose th {
  background: var(--bg-card);
  font-weight: 600; color: var(--text-secondary);
  font-size: 0.8125rem; letter-spacing: 0.03em;
}

/* Inline code */
.prose :not(pre) > code {
  background: rgba(14, 165, 233, 0.1);
  border: 1px solid rgba(14, 165, 233, 0.2);
  padding: 0.15em 0.45em;
  border-radius: 5px;
  font-size: 0.875em;
  font-family: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', ui-monospace, monospace;
  color: #67e8f9;
}

/* Code blocks */
.code-block {
  background: #0d1117;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden; margin-bottom: 0.875rem;
}
.code-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.5rem 1rem;
  background: rgba(255, 255, 255, 0.03);
  border-bottom: 1px solid var(--border);
}
.code-lang {
  font-size: 0.75rem; color: var(--text-muted);
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-weight: 500;
}
.code-copy-btn {
  font-size: 0.75rem; padding: 0.2rem 0.625rem;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted); cursor: pointer;
  transition: var(--transition);
  font-family: inherit; font-weight: 500;
}
.code-copy-btn:hover { border-color: var(--border-strong); color: var(--text); }
.code-copy-btn.copied { color: var(--green); border-color: rgba(16, 185, 129, 0.4); }
.code-block pre {
  margin: 0; padding: 1.125rem 1rem;
  overflow-x: auto;
  font-size: 0.875rem; line-height: 1.65;
  font-family: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', ui-monospace, monospace;
}
.code-block code { background: none; padding: 0; font-size: inherit; border: none; color: inherit; }

/* ============================================================
   IMAGE GENERATION TAB
   ============================================================ */
.image-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 1.5rem;
  padding: 1.5rem;
  height: 100%;
  overflow-y: auto;
}

@media (max-width: 768px) {
  .image-layout { grid-template-columns: 1fr; padding: 1rem; gap: 1rem; }
}

.panel {
  background: var(--glass-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 1.5rem;
  display: flex; flex-direction: column; gap: 1.125rem;
  backdrop-filter: var(--glass-blur);
  box-shadow: var(--shadow-card);
  height: fit-content;
}
.panel-title {
  display: flex; align-items: center; gap: 0.5rem;
  font-size: 0.9375rem; font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}

.gallery-title {
  font-size: 0.9375rem; font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.875rem;
  letter-spacing: 0.01em;
}

.generated-images { display: flex; flex-direction: column; gap: 1rem; }
.empty-gallery {
  background: var(--glass-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 3.5rem 2rem;
  text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 0.875rem;
  backdrop-filter: var(--glass-blur);
}
.empty-gallery svg { color: var(--text-dim); }
.empty-gallery p { color: var(--text-muted); font-weight: 500; }
.empty-gallery small { color: var(--text-dim); font-size: 0.75rem; }

.generated-image-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  overflow: hidden;
}
.generated-image-card img {
  width: 100%; aspect-ratio: 1;
  object-fit: cover; display: block;
}
.generated-image-overlay {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.2s;
}
.generated-image-card:hover .generated-image-overlay { opacity: 1; }

/* ============================================================
   SETTINGS SHEET
   ============================================================ */
.sheet-overlay {
  position: fixed; inset: 0; z-index: 500;
  display: flex;
}
.sheet-backdrop {
  position: absolute; inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}
.sheet-panel {
  position: relative;
  margin-left: auto;
  width: 100%; max-width: 400px;
  height: 100%;
  background: var(--glass-bg);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  animation: slideInRight 0.25s var(--ease) both;
  backdrop-filter: var(--glass-blur);
  box-shadow: -20px 0 60px rgba(0, 0, 0, 0.5);
}
/* Accent left border glow */
.sheet-panel::before {
  content: '';
  position: absolute; top: 0; left: -1px; bottom: 0;
  width: 1px;
  background: linear-gradient(
    180deg,
    rgba(14, 165, 233, 0.5) 0%,
    transparent 40%,
    rgba(14, 165, 233, 0.2) 100%
  );
}
@keyframes slideInRight {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0); opacity: 1; }
}
.sheet-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1.375rem 1.375rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sheet-title { font-size: 1.0625rem; font-weight: 700; letter-spacing: -0.01em; }
.sheet-body {
  flex: 1; overflow-y: auto;
  padding: 1.375rem;
  display: flex; flex-direction: column; gap: 1.25rem;
}
.separator {
  border: none;
  border-top: 1px solid var(--border);
  margin: 0;
}

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
.toast-container {
  position: fixed; bottom: 1.25rem; right: 1.25rem;
  z-index: 600;
  display: flex; flex-direction: column-reverse; gap: 0.625rem;
  pointer-events: none;
}
.toast {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 0.875rem;
  padding: 1rem 1.125rem;
  background: var(--glass-bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  min-width: 300px; max-width: 400px;
  box-shadow: var(--shadow-dropdown);
  pointer-events: all;
  animation: toastIn 0.3s var(--ease) both;
  backdrop-filter: var(--glass-blur);
}
.toast-error { border-color: rgba(239, 68, 68, 0.4); background: rgba(239, 68, 68, 0.06); }
.toast-content { flex: 1; }
.toast-title { font-size: 0.875rem; font-weight: 600; display: block; }
.toast-desc { font-size: 0.8125rem; color: var(--text-muted); margin-top: 3px; }
.toast-close {
  flex-shrink: 0;
  background: transparent; border: none;
  color: var(--text-muted); cursor: pointer;
  padding: 0; line-height: 1;
  font-size: 1rem; pointer-events: all;
  transition: color 0.15s;
}
.toast-close:hover { color: var(--text); }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(16px); }
  to   { opacity: 1; transform: translateX(0); }
}
.toast.removing {
  animation: toastOut 0.2s var(--ease) forwards;
}
@keyframes toastOut {
  to { opacity: 0; transform: translateX(16px); }
}

/* ============================================================
   RESPONSIVE — Tablet (769–1024px)
   ============================================================ */
@media (max-width: 1024px) and (min-width: 769px) {
  :root { --sidebar-w: 240px; }
}

/* ============================================================
   RESPONSIVE — Large Desktop (1280px+)
   ============================================================ */
@media (min-width: 1280px) {
  :root { --sidebar-w: 280px; }
  .messages-scroll { padding: 2rem 1.5rem; }
  .messages-list { max-width: 840px; }
  .message-row { max-width: 840px; }
  .input-area > * { max-width: 840px; }
}

/* ============================================================
   RESPONSIVE — Small Mobile (max 375px)
   ============================================================ */
@media (max-width: 375px) {
  .user-bubble { max-width: 88%; }
  .api-key-card { padding: 1.75rem 1.25rem; }
}
