/* Image Illustrator — refined SaaS design system
 * Inspired by Linear, Vercel, Stripe Dashboard.
 * Light, spacious, subtly elevated. One accent. Calm typography.
 */

:root {
  color-scheme: light;

  /* Surface */
  --bg:           #fafafa;
  --surface:      #ffffff;
  --surface-2:    #f7f7f8;
  --surface-3:    #f1f1f3;

  /* Text */
  --text:         #18181b;
  --text-muted:   #52525b;
  --text-faint:   #a1a1aa;

  /* Lines */
  --line:         #ececef;
  --line-strong:  #d4d4d8;

  /* Accent — calm indigo, not too saturated */
  --accent:       #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft:  #eef2ff;
  --accent-text:  #ffffff;
  --accent-glow:  rgba(79, 70, 229, 0.18);

  /* Status */
  --success:       #15803d;
  --success-soft:  #f0fdf4;
  --warning:       #b45309;
  --warning-soft:  #fffbeb;
  --danger:        #b91c1c;
  --danger-soft:   #fef2f2;
  --info:          #1d4ed8;
  --info-soft:     #eff6ff;

  /* Effects */
  --shadow-xs:    0 1px 0 rgba(17, 24, 39, 0.04);
  --shadow-sm:    0 1px 2px rgba(17, 24, 39, 0.06), 0 1px 1px rgba(17, 24, 39, 0.03);
  --shadow-md:    0 4px 12px rgba(17, 24, 39, 0.06), 0 2px 4px rgba(17, 24, 39, 0.04);
  --shadow-lg:    0 12px 32px rgba(17, 24, 39, 0.10), 0 4px 8px rgba(17, 24, 39, 0.04);
  --ring:         0 0 0 3px var(--accent-glow);

  /* Radius */
  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius:    8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 40px;
  --space-9: 56px;
  --space-10: 72px;

  /* Type */
  --font-sans: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
  --font-mono: ui-monospace, 'JetBrains Mono', 'SF Mono', Menlo, Consolas, monospace;

  /* Layout */
  --sidebar-w: 244px;
  --topbar-h:  52px;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg:          #0a0a0b;
    --surface:     #111113;
    --surface-2:   #161618;
    --surface-3:   #1d1d20;
    --text:        #f4f4f5;
    --text-muted:  #a1a1aa;
    --text-faint:  #71717a;
    --line:        #26262a;
    --line-strong: #35353a;
    --accent:       #818cf8;
    --accent-hover: #a5b4fc;
    --accent-soft:  rgba(129, 140, 248, 0.12);
    --accent-text:  #0a0a0b;
    --accent-glow:  rgba(129, 140, 248, 0.22);
    --success-soft: rgba(34, 197, 94, 0.10);
    --warning-soft: rgba(245, 158, 11, 0.10);
    --danger-soft:  rgba(239, 68, 68, 0.10);
    --info-soft:    rgba(59, 130, 246, 0.10);
    --shadow-xs:    0 1px 0 rgba(0, 0, 0, 0.5);
    --shadow-sm:    0 1px 2px rgba(0, 0, 0, 0.45);
    --shadow-md:    0 4px 14px rgba(0, 0, 0, 0.5);
    --shadow-lg:    0 12px 32px rgba(0, 0, 0, 0.55);
  }
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11', 'ss01';
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Typography */
h1, h2, h3, h4 { margin: 0; color: var(--text); font-weight: 600; letter-spacing: -0.014em; }
h1 { font-size: 22px; line-height: 1.25; letter-spacing: -0.02em; }
h2 { font-size: 15px; line-height: 1.4; }
h3 { font-size: 13.5px; }
p  { margin: 0; }
small, .muted { color: var(--text-muted); font-size: 12.5px; }
code, .mono {
  font-family: var(--font-mono); font-size: 12.5px;
  background: var(--surface-3); padding: 1px 6px;
  border-radius: var(--radius-xs); border: 1px solid var(--line);
}

/* Links */
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* Focus */
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible,
textarea:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; }

/* Skip link */
.skip-link {
  position: absolute; top: -40px; left: 8px;
  background: var(--accent); color: var(--accent-text);
  padding: 8px 14px; border-radius: var(--radius-sm);
  z-index: 100; transition: top 0.15s ease;
  font-weight: 500; font-size: 13px;
}
.skip-link:focus { top: 8px; color: var(--accent-text); }

/* ─────────── App shell ─────────── */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: var(--space-4) var(--space-3);
  position: sticky; top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 600; font-size: 14px;
  color: var(--text);
  padding: 6px var(--space-3);
  margin-bottom: var(--space-4);
  letter-spacing: -0.01em;
}
.brand-mark {
  width: 26px; height: 26px;
  border-radius: 7px;
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  color: white;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700;
  box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255, 255, 255, 0.16);
  letter-spacing: -0.02em;
}
.sidebar nav {
  display: flex; flex-direction: column;
  gap: 1px;
}
.sidebar-section-label {
  text-transform: uppercase;
  font-size: 10.5px;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  padding: var(--space-4) var(--space-3) 6px;
  font-weight: 600;
}
.sidebar nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 13px;
  transition: background 0.1s ease, color 0.1s ease;
}
.sidebar nav a .icon {
  width: 16px; height: 16px; flex-shrink: 0;
  color: currentColor; opacity: 0.85;
}
.sidebar nav a:hover {
  background: var(--surface-2);
  color: var(--text);
}
.sidebar nav a[aria-current="page"] {
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  box-shadow: inset 2px 0 0 var(--accent);
}
.sidebar nav a[aria-current="page"] .icon { color: var(--accent); opacity: 1; }

.sidebar-foot {
  margin-top: auto;
  padding-top: var(--space-3);
  border-top: 1px solid var(--line);
  display: grid; gap: 4px;
}
.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: inherit;
}
.user-chip:hover { background: var(--surface-2); color: inherit; }
.user-chip .avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #a855f7);
  color: white;
  display: grid; place-items: center;
  font-weight: 600; font-size: 10px;
  letter-spacing: 0;
  box-shadow: var(--shadow-xs), inset 0 1px 0 rgba(255, 255, 255, 0.18);
}
.user-chip .meta { display: grid; gap: 0; min-width: 0; flex: 1; }
.user-chip .meta strong {
  font-size: 12.5px; font-weight: 500; color: var(--text);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.user-chip .meta small {
  color: var(--text-faint);
  font-size: 11px; font-weight: 500;
  text-transform: capitalize; letter-spacing: 0;
}
.sidebar-foot .logout {
  font-size: 12.5px;
  color: var(--accent-text);
  padding: 6px 10px; border-radius: var(--radius-sm);
  display: flex; align-items: center; gap: 10px;
  font-weight: 500;
}
.sidebar-foot .logout:hover { background: var(--accent-hover); color: var(--accent-text); }
.sidebar-foot .logout .icon { width: 14px; height: 14px; opacity: 0.9; }

/* Main */
.main-area { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: var(--topbar-h);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: saturate(180%) blur(10px);
  -webkit-backdrop-filter: saturate(180%) blur(10px);
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: var(--space-4);
  padding: 0 var(--space-7);
}
@media (prefers-color-scheme: dark) {
  .topbar { background: rgba(17, 17, 19, 0.72); }
}
.topbar .crumbs {
  display: flex; align-items: center; gap: 6px;
  font-size: 13px; color: var(--text-muted);
  flex: 1; min-width: 0;
}
.topbar .crumbs strong { color: var(--text); font-weight: 500; }
.topbar .crumbs a { color: var(--text-muted); }
.topbar .crumbs a:hover { color: var(--text); }
.topbar .crumbs .sep { color: var(--text-faint); font-weight: 400; }

.content {
  padding: var(--space-7) var(--space-7) var(--space-9);
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
}
.content.narrow { max-width: 720px; }

/* Page header */
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
  flex-wrap: wrap;
}
.page-head .title { display: grid; gap: 6px; }
.page-head .title h1 { letter-spacing: -0.025em; }
.page-head .title p { color: var(--text-muted); font-size: 13.5px; }
.page-actions { display: flex; gap: var(--space-2); align-items: center; flex-wrap: wrap; }

/* Panel */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  box-shadow: var(--shadow-xs);
}
.panel + .panel { margin-top: var(--space-4); }
.content > * + * { margin-top: var(--space-4); }
.content > .page-head + * { margin-top: 0; }
.content > section + section,
.content > .panel + section,
.content > section + .panel,
.content > .metrics + .panel,
.content > .panel + .metrics,
.content > .metrics + section { margin-top: var(--space-4); }
.panel h2 + .grid-2,
.panel h2 + .grid-3,
.panel h2 + .grid-4 { margin-top: var(--space-3); }
.panel h2:not(:first-child) { margin-top: var(--space-5); }
.chip.danger { color: var(--danger); border-color: var(--danger-soft); }
.panel > h2:first-child, .panel > h1:first-child { margin-bottom: var(--space-4); }
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}
.panel-head h2 { font-size: 14px; }

/* Buttons */
button, .button {
  font: inherit; font-size: 13px; font-weight: 500;
  padding: 7px 13px;
  min-height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--accent); color: var(--accent-text);
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  transition: background 0.12s ease, border-color 0.12s ease,
              color 0.12s ease, box-shadow 0.12s ease, transform 0.05s ease;
  text-decoration: none;
  letter-spacing: -0.005em;
  box-shadow: var(--shadow-xs), inset 0 1px 0 rgba(255, 255, 255, 0.12);
  white-space: nowrap;
}
button:hover, .button:hover {
  background: var(--accent-hover);
  color: var(--accent-text);
}
button:active, .button:active { transform: translateY(0.5px); }
button:focus-visible, .button:focus-visible { box-shadow: var(--ring); }
button:disabled, .button:disabled { opacity: 0.5; cursor: not-allowed; }

button.secondary, .button.secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--line-strong);
  box-shadow: var(--shadow-xs);
}
button.secondary:hover, .button.secondary:hover {
  background: var(--surface-2);
  border-color: var(--line-strong);
  color: var(--text);
}

button.ghost, .button.ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: transparent;
  box-shadow: none;
}
button.ghost:hover, .button.ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}

button.danger, .button.danger {
  background: var(--danger);
  border-color: transparent;
  color: white;
}
button.danger:hover, .button.danger:hover { background: #991b1b; color: white; }

button.sm, .button.sm {
  min-height: 28px;
  padding: 4px 9px;
  font-size: 12px;
  border-radius: var(--radius-xs);
}

button.lg, .button.lg {
  min-height: 38px;
  padding: 9px 18px;
  font-size: 14px;
}

a.chip, button.chip {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--line);
  box-shadow: none;
}
a.chip:hover, button.chip:hover {
  background: var(--surface-3);
  color: var(--text);
  border-color: var(--line-strong);
}
a.chip.danger, button.chip.danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: transparent;
}
a.chip.danger:hover, button.chip.danger:hover {
  background: var(--danger);
  color: #fff;
}
a.chip.success, button.chip.success {
  background: var(--success-soft);
  color: var(--success);
  border-color: transparent;
}
a.chip.success:hover, button.chip.success:hover {
  background: var(--success);
  color: #fff;
}

/* Forms */
form { display: grid; gap: var(--space-4); }
form.inline { display: inline; }
label {
  display: grid; gap: 6px;
  font-weight: 500; font-size: 12.5px;
  color: var(--text);
  letter-spacing: -0.005em;
}
label.compact {
  display: inline-flex; align-items: center; gap: 7px;
  font-weight: 500; font-size: 13px;
  color: var(--text-muted);
}
fieldset.panel-subsection {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  display: grid;
  gap: var(--space-2);
}
fieldset.panel-subsection legend {
  padding: 0 var(--space-2);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}
input, select, textarea {
  font: inherit; font-size: 13.5px;
  padding: 7px 11px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  color: var(--text);
  border-radius: var(--radius-sm);
  min-height: 34px;
  width: 100%;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
textarea { min-height: 96px; resize: vertical; line-height: 1.55; }
input:hover, select:hover, textarea:hover { border-color: var(--text-faint); }
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: var(--ring);
}
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input[type="checkbox"], input[type="radio"] {
  width: auto; min-height: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
input[type="file"] { padding: 4px; cursor: pointer; }
.file-dropzone {
  position: relative;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
  min-height: 132px;
  overflow: hidden;
  transition: border-color 0.12s ease, box-shadow 0.12s ease, background 0.12s ease, transform 0.12s ease;
}
.file-dropzone:hover {
  border-color: var(--accent);
  background: linear-gradient(180deg, var(--surface) 0%, var(--accent-soft) 100%);
}
.file-dropzone:focus-within,
.file-dropzone.is-dragover {
  border-color: var(--accent);
  box-shadow: var(--ring);
  background: linear-gradient(180deg, var(--surface) 0%, var(--accent-soft) 100%);
}
.file-dropzone.has-file {
  border-style: solid;
  border-color: var(--accent);
}
.file-dropzone-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  padding: 0;
  margin: 0;
  z-index: 1;
}
.file-dropzone-input:disabled {
  cursor: not-allowed;
}
.file-dropzone-body {
  pointer-events: none;
  min-height: 132px;
  display: grid;
  place-content: center;
  gap: var(--space-2);
  padding: var(--space-5);
  text-align: center;
}
.file-dropzone-body strong {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}
.file-dropzone-body span {
  font-size: 12.5px;
  color: var(--text-muted);
}
.file-dropzone-meta {
  justify-self: center;
  max-width: min(100%, 360px);
  display: inline-block;
  padding: 5px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-dropzone.has-file .file-dropzone-meta {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
}
.reference-prompt-field {
  position: relative;
  display: grid;
  gap: var(--space-2);
}
.reference-prompt-stack {
  position: relative;
}
.reference-prompt-source[hidden] {
  display: none;
}
.reference-prompt-editor {
  min-height: calc(5 * 1.55em + 14px);
  width: 100%;
  padding: 7px 11px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  color: var(--text);
  border-radius: var(--radius-sm);
  line-height: 1.55;
  font: inherit;
  font-size: 13.5px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  cursor: text;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.reference-prompt-editor:hover {
  border-color: var(--text-faint);
}
.reference-prompt-editor:focus,
.reference-prompt-editor:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.reference-prompt-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--text-faint);
  pointer-events: none;
}
.reference-prompt-editor .prompt-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 2px;
  padding: 2px 8px 2px 3px;
  border-radius: var(--radius-sm);
  background:
    linear-gradient(135deg,
      color-mix(in srgb, var(--info-soft) 72%, var(--surface)) 0%,
      color-mix(in srgb, var(--warning-soft) 68%, var(--surface)) 100%);
  color: var(--text);
  border: 1px solid color-mix(in srgb, var(--info) 34%, var(--line));
  vertical-align: baseline;
  line-height: 1.35;
  white-space: nowrap;
  user-select: none;
  -webkit-user-select: none;
  box-shadow:
    inset 3px 0 0 color-mix(in srgb, var(--info) 68%, transparent),
    0 1px 2px rgba(17, 24, 39, 0.08);
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}
.reference-prompt-editor .prompt-chip-thumb {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
}
.reference-prompt-editor .prompt-chip img {
  width: 22px;
  height: 22px;
  border-radius: var(--radius-xs);
  object-fit: cover;
  display: block;
  background: var(--surface);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--info) 35%, transparent);
  pointer-events: none;
}
.reference-prompt-editor .prompt-chip-token {
  white-space: pre;
  line-height: inherit;
  font-weight: 650;
}
.reference-upload-list {
  display: grid;
  gap: var(--space-4);
  margin-top: var(--space-3);
}
.reference-upload-section {
  display: grid;
  gap: var(--space-2);
}
.reference-upload-section-title {
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}
.reference-upload-section-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 180px));
  justify-content: start;
  gap: var(--space-3);
}
.reference-upload-card,
.reference-alias-option {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}
.reference-upload-card {
  position: relative;
}
.reference-upload-card-select {
  appearance: none;
  display: block;
  width: 100%;
  padding: 0;
  background: transparent;
  border: 0;
  text-align: left;
  color: inherit;
  cursor: pointer;
}
.reference-upload-card-static {
  cursor: default;
}
button.reference-upload-card-select:hover,
button.reference-upload-card-select:focus-visible {
  background: var(--surface-2);
  color: inherit;
  outline: none;
}
.reference-upload-card:has(button.reference-upload-card-select:hover),
.reference-upload-card:has(button.reference-upload-card-select:focus-visible) {
  border-color: var(--accent);
  box-shadow: var(--ring);
}
.reference-upload-card img,
.reference-alias-option img {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: contain;
  box-sizing: border-box;
  padding: 6px;
  background: var(--surface-2);
}
.reference-upload-card-meta {
  display: grid;
  gap: 2px;
  padding: var(--space-3);
}
.reference-upload-card-meta span {
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
}
.reference-upload-card-meta small {
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reference-upload-card-remove {
  appearance: none;
  position: absolute;
  top: 8px;
  right: 8px;
  width: 34px;
  height: 34px;
  min-height: 34px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid color-mix(in srgb, var(--danger) 45%, var(--line));
  background: rgba(255, 255, 255, 0.98);
  color: var(--danger);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  z-index: 3;
  line-height: 1;
  transition: background 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease, transform 0.12s ease;
}
.reference-upload-card-remove:hover,
.reference-upload-card-remove:focus-visible {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 70%, var(--line));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--danger) 16%, transparent), var(--shadow-sm);
  transform: translateY(-1px);
}
.reference-upload-card-remove .bi {
  font-size: 16px;
  line-height: 1;
}
.reference-alias-popup {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 8px);
  z-index: 20;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  padding: var(--space-3);
  display: grid;
  gap: var(--space-3);
  max-height: 360px;
  overflow: auto;
}
.reference-alias-popup[hidden] {
  display: none;
}
.reference-alias-popup-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-2);
}
.reference-alias-popup-head span {
  font-size: 12px;
  color: var(--text-muted);
}
.reference-alias-popup-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: var(--space-2);
}
.reference-alias-option {
  appearance: none;
  width: 100%;
  padding: 0;
  text-align: left;
  cursor: pointer;
}
.reference-alias-option span {
  display: grid;
  gap: 2px;
  padding: var(--space-3);
}
.reference-alias-option small {
  color: var(--text-muted);
}
.lb-validation-list {
  display: grid;
  gap: var(--space-2);
  padding: 0;
  margin: 0;
  list-style: none;
}
.lb-validation-list li {
  display: grid;
  gap: 2px;
  padding: var(--space-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}
.lb-validation-list span,
.lb-validation-list small {
  color: var(--text-muted);
  font-size: 12px;
}
.reference-alias-option:hover,
.reference-alias-option:focus-visible,
.reference-alias-option.is-active {
  border-color: var(--accent);
  box-shadow: var(--ring);
}
input[type="range"] { padding: 0; min-height: 0; accent-color: var(--accent); }
input:disabled, select:disabled, textarea:disabled {
  background: var(--surface-3);
  color: var(--text-muted);
  cursor: not-allowed;
}
select {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2371717a' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'></polyline></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
}

/* Grid helpers */
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-3); }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--space-3); }
.grid-4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--space-3); }
.profile-overview {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding-block: var(--space-4);
}
.profile-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #a855f7);
  color: white;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
  box-shadow: var(--shadow-xs), inset 0 1px 0 rgba(255, 255, 255, 0.18);
  flex: 0 0 auto;
}
.profile-overview-copy {
  display: grid;
  gap: 2px;
  min-width: 0;
}
.profile-overview-copy h2 {
  font-size: 15px;
  overflow-wrap: anywhere;
}
.profile-overview-copy p {
  color: var(--text-muted);
  font-size: 12.5px;
}
.profile-form {
  display: grid;
  grid-template-columns: minmax(160px, 220px) minmax(0, 1fr);
  gap: var(--space-6);
  align-items: start;
}
.profile-form-copy {
  display: grid;
  gap: 6px;
}
.profile-form-copy h2 {
  font-size: 14px;
}
.profile-form-copy p {
  color: var(--text-muted);
  font-size: 12.5px;
}
.profile-form-fields {
  display: grid;
  gap: var(--space-3);
}
.profile-form-actions {
  display: flex;
  justify-content: flex-end;
  padding-top: var(--space-1);
}
@media (max-width: 760px) {
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .profile-form { grid-template-columns: 1fr; gap: var(--space-4); }
  .profile-form-actions { justify-content: stretch; }
  .profile-form-actions button { width: 100%; }
}

.stack { display: grid; gap: var(--space-4); }
.stack.sm { gap: var(--space-2); }
.stack > * { margin: 0; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: var(--space-4); }
.chip-list { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
}
.inline-actions { display: flex; gap: var(--space-2); align-items: center; justify-content: flex-end; flex-wrap: wrap; }
.form-note { margin-top: -6px; }

/* Metrics */
.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: var(--space-3);
  margin-bottom: var(--space-5);
}
.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--space-4) var(--space-5);
  box-shadow: var(--shadow-xs);
  display: grid; gap: 6px;
  position: relative;
}
.metric .label {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0;
  text-transform: none;
}
.metric .value {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.025em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.metric .muted { font-size: 12px; }
.metric .delta { font-size: 12px; color: var(--success); font-weight: 500; }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px; font-weight: 500;
  background: var(--surface-3); color: var(--text-muted);
  border: 1px solid var(--line);
  letter-spacing: 0;
  text-transform: none;
  line-height: 1.5;
}
.badge::before {
  content: ''; display: inline-block;
  width: 5px; height: 5px; border-radius: 50%;
  background: currentColor; opacity: 0.7;
}
.badge.success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge.warning { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge.danger  { background: var(--danger-soft);  color: var(--danger);  border-color: transparent; }
.badge.info    { background: var(--info-soft);    color: var(--info);    border-color: transparent; }
.badge.accent  { background: var(--accent-soft);  color: var(--accent);  border-color: transparent; }
.badge.queued,
.badge.not_started,
.badge.pending,
.badge.spawned { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge.running,
.badge.processing,
.badge.finalizing,
.badge.active { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge.completed,
.badge.succeeded,
.badge.ready,
.badge.done { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge.failed,
.badge.error,
.badge.timed_out,
.badge.cancelled,
.badge.deleted { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

/* Tables */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-xs);
}
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead { background: var(--surface-2); }
th, td {
  text-align: left;
  padding: 10px var(--space-4);
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
th {
  font-weight: 500;
  color: var(--text-muted);
  font-size: 11.5px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.preset-reference-thumb {
  display: block;
  width: 86px;
  aspect-ratio: 4 / 3;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--line);
  background: var(--surface-2);
  box-shadow: var(--shadow-xs);
}
.preset-reference-thumb:hover {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.preset-reference-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.1s ease; }
tbody tr:hover { background: var(--surface-2); }
td.actions, th.actions { text-align: right; white-space: nowrap; }
.provider-log-toggle {
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--accent);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.provider-log-toggle:hover,
.provider-log-toggle:focus-visible {
  color: var(--accent-strong);
  text-decoration: underline;
}
.provider-log-detail-row:hover {
  background: transparent;
}
.provider-log-detail-row td {
  padding-top: 0;
  background: var(--surface);
}
.provider-log-detail-panel {
  margin: 0 0 var(--space-3);
  padding: var(--space-4);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-2);
}
.provider-log-detail-section + .provider-log-detail-section {
  margin-top: var(--space-4);
}
.provider-log-detail-section h3 {
  margin: var(--space-3) 0 var(--space-1);
  font-size: 12px;
  color: var(--text-muted);
}
.log-response {
  max-width: 100%;
  max-height: 420px;
  overflow: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--surface-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text);
}

/* Image grid */
.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--space-4);
}
.job-watch {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
}
.job-watch-copy {
  display: grid;
  gap: 2px;
}
.job-watch-copy strong {
  font-size: 13px;
}
.job-watch-copy small {
  color: var(--text-muted);
}
.job-watch-spinner,
.job-card-spinner {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 3px solid color-mix(in srgb, var(--accent) 24%, transparent);
  border-top-color: var(--accent);
  animation: btn-spin 0.9s linear infinite;
  flex: 0 0 auto;
}
.job-watch[data-state="succeeded"] {
  border-color: color-mix(in srgb, var(--success) 32%, var(--line-strong));
  background: var(--success-soft);
}
.job-watch[data-state="succeeded"] .job-watch-copy small {
  color: var(--success);
}
.job-watch[data-state="failed"] {
  border-color: color-mix(in srgb, var(--danger) 45%, var(--line-strong));
  background: var(--danger-soft);
}
.job-watch[data-state="failed"] .job-watch-copy small {
  color: var(--danger);
}
.job-watch[data-state="succeeded"] .job-watch-spinner,
.job-watch[data-state="failed"] .job-watch-spinner {
  animation: none;
  border-color: transparent;
  position: relative;
}
.job-watch[data-state="succeeded"] .job-watch-spinner::before,
.job-watch[data-state="failed"] .job-watch-spinner::before {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 18px;
  font-weight: 700;
}
.job-watch[data-state="succeeded"] .job-watch-spinner::before {
  content: '✓';
  color: var(--success);
}
.job-watch[data-state="failed"] .job-watch-spinner::before {
  content: '!';
  color: var(--danger);
}
.album-toolbar {
  padding: var(--space-3) var(--space-4);
}
.album-toolbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.album-current-view {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.album-current-view strong {
  font-size: 15px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.album-view-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 3px;
}
.album-view-toggle button {
  border: 0;
  background: transparent;
  padding: 4px 10px;
  font-size: 12.5px;
  border-radius: calc(var(--radius) - 3px);
  color: var(--text-muted);
}
.album-view-toggle button.is-active {
  background: var(--accent);
  color: var(--accent-text);
}
.album-select-all-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text-muted);
  cursor: pointer;
}
.album-select-all-label input { margin: 0; }
.album-shell {
  display: grid;
  grid-template-columns: minmax(240px, 290px) minmax(0, 1fr);
  gap: var(--space-4);
  align-items: start;
}
.album-sidebar {
  display: grid;
  gap: var(--space-4);
  position: sticky;
  top: var(--space-4);
}
.album-sidebar-section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
  box-shadow: var(--shadow-xs);
}
.album-sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: 0 4px var(--space-2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  color: var(--text-muted);
}
.album-folder-empty {
  font-size: 12.5px;
  padding: var(--space-2) 4px;
  margin: 0;
}
.album-new-folder { position: relative; }
.album-new-folder summary.album-new-folder-toggle {
  list-style: none; cursor: pointer;
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 12px; padding: 4px 9px;
  text-transform: none; letter-spacing: 0;
}
.album-new-folder summary::-webkit-details-marker { display: none; }
.album-new-folder[open] summary { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.album-folder-create {
  position: absolute; top: calc(100% + 6px); right: 0;
  z-index: 20;
  display: flex; gap: 6px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  padding: 8px;
  min-width: 240px;
}
.album-folder-create input { flex: 1; min-width: 0; }
.album-folder-list {
  display: grid;
  gap: 4px;
}
.album-folder-link {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-2);
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text);
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease;
}
.album-folder-link:hover { background: var(--surface-2); }
.album-folder-icon {
  font-size: 18px;
  line-height: 1;
  display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px;
  color: var(--text-muted);
}
.album-folder-icon-favorite { color: #f59e0b; }
.album-folder-text { min-width: 0; display: grid; gap: 0; }
.album-folder-text strong,
.album-folder-text small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}
.album-folder-text strong { font-weight: 600; }
.album-folder-text small {
  color: var(--text-muted);
  font-size: 11.5px;
  font-weight: 400;
}
.album-folder-link.is-current,
.album-folder-row.is-current .album-folder-link {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
}
.album-folder-link.is-current .album-folder-icon,
.album-folder-row.is-current .album-folder-icon { color: var(--accent); }
.album-folder-link.is-current .album-folder-text small,
.album-folder-row.is-current .album-folder-text small { color: var(--accent); opacity: 0.75; }
.album-folder-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  border-radius: var(--radius);
  position: relative;
}
.album-folder-row .album-folder-link { padding-right: 4px; }
.album-folder-row.is-dragover,
.album-folder-link.is-dragover {
  background: rgba(99,102,241,0.10);
  outline: 2px dashed var(--accent);
  outline-offset: -2px;
}
.album-folder-row.is-dragover .album-folder-link,
.album-folder-link.is-dragover { background: transparent; }
.album-folder-menu { margin-left: 0; padding-right: 6px; }
.album-folder-menu summary { width: 24px; height: 24px; font-size: 16px; }
.album-main {
  min-width: 0;
  display: grid;
  gap: var(--space-4);
}

/* Sticky selection bar */
.album-selection-bar {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(8px);
  z-index: 80;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  box-shadow: 0 16px 40px rgba(15,23,42,0.18), 0 2px 8px rgba(15,23,42,0.08);
  padding: 6px 8px 6px 18px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.album-selection-bar.is-visible {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(-50%) translateY(0);
}
.album-selection-bar-inner {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}
.album-selection-bar-count {
  display: inline-flex; align-items: baseline; gap: 4px;
  font-size: 13px;
  color: var(--text);
}
.album-selection-bar-count strong { font-size: 16px; color: var(--accent); }
.album-selection-bar-actions {
  display: inline-flex; align-items: center; gap: 6px;
  flex-wrap: wrap;
}
.album-selection-bar-move {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--surface-2);
  border-radius: 999px;
  padding: 2px 4px 2px 10px;
}
.album-selection-bar-move select {
  border: 0; background: transparent;
  font-size: 12.5px;
  padding: 4px 4px;
  min-width: 110px;
}
.album-selection-bar-move button {
  min-height: 24px; padding: 4px 12px;
  border-radius: 999px;
}
.album-selection-bar-actions form.inline button {
  border-radius: 999px;
  padding: 4px 14px;
}
.album-selection-bar-actions .button.ghost { padding: 4px 12px; border-radius: 999px; }
.album-results-wrap {
  display: grid;
  gap: var(--space-4);
}
.album-results.is-list {
  display: flex;
  flex-direction: column;
}
.image-card {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-xs);
  transition: box-shadow 0.18s ease, transform 0.18s ease, border-color 0.18s ease;
}
.image-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  border-color: var(--line-strong);
}
.image-card.is-selected {
  border-color: rgba(99, 102, 241, 0.42);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12), var(--shadow-md);
}
.image-card-thumb {
  position: relative;
  overflow: hidden;
  border-top-left-radius: calc(var(--radius-lg) - 1px);
  border-top-right-radius: calc(var(--radius-lg) - 1px);
  background: var(--surface-3);
}
.image-card-thumb > a[data-lightbox] { display: block; }
.image-card img {
  width: 100%; height: 200px;
  object-fit: cover; display: block;
  background: var(--surface-3);
}
.image-card-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4) 0;
}
.image-card-select-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}
.image-card-select-row input {
  margin: 0;
  inline-size: 16px;
  block-size: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}
.image-card-favorite-form {
  margin: 0;
  margin-left: auto;
}
.image-card-favorite {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  inline-size: 36px;
  block-size: 36px;
  padding: 0;
  border-radius: 999px;
  border: 1px solid rgba(15, 23, 42, 0.10);
  background: rgba(255, 255, 255, 0.96);
  color: #64748b;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
  transition: transform 0.18s ease, background 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease, color 0.18s ease;
}
.image-card-favorite:hover {
  transform: translateY(-1px);
  border-color: rgba(244, 114, 182, 0.24);
  color: #e11d48;
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.10);
}
.image-card-favorite-heart {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  inline-size: 20px;
  block-size: 20px;
}
.image-card-favorite-icon {
  font-size: 18px;
  line-height: 1;
  transition: transform 0.18s ease;
}
.image-card-favorite.is-active {
  background: rgba(255, 241, 242, 0.98);
  color: #be123c;
  border-color: rgba(225, 29, 72, 0.25);
}
.image-card-favorite.is-active .image-card-favorite-icon {
  transform: scale(1.12);
}

@keyframes favorite-pulse {
  0%   { transform: scale(1); }
  30%  { transform: scale(1.35); }
  60%  { transform: scale(0.9); }
  100% { transform: scale(1); }
}
.image-card-favorite.is-favorite-pulse .image-card-favorite-icon {
  animation: favorite-pulse 0.42s ease forwards;
}
.image-card-badges {
  position: absolute; left: 8px; bottom: 8px;
  display: inline-flex;
  flex-wrap: wrap;
  gap: 4px;
  z-index: 2;
}
.image-card-badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.02em;
  padding: 3px 8px; border-radius: 999px;
  color: #fff;
  background: rgba(15,23,42,0.78);
  backdrop-filter: blur(4px);
}
.image-card-badge-shared { background: rgba(99,102,241,0.92); }
.image-card-badge-4k { background: rgba(3, 105, 161, 0.9); }
.image-card-badge-workflow { background: rgba(20, 83, 45, 0.9); }
.image-card-badge-processing {
  background: rgba(180, 83, 9, 0.94);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.24) inset;
}
.image-card-badge-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #fef3c7;
  box-shadow: 0 0 0 0 rgba(254, 243, 199, 0.78);
  animation: workflow-processing-pulse 1.3s ease-out infinite;
}
.image-card.is-workflow-processing {
  border-color: rgba(180, 83, 9, 0.28);
}
.image-card-processing-copy {
  color: #92400e !important;
  font-weight: 600;
}
.image-card-badge-folder { background: rgba(107, 33, 168, 0.88); max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@keyframes workflow-processing-pulse {
  0% { box-shadow: 0 0 0 0 rgba(254, 243, 199, 0.78); }
  70% { box-shadow: 0 0 0 6px rgba(254, 243, 199, 0); }
  100% { box-shadow: 0 0 0 0 rgba(254, 243, 199, 0); }
}
.image-card-meta {
  display: grid; gap: 2px;
  padding: var(--space-3) var(--space-4) var(--space-2);
  min-width: 0;
}
.image-card-meta strong {
  font-size: 13.5px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.image-card-meta small {
  color: var(--text-muted);
  font-size: 11.5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.image-card-footer {
  display: flex; align-items: center; gap: 6px;
  padding: var(--space-2) var(--space-3) var(--space-3);
  margin-top: auto;
  flex-wrap: wrap;
}
.image-card-footer form.inline { display: inline-flex; margin: 0; }
.image-card-footer > .button,
.image-card-footer button {
  min-height: 28px; padding: 4px 10px;
  font-size: 12px; font-weight: 500;
  border-radius: var(--radius-xs);
  display: inline-flex; align-items: center; gap: 4px;
}
.image-card-action-share { color: var(--accent); }
.image-card-action-share:hover { background: var(--accent-soft); border-color: transparent; }
@media (max-width: 480px) {
  .image-card-action-label { display: none; }
}
.image-card-menu { position: relative; margin-left: auto; }
.image-card-menu summary {
  list-style: none; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 26px;
  border: 1px solid transparent; border-radius: var(--radius-xs);
  color: var(--text-muted);
  font-size: 18px; line-height: 1;
  user-select: none;
}
.image-card-menu summary::-webkit-details-marker { display: none; }
.image-card-menu summary:hover,
.image-card-menu[open] summary {
  background: var(--surface-2);
  border-color: var(--line);
  color: var(--text);
}
.image-card-menu-panel {
  position: absolute; right: 0; bottom: calc(100% + 4px);
  z-index: 30;
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  padding: 4px;
  display: flex; flex-direction: column; gap: 1px;
}
.image-card-menu-panel form.inline,
.image-card-menu-panel form { display: block; margin: 0; }
.image-card-menu-panel .menu-item {
  display: block; width: 100%; text-align: left;
  padding: 7px 10px; min-height: 0;
  background: transparent; border: 0; color: var(--text);
  font-size: 12.5px; font-weight: 500;
  border-radius: var(--radius-xs); cursor: pointer;
}
.image-card-menu-panel .menu-item:hover,
.image-card-menu-panel .menu-item:focus-visible {
  background: var(--surface-2); color: var(--text); outline: none;
}
.image-card-menu-panel .menu-item.danger { color: var(--danger); }
.image-card-menu-panel .menu-item.danger:hover { background: var(--danger-soft); }
.image-card-menu-panel .menu-item-option {
  display: flex; align-items: center; gap: 6px;
  padding: 4px 10px 8px; font-size: 11.5px; color: var(--text-muted);
}
.image-card-menu-panel .menu-item-option input { margin: 0; }
.image-card-menu-panel .menu-divider {
  border: 0; border-top: 1px solid var(--line);
  margin: 3px 2px;
}
.image-card-share { padding-bottom: 2px; }

.album-results.is-list .image-card {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr) auto;
  gap: var(--space-3);
  align-items: center;
  padding: var(--space-3);
}
.album-results.is-list .image-card:hover {
  transform: none;
}
.album-results.is-list .image-card-thumb {
  grid-column: 1;
  grid-row: 1 / span 2;
  width: 88px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
}
.album-results.is-list .image-card img,
.album-results.is-list .placeholder-art {
  width: 88px;
  height: 60px;
}
.album-results.is-list .image-card-meta {
  grid-column: 2;
  grid-row: 2;
  padding: 0;
  gap: 4px;
}
.album-results.is-list .image-card-controls {
  grid-column: 2;
  grid-row: 1;
  padding: 0;
}
.album-results.is-list .image-card-footer {
  grid-column: 3;
  grid-row: 1 / span 2;
  padding: 0;
  gap: var(--space-2);
  flex-wrap: wrap;
  justify-content: flex-end;
}
.album-results.is-list .image-card-menu {
  margin-left: 0;
}
.album-results.is-list .image-card-badges {
  top: 36px;
  right: 6px;
}

.album-load-indicator {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 44px;
  color: var(--text-muted);
}
.album-load-indicator[hidden],
.album-load-end[hidden] {
  display: none;
}
.album-load-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: album-spin 0.8s linear infinite;
}
.album-load-end {
  text-align: center;
}
.album-load-sentinel {
  height: 1px;
}
@keyframes album-spin {
  to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
  .album-load-spinner {
    animation: none;
    border-top-color: var(--line-strong);
  }
}

.image-card.placeholder { border-style: dashed; box-shadow: none; }
.image-card.placeholder .image-card-meta strong { color: var(--accent); }
.image-card.failed { border-color: var(--danger); }
.image-card.failed .image-card-meta strong,
.image-card.failed .image-meta strong { color: var(--danger); }
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}
.placeholder-art {
  height: 200px;
  background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 37%, var(--surface-3) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.6s ease infinite;
}
.job-card-status {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: var(--space-2);
  padding: var(--space-4);
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.08), rgba(15, 23, 42, 0.28));
  text-align: center;
}
.job-card-copy {
  display: grid;
  gap: 2px;
}
.job-card-copy strong {
  color: #fff;
  font-size: 14px;
}
.job-card-copy small {
  color: rgba(255, 255, 255, 0.86);
  font-size: 11.5px;
  max-width: 18rem;
}
.image-card.failed .job-card-status {
  background: linear-gradient(180deg, rgba(127, 29, 29, 0.18), rgba(127, 29, 29, 0.34));
}
.image-card.failed .job-card-spinner {
  animation: none;
  border-color: color-mix(in srgb, var(--danger) 30%, transparent);
  position: relative;
}
.image-card.failed .job-card-spinner::before {
  content: '!';
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 18px;
  font-weight: 700;
  color: var(--danger);
}
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
@media (prefers-reduced-motion: reduce) {
  .placeholder-art,
  .job-watch-spinner,
  .job-card-spinner {
    animation: none;
  }
}
@media (max-width: 760px) {
  .album-results.is-list .image-card {
    grid-template-columns: 72px minmax(0, 1fr);
    grid-template-rows: auto auto auto;
  }
  .album-results.is-list .image-card-thumb,
  .album-results.is-list .image-card img,
  .album-results.is-list .placeholder-art {
    width: 72px;
    height: 52px;
  }
  .album-results.is-list .image-card-thumb {
    grid-row: 1 / span 3;
  }
  .album-results.is-list .image-card-controls {
    grid-column: 2;
    grid-row: 1;
    justify-content: space-between;
  }
  .album-results.is-list .image-card-meta {
    grid-column: 2;
    grid-row: 2;
  }
  .album-results.is-list .image-card-controls,
  .album-results.is-list .image-card-footer {
    grid-column: 2;
    justify-content: flex-start;
  }
  .album-results.is-list .image-card-footer {
    grid-row: 3;
  }
}

/* Empty states */
.empty {
  text-align: center;
  padding: var(--space-10) var(--space-5);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
  background: var(--surface);
}
.empty h2 {
  color: var(--text); margin-bottom: 6px; font-size: 16px;
}
.empty p { font-size: 13.5px; margin-bottom: var(--space-4); }
.empty .icon-lg {
  width: 40px; height: 40px;
  margin: 0 auto var(--space-3);
  color: var(--text-faint);
}
/* Shared with me */
.shared-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--space-4);
}
.shared-card {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
  text-decoration: none;
  color: var(--text);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
.shared-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--line-strong);
}
.shared-card-thumb {
  position: relative;
  height: 170px;
  background: var(--surface-3);
  overflow: hidden;
}
.shared-card-thumb img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.shared-card-thumb-folder {
  background: linear-gradient(135deg, var(--accent-soft) 0%, var(--surface-3) 100%);
}
.shared-card-placeholder {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  color: var(--accent);
}
.shared-card-placeholder svg { width: 64px; height: 64px; }
.shared-card-lock {
  position: absolute; top: 8px; left: 8px;
  background: rgba(15,23,42,0.82);
  color: #fff;
  border-radius: 999px;
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px;
}
.shared-card-type {
  position: absolute; top: 8px; right: 8px;
  background: rgba(255,255,255,0.95);
  color: var(--text);
  font-size: 10.5px; font-weight: 600;
  letter-spacing: 0.04em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 999px;
}
.shared-card-body {
  display: grid;
  gap: 4px;
  padding: var(--space-3) var(--space-4) var(--space-4);
}
.shared-card-title {
  font-size: 14px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.shared-card-meta, .shared-card-owner {
  font-size: 11.5px; color: var(--text-muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Share preview (public token) */
.shared-preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--space-4);
}
.shared-preview-card {
  display: grid;
  gap: var(--space-2);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: var(--space-3);
  box-shadow: var(--shadow-xs);
}
.shared-preview-thumb {
  width: 100%;
  height: 180px;
  object-fit: cover;
  border-radius: var(--radius);
  background: var(--surface-3);
}
.shared-preview-title {
  font-size: 13px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.share-single-grid {
  grid-template-columns: minmax(280px, 460px);
}
.share-preview-single {
  display: grid; gap: var(--space-3); justify-items: center;
  padding: var(--space-4); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-lg);
}
.share-preview-single .shared-image {
  max-width: 100%; max-height: 70vh;
  border-radius: var(--radius);
}
.share-preview-single-caption { margin: 0; }

/* Share preview banner */
.share-preview-banner {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--accent-soft);
  border-radius: var(--radius-lg);
  border: 1px solid transparent;
  margin-bottom: var(--space-4);
}
.share-preview-banner-icon {
  font-size: 22px;
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.7);
  border-radius: 999px;
  flex-shrink: 0;
}
.share-preview-banner-text {
  flex: 1; min-width: 0;
  display: flex; flex-direction: column; gap: 2px;
  font-size: 13px;
}
.share-preview-banner-text strong { color: var(--accent); }
.share-preview-banner-text span { color: var(--text-muted); }

/* Share unlock (full-screen focused) */
.share-unlock-screen {
  display: flex; align-items: center; justify-content: center;
  min-height: 60vh;
  padding: var(--space-4);
}
.share-unlock-card {
  width: 100%;
  max-width: 420px;
  display: grid;
  gap: var(--space-3);
  text-align: center;
  padding: var(--space-5) var(--space-4);
}
.share-unlock-card h1 { margin: 0; font-size: 22px; }
.share-unlock-card p { margin: 0; }
.share-unlock-icon {
  margin: 0 auto var(--space-2);
  width: 64px; height: 64px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent);
  border-radius: 999px;
  font-size: 28px;
}
.share-unlock-form {
  display: grid; gap: var(--space-3);
  margin-top: var(--space-2);
}
.share-unlock-form input { text-align: center; font-size: 15px; padding: 10px; }

/* Share manage */
.share-send-panel { display: grid; gap: var(--space-2); }
.share-send-form { display: grid; gap: var(--space-2); }
.share-send-grid {
  display: grid;
  grid-template-columns: 2fr 1fr auto;
  gap: var(--space-3);
  align-items: end;
}
.share-send-field { display: grid; gap: 4px; }
.share-send-field span { font-size: 12.5px; color: var(--text-muted); }
.share-send-actions { display: flex; align-items: stretch; }
.share-send-actions button { white-space: nowrap; }
.share-send-hint { display: block; }
@media (max-width: 720px) {
  .share-send-grid { grid-template-columns: 1fr; }
}
.share-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.share-list-item {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.share-list-item:hover { border-color: var(--line-strong); }
.share-list-icon {
  width: 36px; height: 36px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--accent-soft); color: var(--accent);
  border-radius: 999px;
  font-size: 16px;
}
.share-list-body { min-width: 0; display: grid; gap: 2px; }
.share-list-head {
  display: flex; align-items: center; gap: var(--space-2);
  flex-wrap: wrap;
}
.share-list-head strong {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  min-width: 0;
}
.share-list-actions {
  display: inline-flex; gap: 6px;
  align-items: center;
}
.empty-compact { padding: var(--space-3) var(--space-4); }
.empty-compact p { margin: 0; }

.share-lock-panel {
  display: grid;
  gap: var(--space-3);
}

/* Flash */
.flash {
  padding: 10px var(--space-4);
  border-radius: var(--radius);
  margin-bottom: var(--space-4);
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 13px;
  display: flex; gap: var(--space-2); align-items: center;
  box-shadow: var(--shadow-xs);
}
.flash.error  { background: var(--danger-soft);  border-color: transparent; color: var(--danger); }
.flash.success{ background: var(--success-soft); border-color: transparent; color: var(--success); }
.flash.info   { background: var(--info-soft);    border-color: transparent; color: var(--info); }

/* Cookie banner */
.cookie-banner {
  position: fixed;
  z-index: 220;
  width: min(460px, calc(100vw - 2 * var(--space-4)));
}
.cookie-banner-bottom-right { right: var(--space-5); bottom: var(--space-5); }
.cookie-banner-bottom-center { left: 50%; bottom: var(--space-5); transform: translateX(-50%); }
.cookie-banner-bottom-left { left: var(--space-5); bottom: var(--space-5); }
.cookie-banner-top-right { right: var(--space-5); top: var(--space-5); }
.cookie-banner-top-center { left: 50%; top: var(--space-5); transform: translateX(-50%); }
.cookie-banner-top-left { left: var(--space-5); top: var(--space-5); }
.cookie-banner-panel {
  display: grid;
  gap: var(--space-4);
  padding: var(--space-5);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: rgba(255,255,255,0.98);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(14px);
}
.cookie-banner-copy {
  display: grid;
  gap: 8px;
}
.cookie-banner-copy h2 {
  margin: 0;
  font-size: 18px;
  color: var(--text);
}
.cookie-banner-copy p,
.cookie-banner-group p,
.cookie-banner-group small,
.cookie-banner-list span,
.cookie-banner-list small {
  margin: 0;
  color: var(--text-muted);
}
.cookie-banner-details {
  display: grid;
  gap: var(--space-3);
}
.cookie-banner-details summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
}
.cookie-banner-groups {
  display: grid;
  gap: var(--space-4);
  padding-top: var(--space-2);
}
.cookie-banner-group {
  display: grid;
  gap: var(--space-2);
}
.cookie-banner-group h3 {
  margin: 0;
  font-size: 14px;
  color: var(--text);
}
.cookie-banner-list {
  display: grid;
  gap: var(--space-2);
  margin: 0;
  padding: 0;
  list-style: none;
}
.cookie-banner-list li {
  display: grid;
  gap: 2px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.cookie-banner-list strong {
  color: var(--text);
}
.cookie-banner-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-2);
}
.cookie-banner-actions .secondary {
  justify-content: center;
}

@media (prefers-color-scheme: dark) {
  .cookie-banner-panel {
    background: rgba(17, 17, 19, 0.96);
    border-color: var(--line-strong);
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.66), 0 8px 18px rgba(0, 0, 0, 0.4);
  }
  .cookie-banner-list li {
    background: rgba(22, 22, 24, 0.96);
    border-color: var(--line);
  }
  .cookie-banner-details summary {
    color: var(--accent-hover);
  }
}

/* Edit canvas */
.canvas-wrap {
  position: relative; width: 100%;
  border: 1px solid var(--line); border-radius: var(--radius-lg);
  background: #0b0d12; overflow: hidden;
  box-shadow: var(--shadow-xs);
}
.canvas-wrap img, .canvas-wrap canvas { width: 100%; display: block; }
.canvas-wrap canvas { position: absolute; inset: 0; cursor: crosshair; }
.canvas-wrap.preview-only a { display: block; cursor: zoom-in; }
.canvas-wrap.preview-only img { height: auto; }

/* ─────────── Public layout (auth, share) ─────────── */
.public-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
  background:
    radial-gradient(900px 600px at 80% -10%, rgba(99, 102, 241, 0.08), transparent 60%),
    radial-gradient(700px 500px at -10% 100%, rgba(168, 85, 247, 0.06), transparent 60%),
    var(--bg);
}
.public-topbar {
  padding: var(--space-5) var(--space-7);
  display: flex; align-items: center; gap: var(--space-3);
}
.public-topbar .brand {
  display: flex; gap: 10px; align-items: center;
  color: var(--text); font-weight: 600; font-size: 15px;
  letter-spacing: -0.01em;
}
.public-content {
  width: min(420px, 100%);
  margin: 0 auto;
  padding: var(--space-6) var(--space-5) var(--space-9);
  display: grid; gap: var(--space-4);
  align-content: start;
}
.public-content.wide { width: min(820px, 100%); }
.public-content .page-head { margin-bottom: 0; text-align: center; justify-content: center; }
.public-content .page-head .title { gap: 8px; }
.public-content .page-head .title h1 { font-size: 24px; }
.public-content .panel {
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  box-shadow: var(--shadow-md);
}
.public-content .row.between a { font-size: 12.5px; }
.shared-image {
  width: 100%; height: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  display: block;
  box-shadow: var(--shadow-md);
}

/* Responsive */
@media (max-width: 880px) {
  .album-shell { grid-template-columns: 1fr; }
  :root { --sidebar-w: 100%; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: static; height: auto;
    flex-direction: row; flex-wrap: wrap;
    padding: var(--space-3);
    gap: var(--space-2);
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .sidebar .brand { margin-right: auto; margin-bottom: 0; padding: 0; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; flex: 0 0 100%; gap: 4px; }
  .sidebar nav a[aria-current="page"] { box-shadow: none; background: var(--accent-soft); color: var(--accent); }
  .sidebar-foot {
    flex-direction: row; flex: 0 0 100%;
    border-top: 1px solid var(--line);
    padding-top: var(--space-2); margin-top: 0;
    align-items: center; gap: var(--space-2);
  }
  .sidebar-section-label { display: none; }
  .content { padding: var(--space-5) var(--space-4) var(--space-7); }
  .topbar { padding: 0 var(--space-4); }
  .cookie-banner {
    left: var(--space-3);
    right: var(--space-3);
    top: auto;
    bottom: var(--space-3);
    width: auto;
    transform: none;
  }
  .cookie-banner-actions {
    grid-template-columns: 1fr;
  }
}

/* Utility */
.row { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.kbd {
  font-family: var(--font-mono); font-size: 11px;
  padding: 2px 6px; border-radius: var(--radius-xs);
  background: var(--surface-3); border: 1px solid var(--line);
  color: var(--text-muted);
  box-shadow: 0 1px 0 var(--line);
}
hr.divider {
  border: none;
  border-top: 1px solid var(--line);
  margin: var(--space-4) 0;
}

/* ─────────── Loading button ─────────── */
button.is-loading, .button.is-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
button.is-loading::after, .button.is-loading::after {
  content: '';
  position: absolute;
  inset: 0;
  margin: auto;
  width: 14px; height: 14px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-top-color: transparent;
  color: var(--accent-text);
  animation: btn-spin 0.7s linear infinite;
}
button.secondary.is-loading::after { color: var(--text); }
@keyframes btn-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  button.is-loading::after { animation: none; }
}

/* ─────────── Toasts ─────────── */
.toast-region {
  position: fixed;
  bottom: var(--space-5);
  right: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: 200;
  pointer-events: none;
  max-width: min(380px, calc(100vw - 2 * var(--space-5)));
}
.toast {
  pointer-events: auto;
  background: var(--surface);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  line-height: 1.45;
  cursor: pointer;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.toast.in { opacity: 1; transform: translateY(0); }
.toast-error   { background: var(--danger-soft);  color: var(--danger);  border-color: transparent; }
.toast-success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.toast-info    { background: var(--info-soft);    color: var(--info);    border-color: transparent; }
@media (prefers-reduced-motion: reduce) {
  .toast { transition: opacity 0.01s; transform: none; }
}

/* ─────────── Modal dialog ─────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(8, 8, 10, 0.55);
  display: grid; place-items: center;
  padding: var(--space-4);
  z-index: 300;
  opacity: 0;
  transition: opacity 0.18s ease;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.modal-overlay.in { opacity: 1; }
.modal-dialog {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: min(480px, 100%);
  max-height: calc(100vh - 2 * var(--space-4));
  overflow: auto;
  display: flex; flex-direction: column;
  transform: translateY(8px) scale(0.98);
  transition: transform 0.18s ease;
}
.modal-overlay.in .modal-dialog { transform: translateY(0) scale(1); }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--line);
}
.modal-head h2 { font-size: 14px; }
.modal-close {
  background: transparent !important;
  color: var(--text-muted) !important;
  border: none !important;
  box-shadow: none !important;
  font-size: 22px; line-height: 1;
  width: 28px; height: 28px;
  padding: 0; min-height: 0;
  border-radius: var(--radius-sm);
}
.modal-close:hover { background: var(--surface-2) !important; color: var(--text) !important; }
.modal-body { padding: var(--space-5); display: grid; gap: var(--space-3); font-size: 13.5px; }
.modal-body p { line-height: 1.55; color: var(--text); }
.modal-foot {
  padding: var(--space-3) var(--space-5) var(--space-4);
  display: flex; gap: var(--space-2); justify-content: flex-end;
  border-top: 1px solid var(--line);
}
.title-edit-form { display: grid; gap: var(--space-3); }
.title-edit-form label { display: grid; gap: var(--space-2); }
.copy-row { display: flex; gap: var(--space-2); align-items: center; }
.copy-row input { flex: 1; font-family: var(--font-mono); font-size: 12.5px; }
@media (prefers-reduced-motion: reduce) {
  .modal-overlay, .modal-dialog { transition: none; }
}

/* ─────────── Lightbox ─────────── */
html.lb-no-scroll, html.lb-no-scroll body { overflow: hidden; }
.lightbox {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.92);
  display: none;
  z-index: 400;
  color: #f4f4f5;
  user-select: none;
}
.lightbox.open {
  display: grid;
  grid-template-rows: 1fr auto;
  animation: lb-in 0.18s ease;
}
@keyframes lb-in { from { opacity: 0; } to { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .lightbox.open { animation: none; } }

.lb-main {
  position: relative;
  display: flex;
  min-height: 0;
  overflow: hidden;
  z-index: 1;
}

.lb-stage {
  position: relative;
  flex: 1 1 auto;
  display: grid; place-items: center;
  overflow: hidden;
  min-width: 0;
  min-height: 0;
}
.lightbox img {
  max-width: 100%;
  max-height: calc(100vh - 88px);
  width: auto; height: auto;
  object-fit: contain;
  display: block;
  cursor: zoom-in;
  transform-origin: center center;
  transition: opacity 0.2s ease;
  opacity: 0;
  background: rgba(255, 255, 255, 0.02);
  will-change: transform;
}
.lightbox img.loaded { opacity: 1; }
.lightbox.zoomed img { cursor: grab; transition: none; }
.lb-spinner {
  position: absolute;
  width: 36px; height: 36px;
  border: 3px solid rgba(255, 255, 255, 0.18);
  border-top-color: #fff;
  border-radius: 50%;
  animation: lb-spin 0.9s linear infinite;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
}
.lb-spinner.on { opacity: 1; }
@keyframes lb-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .lb-spinner { animation: none; } }

.lb-close, .lb-nav {
  position: absolute;
  background: rgba(20, 20, 22, 0.55) !important;
  color: #f4f4f5 !important;
  border: 1px solid rgba(255, 255, 255, 0.12) !important;
  box-shadow: none !important;
  width: 40px; height: 40px;
  border-radius: 50%;
  font-size: 22px; line-height: 1;
  padding: 0; min-height: 0;
  display: grid; place-items: center;
  z-index: 6;
  pointer-events: auto;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.lb-close { top: 16px; right: 16px; }
.lb-prev { left: 16px; top: 50%; transform: translateY(-50%); }
.lb-next { right: 16px; top: 50%; transform: translateY(-50%); }
.lb-close:hover, .lb-nav:hover { background: rgba(40, 40, 44, 0.85) !important; }
.lb-nav.hidden { display: none; }
.lb-caption {
  padding: 12px var(--space-5) calc(12px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(0deg, rgba(0, 0, 0, 0.55), transparent);
  display: flex; align-items: center; gap: var(--space-3);
  flex-wrap: wrap; justify-content: space-between;
  font-size: 13px;
}
.lb-caption strong { color: #fff; font-weight: 500; }
.lb-caption small { color: rgba(244, 244, 245, 0.72); font-size: 12px; }
.lb-workflow-nav {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  max-width: min(100%, 760px);
}
.lb-workflow-nav button {
  min-height: 30px;
  padding: 5px 10px;
  border-radius: var(--radius-xs);
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.10);
  color: rgba(244, 244, 245, 0.86);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.2;
}
.lb-workflow-nav button:hover,
.lb-workflow-nav button.is-active {
  background: rgba(255, 255, 255, 0.22);
  border-color: rgba(255, 255, 255, 0.34);
  color: #fff;
}
.lb-caption .lb-actions {
  display: flex; gap: 6px; flex-wrap: wrap;
  margin-left: auto;
}
.lb-caption .lb-actions .button {
  background: rgba(255, 255, 255, 0.1) !important;
  color: #f4f4f5 !important;
  border-color: rgba(255, 255, 255, 0.18) !important;
}
.lb-caption .lb-actions .button:hover {
  background: rgba(255, 255, 255, 0.18) !important;
  color: #fff !important;
}
@media (max-width: 600px) {
  .lb-close, .lb-nav { width: 36px; height: 36px; font-size: 20px; }
  .lb-prev { left: 8px; }
  .lb-next { right: 8px; }
  .lb-close { top: 8px; right: 8px; }
  .lb-caption { padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px)); }
  .lb-workflow-nav { width: 100%; order: 3; }
  .lb-workflow-nav button { flex: 1 1 120px; }
  .lb-caption .lb-actions { margin-left: 0; width: 100%; }
  .lightbox img { max-height: calc(100vh - 110px); }
}

/* Cursor cue on lightbox-eligible thumbnails */
.image-card a[data-lightbox] { cursor: zoom-in; }
.shared-image[data-lightbox] { cursor: zoom-in; }

/* Lightbox info panel: prompt + reference list + recreate */
.lb-info-toggle {
  position: absolute;
  top: 16px;
  right: 70px;
  z-index: 3;
  background: rgba(20, 20, 22, 0.55);
  color: #f4f4f5;
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.lb-info-toggle:hover { background: rgba(40, 40, 44, 0.85); }
.lightbox.lb-info-open .lb-info-toggle { background: rgba(60, 60, 65, 0.9); }

.lb-info {
  flex: 0 0 380px;
  max-width: 90vw;
  background: rgba(18, 18, 22, 0.96);
  color: #f4f4f5;
  border-left: 1px solid rgba(255,255,255,0.1);
  display: none;
  flex-direction: column;
  min-height: 0;
}
.lightbox.lb-info-open .lb-info { display: flex; }

.lb-info-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}
.lb-info-head strong { color: #fff; font-size: 14px; font-weight: 600; }
.lb-info-close {
  background: transparent;
  color: rgba(244,244,245,0.7);
  border: 0;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
}
.lb-info-close:hover { color: #fff; }

.lb-info-body {
  flex: 1 1 auto;
  overflow: auto;
  padding: 14px 16px 18px;
  font-size: 13px;
  line-height: 1.5;
}
.lb-info-loading, .lb-info-empty { color: rgba(244,244,245,0.6); }
.lb-info-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 14px;
}
.lb-info-meta span {
  background: rgba(255,255,255,0.08);
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  color: rgba(244,244,245,0.85);
}
.lb-info-section { margin-bottom: 16px; }
.lb-info-section header {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 8px;
}
.lb-info-section header strong { color: #fff; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.lb-info-section header .muted { color: rgba(244,244,245,0.5); font-size: 11px; }
.lb-info-prompt {
  white-space: pre-wrap;
  background: rgba(255,255,255,0.05);
  padding: 10px 12px;
  border-radius: 8px;
  margin: 0;
  font-size: 13px;
  color: rgba(244,244,245,0.95);
}
.lb-ref-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}
.lb-ref-item {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 10px;
  align-items: center;
  background: rgba(255,255,255,0.05);
  border-radius: 8px;
  padding: 8px;
}
.lb-ref-item img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 6px;
  background: #000;
  display: block;
}
.lb-ref-meta { display: grid; gap: 3px; min-width: 0; }
.lb-ref-meta strong {
  color: #fff;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}
.lb-ref-meta small { color: rgba(244,244,245,0.6); font-size: 11px; line-height: 1.35; }
.lb-ref-tag {
  display: inline-block;
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 999px;
  background: rgba(255,255,255,0.1);
  color: rgba(244,244,245,0.85);
  width: fit-content;
}
.lb-ref-tag-uploaded { background: color-mix(in srgb, var(--accent) 35%, rgba(0,0,0,0.4)); color: #fff; }
.lb-ref-tag-preset { background: rgba(120, 180, 255, 0.18); color: #cfe3ff; }

.lb-info-actions { margin-top: 8px; }
.lb-info-actions .button {
  width: 100%;
  justify-content: center;
  text-align: center;
  background: rgba(255,255,255,0.12) !important;
  color: #fff !important;
  border-color: rgba(255,255,255,0.2) !important;
}
.lb-info-actions .button:hover { background: rgba(255,255,255,0.2) !important; }

@media (max-width: 960px) {
  .lb-main { flex-direction: column; }
  .lb-info {
    flex: 0 0 auto;
    max-height: 50vh;
    width: 100%;
    border-left: 0;
    border-top: 1px solid rgba(255,255,255,0.1);
  }
  .lb-info-toggle { right: 64px; top: 12px; }
}

.reference-upload-card.is-carry {
  border-color: color-mix(in srgb, var(--accent) 35%, var(--line));
}
.reference-upload-card.is-carry .reference-upload-card-meta small {
  color: var(--accent);
}
.reference-upload-card.is-environment {
  border-color: color-mix(in srgb, var(--info) 40%, var(--line));
}
.reference-upload-card.is-environment .reference-upload-card-meta span {
  color: var(--info);
}


/* Wider results grid for high-density columns */
@media (min-width: 1400px) {
  .results-grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
}
