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

:root {
  --bg-0: #09090b;
  --bg-1: #111113;
  --bg-2: #1a1a1f;
  --bg-3: #232329;
  --border: #2a2a32;
  --border-hover: #3a3a44;
  --text: #e4e4e7;
  --text-muted: #8b8b96;
  --text-dim: #5a5a66;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --green: #22c55e;
  --blue: #3b82f6;
  --purple: #a855f7;
  --orange: #f59e0b;
  --red: #ef4444;
  --radius: 10px;
  --radius-sm: 6px;
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', monospace;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg-0);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  overflow: hidden;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-3); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-hover); }

/* ===== Top Bar ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 52px;
  padding: 0 20px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 100;
}
.topbar-left { display: flex; align-items: center; gap: 32px; }
.logo { font-size: 16px; font-weight: 800; letter-spacing: 3px; color: var(--accent); user-select: none; }
.nav { display: flex; gap: 4px; }
.nav-btn {
  background: none; border: none; color: var(--text-muted);
  font-family: var(--font); font-size: 13px; font-weight: 500;
  padding: 6px 14px; border-radius: var(--radius-sm);
  cursor: pointer; transition: all .15s;
}
.nav-btn:hover { color: var(--text); background: var(--bg-2); }
.nav-btn.active { color: var(--text); background: var(--bg-3); }

.spending-bar {
  display: flex; align-items: center; gap: 12px;
  font-size: 12px; font-family: var(--font-mono); color: var(--text-muted);
}
.spending-divider { width: 1px; height: 16px; background: var(--border); }

/* ===== Budget Alert ===== */
.budget-alert {
  padding: 8px 20px; text-align: center; font-size: 13px; font-weight: 600;
  position: fixed; top: 52px; left: 0; right: 0; z-index: 99;
}
.budget-alert.warning { background: #422006; color: var(--orange); }
.budget-alert.danger { background: #450a0a; color: var(--red); }
.budget-alert.hidden { display: none; }

/* ===== Pages ===== */
.page {
  display: none; position: fixed;
  top: 52px; left: 0; right: 0; bottom: 0;
}
.page.active { display: flex; }

/* ===== Studio Layout ===== */
.studio-layout { display: flex; width: 100%; height: 100%; }

/* ===== Chat Sidebar (left) ===== */
.sidebar {
  width: 260px; min-width: 260px;
  background: var(--bg-1);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-header h2 {
  font-size: 13px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 1px; color: var(--text-muted);
}

.chats-list {
  flex: 1; overflow-y: auto; padding: 6px 8px;
  display: flex; flex-direction: column; gap: 2px;
}

/* Chat item in sidebar */
.chat-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer; transition: all .12s;
  position: relative;
}
.chat-item:hover { background: var(--bg-2); }
.chat-item.active { background: var(--bg-3); }

.chat-item-icon {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--bg-2); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: var(--accent);
  flex-shrink: 0;
}
.chat-item.active .chat-item-icon { border-color: var(--accent); }

.chat-item-text { flex: 1; min-width: 0; }
.chat-item-name {
  font-size: 13px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-item-meta {
  font-size: 11px; color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.chat-item-actions {
  display: none; position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  gap: 2px;
}
.chat-item:hover .chat-item-actions { display: flex; }
.chat-item-actions button {
  width: 24px; height: 24px;
  background: var(--bg-3); border: 1px solid var(--border);
  color: var(--text-dim); border-radius: 4px;
  cursor: pointer; font-size: 12px;
  display: flex; align-items: center; justify-content: center;
}
.chat-item-actions button:hover { color: var(--red); border-color: var(--red); }

/* ===== Preset Picker (in prompt bar) ===== */
.preset-picker { position: relative; }
.preset-picker-btn {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-2); border: 1px solid var(--border);
  color: var(--text); font-family: var(--font); font-size: 12px; font-weight: 500;
  padding: 5px 12px; border-radius: var(--radius-sm);
  cursor: pointer; transition: all .15s; white-space: nowrap;
}
.preset-picker-btn:hover { border-color: var(--border-hover); }
.preset-picker-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
  background: var(--text-dim);
}

.preset-dropdown {
  position: absolute; bottom: calc(100% + 6px); left: 0;
  width: 320px; max-height: 400px;
  background: var(--bg-1); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 8px 32px rgba(0,0,0,.5);
  z-index: 50; overflow: hidden;
  display: flex; flex-direction: column;
}
.preset-dropdown.hidden { display: none; }
.preset-dropdown-list {
  flex: 1; overflow-y: auto; padding: 6px;
  display: flex; flex-direction: column; gap: 2px;
}
.preset-dropdown-footer {
  padding: 8px; border-top: 1px solid var(--border);
  display: flex; justify-content: center;
}

/* Preset items in dropdown */
.preset-option {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  cursor: pointer; transition: background .1s;
}
.preset-option:hover { background: var(--bg-2); }
.preset-option.active { background: var(--bg-3); }
.preset-option-dot {
  width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0;
}
.preset-option-info { flex: 1; min-width: 0; }
.preset-option-name { font-size: 12px; font-weight: 600; }
.preset-option-desc { font-size: 10px; color: var(--text-dim); }
.preset-option-provider {
  font-size: 9px; color: var(--text-dim); text-transform: uppercase;
  letter-spacing: .5px; font-weight: 600;
}

/* ===== Studio main ===== */
.studio-main {
  flex: 1; display: flex; flex-direction: column; overflow: hidden;
}

/* Chat area */
.chat-area {
  flex: 1; overflow-y: auto; padding: 24px;
  display: flex; flex-direction: column; gap: 16px;
}
.chat-empty {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  gap: 12px; color: var(--text-dim);
}
.chat-empty-icon {
  width: 64px; height: 64px; border-radius: 16px;
  background: var(--bg-2); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; font-weight: 900; color: var(--accent); letter-spacing: 2px;
}
.chat-empty p { font-size: 14px; }
.chat-empty.hidden { display: none; }

/* Chat message */
.chat-msg { display: flex; max-width: 80%; }
.chat-msg.user { align-self: flex-end; }
.chat-msg.assistant { align-self: flex-start; }
.chat-bubble {
  padding: 12px 16px; border-radius: var(--radius);
  font-size: 13px; line-height: 1.6;
}
.chat-msg.user .chat-bubble {
  background: var(--accent); color: #fff; border-bottom-right-radius: 4px;
}
.chat-msg.assistant .chat-bubble {
  background: var(--bg-2); border: 1px solid var(--border); border-bottom-left-radius: 4px;
}

/* User attached image thumbnail */
.chat-user-image {
  margin-bottom: 8px;
  border-radius: 8px;
  overflow: hidden;
  max-width: 160px;
}
.chat-user-image img {
  width: 100%; display: block; border-radius: 8px;
  background: repeating-conic-gradient(#1a1a1f 0% 25%, #232329 0% 50%) 0 0 / 12px 12px;
}

/* Drag & drop highlight */
.prompt-bar.drag-over {
  background: rgba(99,102,241,.08);
  border-color: var(--accent);
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
}

.chat-image-card {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; max-width: 420px;
}
.chat-image-card img {
  width: 100%; aspect-ratio: 1; display: block; cursor: pointer;
  background: repeating-conic-gradient(#1a1a1f 0% 25%, #232329 0% 50%) 0 0 / 16px 16px;
  object-fit: contain;
}
.chat-image-deleted {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 40px 20px; aspect-ratio: 1;
  background: var(--bg-3); color: var(--text-dim);
  font-size: 12px; text-align: center;
}
.chat-image-deleted svg { opacity: .5; }
.chat-image-meta {
  padding: 10px 14px; display: flex; flex-direction: column; gap: 6px;
}
.chat-image-info {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 4px;
  font-size: 11px; font-weight: 600; font-family: var(--font-mono);
}
.badge-cost { background: rgba(34,197,94,.12); color: var(--green); }
.badge-cost-estimate { background: rgba(245,158,11,.12); color: var(--orange); cursor: help; }
.badge-model { background: rgba(99,102,241,.12); color: var(--accent-hover); }
.badge-quality-low { background: rgba(34,197,94,.12); color: var(--green); }
.badge-quality-medium { background: rgba(59,130,246,.12); color: var(--blue); }
.badge-quality-high { background: rgba(168,85,247,.12); color: var(--purple); }

.chat-image-actions { display: flex; gap: 6px; }
.chat-image-actions button {
  background: var(--bg-3); border: 1px solid var(--border);
  color: var(--text-muted); font-family: var(--font); font-size: 11px;
  padding: 4px 10px; border-radius: var(--radius-sm);
  cursor: pointer; transition: all .15s;
}
.chat-image-actions button:hover { color: var(--text); border-color: var(--border-hover); }

/* ===== Prompt bar ===== */
.prompt-bar {
  padding: 12px 24px 20px; background: var(--bg-1);
  border-top: 1px solid var(--border);
}
.prompt-options {
  display: flex; align-items: center; gap: 12px; margin-bottom: 10px;
}
.size-selector {
  display: flex; gap: 2px; background: var(--bg-2);
  border-radius: var(--radius-sm); padding: 2px;
}
.size-btn {
  background: none; border: none; color: var(--text-muted);
  font-family: var(--font); font-size: 11px; font-weight: 600;
  padding: 4px 10px; border-radius: 4px;
  cursor: pointer; transition: all .15s;
}
.size-btn.active { background: var(--bg-3); color: var(--text); }
.size-btn:hover { color: var(--text); }

.toggle-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-muted); cursor: pointer;
}
.toggle-label input[type="checkbox"] {
  appearance: none; width: 32px; height: 18px;
  background: var(--bg-3); border-radius: 9px;
  position: relative; cursor: pointer; transition: background .15s;
}
.toggle-label input[type="checkbox"]::after {
  content: ''; position: absolute; top: 2px; left: 2px;
  width: 14px; height: 14px; background: var(--text-muted);
  border-radius: 50%; transition: all .15s;
}
.toggle-label input[type="checkbox"]:checked { background: var(--accent); }
.toggle-label input[type="checkbox"]:checked::after { left: 16px; background: #fff; }

.prompt-input-row {
  display: flex; align-items: flex-end; gap: 8px;
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 8px 10px;
  transition: border-color .15s;
}
.prompt-input-row:focus-within { border-color: var(--accent); }

.btn-upload {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  color: var(--text-muted); cursor: pointer; transition: all .15s;
  flex-shrink: 0;
}
.btn-upload:hover { color: var(--text); background: var(--bg-3); }

.upload-preview {
  position: relative; width: 48px; height: 48px; flex-shrink: 0;
  border-radius: var(--radius-sm); overflow: hidden;
}
.upload-preview.hidden { display: none; }
.upload-preview img { width: 100%; height: 100%; object-fit: cover; }
.btn-remove-upload {
  position: absolute; top: -2px; right: -2px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--red); border: none; color: #fff;
  font-size: 12px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

#prompt-input {
  flex: 1; background: none; border: none; color: var(--text);
  font-family: var(--font); font-size: 14px; line-height: 1.5;
  resize: none; outline: none; max-height: 120px; min-height: 36px;
  padding: 6px 0;
}
#prompt-input::placeholder { color: var(--text-dim); }

.btn-generate {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--accent); border: none; color: #fff;
  font-family: var(--font); font-size: 13px; font-weight: 600;
  padding: 8px 20px; border-radius: var(--radius-sm);
  cursor: pointer; transition: background .15s; flex-shrink: 0; height: 36px;
}
.btn-generate:hover { background: var(--accent-hover); }
.btn-generate:disabled { opacity: .5; cursor: not-allowed; }

.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.3); border-top-color: #fff;
  border-radius: 50%; animation: spin .6s linear infinite;
}
.spinner.hidden { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Gallery ===== */
#page-gallery { flex-direction: column; overflow-y: auto; overflow-x: hidden; }
.gallery-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
  background: var(--bg-0);
}
.gallery-header h2 { font-size: 18px; font-weight: 700; }
.gallery-filters { display: flex; gap: 8px; }
.gallery-filters select, .gallery-filters input {
  background: var(--bg-2); border: 1px solid var(--border); color: var(--text);
  font-family: var(--font); font-size: 12px; padding: 6px 10px;
  border-radius: var(--radius-sm);
}

/* Masonry layout — horizontal order, each card matches its image's natural height */
.gallery-grid {
  padding: 20px 24px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  grid-auto-rows: 10px;
  gap: 14px;
  align-items: start;
}
.gallery-item {
  border-radius: var(--radius); overflow: hidden;
  background: var(--bg-2); border: 1px solid var(--border);
  cursor: pointer; transition: all .15s; position: relative;
}
.gallery-item:hover { border-color: var(--border-hover); transform: translateY(-2px); }
.gallery-item img {
  width: 100%; height: auto; display: block;
  background: repeating-conic-gradient(#1a1a1f 0% 25%, #232329 0% 50%) 0 0 / 16px 16px;
}
.gallery-item-info {
  padding: 10px 12px;
  display: flex; flex-direction: column; gap: 6px;
  background: var(--bg-2); border-top: 1px solid var(--border);
}
.gallery-item-badges {
  display: flex; gap: 4px; flex-wrap: wrap;
}
.gallery-item-badges .badge {
  font-size: 10px; padding: 2px 6px; white-space: nowrap;
}
.gallery-item-date {
  font-size: 10px; color: var(--text-dim); font-family: var(--font-mono);
}
.gallery-item-cost {
  font-family: var(--font-mono); color: var(--green); font-weight: 600;
}
.gallery-item-actions {
  position: absolute; top: 6px; right: 6px;
  display: none; gap: 4px;
}
.gallery-item:hover .gallery-item-actions { display: flex; }
.gallery-item-actions button {
  width: 28px; height: 28px; border-radius: 6px;
  background: rgba(0,0,0,.7); border: 1px solid rgba(255,255,255,.1);
  color: #fff; cursor: pointer; font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
}
.gallery-item-actions button:hover { background: rgba(239,68,68,.8); }

/* ===== Stats ===== */
#page-stats { flex-direction: column; overflow-y: auto; padding: 24px; gap: 24px; }
.stats-header-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.stat-card {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px;
}
.stat-card-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px; }
.stat-card-value { font-size: 24px; font-weight: 700; font-family: var(--font-mono); }

.stats-month-selector {
  display: flex; align-items: center; gap: 12px; justify-content: center;
}
.stats-month-selector span { font-size: 15px; font-weight: 600; min-width: 120px; text-align: center; }
.stats-charts { display: flex; flex-direction: column; gap: 16px; }
.stats-pies { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.chart-card {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
}
.chart-card h3 { font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 16px; }
.stats-comparison {
  background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 20px;
  font-size: 13px; color: var(--text-muted);
}

/* ===== Settings ===== */
#page-settings { flex-direction: column; overflow-y: auto; }
.settings-container { max-width: 640px; margin: 0 auto; padding: 24px; width: 100%; }
.settings-section { margin-bottom: 32px; }
.settings-section h2 {
  font-size: 15px; font-weight: 700; margin-bottom: 16px;
  padding-bottom: 8px; border-bottom: 1px solid var(--border);
}
.setting-row {
  display: flex; align-items: center; gap: 12px; margin-bottom: 12px;
}
.setting-row label { min-width: 140px; font-size: 13px; color: var(--text-muted); }
.setting-row input, .setting-row select {
  flex: 1; background: var(--bg-2); border: 1px solid var(--border);
  color: var(--text); font-family: var(--font); font-size: 13px;
  padding: 8px 12px; border-radius: var(--radius-sm);
  outline: none; transition: border-color .15s;
}
.setting-row input:focus, .setting-row select:focus { border-color: var(--accent); }
.setting-row input[type="color"] { width: 48px; height: 36px; padding: 2px; cursor: pointer; }

.input-with-toggle { flex: 1; display: flex; gap: 6px; }
.input-with-toggle input { flex: 1; }
.btn-toggle-vis {
  background: var(--bg-3); border: 1px solid var(--border);
  color: var(--text-muted); font-family: var(--font); font-size: 11px;
  padding: 6px 10px; border-radius: var(--radius-sm);
  cursor: pointer; white-space: nowrap;
}

#presets-manager { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.preset-manager-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; background: var(--bg-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.preset-manager-item .pm-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.preset-manager-item .pm-name { flex: 1; font-size: 13px; font-weight: 500; }
.preset-manager-item .pm-provider { font-size: 11px; color: var(--text-dim); text-transform: uppercase; }
.preset-manager-item button {
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; font-size: 13px; padding: 2px 6px; border-radius: 4px;
}
.preset-manager-item button:hover { color: var(--red); background: rgba(239,68,68,.1); }

/* ===== Buttons ===== */
.btn-icon {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-2); border: 1px solid var(--border);
  color: var(--text-muted); font-size: 16px;
  border-radius: var(--radius-sm); cursor: pointer; transition: all .15s;
}
.btn-icon:hover { color: var(--text); border-color: var(--border-hover); }

.btn-primary {
  background: var(--accent); border: none; color: #fff;
  font-family: var(--font); font-size: 13px; font-weight: 600;
  padding: 10px 20px; border-radius: var(--radius-sm);
  cursor: pointer; transition: background .15s;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg-3); border: 1px solid var(--border); color: var(--text);
  font-family: var(--font); font-size: 13px; padding: 10px 20px;
  border-radius: var(--radius-sm); cursor: pointer;
}

.btn-danger {
  background: var(--red); border: none; color: #fff;
  font-family: var(--font); font-size: 13px; font-weight: 600;
  padding: 10px 20px; border-radius: var(--radius-sm);
  cursor: pointer; transition: background .15s;
}
.btn-danger:hover { background: #dc2626; }

.btn-sm {
  background: var(--bg-2); border: 1px solid var(--border);
  color: var(--text-muted); font-family: var(--font); font-size: 12px;
  padding: 4px 12px; border-radius: var(--radius-sm); cursor: pointer;
}
.btn-sm:hover { color: var(--text); border-color: var(--border-hover); }

.save-feedback { font-size: 13px; color: var(--green); margin-left: 12px; }
.save-feedback.hidden { opacity: 0; }

/* ===== Lightbox ===== */
.lightbox {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
}
.lightbox.hidden { display: none; }
.lightbox-overlay { position: absolute; inset: 0; background: rgba(0,0,0,.85); }
.lightbox-content { position: relative; max-width: 90vw; max-height: 90vh; }
.lightbox-content img {
  max-width: 100%; max-height: 80vh; border-radius: var(--radius); display: block;
  background: repeating-conic-gradient(#1a1a1f 0% 25%, #232329 0% 50%) 0 0 / 16px 16px;
}
.lightbox-meta { margin-top: 12px; text-align: center; font-size: 12px; color: var(--text-muted); }
.lightbox-close {
  position: absolute; top: -12px; right: -12px;
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--bg-3); border: 1px solid var(--border);
  color: var(--text); font-size: 18px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}

/* ===== Modal ===== */
.modal {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
}
.modal.hidden { display: none; }
.modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,.7); }
.modal-content {
  position: relative; background: var(--bg-1);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 24px; width: 400px; max-width: 90vw;
}
.modal-sm { width: 340px; }
.modal-content h3 { font-size: 16px; font-weight: 700; margin-bottom: 16px; }
.modal-content p { font-size: 13px; color: var(--text-muted); margin-bottom: 20px; line-height: 1.5; }
.modal-body { margin-bottom: 20px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ===== Hamburger menu ===== */
.hamburger {
  display: none; background: none; border: none; cursor: pointer;
  width: 32px; height: 32px; flex-direction: column; justify-content: center;
  align-items: center; gap: 5px; padding: 4px; flex-shrink: 0;
}
.hamburger span {
  display: block; width: 20px; height: 2px; background: var(--text-muted);
  border-radius: 1px; transition: all .2s;
}
.hamburger:hover span { background: var(--text); }

/* ===== Sidebar overlay (mobile) ===== */
.sidebar-overlay {
  display: none; position: fixed; inset: 0; top: 52px;
  background: rgba(0,0,0,.6); z-index: 49;
}

/* ===== Utility ===== */
.hidden { display: none !important; }

/* Chat loading fade — hides messages while images load */
.chat-loading-fade > .chat-msg { opacity: 0; }
.chat-area:not(.chat-loading-fade) > .chat-msg {
  opacity: 1; animation: chatReveal .3s ease;
}
@keyframes chatReveal {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Skeleton placeholder while loading conversation */
.chat-skeleton {
  flex: 1; display: flex; align-items: center; justify-content: center;
  color: var(--text-dim); font-size: 13px; gap: 8px;
}
.chat-skeleton .spinner { border-color: var(--border); border-top-color: var(--accent); }

.chat-loading {
  display: flex; align-items: center; gap: 8px;
  padding: 16px; color: var(--text-muted); font-size: 13px;
}
.chat-loading .spinner { border-color: var(--border); border-top-color: var(--accent); }

.chat-error {
  background: rgba(239,68,68,.08); border: 1px solid rgba(239,68,68,.2);
  color: var(--red); padding: 10px 14px; border-radius: var(--radius);
  font-size: 13px; max-width: 80%; align-self: flex-start;
}

/* ===== Responsive — Tablet ===== */
@media (max-width: 1024px) {
  .stats-header-cards { grid-template-columns: repeat(2, 1fr); }
  .stats-pies { grid-template-columns: 1fr; }
  .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .chat-image-card { max-width: 360px; }
}

/* ===== Responsive — Mobile ===== */
@media (max-width: 768px) {
  /* Hamburger visible */
  .hamburger { display: flex; }

  /* Top bar */
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar-left { gap: 12px; }
  .logo { font-size: 14px; letter-spacing: 2px; }
  .nav-btn { padding: 6px 8px; font-size: 12px; }
  .spending-bar { gap: 8px; font-size: 11px; }

  /* Sidebar: off-canvas */
  .sidebar {
    position: fixed; left: -280px; top: 52px; bottom: 0;
    width: 280px; min-width: 280px; z-index: 50;
    transition: left .25s ease;
  }
  .sidebar.open { left: 0; }
  .sidebar-overlay { display: block; }
  .sidebar-overlay.hidden { display: none; }

  /* Studio main full width */
  .studio-main { width: 100%; }

  /* Chat */
  .chat-area { padding: 16px 12px; }
  .chat-msg { max-width: 95%; }
  .chat-image-card { max-width: 100%; }

  /* Prompt bar */
  .prompt-bar { padding: 8px 12px 14px; }
  .prompt-options { flex-wrap: wrap; gap: 8px; }
  .preset-picker-btn { font-size: 11px; padding: 4px 8px; }
  .preset-dropdown { width: 280px; }

  /* Gallery */
  .gallery-header { padding: 14px 12px; flex-direction: column; gap: 10px; align-items: flex-start; }
  .gallery-grid { padding: 12px; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }

  /* Stats */
  #page-stats { padding: 16px 12px; }
  .stats-header-cards { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat-card { padding: 12px; }
  .stat-card-value { font-size: 18px; }
  .stats-pies { grid-template-columns: 1fr; }

  /* Settings */
  .settings-container { padding: 16px 12px; }
  .setting-row { flex-direction: column; align-items: stretch; gap: 6px; }
  .setting-row label { min-width: auto; }
  .modal-content { width: 95vw; padding: 16px; }
}

/* ===== Responsive — Small phone ===== */
@media (max-width: 480px) {
  .topbar-left { width: 100%; }
  .topbar-right { display: none; }
  .topbar { height: auto; padding: 8px 10px; }
  .page { top: 44px; }
  .sidebar { top: 44px; }
  .budget-alert { top: 44px; }

  .nav { gap: 0; }
  .nav-btn { padding: 4px 6px; font-size: 11px; }

  .gallery-grid { grid-template-columns: repeat(2, 1fr); }
  .stats-header-cards { grid-template-columns: 1fr; }

  .prompt-options { gap: 6px; }
  .size-btn { padding: 3px 6px; font-size: 10px; }
  .toggle-label { font-size: 11px; }
  .toggle-label span { display: none; }

  .preset-dropdown { width: calc(100vw - 24px); left: -12px; }
}
