/* Generator — Canvas-Centric Layout */
:root {
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #f1f5f9;
  --green: #22c55e;
  --red: #ef4444;
  --sidebar-w: 300px;
  --topbar-h: 52px;
  --history-h: 72px;
}

html, body { height: 100%; overflow: hidden; }
body {
  font-family: var(--font); color: #0f172a; background: #f0f2f5;
  display: flex; flex-direction: column; -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

/* ── TOPBAR ── */
.topbar {
  height: var(--topbar-h); background: #fff;
  border-bottom: 1px solid #e2e8f0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; flex-shrink: 0; z-index: 100;
}
.topbar-left { display: flex; align-items: center; gap: 16px; }
.topbar-brand {
  font-size: 15px; font-weight: 800; color: var(--navy); text-decoration: none;
}
.topbar-brand span { color: var(--accent); font-weight: 700; }

.topbar-center {
  display: flex; align-items: center; gap: 4px;
  position: absolute; left: 50%; transform: translateX(-50%);
}

.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-credits {
  display: flex; align-items: center; gap: 6px; padding: 5px 14px;
  background: var(--accent-subtle); border: 1px solid var(--accent-border);
  border-radius: 100px; font-size: 13px; font-weight: 600; color: var(--accent);
  text-decoration: none; cursor: pointer;
}
.topbar-credits:hover { background: var(--accent-subtle); }
.topbar-credits svg { width: 14px; height: 14px; }
.topbar-link { font-size: 13px; color: #475569; text-decoration: none; font-weight: 500; }
.topbar-link:hover { color: var(--accent); }
.topbar-avatar {
  width: 32px; height: 32px; border-radius: 50%; background: #f1f5f9;
  border: 2px solid #e2e8f0; display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: #475569; cursor: pointer;
}
.topbar-user-menu { position: relative; }
.topbar-dropdown {
  display: none; position: absolute; top: 100%; right: 0; margin-top: 8px;
  background: #fff; border: 1px solid #e2e8f0;
  border-radius: 8px; padding: 4px; min-width: 160px; z-index: 200;
  box-shadow: 0 8px 32px rgba(0,0,0,0.08);
}
.topbar-dropdown.open { display: block; }
.topbar-dropdown a {
  display: block; padding: 8px 12px; font-size: 13px; color: #475569;
  text-decoration: none; border-radius: 6px; transition: all 0.15s;
}
.topbar-dropdown a:hover { background: #f1f5f9; color: #0f172a; }
.topbar-dropdown a.danger:hover { color: var(--red); }

/* ── COMING SOON BADGE (reused in tool picker) ── */
.coming-soon-badge {
  display: inline-block; margin-left: 8px; padding: 1px 8px;
  background: var(--accent-subtle);
  border: 1px solid var(--accent-border);
  border-radius: 100px; font-size: 11px; font-weight: 600;
  color: var(--accent); vertical-align: middle;
}

/* ── MAIN LAYOUT ── */
.main-layout {
  display: flex; flex: 1; overflow: hidden;
  position: relative;
}

/* ── SIDEBAR ── */
:root { --sidebar-strip-w: 48px; }

.sidebar {
  width: var(--sidebar-w); flex-shrink: 0;
  background: #fff; border-right: 1px solid #e2e8f0;
  display: flex; flex-direction: column;
  transition: width 0.25s ease, opacity 0.25s ease;
  overflow: hidden;
  position: relative; z-index: 25;
}

/* Sidebar strip (narrow collapsed view) */
.sidebar-strip {
  display: none;
  flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; width: var(--sidebar-strip-w); height: 100%;
  cursor: pointer; color: #94a3b8; transition: background 0.15s;
}
.sidebar-strip:hover { background: #f8fafc; color: #0f172a; }
.sidebar-strip-icon {
  width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  color: var(--accent);
}
.sidebar-strip-icon svg { width: 18px; height: 18px; }
.sidebar-strip > svg { width: 14px; height: 14px; flex-shrink: 0; }

/* Sidebar data-state rules */
/* TODO: Re-enable dynamic tool picker when more tools are added
.sidebar[data-state="tool-picker"] .sidebar-strip { display: none; }
.sidebar[data-state="tool-picker"] .sidebar-edge { display: none; }
.sidebar[data-state="tool-picker"] .sidebar-back { display: none !important; }
.sidebar[data-state="tool-picker"] .sidebar-footer { display: none; }
.sidebar[data-state="tool-picker"] .sidebar-tool-icon { display: none; }
*/

.sidebar[data-state="controls-expanded"] .sidebar-strip { display: none; }

.sidebar[data-state="controls-collapsed"] { width: var(--sidebar-strip-w); }
.sidebar[data-state="controls-collapsed"] .sidebar-header,
.sidebar[data-state="controls-collapsed"] .sidebar-body,
.sidebar[data-state="controls-collapsed"] .sidebar-footer { display: none; }
.sidebar[data-state="controls-collapsed"] .sidebar-strip { display: flex; }
.sidebar[data-state="controls-collapsed"] .sidebar-edge { display: none; }

.sidebar-handle { display: none; }

.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid #e2e8f0;
  flex-shrink: 0; gap: 8px;
}
.sidebar-back {
  width: 28px; height: 28px; border-radius: 6px; border: none;
  background: transparent; color: #94a3b8; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s; flex-shrink: 0;
}
.sidebar-back:hover { background: #f1f5f9; color: #0f172a; }
.sidebar-tool-info {
  display: flex; align-items: center; gap: 10px;
  min-width: 0; flex: 1;
}
.sidebar-tool-icon {
  width: 28px; height: 28px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: var(--accent);
}
.sidebar-tool-icon svg { width: 18px; height: 18px; }
.sidebar-tool-name {
  font-size: 14px; font-weight: 700; color: #0f172a;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
/* Sidebar edge handle */
.sidebar-edge {
  position: absolute; right: -4px; top: 0; bottom: 0;
  width: 8px; cursor: col-resize; z-index: 26;
}
.sidebar-edge::after {
  content: ''; position: absolute;
  right: 3px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 24px; border-radius: 3px;
  background: transparent; transition: background 0.2s;
}
.sidebar-edge:hover::after {
  background: #cbd5e1;
}

/* ── 2D/3D TOOL TOGGLE ── */
.tool-toggle {
  display: flex;
  background: #f1f5f9;
  border-radius: 8px;
  padding: 3px;
  gap: 2px;
  width: 100%;
}
.tool-toggle-option {
  flex: 1;
  padding: 6px 16px;
  border: none;
  border-radius: 6px;
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
  transition: all 0.2s;
}
.tool-toggle-option.active {
  background: #fff;
  color: #0f172a;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.tool-toggle-option:hover:not(.active) {
  color: #0f172a;
}

/* Mobile header layout — hidden on desktop */
.sidebar-header-row {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}
.sidebar-header-row .tool-toggle { flex: 1; }
.mobile-settings-btn {
  display: none; /* shown only on mobile via media query */
}
.sidebar-header-generate {
  display: none; /* shown only on mobile via media query */
}

/* TODO: Re-enable dynamic tool picker when more tools are added
.tool-picker-category { margin-bottom: 16px; }
.tool-picker-category:last-child { margin-bottom: 0; }
.tool-picker-category-label {
  font-size: 11px; font-weight: 700; color: #94a3b8;
  text-transform: uppercase; letter-spacing: 0.5px;
  padding: 0 12px; margin-bottom: 6px;
}
.tool-picker-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 8px; cursor: pointer;
  transition: background 0.15s;
}
.tool-picker-item:hover { background: #f8fafc; }
.tool-picker-icon {
  width: 32px; height: 32px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: #f1f5f9; color: #64748b;
}
.tool-picker-icon svg { width: 18px; height: 18px; }
.tool-picker-name { font-size: 13px; font-weight: 600; color: #0f172a; }
.tool-picker-desc { font-size: 11px; color: #94a3b8; margin-top: 1px; }
.tool-picker-item.coming-soon { opacity: 0.5; cursor: default; pointer-events: none; }
.tool-picker-item.coming-soon:hover { background: transparent; }
*/

.sidebar-body {
  flex: 1; overflow-y: auto; padding: 20px;
}

.sidebar-footer {
  padding: 16px 20px; border-top: 1px solid #e2e8f0;
  background: #fff; flex-shrink: 0;
}

/* ── CONTROL ELEMENTS (reused from old layout) ── */
.control { margin-bottom: 20px; }
.control:last-child { margin-bottom: 0; }
.control-label {
  font-size: 12px; font-weight: 600; color: #475569; margin-bottom: 8px;
  display: flex; align-items: center; justify-content: space-between;
}

.ctrl-select {
  width: 100%; padding: 9px 12px; padding-right: 32px;
  background: #fff; border: 1px solid #e2e8f0;
  border-radius: 8px; color: #0f172a; font-size: 13px;
  font-family: var(--font); font-weight: 500;
  appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='12' viewBox='0 0 12 12' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%2394a3b8' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  transition: border-color 0.2s;
}
.ctrl-select:hover { border-color: #cbd5e1; }
.ctrl-select:focus { outline: none; border-color: var(--accent); }

.ctrl-segment {
  display: flex; gap: 2px; background: #f8fafc;
  border: 1px solid #e2e8f0; border-radius: 8px; padding: 3px;
}
.ctrl-seg-option {
  flex: 1; padding: 7px 6px; border-radius: 6px; font-size: 12px; font-weight: 600;
  color: #94a3b8; text-align: center; cursor: pointer;
  transition: all 0.2s; position: relative; white-space: nowrap;
  display: flex; align-items: center; justify-content: center; gap: 4px;
}
.ctrl-seg-option:hover { color: #475569; }
.ctrl-seg-option.active {
  background: var(--accent); color: #fff; box-shadow: 0 2px 8px var(--accent-border);
}

.ctrl-checks { display: flex; flex-direction: column; gap: 8px; }
.ctrl-check {
  display: flex; align-items: center; gap: 10px; cursor: pointer;
  padding: 8px 10px; border-radius: 8px; transition: background 0.2s;
}
.ctrl-check:hover { background: #f8fafc; }
.ctrl-checkbox {
  width: 18px; height: 18px; border-radius: 4px; border: 2px solid #e2e8f0;
  background: #fff; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.ctrl-check.checked .ctrl-checkbox {
  background: var(--accent); border-color: var(--accent);
}
.ctrl-check.checked .ctrl-checkbox::after {
  content: ''; width: 10px; height: 6px;
  border-left: 2px solid #fff; border-bottom: 2px solid #fff;
  transform: rotate(-45deg) translateY(-1px);
}
.ctrl-check-label { font-size: 13px; color: #0f172a; font-weight: 500; flex: 1; }

/* Quality options */
.quality-options { display: flex; gap: 6px; margin-bottom: 14px; }
.quality-option {
  flex: 1; padding: 10px 6px; border-radius: 8px;
  background: #fff; border: 1.5px solid #e2e8f0;
  text-align: center; cursor: pointer; transition: all 0.2s;
}
.quality-option:hover { border-color: #cbd5e1; }
.quality-option.active { border-color: var(--accent); background: var(--accent-subtle); }
.quality-name { font-size: 12px; font-weight: 700; color: #0f172a; margin-bottom: 1px; }
.quality-option.active .quality-name { color: var(--accent); }
.quality-cost { font-size: 10px; color: #94a3b8; font-family: var(--mono); }
.quality-option.active .quality-cost { color: var(--accent); }

/* Generate button */
.btn-generate {
  width: 100%; padding: 13px; border: none; border-radius: 8px;
  background: var(--accent); color: #fff; font-family: var(--font);
  font-size: 14px; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  transition: all 0.2s; position: relative; overflow: hidden;
}
.btn-generate:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 4px 20px var(--accent-border); }
.btn-generate:active { transform: translateY(0); }
.btn-generate:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-generate-cost {
  font-size: 11px; font-weight: 500; opacity: 0.8;
  margin-left: 4px; padding-left: 8px;
  border-left: 1px solid rgba(255,255,255,0.3);
}

.balance-info {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 10px; font-size: 12px;
}
.balance-label { color: #94a3b8; }
.balance-count { color: #475569; font-weight: 600; }
.balance-buy { color: var(--accent); text-decoration: none; font-weight: 600; }
.balance-buy:hover { text-decoration: underline; }

/* ── GLOBAL CONTROLS (reference images + additional instructions) ── */
.global-controls-divider {
  height: 1px; background: #e2e8f0; margin: 20px 0;
}

.ref-images { margin-bottom: 20px; }
.ref-images-label {
  font-size: 12px; font-weight: 600; color: #475569; margin-bottom: 8px;
  display: flex; align-items: center; justify-content: space-between;
}
.ref-images-label .optional { font-weight: 400; color: #94a3b8; }
.ref-count { font-size: 11px; color: #94a3b8; font-weight: 500; }

.ref-dropzone {
  border: 1.5px dashed #cbd5e1; border-radius: 8px;
  padding: 12px; text-align: center; cursor: pointer;
  transition: all 0.2s; background: #fafbfc;
  display: flex; align-items: center; justify-content: center; gap: 6px;
  font-size: 12px; color: #94a3b8; font-weight: 500;
}
.ref-dropzone:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-subtle); }
.ref-dropzone.dragover { border-color: var(--accent); background: var(--accent-subtle); color: var(--accent); }
.ref-dropzone.disabled {
  opacity: 0.4; cursor: not-allowed; pointer-events: none;
}
.ref-dropzone svg { width: 16px; height: 16px; flex-shrink: 0; }

.ref-thumbs {
  display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap;
}
.ref-thumb {
  width: 56px; height: 56px; border-radius: 6px; position: relative;
  overflow: hidden; border: 1.5px solid #e2e8f0; flex-shrink: 0;
}
.ref-thumb img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.ref-thumb-remove {
  position: absolute; top: 2px; right: 2px;
  width: 18px; height: 18px; border-radius: 50%;
  background: rgba(0,0,0,0.6); color: #fff; border: none;
  font-size: 11px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transition: opacity 0.15s;
}
.ref-thumb:hover .ref-thumb-remove { opacity: 1; }

.additional-instructions { margin-bottom: 0; }
.additional-instructions-label {
  font-size: 12px; font-weight: 600; color: #475569; margin-bottom: 8px;
  display: flex; align-items: center; justify-content: space-between;
}
.additional-instructions-label .optional { font-weight: 400; color: #94a3b8; }
.additional-instructions textarea {
  width: 100%; padding: 9px 12px; border: 1px solid #e2e8f0;
  border-radius: 8px; font-size: 13px; font-family: var(--font);
  color: #0f172a; resize: vertical; min-height: 60px;
  transition: border-color 0.2s; background: #fff;
  box-sizing: border-box;
}
.additional-instructions textarea::placeholder { color: #94a3b8; }
.additional-instructions textarea:hover { border-color: #cbd5e1; }
.additional-instructions textarea:focus { outline: none; border-color: var(--accent); }
.additional-instructions .char-count {
  text-align: right; font-size: 11px; color: #94a3b8; margin-top: 4px;
  font-family: var(--mono);
}

/* ── VISUAL-SELECT CONTROL ── */
.ctrl-visual-select { position: relative; }

.ctrl-visual-selected {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border: 1.5px solid #e2e8f0;
  border-radius: 8px; cursor: pointer; transition: all 0.2s;
  background: #fff; user-select: none;
}
.ctrl-visual-selected:hover { border-color: #cbd5e1; }
.ctrl-visual-selected.open { border-color: var(--accent); }

.ctrl-visual-thumb {
  width: 48px; height: 36px; border-radius: 4px;
  object-fit: cover; flex-shrink: 0; background: #f1f5f9;
}
.ctrl-visual-label {
  flex: 1; font-size: 13px; font-weight: 500; color: #0f172a;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ctrl-visual-chevron {
  width: 16px; height: 16px; flex-shrink: 0; color: #94a3b8;
  transition: transform 0.2s;
}
.ctrl-visual-selected.open .ctrl-visual-chevron { transform: rotate(180deg); }

/* ── OPTIONS DRAWER ── */
.options-drawer {
  position: absolute; left: var(--sidebar-w); top: 0; bottom: 0;
  width: 260px; z-index: 20; background: #fff;
  border-right: 1px solid #e2e8f0;
  transform: translateX(-100%); transition: transform 0.25s ease, opacity 0.25s ease, visibility 0.25s;
  display: flex; flex-direction: column;
  box-shadow: 4px 0 24px rgba(0,0,0,0.06);
  opacity: 0; visibility: hidden; pointer-events: none;
}
.options-drawer.visible { transform: translateX(0); opacity: 1; visibility: visible; pointer-events: auto; }

.options-drawer-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 16px; border-bottom: 1px solid #e2e8f0; flex-shrink: 0;
}
.options-drawer-title {
  font-size: 13px; font-weight: 700; color: #0f172a;
}
.options-drawer-close {
  width: 28px; height: 28px; border: none; background: transparent;
  font-size: 18px; color: #94a3b8; cursor: pointer; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
}
.options-drawer-close:hover { background: #f1f5f9; color: #0f172a; }

.options-drawer-handle { display: none; }

.options-drawer-list {
  flex: 1; overflow-y: auto; padding: 8px;
}

.options-drawer-item {
  display: flex; flex-direction: column; align-items: stretch; gap: 6px;
  padding: 10px 12px; border-radius: 8px; cursor: pointer;
  transition: all 0.15s; margin-bottom: 4px;
}
.options-drawer-item:hover { background: #f8fafc; }
.options-drawer-item.active {
  background: var(--accent-subtle); border: 1.5px solid var(--accent-border);
}

.options-drawer-item-thumb {
  width: 100%; aspect-ratio: 4/3; border-radius: 6px;
  object-fit: cover; background: #f1f5f9;
}
.options-drawer-item-label {
  font-size: 13px; font-weight: 500; color: #0f172a;
  text-align: center;
}
.options-drawer-item.active .options-drawer-item-label {
  color: var(--accent); font-weight: 600;
}

.options-drawer-backdrop {
  display: none; position: fixed; inset: 0; z-index: 14;
}
.options-drawer-backdrop.visible { display: block; }

/* ── CANVAS AREA ── */
.canvas-area {
  flex: 1; position: relative; display: flex; flex-direction: column;
  background: #f0f2f5; overflow: hidden;
}

/* Upload zone — full canvas area */
.canvas-upload {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; cursor: pointer; z-index: 5;
}
.canvas-upload-content {
  display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 48px 64px; border: 2px dashed #cbd5e1; border-radius: 16px;
  transition: all 0.3s; background: rgba(255,255,255,0.6);
}
.canvas-upload:hover .canvas-upload-content,
.canvas-upload.dragover .canvas-upload-content {
  border-color: var(--accent); background: var(--accent-subtle);
}
.canvas-upload-content svg { color: #94a3b8; }
.canvas-upload:hover .canvas-upload-content svg { color: var(--accent); }
.canvas-upload-title { font-size: 15px; font-weight: 600; color: #475569; }
.canvas-upload-sub { font-size: 12px; color: #94a3b8; }
.canvas-upload-divider {
  font-size: 12px; color: #cbd5e1; font-weight: 500;
  margin: 4px 0;
}
.canvas-upload-history {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 18px; border-radius: 100px;
  background: transparent; border: 1.5px solid #e2e8f0;
  color: #64748b; font-size: 13px; font-weight: 600;
  font-family: var(--font); cursor: pointer; transition: all 0.2s;
}
.canvas-upload-history svg { width: 15px; height: 15px; }
.canvas-upload-history:hover {
  border-color: var(--accent); color: var(--accent); background: var(--accent-subtle);
}

/* Canvas frame */
.canvas-frame {
  flex: 1; display: flex; align-items: center; justify-content: center;
  padding: 32px; overflow: auto; position: relative;
}
.canvas-frame img {
  max-width: 100%; max-height: 100%; object-fit: contain;
  border-radius: 8px; box-shadow: 0 8px 40px rgba(0,0,0,0.1);
  transition: transform 0.2s;
}

/* Before image (comparison) */
#canvasBeforeImage {
  position: absolute;
  border-radius: 8px; box-shadow: none;
  pointer-events: none;
  z-index: 0;
  object-fit: contain;
}
#canvasImage {
  position: relative;
  z-index: 1;
}

/* Compare slider */
.canvas-compare {
  display: flex; align-items: center; gap: 8px;
  background: #fff; border: 1px solid #e2e8f0;
  border-radius: 100px; padding: 6px 14px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.canvas-compare-label {
  font-size: 12px; font-weight: 600; color: #94a3b8;
  white-space: nowrap; user-select: none;
}
.canvas-compare-slider {
  width: 120px; height: 4px;
  -webkit-appearance: none; appearance: none;
  background: #e2e8f0; border-radius: 2px; outline: none;
  cursor: pointer;
}
.canvas-compare-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
  cursor: pointer;
}
.canvas-compare-slider::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.15);
  cursor: pointer;
}

/* Generating overlay */
.generating-overlay {
  position: absolute; inset: 0;
  background: rgba(240,242,245,0.85);
  display: none; align-items: center; justify-content: center;
  flex-direction: column; gap: 16px; z-index: 10;
  backdrop-filter: blur(4px);
}
.generating-overlay.visible { display: flex; }
.generating-spinner {
  width: 40px; height: 40px; border: 3px solid #e2e8f0;
  border-top-color: var(--accent); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.generating-text { font-size: 14px; color: #475569; font-weight: 500; }

/* Canvas actions (bottom overlay) */
.canvas-actions {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; z-index: 8;
  pointer-events: none;
}
.canvas-actions > * { pointer-events: auto; }

.canvas-zoom {
  display: flex; align-items: center; gap: 2px;
  background: #fff; border: 1px solid #e2e8f0;
  border-radius: 100px; padding: 4px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.canvas-zoom-btn {
  width: 28px; height: 28px; border-radius: 50%; border: none; background: transparent;
  color: #94a3b8; cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: all 0.2s; font-size: 14px; font-family: var(--font);
}
.canvas-zoom-btn:hover { color: #0f172a; background: #f1f5f9; }
.canvas-zoom-level {
  padding: 0 10px; font-size: 12px; font-weight: 600; color: #475569;
  font-family: var(--mono);
}

.canvas-buttons { display: flex; gap: 8px; }
.canvas-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; font-size: 13px; font-weight: 600;
  border: 1.5px solid #e2e8f0; background: #fff; color: #475569;
  cursor: pointer; transition: all 0.2s; text-decoration: none;
  font-family: var(--font); box-shadow: 0 2px 8px rgba(0,0,0,0.04);
}
.canvas-btn:hover { border-color: var(--accent-border); color: var(--accent); }
.canvas-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.canvas-btn-primary {
  background: var(--accent); color: #fff; border-color: var(--accent);
}
.canvas-btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.canvas-btn-danger { color: #475569; }
.canvas-btn-danger:hover { color: var(--red); background: #fff; }

/* ── CONFIRM DELETE DIALOG ── */
.confirm-overlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
}
.confirm-box {
  background: #fff; border-radius: 12px; padding: 28px; max-width: 360px; width: 100%;
  text-align: center;
}
.confirm-box h3 { font-size: 18px; font-weight: 700; margin: 0 0 8px; }
.confirm-box p { font-size: 14px; color: #94a3b8; margin: 0 0 20px; }
.confirm-actions { display: flex; gap: 10px; justify-content: center; }
.btn-cancel {
  padding: 8px 20px; border-radius: 8px; font-size: 13px; font-weight: 600;
  background: #fff; color: #475569; border: 1px solid #e2e8f0;
  font-family: var(--font); cursor: pointer; transition: all 0.15s;
}
.btn-cancel:hover { border-color: #94a3b8; }
.btn-danger {
  padding: 8px 20px; border-radius: 8px; font-size: 13px; font-weight: 600;
  background: #ef4444; color: #fff; border: none;
  font-family: var(--font); cursor: pointer; transition: all 0.15s;
}
.btn-danger:hover { background: #dc2626; }

/* ── HISTORY STRIP ── */
.history-strip {
  height: var(--history-h); background: #fff;
  border-top: 1px solid #e2e8f0;
  display: flex; align-items: center; gap: 8px;
  padding: 0 16px; overflow-x: auto; flex-shrink: 0;
}
.history-strip::-webkit-scrollbar { height: 4px; }
.history-strip::-webkit-scrollbar-thumb { background: #e2e8f0; border-radius: 2px; }

.history-thumb {
  width: 48px; height: 48px; border-radius: 6px; flex-shrink: 0;
  overflow: hidden; cursor: pointer; border: 2px solid transparent;
  transition: all 0.2s; position: relative;
}
.history-thumb img {
  width: 100%; height: 100%; object-fit: cover;
}
.history-thumb:hover { border-color: #cbd5e1; transform: scale(1.05); }
.history-thumb.active { border-color: var(--accent); }
.history-thumb-label {
  position: absolute; bottom: 0; left: 0; right: 0;
  background: rgba(0,0,0,0.5); color: #fff; font-size: 7px;
  text-align: center; padding: 1px 0; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.3px;
}

/* Pro CTA — top-right of canvas area */
.pro-cta {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); z-index: 8;
  display: flex; align-items: center; gap: 8px;
  padding: 6px 14px;
  background: linear-gradient(135deg, #fef9ee 0%, #fff7ed 100%);
  border: 1.5px solid #fed7aa; border-radius: 8px;
  color: #9a3412; font-size: 11px; font-weight: 600;
  cursor: pointer; transition: all 0.2s; white-space: nowrap;
  text-decoration: none;
}
.pro-cta:hover { background: #fff7ed; border-color: #fb923c; transform: translateX(-50%) translateY(-1px); box-shadow: 0 2px 8px rgba(251,146,60,0.15); }
.pro-cta svg { flex-shrink: 0; color: #ea580c; }
.pro-cta span { color: #78350f; }

/* Meeting CTA — bottom-right of canvas area */
.meeting-cta {
  position: absolute; bottom: 12px; right: 12px; z-index: 8;
  display: flex; align-items: center; gap: 8px;
  padding: 6px 14px;
  background: linear-gradient(135deg, #eef6fe 0%, #e0f2fe 100%);
  border: 1.5px solid #93c5fd; border-radius: 8px;
  color: #1e40af; font-size: 11px; font-weight: 600;
  cursor: pointer; transition: all 0.2s; white-space: nowrap;
  text-decoration: none;
}
.meeting-cta:hover { background: #dbeafe; border-color: #3b82f6; transform: translateY(-1px); box-shadow: 0 2px 8px rgba(59,130,246,0.15); }
.meeting-cta svg { flex-shrink: 0; color: #2563eb; }
.meeting-cta span { color: #1e3a8a; }

/* ── HISTORY GALLERY ── */
.history-gallery {
  position: absolute;
  inset: 0;
  background: #f0f2f5;
  z-index: 9;
  display: none;
  flex-direction: column;
  overflow: hidden;
}
.history-gallery.visible { display: flex; }

.history-gallery-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid #e2e8f0;
  background: #fff;
  flex-shrink: 0;
}
.history-gallery-header h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  color: #1e293b;
}
.history-gallery-close {
  width: 32px; height: 32px;
  border: none; background: none;
  font-size: 22px; color: #64748b;
  cursor: pointer; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
}
.history-gallery-close:hover { background: #f1f5f9; color: #1e293b; }

.history-gallery-grid {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  align-content: start;
}

.history-card {
  background: #fff;
  border-radius: 10px;
  overflow: hidden;
  border: 1.5px solid #e2e8f0;
  cursor: pointer;
  transition: all 0.2s;
}
.history-card:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 16px var(--accent-subtle);
  transform: translateY(-2px);
}
.history-card-img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  display: block;
  background: #f1f5f9;
}
.history-card-info {
  padding: 10px 12px;
}
.history-card-tool {
  font-size: 12px;
  font-weight: 600;
  color: #334155;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-card-meta {
  font-size: 11px;
  color: #94a3b8;
  display: flex;
  align-items: center;
  gap: 8px;
}
.history-card-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
}
.history-card-badge.standard { background: #f1f5f9; color: #64748b; }
.history-card-badge.high     { background: #dbeafe; color: #2563eb; }
.history-card-badge.ultra    { background: #ede9fe; color: #7c3aed; }

.history-gallery-loading,
.history-gallery-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  color: #94a3b8;
  font-size: 14px;
}

/* ── REGISTER MODAL (guest mode) ── */
.register-modal-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(2px);
}
.register-modal {
  background: #fff; border-radius: 16px; padding: 32px;
  max-width: 440px; width: 90%; position: relative;
  box-shadow: 0 16px 64px rgba(0,0,0,0.15);
  max-height: 90vh; overflow-y: auto;
}
.register-modal-close {
  position: absolute; top: 12px; right: 12px;
  width: 32px; height: 32px; border: none; background: transparent;
  font-size: 22px; color: #94a3b8; cursor: pointer; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
}
.register-modal-close:hover { background: #f1f5f9; color: #0f172a; }
.register-modal h2 { font-size: 20px; font-weight: 700; margin: 0 0 4px; color: #0f172a; }
.register-modal .auth-subtitle { margin: 0 0 16px; }
.register-modal-login {
  text-align: center; margin-top: 16px; font-size: 13px; color: #64748b;
}
.register-modal-login a { color: var(--accent); font-weight: 600; text-decoration: none; }
.register-modal-login a:hover { text-decoration: underline; }

/* ── USER PRESET MODAL ── */
.user-preset-modal-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(2px);
}
.user-preset-modal {
  background: #fff; border-radius: 16px;
  max-width: 780px; width: 94%; position: relative;
  box-shadow: 0 16px 64px rgba(0,0,0,0.15);
  max-height: 90vh; display: flex; flex-direction: column;
}
.user-preset-modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px 0; flex-shrink: 0;
}
.user-preset-modal-header h2 {
  font-size: 18px; font-weight: 700; margin: 0; color: #0f172a;
}
.user-preset-modal-close {
  width: 32px; height: 32px; border: none; background: transparent;
  font-size: 22px; color: #94a3b8; cursor: pointer; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
}
.user-preset-modal-close:hover { background: #f1f5f9; color: #0f172a; }
.user-preset-modal-body {
  padding: 16px 24px; overflow-y: auto; flex: 1;
}
.user-preset-modal-body label {
  display: block; font-size: 11px; font-weight: 600; color: #94a3b8;
  text-transform: uppercase; letter-spacing: 0.5px; margin: 14px 0 5px;
}
.user-preset-modal-body label:first-child { margin-top: 0; }
.user-preset-modal-body .form-input {
  width: 100%; padding: 10px 14px; border: 1.5px solid #e2e8f0;
  border-radius: 10px; font-size: 14px; font-family: var(--font);
  color: #0f172a; background: #fff; transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box; outline: none;
}
.user-preset-modal-body .form-input::placeholder { color: #cbd5e1; }
.user-preset-modal-body .form-input:hover { border-color: #cbd5e1; }
.user-preset-modal-body .form-input:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-subtle);
}
.user-preset-modal-body select.form-input {
  appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg width='12' height='12' viewBox='0 0 12 12' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M3 4.5L6 7.5L9 4.5' stroke='%2394a3b8' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
  padding-right: 36px;
}
.user-preset-top-fields {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
}
.user-preset-modal-footer {
  display: flex; gap: 10px; justify-content: flex-end;
  padding: 16px 24px; border-top: 1px solid #e2e8f0; flex-shrink: 0;
}
.user-preset-modal-footer .btn-cancel {
  padding: 9px 20px; border-radius: 8px; font-size: 13px; font-weight: 600;
  background: #fff; color: #64748b; border: 1px solid #e2e8f0;
  font-family: var(--font); cursor: pointer; transition: all 0.15s;
}
.user-preset-modal-footer .btn-cancel:hover { border-color: #94a3b8; color: #475569; }
.user-preset-modal-footer .btn-save-use {
  padding: 9px 24px; border-radius: 8px; font-size: 13px; font-weight: 700;
  background: var(--accent); color: #fff; border: none;
  font-family: var(--font); cursor: pointer; transition: all 0.15s;
  box-shadow: 0 2px 8px var(--accent-border);
}
.user-preset-modal-footer .btn-save-use:hover {
  background: var(--accent-hover); transform: translateY(-1px);
  box-shadow: 0 4px 16px var(--accent-border);
}
.user-preset-modal-footer .btn-save-use:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

/* Roles section label */
.user-preset-roles-label {
  font-size: 12px; font-weight: 600; color: #475569;
  text-transform: uppercase; letter-spacing: 0.5px;
  margin: 16px 0 4px;
}
.user-preset-roles-desc {
  font-size: 12px; color: #94a3b8; margin: 0 0 4px;
}

/* Roles 2-column grid */
#userPresetRolesContainer {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 12px;
}

/* Role rows — card style */
.user-preset-role-row {
  border: 1px solid #e2e8f0; border-radius: 12px; padding: 14px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  transition: box-shadow 0.15s;
  position: relative; z-index: 1;
}
.user-preset-role-row.popover-open { z-index: 20; }
.user-preset-role-row:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
.user-preset-role-header {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px;
}
.user-preset-role-label { font-size: 13px; font-weight: 600; color: #0f172a; }
.user-preset-role-toggle {
  display: flex; background: #f1f5f9; border-radius: 8px; padding: 2px; gap: 2px;
}
.user-preset-toggle-btn {
  padding: 4px 12px; font-size: 11px; font-weight: 600; border: none;
  background: transparent; color: #94a3b8; cursor: pointer; font-family: var(--font);
  border-radius: 6px; transition: all 0.2s;
}
.user-preset-toggle-btn.active {
  background: var(--accent); color: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}
.user-preset-toggle-btn:not(.active):hover { color: #475569; }
.user-preset-role-inputs { position: relative; }
.user-preset-color-input { display: flex; align-items: center; gap: 8px; }
.user-preset-texture-input { }

/* ── Custom Color Picker ── */
.upm-color-trigger {
  width: 32px; height: 32px; border-radius: 50%;
  border: 2px solid #e2e8f0; cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  flex-shrink: 0;
}
.upm-color-trigger:hover { border-color: #cbd5e1; box-shadow: 0 0 0 3px rgba(0,0,0,0.04); }
.upm-color-trigger.open { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-subtle); }

.upm-color-hex {
  width: 80px; padding: 5px 8px; border: 1px solid #e2e8f0; border-radius: 6px;
  font-family: var(--mono); font-size: 12px; color: #0f172a; background: #fff;
  transition: border-color 0.15s;
}
.upm-color-hex:focus { outline: none; border-color: var(--accent); }

.upm-color-popover {
  position: absolute; top: 100%; left: 0; z-index: 10;
  margin-top: 8px; padding: 12px;
  background: #fff; border: 1px solid #e2e8f0; border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.12);
  width: 244px;
  display: none;
}
.upm-color-popover.open { display: block; }

.upm-color-grid {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px;
  margin-bottom: 10px;
}
.upm-color-swatch {
  width: 28px; height: 28px; border-radius: 6px;
  border: 2px solid transparent; cursor: pointer;
  transition: transform 0.1s, border-color 0.1s;
}
.upm-color-swatch:hover { transform: scale(1.15); border-color: rgba(0,0,0,0.15); }
.upm-color-swatch.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-subtle); }

.upm-color-popover-footer {
  display: flex; align-items: center; gap: 6px;
  padding-top: 10px; border-top: 1px solid #f1f5f9;
}
.upm-color-popover-hex {
  flex: 1; padding: 5px 8px; border: 1px solid #e2e8f0; border-radius: 6px;
  width: 80px;
  font-family: var(--mono); font-size: 12px; color: #0f172a;
}
.upm-color-popover-hex:focus { outline: none; border-color: var(--accent); }
.upm-color-custom-btn {
  padding: 6px 10px; border: 1px solid #e2e8f0; border-radius: 6px;
  background: #fff; font-size: 11px; font-weight: 600; color: #64748b;
  cursor: pointer; font-family: var(--font); transition: all 0.15s;
  white-space: nowrap;
}
.upm-color-custom-btn:hover { border-color: var(--accent); color: var(--accent); }
.upm-color-native { position: absolute; opacity: 0; width: 0; height: 0; pointer-events: none; }

/* ── Visual Texture Picker — Trigger ── */
.upm-texture-trigger {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px; border: 1px solid #e2e8f0; border-radius: 8px;
  cursor: pointer; transition: all 0.15s; background: #fff;
  min-height: 36px;
}
.upm-texture-trigger:hover { border-color: #cbd5e1; }
.upm-texture-trigger.open { border-color: var(--accent); }
.upm-texture-trigger-thumb {
  width: 40px; height: 30px; border-radius: 4px; object-fit: cover; flex-shrink: 0;
  background: #f1f5f9;
}
.upm-texture-trigger-label {
  flex: 1; font-size: 12px; color: #64748b; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.upm-texture-trigger-label.has-value { color: #0f172a; }
.upm-texture-trigger-chevron {
  width: 14px; height: 14px; flex-shrink: 0; color: #94a3b8;
  transition: transform 0.2s;
}

/* ── Texture Bottom Sheet ── */
.user-preset-modal { position: relative; overflow: hidden; }
.upm-texture-sheet-backdrop {
  position: absolute; inset: 0; background: rgba(0,0,0,0.3); z-index: 50;
  opacity: 0; pointer-events: none; transition: opacity 0.25s;
}
.upm-texture-sheet-backdrop.open { opacity: 1; pointer-events: auto; }
.upm-texture-sheet {
  position: absolute; bottom: 0; left: 0; right: 0; z-index: 51;
  max-height: 70%; background: #fff; border-radius: 16px 16px 0 0;
  box-shadow: 0 -8px 32px rgba(0,0,0,0.12);
  display: flex; flex-direction: column;
  transform: translateY(100%); transition: transform 0.3s cubic-bezier(0.33,1,0.68,1);
}
.upm-texture-sheet.open { transform: translateY(0); }
.upm-texture-sheet-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px 12px; border-bottom: 1px solid #e2e8f0; flex-shrink: 0;
}
.upm-texture-sheet-header span {
  font-size: 15px; font-weight: 700; color: #0f172a;
}
.upm-texture-sheet-close {
  width: 28px; height: 28px; border: none; background: transparent;
  font-size: 20px; color: #94a3b8; cursor: pointer; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
}
.upm-texture-sheet-close:hover { background: #f1f5f9; color: #0f172a; }
.upm-texture-sheet-body {
  overflow-y: auto; padding: 16px 20px 20px; flex: 1;
}
.upm-texture-cat-title {
  font-size: 13px; font-weight: 700; color: #475569;
  text-transform: uppercase; letter-spacing: 0.5px;
  margin: 0 0 10px; padding-top: 16px;
}
.upm-texture-cat-title:first-child { padding-top: 0; }
.upm-texture-cat-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
  margin-bottom: 8px;
}
.upm-texture-card {
  display: flex; flex-direction: column; gap: 6px;
  border: 2px solid transparent; border-radius: 10px;
  padding: 6px; cursor: pointer; transition: all 0.15s;
}
.upm-texture-card:hover { background: #f8fafc; border-color: #e2e8f0; }
.upm-texture-card.selected { border-color: var(--accent); background: var(--accent-subtle); }
.upm-texture-card img {
  width: 100%; aspect-ratio: 4/3; border-radius: 6px; object-fit: cover;
  background: #f1f5f9;
}
.upm-texture-card span {
  font-size: 11px; color: #64748b; font-weight: 500;
  text-align: center; line-height: 1.2;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ── DRAWER: Build Your Own + User Presets ── */
.options-drawer-build-own {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; margin: 12px 0 20px; border-radius: 10px;
  border: 2px dashed var(--accent-border); background: #fff;
  cursor: pointer; transition: all 0.15s;
  font-size: 13px; font-weight: 600; color: var(--accent);
}
.options-drawer-build-own:hover {
  border-color: var(--accent); background: var(--accent-subtle);
}
.options-drawer-build-own svg { flex-shrink: 0; stroke: var(--accent); }

.options-drawer-user-preset {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; margin: 0 12px; border-radius: 8px;
  cursor: pointer; transition: background 0.15s;
}
.options-drawer-user-preset:hover { background: #f8fafc; }
.options-drawer-user-preset.active { background: var(--accent-subtle); }
.options-drawer-user-preset-body {
  display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0;
}
.options-drawer-user-preset-name {
  font-size: 13px; font-weight: 600; color: #0f172a;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.options-drawer-user-preset-swatches { display: flex; gap: 4px; flex-wrap: wrap; }
.options-drawer-swatch {
  width: 16px; height: 16px; border-radius: 4px; border: 1px solid rgba(0,0,0,0.1);
  display: inline-block;
}
.options-drawer-swatch-texture {
  background: repeating-linear-gradient(45deg, #e2e8f0, #e2e8f0 2px, #f8fafc 2px, #f8fafc 4px);
}
.options-drawer-user-preset-actions {
  display: flex; gap: 4px; flex-shrink: 0; margin-left: 8px;
}
.options-drawer-user-preset-action {
  width: 28px; height: 28px; border: none; background: transparent;
  color: #94a3b8; cursor: pointer; border-radius: 6px;
  display: flex; align-items: center; justify-content: center; transition: all 0.15s;
}
.options-drawer-user-preset-action:hover { background: #f1f5f9; color: #475569; }
.options-drawer-user-preset-action-danger:hover { color: var(--red); }

.options-drawer-user-divider {
  height: 1px; background: #e2e8f0; margin: 8px 16px;
}

.ctrl-visual-thumb-icon {
  width: 24px; height: 24px; flex-shrink: 0; color: var(--accent);
}

/* ── RESPONSIVE ── */
@media (max-width: 900px) {
  #userPresetRolesContainer { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 768px) {
  .topbar-center {
    position: static; transform: none;
    overflow-x: auto; flex: 1; justify-content: center;
    margin: 0 8px;
  }
  .topbar-center::-webkit-scrollbar { display: none; }

  .main-layout { flex-direction: column; }

  .sidebar-edge { display: none !important; }

  .sidebar {
    width: 100% !important; border-right: none;
    position: fixed; bottom: 0; left: 0; right: 0;
    z-index: 50; max-height: 60vh;
    border-top: 1px solid #e2e8f0;
    border-radius: 0;
    box-shadow: 0 -4px 16px rgba(0,0,0,0.08);
    transition: max-height 0.3s ease, opacity 0.3s ease;
  }

  /* Mobile sidebar: collapsed = only header visible at bottom */
  .sidebar.mobile-collapsed .sidebar-body,
  .sidebar.mobile-collapsed .sidebar-footer {
    max-height: 0; overflow: hidden; opacity: 0; padding: 0;
  }
  .sidebar.mobile-collapsed { border-radius: 0; }
  .sidebar.mobile-expanded {
    max-height: calc(100dvh - 44px);
  }
  .sidebar.mobile-expanded .sidebar-body,
  .sidebar.mobile-expanded .sidebar-footer {
    opacity: 1;
  }

  /* Mobile header: two rows, always visible */
  .sidebar-header {
    flex-direction: column; padding: 10px 16px; gap: 8px;
  }
  .sidebar-header-generate {
    display: flex; align-items: center; gap: 8px; width: 100%;
  }
  .sidebar-header-generate .btn-generate { flex: 1; padding: 10px; font-size: 13px; }

  /* Settings cog button */
  .mobile-settings-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px; height: 36px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    background: #fff;
    color: #64748b;
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.2s;
  }
  .mobile-settings-btn:hover { background: #f8fafc; color: #0f172a; }
  .mobile-settings-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
  }

  /* Mobile toggle compact sizing */
  .tool-toggle-option { padding: 5px 12px; font-size: 12px; }

  /* Hide footer generate button on mobile (it lives in the header now) */
  .sidebar-footer .btn-generate { display: none; }
  .sidebar-footer .balance-info { margin-top: 0; }

  /* Hide drag handle on mobile — sidebar is button-controlled */
  .sidebar-handle { display: none !important; }

  /* Mobile collapsed (strip): thin bottom bar */
  .sidebar[data-state="controls-collapsed"] .sidebar-handle { display: none; }
  .sidebar[data-state="controls-collapsed"] {
    width: 100% !important; max-height: 48px;
    border-radius: 0;
  }
  .sidebar[data-state="controls-collapsed"] .sidebar-strip {
    flex-direction: row; width: 100%; height: 48px;
  }
  .sidebar[data-state="controls-collapsed"] .sidebar-strip > svg {
    transform: rotate(-90deg);
  }

  .canvas-area { flex: 1; }

  .canvas-actions { padding: 8px 12px; margin-bottom: 50px; }

  .history-strip { height: 60px; }
  .history-thumb { width: 40px; height: 40px; }

  .options-drawer {
    position: fixed; left: 0; right: 0; bottom: 0;
    width: 100%; z-index: 60;
    border-right: none;
    border-radius: 16px 16px 0 0;
    top: 44px; max-height: calc(100% - 44px);
    transform: translateY(100%);
    box-shadow: 0 -8px 32px rgba(0,0,0,0.15);
    will-change: transform;
  }
  /* Mobile: visible = fully open, no collapsed state */
  .options-drawer.visible { transform: translateY(0); border-radius: 0; }
  .options-drawer.visible .options-drawer-list { opacity: 1; overflow-y: auto; }
  /* Hide drag handle on mobile */
  .options-drawer-handle { display: none; }
  .options-drawer-header { position: relative; }
  .options-drawer-close { width: 44px; height: 44px; }
  .options-drawer-backdrop {
    position: fixed; inset: 0; z-index: 55;
  }
  .options-drawer-backdrop.visible { display: block; background: rgba(0,0,0,0.3); }

  .topbar { height: 44px; padding: 0 12px; position: relative; }
  .topbar-center { gap: 2px; }

  .canvas-upload-content { padding: 24px 32px; }

  .canvas-frame { padding: 16px; }

  .sidebar[data-state="controls-expanded"] ~ .canvas-area .history-strip { display: none; }

  .canvas-actions { gap: 6px; flex-wrap: wrap; }
  .canvas-btn-label { display: none; }
  .canvas-btn svg { width: 18px; height: 18px; }

  /* Match canvas action buttons to mobile generate button size */
  .canvas-zoom { padding: 3px; border-radius: 8px; }
  .canvas-zoom-btn { width: 34px; height: 34px; font-size: 16px; border-radius: 6px; }
  .canvas-zoom-level { padding: 0 6px; font-size: 12px; }

  .canvas-btn {
    padding: 10px; min-height: 40px;
    font-size: 13px; border-radius: 8px;
  }
  .canvas-btn-primary {
    background: #fff; color: #475569; border-color: #e2e8f0;
  }
  .canvas-btn-primary:hover { background: #f8fafc; color: var(--accent); border-color: var(--accent-border); }

  .canvas-compare {
    position: static;
    transform: none;
    z-index: auto;
    width: 100%;
    order: 10;
    border-radius: 8px;
    padding: 8px 12px;
  }
  .canvas-compare-slider { flex: 1; width: auto; }

  .pro-cta, .meeting-cta { display: none; }

  /* User preset modal: full-screen on mobile */
  .user-preset-modal {
    width: 100%; height: 100%; max-width: 100%; max-height: 100%;
    border-radius: 0;
  }
  #userPresetRolesContainer { grid-template-columns: 1fr; }
  .user-preset-top-fields { grid-template-columns: 1fr; gap: 0; }
  .upm-color-popover { width: 200px; }
  .upm-texture-sheet { max-height: 85%; }
  .upm-texture-cat-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ── SMALL PHONES ── */
@media (max-width: 480px) {
  .sidebar { max-height: 50vh; }

  .canvas-upload-content { padding: 20px 24px; }
  .canvas-upload-title { font-size: 13px; }
  .canvas-upload-sub { font-size: 11px; }

  .canvas-frame { padding: 8px; }

  .quality-options { flex-direction: column; }

}
