@import url('https://fonts.googleapis.com/css2?family=DM+Mono:ital,wght@0,300;0,400;0,500;1,300&family=Syne:wght@400;500;600;700;800&display=swap');

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

:root {
  --bg: #0a0a0f;
  --panel-bg: #0f0f17;
  --surface: #16161f;
  --surface2: #1e1e2a;
  --border: #2a2a3a;
  --accent: #7c6ef7;
  --accent2: #e85d8a;
  --accent3: #4ecdc4;
  --text: #e8e8f0;
  --muted: #6b6b80;
  --success: #4ecdc4;
  --warning: #f7c948;
  --sidebar-w: 72px;
  --sidebar-w-exp: 200px;
  --drawer-w: 300px;
  --t-fast: 0.15s;
  --t-normal: 0.25s;
  --ease-out: cubic-bezier(0.4, 0, 0.2, 1);
}

html, body { height: 100%; overflow: hidden; }

body {
  font-family: 'DM Mono', monospace;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-bg);
  flex-shrink: 0; z-index: 10;
}

.logo {
  font-family: 'Syne', sans-serif; font-weight: 800; font-size: 20px;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.logo span { font-weight: 400; opacity: 0.5; -webkit-text-fill-color: var(--muted); font-size: 13px; margin-left: 8px; font-family: 'DM Mono', monospace; }

.header-right {
  display: flex; align-items: center; gap: 12px;
  font-family: 'DM Mono', monospace; font-size: 12px;
}
.credits-pill {
  display: inline-flex; align-items: center;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: rgba(255,255,255,0.04);
  color: var(--fg, #e7e7ea);
  letter-spacing: 0.2px;
  white-space: nowrap;
}
.credits-pill.low { border-color: #c5523f; color: #ffb1a4; background: rgba(197,82,63,0.12); }
.credits-pill.admin { border-color: var(--accent); color: var(--accent); background: rgba(0,0,0,0); }
.user-email { color: var(--muted); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.signout-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  font: inherit;
}
.signout-btn:hover { color: var(--fg, #e7e7ea); border-color: var(--accent); }

@media (max-width: 640px) {
  .user-email { display: none; }
  .header-right { gap: 8px; }
}


/* ── Main Layout ─────────────────────────────────────────────────────────── */
.main { display: flex; flex: 1; overflow: hidden; }

/* ── Image Sidebar ───────────────────────────────────────────────────────── */
.image-sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  display: flex; flex-direction: column;
  background: var(--bg); border-right: 1px solid var(--border);
  overflow: hidden;
  transition: width var(--t-normal) var(--ease-out);
  z-index: 5;
}
.image-sidebar:hover { width: var(--sidebar-w-exp); }

.sidebar-header {
  padding: 10px 0 8px; display: flex; flex-direction: column; align-items: center; gap: 8px;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}

.sidebar-title {
  font-size: 9px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted);
  white-space: nowrap; overflow: hidden;
}
.sidebar-add-btn {
  width: 48px; height: 48px; border-radius: 10px;
  border: 2px dashed var(--border); background: var(--panel-bg);
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 22px; color: var(--muted);
  transition: all var(--t-fast);
}
.sidebar-add-btn:hover { border-color: var(--accent); color: var(--accent); background: rgba(124,110,247,0.05); }

.sidebar-list {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: 8px 0; display: flex; flex-direction: column; align-items: center; gap: 8px;
  scrollbar-width: thin; scrollbar-color: var(--border) transparent;
}
.sidebar-list::-webkit-scrollbar { width: 3px; }
.sidebar-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.sidebar-item {
  width: calc(100% - 16px); position: relative; cursor: pointer;
  transition: all var(--t-fast); padding: 4px; border-radius: 10px;
}
.sidebar-item:hover { background: var(--surface); }

.sidebar-thumb {
  width: 100%; aspect-ratio: 1; border-radius: 8px;
  border: 2px solid var(--border); overflow: hidden;
  transition: border-color var(--t-fast), box-shadow 0.2s;
}
.sidebar-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; filter: brightness(0.85); transition: filter var(--t-fast); }
.sidebar-item:hover .sidebar-thumb img { filter: brightness(1); }
.sidebar-item.active .sidebar-thumb {
  border-color: var(--accent);
  box-shadow: 0 0 12px rgba(124,110,247,0.3);
}
.sidebar-item.active .sidebar-thumb img { filter: brightness(1); }
.sidebar-item.active::before {
  content: ''; position: absolute; left: 0; top: 4px; bottom: 4px; width: 3px;
  background: linear-gradient(180deg, var(--accent), var(--accent2));
  border-radius: 0 2px 2px 0;
}

.sidebar-label {
  font-size: 9px; color: var(--muted); text-align: center; margin-top: 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  opacity: 0; height: 0; transition: opacity 0.2s, height 0.2s;
}
.image-sidebar:hover .sidebar-label { opacity: 1; height: 14px; }

.sidebar-badge {
  position: absolute; top: 0; right: 0;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
  background: var(--accent2); color: #fff;
  font-size: 9px; font-weight: 500;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 6px rgba(232,93,138,0.3);
}

.sidebar-close {
  position: absolute; top: 0; left: 0;
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--muted); font-size: 10px; cursor: pointer;
  display: none; align-items: center; justify-content: center;
  line-height: 1;
}
.sidebar-item:hover .sidebar-close { display: flex; }
.sidebar-close:hover { color: var(--accent2); border-color: var(--accent2); }

/* Sidebar edit history items */
.sidebar-hist {
  width: calc(100% - 16px); position: relative; cursor: pointer;
  transition: all var(--t-fast); padding: 4px; border-radius: 10px;
}
.sidebar-hist:hover { background: var(--surface); }
.sidebar-hist-thumb {
  width: 100%; aspect-ratio: 1; border-radius: 8px;
  border: 2px solid var(--border); overflow: hidden;
  transition: border-color var(--t-fast), box-shadow 0.2s;
}
.sidebar-hist-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; filter: brightness(0.85); transition: filter var(--t-fast); }
.sidebar-hist:hover .sidebar-hist-thumb img { filter: brightness(1); }
.sidebar-hist.current .sidebar-hist-thumb { border-color: var(--accent); box-shadow: 0 0 12px rgba(124,110,247,0.3); }
.sidebar-hist.current .sidebar-hist-thumb img { filter: brightness(1); }
.sidebar-hist-label {
  font-size: 9px; color: var(--muted); text-align: center; margin-top: 3px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  opacity: 0; height: 0; transition: opacity 0.2s, height 0.2s;
}
.image-sidebar:hover .sidebar-hist-label { opacity: 1; height: 14px; }
.sidebar-empty { padding: 20px 8px; text-align: center; font-size: 10px; color: var(--muted); }

/* ── Chat Panel ──────────────────────────────────────────────────────────── */
.chat-panel {
  width: 380px; flex-shrink: 0;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border); background: var(--panel-bg);
}
.chat-header {
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 11px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 1.5px;
  display: flex; justify-content: space-between; align-items: center;
}
.chat-context-label {
  font-size: 10px; color: var(--accent); text-transform: none;
  letter-spacing: 0; max-width: 160px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.messages {
  flex: 1; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
  scroll-behavior: smooth;
}
.messages::-webkit-scrollbar { width: 4px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.messages.switching-out { animation: chatFadeOut 0.15s ease forwards; }
.messages.switching-in { animation: chatFadeIn 0.2s ease forwards; }
@keyframes chatFadeOut { to { opacity: 0; transform: translateY(-4px); } }
@keyframes chatFadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.msg { display: flex; gap: 10px; align-items: flex-start; animation: msgIn 0.25s ease; }
@keyframes msgIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

.msg-avatar {
  width: 28px; height: 28px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; flex-shrink: 0; margin-top: 2px;
}
.msg.agent .msg-avatar { background: linear-gradient(135deg, var(--accent), var(--accent2)); }
.msg.user .msg-avatar { background: var(--surface2); border: 1px solid var(--border); }
.msg.user { flex-direction: row-reverse; }
.msg.user .msg-bubble { background: var(--surface2); border-color: rgba(124,110,247,0.3); }

.tool-avatar {
  font-size: 11px !important;
}
.tool-avatar.call { background: rgba(124,110,247,0.15) !important; border: 1px solid rgba(124,110,247,0.3); }
.tool-avatar.result { background: rgba(78,205,196,0.1) !important; border: 1px solid rgba(78,205,196,0.3); }

.msg-bubble {
  max-width: 270px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 14px; font-size: 13px; line-height: 1.6; color: var(--text);
}

.tool-call {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--accent); border-radius: 8px;
  padding: 10px 14px; font-size: 11px; color: var(--muted);
  max-width: 310px;
}
.tool-call .tool-name {
  color: var(--accent); font-size: 11px; margin-bottom: 4px;
  display: flex; align-items: center; gap: 6px;
}
.tool-call .tool-name::before { content: '\26A1'; font-size: 10px; }
.tool-result { border-left-color: var(--success); }
.tool-result .tool-name { color: var(--success); }
.tool-result .tool-name::before { content: '\2713'; }

.typing { display: flex; gap: 4px; align-items: center; padding: 4px 0; }
.typing span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--muted); animation: blink 1.2s infinite;
}
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); } 40% { opacity: 1; transform: scale(1); } }

/* ── Chat Input ──────────────────────────────────────────────────────────── */
.chat-input-area {
  padding: 16px; border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 10px;
}
.input-row { display: flex; gap: 8px; align-items: flex-end; }
.upload-status { font-size: 11px; color: var(--muted); padding: 0 4px; min-height: 14px; }
.upload-status:empty { display: none; }

.chat-input {
  flex: 1; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 14px; color: var(--text);
  font-family: 'DM Mono', monospace; font-size: 13px;
  resize: none; min-height: 42px; max-height: 120px;
  outline: none; transition: border-color 0.2s; line-height: 1.5;
}
.chat-input:focus { border-color: var(--accent); }
.chat-input::placeholder { color: var(--muted); }

.send-btn {
  width: 42px; height: 42px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; transition: opacity 0.2s, transform var(--t-fast);
  flex-shrink: 0;
}
.send-btn:hover { opacity: 0.85; transform: scale(1.05); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.suggestions { display: flex; flex-wrap: wrap; gap: 6px; }
.suggestion {
  padding: 4px 10px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 20px;
  font-size: 11px; color: var(--muted); cursor: pointer;
  font-family: 'DM Mono', monospace; transition: all var(--t-fast);
  white-space: nowrap;
}
.suggestion:hover { border-color: var(--accent); color: var(--accent); }

.upload-area {
  margin: 0 0 8px; border: 2px dashed var(--border); border-radius: 12px;
  padding: 14px; text-align: center; cursor: pointer;
  transition: all 0.2s; background: var(--surface);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.upload-area:hover, .upload-area.dragging { border-color: var(--accent); background: rgba(124,110,247,0.05); }
.upload-area .upload-icon { font-size: 22px; }
.upload-area .upload-title { font-size: 12px; color: var(--text); font-family: 'Syne', sans-serif; font-weight: 600; }
.upload-area .upload-sub { font-size: 10px; color: var(--muted); }

/* ── Canvas Panel ────────────────────────────────────────────────────────── */
.canvas-panel {
  flex: 1; display: flex; flex-direction: column;
  background: var(--bg); overflow: hidden; position: relative;
}

.canvas-toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 20px; border-bottom: 1px solid var(--border);
  background: var(--panel-bg); flex-shrink: 0;
}
.toolbar-group {
  display: flex; align-items: center; gap: 4px;
  padding: 0 8px; border-right: 1px solid var(--border);
}
.toolbar-group:last-child { border-right: none; margin-left: auto; }

.tool-btn {
  padding: 6px 10px; border-radius: 7px;
  background: transparent; border: 1px solid transparent;
  color: var(--muted); cursor: pointer; font-size: 12px;
  font-family: 'DM Mono', monospace;
  display: flex; align-items: center; gap: 5px;
  transition: all var(--t-fast);
}
.tool-btn:hover { background: var(--surface); color: var(--text); border-color: var(--border); }
.tool-btn.active { background: var(--surface2); color: var(--accent); border-color: rgba(124,110,247,0.4); }
.tool-btn .icon { font-size: 14px; }

.download-btn {
  padding: 7px 14px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none; color: white; cursor: pointer; font-size: 12px;
  font-family: 'DM Mono', monospace;
  display: flex; align-items: center; gap: 6px;
  transition: opacity var(--t-fast);
}
.download-btn:hover { opacity: 0.85; }
.download-btn:disabled { opacity: 0.3; cursor: not-allowed; }

#imageDimensions { font-size: 11px; color: var(--muted); }

/* ── Canvas Area ─────────────────────────────────────────────────────────── */
.canvas-area {
  flex: 1; display: flex; align-items: center; justify-content: center;
  position: relative; overflow: hidden;
  background:
    radial-gradient(ellipse at 20% 80%, rgba(124,110,247,0.04) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(232,93,138,0.04) 0%, transparent 60%),
    repeating-linear-gradient(0deg, transparent, transparent 39px, rgba(255,255,255,0.02) 39px, rgba(255,255,255,0.02) 40px),
    repeating-linear-gradient(90deg, transparent, transparent 39px, rgba(255,255,255,0.02) 39px, rgba(255,255,255,0.02) 40px);
}

.drop-zone {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; color: var(--muted); text-align: center; padding: 40px;
}
.drop-zone .drop-icon {
  width: 80px; height: 80px; border-radius: 20px;
  border: 2px dashed var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 32px; background: var(--surface); transition: all 0.2s;
}
.drop-zone.dragging .drop-icon { border-color: var(--accent); background: rgba(124,110,247,0.05); transform: scale(1.05); }
.drop-zone h3 { font-family: 'Syne', sans-serif; font-size: 18px; color: var(--text); font-weight: 600; }
.drop-zone p { font-size: 12px; max-width: 280px; line-height: 1.6; }
.drop-zone .upload-trigger {
  padding: 10px 20px; border-radius: 8px; background: var(--surface2);
  border: 1px solid var(--border); color: var(--text); cursor: pointer;
  font-family: 'DM Mono', monospace; font-size: 13px; transition: all var(--t-fast);
}
.drop-zone .upload-trigger:hover { border-color: var(--accent); color: var(--accent); }

/* ── Image Grid View ─────────────────────────────────────────────────────── */
.image-grid-view {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  background: var(--bg); z-index: 2;
  overflow: hidden;
}
.grid-toolbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  background: var(--panel-bg); flex-shrink: 0;
}
.grid-count { font-size: 11px; color: var(--muted); flex: 1; }

.grid-container {
  flex: 1; overflow-y: auto; padding: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px; align-content: start;
}
.grid-container::-webkit-scrollbar { width: 4px; }
.grid-container::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.grid-card {
  position: relative; border-radius: 10px;
  border: 2px solid var(--border); overflow: hidden;
  cursor: pointer; transition: all var(--t-fast);
  background: var(--surface);
}
.grid-card:hover { border-color: rgba(124,110,247,0.4); transform: translateY(-2px); box-shadow: 0 4px 16px rgba(0,0,0,0.3); }
.grid-card.selected { border-color: var(--accent); box-shadow: 0 0 12px rgba(124,110,247,0.3); }

.grid-card-img {
  width: 100%; aspect-ratio: 4/3; object-fit: cover; display: block;
  filter: brightness(0.9); transition: filter var(--t-fast);
}
.grid-card:hover .grid-card-img { filter: brightness(1); }

.grid-card-info {
  padding: 6px 8px; display: flex; align-items: center; gap: 6px;
}
.grid-card-name {
  flex: 1; font-size: 10px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.grid-card-check {
  width: 18px; height: 18px; border-radius: 4px;
  border: 2px solid var(--border); background: transparent;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all var(--t-fast); flex-shrink: 0;
  font-size: 11px; color: transparent;
}
.grid-card-check:hover { border-color: var(--accent); }
.grid-card-check.checked { border-color: var(--accent); background: var(--accent); color: #fff; }

.grid-card-remove {
  position: absolute; top: 4px; right: 4px;
  width: 20px; height: 20px; border-radius: 4px;
  background: rgba(0,0,0,0.6); border: none;
  color: var(--muted); cursor: pointer; font-size: 12px;
  display: none; align-items: center; justify-content: center;
  transition: all var(--t-fast);
}
.grid-card:hover .grid-card-remove { display: flex; }
.grid-card-remove:hover { color: var(--accent2); background: rgba(0,0,0,0.8); }

.grid-card-progress {
  position: absolute; inset: 0;
  background: rgba(10,10,15,0.7); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: var(--muted);
}
.grid-card-progress .mini-spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
.grid-card-progress.done { display: none; }

.grid-verify-badge {
  position: absolute; top: 4px; left: 4px;
  min-width: 20px; height: 20px; padding: 0 4px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: bold; line-height: 1;
  background: rgba(10,10,15,0.85); border: 1px solid var(--border);
  cursor: help; user-select: none;
}
.grid-verify-badge.ok { color: #6dd96d; border-color: rgba(109,217,109,0.5); }
.grid-verify-badge.warn { color: #f0c660; border-color: rgba(240,198,96,0.5); }
.grid-verify-badge.fail { color: var(--accent2); border-color: rgba(255,80,80,0.5); }
.grid-verify-badge.unknown { color: var(--muted); border-color: var(--border); }

/* ── Lightbox Overlay ──────────────────────────────────────────────────────── */
.lightbox-overlay {
  position: absolute; inset: 0;
  background: rgba(10, 10, 15, 0.92);
  display: none;
  align-items: center; justify-content: center;
  z-index: 10;
}
.lightbox-overlay.active { display: flex; animation: lightboxFadeIn 0.2s ease; }

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

.lightbox-content {
  display: flex; flex-direction: column; align-items: center;
  gap: 12px; max-width: 85%; max-height: 85%;
}
.lightbox-img {
  max-width: 100%; max-height: calc(100vh - 160px);
  object-fit: contain; border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,255,255,0.05);
  transition: opacity var(--t-fast) ease;
}
.lightbox-img.transitioning { opacity: 0.3; }

.lightbox-info {
  display: flex; align-items: center; gap: 12px;
  font-family: 'DM Mono', monospace; font-size: 12px; color: var(--muted);
}
.lightbox-title {
  max-width: 300px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.lightbox-counter { opacity: 0.6; }

.lightbox-close {
  position: absolute; top: 16px; right: 16px;
  width: 36px; height: 36px; border-radius: 8px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; z-index: 1;
  transition: all var(--t-fast);
}
.lightbox-close:hover { color: var(--text); border-color: var(--accent2); }

.lightbox-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 40px; height: 64px; border-radius: 8px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; z-index: 1;
  transition: all var(--t-fast);
}
.lightbox-nav:hover { color: var(--text); background: var(--surface2); border-color: rgba(124,110,247,0.4); }
.lightbox-prev { left: 16px; }
.lightbox-next { right: 16px; }

#mainCanvas {
  max-width: 100%; max-height: 100%; border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5), 0 0 0 1px rgba(255,255,255,0.05);
  display: none; image-rendering: auto;
}

/* Canvas transition animations */
.canvas-exit { animation: canvasExit 0.18s ease forwards; }
.canvas-enter { animation: canvasEnter 0.25s ease forwards; }
@keyframes canvasExit { from { opacity: 1; transform: scale(1); } to { opacity: 0; transform: scale(0.97); filter: blur(2px); } }
@keyframes canvasEnter { from { opacity: 0; transform: scale(1.02); filter: blur(2px); } to { opacity: 1; transform: scale(1); filter: blur(0); } }

/* ── Processing Overlay ──────────────────────────────────────────────────── */
.processing-overlay {
  position: absolute; inset: 0;
  background: rgba(10,10,15,0.7);
  display: none; align-items: center; justify-content: center;
  flex-direction: column; gap: 16px;
  backdrop-filter: blur(4px); z-index: 5;
}
.processing-overlay.active { display: flex; }
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.processing-label { font-size: 13px; color: var(--muted); }

/* ── Settings Drawer ─────────────────────────────────────────────────────── */
.settings-drawer {
  position: absolute; top: 0; right: 0; bottom: 0;
  width: var(--drawer-w); background: var(--panel-bg);
  border-left: 1px solid var(--border); z-index: 8;
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform var(--t-normal) var(--ease-out);
  box-shadow: -8px 0 32px rgba(0,0,0,0.4);
}
.settings-drawer.open { transform: translateX(0); }

.settings-drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.settings-drawer-title {
  font-family: 'Syne', sans-serif; font-weight: 600; font-size: 14px;
  color: var(--text); letter-spacing: -0.3px;
}
.settings-close {
  width: 28px; height: 28px; border-radius: 6px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--muted); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; transition: all var(--t-fast);
}
.settings-close:hover { color: var(--text); border-color: var(--accent2); }

.settings-content {
  flex: 1; overflow-y: auto; padding: 16px 20px;
  display: flex; flex-direction: column; gap: 20px;
}

.settings-section { display: flex; flex-direction: column; gap: 10px; }
.settings-section-title {
  font-size: 10px; color: var(--muted); text-transform: uppercase;
  letter-spacing: 1.5px; padding-bottom: 6px;
  border-bottom: 1px solid rgba(42,42,58,0.5);
}

.settings-label { font-size: 11px; color: var(--text); }

.settings-radio-group {
  display: flex; background: var(--surface);
  border: 1px solid var(--border); border-radius: 6px; overflow: hidden;
}
.settings-format-opt,
.settings-model-opt {
  flex: 1; padding: 7px 0; text-align: center;
  font-family: 'DM Mono', monospace; font-size: 11px;
  color: var(--muted); cursor: pointer;
  border-right: 1px solid var(--border);
  transition: all var(--t-fast); background: transparent; border-top: none; border-bottom: none; border-left: none;
}
.settings-format-opt:last-child,
.settings-model-opt:last-child { border-right: none; }
.settings-format-opt:hover,
.settings-model-opt:hover { color: var(--text); background: var(--surface2); }
.settings-format-opt.selected,
.settings-model-opt.selected { background: rgba(124,110,247,0.15); color: var(--accent); box-shadow: inset 0 -2px 0 var(--accent); }

.settings-slider-row { display: flex; align-items: center; gap: 10px; }
.settings-slider {
  flex: 1; -webkit-appearance: none; height: 4px;
  background: var(--surface2); border-radius: 2px; outline: none;
}
.settings-slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); cursor: pointer;
  border: 2px solid var(--panel-bg);
  box-shadow: 0 0 6px rgba(124,110,247,0.4);
}
.settings-slider-val { font-size: 11px; color: var(--accent); min-width: 36px; text-align: right; }

.settings-select {
  width: 100%; padding: 8px 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  color: var(--text); font-family: 'DM Mono', monospace; font-size: 12px;
  outline: none; cursor: pointer;
  transition: border-color var(--t-fast);
}
.settings-select:focus { border-color: var(--accent); }

/* ── Project Strip (bottom) ──────────────────────────────────────────────── */
.project-strip {
  display: flex; align-items: center;
  padding: 8px 0; border-top: 1px solid var(--border);
  background: var(--panel-bg); flex-shrink: 0; height: 108px;
}
.strip-arrow {
  width: 28px; flex-shrink: 0; height: 72px;
  border: none; background: transparent; color: var(--muted);
  cursor: pointer; font-size: 22px; display: flex;
  align-items: center; justify-content: center;
  transition: all var(--t-fast);
}
.strip-arrow:hover:not(:disabled) { color: var(--text); background: var(--surface); }
.strip-arrow:disabled { opacity: 0.2; cursor: default; }

.strip-viewport { flex: 1; overflow: hidden; }
.strip-track {
  display: flex; gap: 10px; padding: 0 4px;
  transition: transform 0.3s var(--ease-out);
}

.project-card {
  width: 72px; flex-shrink: 0;
  display: flex; flex-direction: column; align-items: center;
  gap: 4px; cursor: pointer; border-radius: 10px; padding: 4px;
  transition: all var(--t-fast);
}
.project-card:hover { background: var(--surface); }

.project-card-thumb {
  width: 72px; height: 72px; border-radius: 8px;
  border: 2px solid var(--border); overflow: visible;
  transition: border-color var(--t-fast), box-shadow 0.2s;
  background: var(--surface); position: relative;
}

.project-card-delete {
  position: absolute; top: -6px; right: -6px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent2); border: 2px solid var(--bg);
  color: #fff; cursor: pointer; font-size: 11px; line-height: 1;
  display: none; align-items: center; justify-content: center;
  padding: 0; z-index: 2;
  transition: all var(--t-fast);
}
.project-card:hover .project-card-delete { display: flex; }
.project-card-delete:hover { background: #c0392b; transform: scale(1.15); }
.project-card-thumb img {
  width: 100%; height: 100%; object-fit: cover; display: block;
  filter: brightness(0.85); transition: filter var(--t-fast);
}
.project-card:hover .project-card-thumb img { filter: brightness(1); }

.project-card.active .project-card-thumb {
  border-color: var(--accent);
  box-shadow: 0 0 14px rgba(124,110,247,0.4);
}
.project-card.active .project-card-thumb img { filter: brightness(1); }

.project-card-name {
  font-size: 9px; color: var(--muted); text-align: center;
  max-width: 72px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.project-card.active .project-card-name { color: var(--accent); }

/* "+" Add New Project card */
.project-card.add-new .project-card-thumb {
  border-style: dashed; display: flex;
  align-items: center; justify-content: center;
}
.project-card.add-new .add-icon {
  font-size: 28px; color: var(--muted); transition: color var(--t-fast);
}
.project-card.add-new:hover .project-card-thumb { border-color: var(--accent); }
.project-card.add-new:hover .add-icon { color: var(--accent); }

#fileInput { display: none; }

/* ── Login Overlay ──────────────────────────────────────────────────────── */
.login-overlay {
  position: fixed; inset: 0; z-index: 1000;
  display: none; align-items: center; justify-content: center;
  background: var(--bg);
}
.login-card {
  display: flex; flex-direction: column; align-items: center; gap: 16px;
  padding: 40px 48px; background: var(--panel-bg);
  border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  min-width: 320px;
}
.login-logo {
  font-family: 'Syne', sans-serif; font-weight: 800; font-size: 28px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.login-sub { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
#loginForm { display: flex; flex-direction: column; gap: 12px; width: 100%; }
.login-input {
  width: 100%; padding: 12px 16px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px;
  color: var(--text); font-family: 'DM Mono', monospace; font-size: 14px;
  outline: none; transition: border-color 0.2s;
}
.login-input:focus { border-color: var(--accent); }
.login-error { font-size: 12px; color: var(--accent2); min-height: 16px; text-align: center; }
.login-btn {
  padding: 12px; border-radius: 10px; border: none;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white; font-family: 'DM Mono', monospace; font-size: 14px;
  cursor: pointer; transition: opacity 0.2s;
}
.login-btn:hover { opacity: 0.85; }

/* ══════════════════════════════════════════════════════════════════════════
   RESPONSIVE — Mobile Navigation Bar (hidden on desktop)
   ══════════════════════════════════════════════════════════════════════════ */
.mobile-nav { display: none; }
.sidebar-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.5); z-index: 99;
}
.sidebar-backdrop.active { display: block; }

/* ══════════════════════════════════════════════════════════════════════════
   RESPONSIVE — Tablet (768px – 1023px)
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 1023px) {
  .header { padding: 10px 16px; }
  .logo span { display: none; }

  .image-sidebar { width: 56px; }
  .image-sidebar:hover { width: 56px; }
  .sidebar-label, .sidebar-hist-label { display: none; }
  .image-sidebar:hover .sidebar-label,
  .image-sidebar:hover .sidebar-hist-label { opacity: 0; height: 0; }

  .chat-panel { width: 280px; }
  .msg-bubble { max-width: 220px; }
  .tool-call { max-width: 240px; }

  .suggestion:nth-child(n+5) { display: none; }

  .settings-drawer { width: 260px; }

  .project-strip { height: 92px; }
  .project-card { width: 60px; }
  .project-card-thumb { width: 60px; height: 60px; }
  .project-card-name { max-width: 60px; }
}

/* ══════════════════════════════════════════════════════════════════════════
   RESPONSIVE — Mobile (< 768px)
   ══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 767px) {
  /* ── Body & structure ────────────────────────────────────────── */
  body { padding-bottom: 56px; }

  /* ── Header ──────────────────────────────────────────────────── */
  .logo { font-size: 17px; }

  /* ── Main layout: stack ──────────────────────────────────────── */
  .main { flex-direction: column; position: relative; }

  /* ── Sidebar: off-screen drawer ──────────────────────────────── */
  .image-sidebar {
    position: fixed; top: 0; left: 0; bottom: 56px;
    width: 200px; z-index: 100;
    transform: translateX(-100%);
    transition: transform var(--t-normal) var(--ease-out);
  }
  .image-sidebar:hover { width: 200px; } /* neutralize tablet hover-lock */
  .image-sidebar.mobile-open { transform: translateX(0); }
  .image-sidebar.mobile-open .sidebar-label,
  .image-sidebar.mobile-open .sidebar-hist-label { opacity: 1; height: 14px; }

  /* ── Chat & Canvas: toggled panels ───────────────────────────── */
  .chat-panel {
    width: 100%; flex-shrink: 1; flex: 1;
    border-right: none; display: none;
  }
  .chat-panel.mobile-active { display: flex; }

  .canvas-panel { flex: 1; width: 100%; display: none; }
  .canvas-panel.mobile-active { display: flex; }

  /* ── Chat tweaks ─────────────────────────────────────────────── */
  .chat-header { padding: 12px 16px 10px; }
  .messages { padding: 12px; }
  .msg-bubble { max-width: calc(100vw - 100px); }
  .tool-call { max-width: calc(100vw - 80px); }
  .chat-input-area { padding: 12px; }
  .chat-input { font-size: 16px; } /* prevent iOS zoom */

  .suggestions {
    flex-wrap: nowrap; overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; padding-bottom: 4px;
  }
  .suggestions::-webkit-scrollbar { display: none; }
  .suggestion { flex-shrink: 0; padding: 8px 14px; font-size: 13px; }

  /* ── Lightbox: full-screen on mobile ─────────────────────────── */
  .lightbox-overlay { position: fixed; inset: 0; z-index: 95; }
  .lightbox-content { max-width: 95%; max-height: 80%; }
  .lightbox-nav { width: 36px; height: 52px; min-height: 44px; }
  .lightbox-prev { left: 8px; }
  .lightbox-next { right: 8px; }
  .lightbox-close { top: 12px; right: 12px; width: 44px; height: 44px; }

  /* ── Touch-friendly tap targets (min 44px) ───────────────────── */
  .tool-btn { padding: 10px 14px; font-size: 13px; min-height: 44px; }
  .send-btn { width: 48px; height: 48px; }
  .strip-arrow { width: 36px; min-height: 44px; }
  .settings-close { width: 36px; height: 36px; font-size: 18px; }
  .download-btn { padding: 10px 16px; min-height: 44px; }
  .upload-trigger { padding: 14px 24px; font-size: 15px; min-height: 44px; }
  .settings-format-opt,
  .settings-model-opt { padding: 12px 0; min-height: 44px; }
  .settings-select { padding: 12px 14px; min-height: 44px; }

  /* ── Always-visible controls (no hover on touch) ─────────────── */
  .sidebar-close { width: 24px; height: 24px; display: flex; }
  .grid-card-remove { display: flex; }
  .project-card-delete { display: flex; }

  /* ── Canvas toolbar: compact ─────────────────────────────────── */
  .canvas-toolbar { padding: 8px 12px; flex-wrap: wrap; gap: 4px; }
  .toolbar-group { padding: 0 4px; }
  #imageDimensions { font-size: 10px; }

  /* ── Settings drawer: full-width bottom sheet ────────────────── */
  .settings-drawer {
    position: fixed; top: auto; right: 0; bottom: 56px; left: 0;
    width: 100%; max-height: 70vh;
    border-left: none; border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
    transition: transform var(--t-normal) var(--ease-out);
    z-index: 90;
  }
  .settings-drawer.open { transform: translateY(0); }

  /* ── Drop zone: compact ──────────────────────────────────────── */
  .drop-zone { padding: 24px 16px; gap: 12px; }
  .drop-zone .drop-icon { width: 64px; height: 64px; font-size: 26px; }
  .drop-zone h3 { font-size: 16px; }
  .drop-zone p { font-size: 11px; }

  /* ── Project strip: smaller + native swipe scroll ────────────── */
  .project-strip { height: 84px; padding: 6px 0; }
  .project-card { width: 56px; }
  .project-card-thumb { width: 56px; height: 56px; }
  .project-card-name { max-width: 56px; font-size: 8px; }
  .strip-viewport { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .strip-track { transition: none; }
  .strip-arrow { display: none; }

  /* ── Image grid: 2-col on small screens ──────────────────────── */
  .grid-container {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    padding: 12px; gap: 10px;
  }

  /* ── Login card: responsive ──────────────────────────────────── */
  .login-card {
    min-width: auto; width: calc(100vw - 32px);
    max-width: 360px; padding: 32px 24px;
  }

  /* ── Mobile nav bar ──────────────────────────────────────────── */
  .mobile-nav {
    display: flex; position: fixed;
    bottom: 0; left: 0; right: 0;
    height: 56px; background: var(--panel-bg);
    border-top: 1px solid var(--border);
    z-index: 50; align-items: center;
    justify-content: space-around; padding: 0 8px;
  }
  .mobile-nav-btn {
    flex: 1; display: flex; flex-direction: column;
    align-items: center; justify-content: center; gap: 2px;
    padding: 8px 4px; background: none; border: none;
    color: var(--muted); font-family: 'DM Mono', monospace;
    font-size: 10px; cursor: pointer;
    transition: color var(--t-fast); min-height: 44px;
  }
  .mobile-nav-btn .nav-icon { font-size: 18px; }
  .mobile-nav-btn.active { color: var(--accent); }
  .mobile-nav-btn:hover { color: var(--text); }

  /* ── iOS safe area ───────────────────────────────────────────── */
  @supports (padding-bottom: env(safe-area-inset-bottom)) {
    .mobile-nav {
      padding-bottom: env(safe-area-inset-bottom);
      height: calc(56px + env(safe-area-inset-bottom));
    }
    body { padding-bottom: calc(56px + env(safe-area-inset-bottom)); }
    .image-sidebar { bottom: calc(56px + env(safe-area-inset-bottom)); }
    .settings-drawer { bottom: calc(56px + env(safe-area-inset-bottom)); }
  }
}
