/* ═══════════════════════════════════════════════
   创作工坊 — AI Creation Workshop
   Fixed Sidebar + Dynamic Content Layout
   ═══════════════════════════════════════════════ */

/* ── Design Tokens ──────────────────────────── */
:root {
  color-scheme: light;
  --white: #ffffff;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --gray-900: #0f172a;
  --purple-50: #f5f3ff;
  --purple-100: #ede9fe;
  --purple-200: #ddd6fe;
  --purple-400: #a78bfa;
  --purple-500: #8b5cf6;
  --purple-600: #7c3aed;
  --purple-700: #6d28d9;
  --cyan-400: #22d3ee;
  --cyan-500: #06b6d4;
  --cyan-600: #0891b2;
  --rose-500: #f43f5e;
  --rose-600: #e11d48;
  --rose-50: #fff1f2;
  --amber-500: #f59e0b;
  --amber-600: #d97706;
  --emerald-500: #10b981;
  --emerald-600: #059669;
  --emerald-50: #ecfdf5;

  --bg: var(--gray-50);
  --bg-card: var(--white);
  --bg-soft: var(--gray-100);
  --text: var(--gray-900);
  --text-secondary: var(--gray-600);
  --text-muted: var(--gray-400);
  --border: var(--gray-200);
  --border-strong: var(--gray-300);
  --primary: var(--purple-600);
  --primary-hover: var(--purple-700);
  --primary-light: var(--purple-100);
  --primary-bg: var(--purple-50);
  --accent: var(--cyan-500);
  --accent-light: #cffafe;
  --danger: var(--rose-600);
  --danger-bg: var(--rose-50);
  --success: var(--emerald-600);
  --success-bg: var(--emerald-50);
  --gradient: linear-gradient(135deg, var(--purple-600) 0%, var(--cyan-500) 100%);
  --gradient-hover: linear-gradient(135deg, var(--purple-700) 0%, var(--cyan-600) 100%);
  --gradient-warm: linear-gradient(135deg, #7c3aed 0%, #f43f5e 50%, #f59e0b 100%);

  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.07);
  --shadow-lg: 0 8px 24px rgba(15, 23, 42, 0.08);
  --shadow-xl: 0 16px 48px rgba(15, 23, 42, 0.10);
  --shadow-glow: 0 4px 20px rgba(124, 58, 237, 0.20);
  --shadow-sidebar: 4px 0 24px rgba(15, 23, 42, 0.06);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-2xl: 24px;
  --radius-full: 9999px;

  --font: "Inter", "SF Pro Display", ui-sans-serif, system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.35s cubic-bezier(0.4, 0, 0.2, 1);

  --sidebar-width: 400px;
}

/* ── Dark Mode ──────────────────────────────── */
:root.dark {
  color-scheme: dark;
  --bg: #0b0f1a;
  --bg-card: #141b2d;
  --bg-soft: #1e293b;
  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.14);
  --primary-bg: rgba(124, 58, 237, 0.10);
  --primary-light: rgba(124, 58, 237, 0.20);
  --danger-bg: rgba(225, 29, 72, 0.10);
  --success-bg: rgba(5, 150, 105, 0.10);
  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.24);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.28);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.32);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.36);
  --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.40);
  --shadow-glow: 0 4px 20px rgba(124, 58, 237, 0.25);
  --shadow-sidebar: 4px 0 24px rgba(0, 0, 0, 0.30);
}

/* ── Reset & Base ────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.45; }
[hidden] { display: none !important; }

/* ═══════════════════════════════════════════════
   App Shell — Fixed Sidebar + Scrollable Content
   ═══════════════════════════════════════════════ */

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────── */
.sidebar {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  box-shadow: var(--shadow-sidebar);
  z-index: 100;
}

/* Brand */
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.brand-logo {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: var(--radius-md);
  background: var(--gradient);
  box-shadow: var(--shadow-glow);
  color: white;
  flex-shrink: 0;
}

.brand-text {
  display: grid;
  gap: 1px;
}

.brand-name {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1.2;
}

.brand-desc {
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* Scrollable body */
.sidebar-scroll {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px 24px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.sidebar-scroll::-webkit-scrollbar { width: 4px; }
.sidebar-scroll::-webkit-scrollbar-track { background: transparent; }
.sidebar-scroll::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--radius-full);
}

/* Footer */
.sidebar-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════
   Main Content Area
   ═══════════════════════════════════════════════ */

.main-content {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 24px 32px 48px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.main-content::-webkit-scrollbar { width: 5px; }
.main-content::-webkit-scrollbar-track { background: transparent; }
.main-content::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--radius-full);
}

/* Content Topbar */
.content-topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}

.topbar-info {
  display: grid;
  gap: 4px;
}

.page-title {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
}

.page-subtitle {
  margin: 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 500;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

/* ── Stats Bar ───────────────────────────────── */
.stats-bar {
  display: flex;
  gap: 16px;
  margin-bottom: 24px;
}

.stat-item {
  flex: 1;
  display: grid;
  gap: 4px;
  padding: 16px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  box-shadow: var(--shadow-xs);
  transition: all var(--transition);
}

.stat-item:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ── Gallery Wrap ────────────────────────────── */
.gallery-wrap {
  display: grid;
  gap: 18px;
}

.gallery-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.gallery-head h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 750;
  color: var(--text);
  letter-spacing: -0.01em;
}

.gallery-badge {
  flex-shrink: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--bg-soft);
  color: var(--text-secondary);
  font-size: 0.74rem;
  font-weight: 700;
  padding: 5px 12px;
}

/* ── Gallery Grid ────────────────────────────── */
.gallery {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 16px;
  min-height: 0;
  align-content: start;
}

/* ── Empty State ─────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 64px 24px;
  text-align: center;
}

.empty-icon {
  width: 80px;
  height: 80px;
  display: grid;
  place-items: center;
  border-radius: var(--radius-2xl);
  background: var(--primary-bg);
  color: var(--primary);
  margin-bottom: 18px;
}

.empty-state h3 {
  margin: 0 0 8px;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.empty-state p {
  margin: 0;
  font-size: 0.86rem;
  color: var(--text-muted);
  max-width: 360px;
  line-height: 1.6;
}

/* ── Grid Placeholder ────────────────────────── */
.grid-placeholder {
  aspect-ratio: 9 / 16;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background:
    radial-gradient(circle at 50% 36%, rgba(124, 58, 237, 0.08), transparent 34%),
    var(--bg-soft);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 650;
  transition: all var(--transition);
}

.grid-placeholder::before {
  content: "+";
  display: grid;
  width: 32px;
  height: 32px;
  margin-bottom: 8px;
  place-items: center;
  border-radius: var(--radius-full);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--primary);
  font-size: 1.1rem;
  line-height: 1;
  box-shadow: var(--shadow-xs);
}

/* ── Pagination ──────────────────────────────── */
.gallery-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 4px 0 0;
}

.page-btn {
  min-height: 34px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-weight: 650;
  font-size: 0.82rem;
  padding: 6px 16px;
  box-shadow: var(--shadow-xs);
  transition: all var(--transition);
}

.page-btn:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}

.page-status {
  color: var(--text-muted);
  font-size: 0.82rem;
  font-weight: 650;
}

/* ═══════════════════════════════════════════════
   Sidebar — Form Elements
   ═══════════════════════════════════════════════ */

#generateForm {
  display: grid;
  gap: 14px;
}

/* Service Tabs */
.service-tabs {
  display: flex;
  gap: 4px;
  padding: 4px;
  border-radius: var(--radius-md);
  background: var(--bg-soft);
  border: 1px solid var(--border);
}

.service-tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.84rem;
  padding: 6px 12px;
  transition: all var(--transition);
}

.service-tab:hover { color: var(--text); }

.service-tab.active {
  background: var(--gradient);
  color: white;
  font-weight: 650;
  box-shadow: var(--shadow-sm);
}

/* Mode Switch */
.mode-switch {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-soft);
  box-shadow: inset 0 1px 3px rgba(15, 23, 42, 0.06);
}

.mode-switch::before {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: calc(50% - 4px);
  height: calc(100% - 8px);
  border-radius: var(--radius-sm);
  background: var(--gradient);
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition);
}

.mode-switch:has(.mode-tab[data-mode="edit"].active)::before {
  transform: translateX(100%);
}

.mode-tab {
  position: relative;
  z-index: 1;
  min-height: 36px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.84rem;
  padding: 6px 12px;
  transition: all var(--transition);
  text-align: center;
}

.mode-tab:hover { color: var(--text); }
.mode-tab.active { color: white; font-weight: 650; }

/* Field */
.field {
  display: grid;
  gap: 6px;
}

.field label {
  font-size: 0.8rem;
  font-weight: 650;
  color: var(--text-secondary);
}

.field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.char-count {
  font-size: 0.74rem;
  color: var(--text-muted);
  font-weight: 500;
}

/* Inputs */
input[type="text"],
input[type="password"],
input[type="number"],
select,
textarea {
  width: 100%;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  outline: none;
  padding: 10px 13px;
  font-size: 0.86rem;
  transition: all var(--transition);
}

textarea {
  min-height: 160px;
  resize: vertical;
  line-height: 1.7;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.10);
}

/* Select with action button */
.select-action {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 38px;
  gap: 8px;
  align-items: center;
}

.btn-icon-sm {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 1.1rem;
  font-weight: 700;
  transition: all var(--transition);
  box-shadow: var(--shadow-xs);
}

.btn-icon-sm:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
}

.refresh-models.spinning {
  animation: spin 0.8s linear infinite;
}

/* Image param layout */
.image-param-layout {
  display: grid;
  gap: 12px;
}

/* Params row */
.params-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

/* Custom size */
.custom-size {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

/* Hint */
.hint {
  font-size: 0.76rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0;
}

.hint.danger-text { color: var(--danger); }

/* ── Reference Panel ─────────────────────────── */
.ref-panel {
  display: grid;
  gap: 10px;
}

.dropzone {
  position: relative;
  border: 2px dashed var(--purple-200);
  border-radius: var(--radius-lg);
  background: var(--primary-bg);
  padding: 20px;
  transition: all var(--transition);
  overflow: hidden;
}

.dropzone:has(input:is(:hover, :focus-visible)) {
  border-color: var(--primary);
  background: var(--purple-100);
}

.dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.dropzone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.dropzone-content {
  display: flex;
  align-items: center;
  gap: 14px;
  pointer-events: none;
}

.dropzone-content svg {
  flex-shrink: 0;
  color: var(--primary);
  opacity: 0.7;
}

.dropzone-content strong {
  display: block;
  font-size: 0.86rem;
  color: var(--text);
  font-weight: 650;
}

.dropzone-content p {
  margin: 2px 0 0;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.ref-preview {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

/* File card */
.file-card {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-soft);
}

.file-card img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
}

.file-card footer {
  display: grid;
  gap: 2px;
  padding: 8px 10px;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.file-card strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
  font-size: 0.76rem;
}

.file-card .btn-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: var(--bg-card);
  color: var(--danger);
  font-weight: 650;
  font-size: 0.72rem;
  padding: 3px 10px;
  backdrop-filter: blur(8px);
  transition: all var(--transition);
}

.file-card .btn-remove:hover {
  background: var(--danger);
  color: white;
  border-color: var(--danger);
}

/* Video panel */
.video-panel {
  display: grid;
  gap: 14px;
}

/* ═══════════════════════════════════════════════
   Generate Button
   ═══════════════════════════════════════════════ */

.btn-generate {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  min-height: 52px;
  border: 0;
  border-radius: var(--radius-md);
  background: var(--gradient);
  color: white;
  font-weight: 750;
  font-size: 1.02rem;
  padding: 12px 24px;
  box-shadow: var(--shadow-glow);
  transition: all var(--transition);
  letter-spacing: -0.01em;
}

.btn-generate:hover {
  background: var(--gradient-hover);
  box-shadow: var(--shadow-glow);
  transform: translateY(-1px);
}

.btn-generate:active { transform: translateY(0); }

.btn-generate:disabled {
  background: var(--gray-300);
  box-shadow: none;
  transform: none;
}

.btn-generate .icon {
  flex-shrink: 0;
}

/* ═══════════════════════════════════════════════
   Icon Button (topbar)
   ═══════════════════════════════════════════════ */

.btn-icon {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--text-secondary);
  box-shadow: var(--shadow-xs);
  transition: all var(--transition);
}

.btn-icon:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
  color: var(--text);
}

/* ═══════════════════════════════════════════════
   Notice Toast
   ═══════════════════════════════════════════════ */

.notice {
  position: fixed;
  top: 22px;
  right: 22px;
  z-index: 3000;
  width: min(380px, calc(100vw - 32px));
  margin: 0;
  border: 1px solid var(--accent);
  border-radius: var(--radius-md);
  background: var(--accent-light);
  padding: 12px 18px;
  color: var(--cyan-600);
  font-weight: 600;
  font-size: 0.86rem;
  box-shadow: var(--shadow-xl);
  backdrop-filter: blur(10px);
  animation: toastIn 0.22s ease;
}

.notice.error {
  border-color: var(--danger);
  background: var(--danger-bg);
  color: var(--danger);
}

.notice.success {
  border-color: var(--success);
  background: var(--success-bg);
  color: var(--success);
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(-8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ═══════════════════════════════════════════════
   Modal
   ═══════════════════════════════════════════════ */

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  animation: fadeIn 0.2s ease;
}

.modal-dialog {
  width: min(520px, calc(100% - 32px));
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-xl);
  animation: scaleIn 0.2s ease;
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
}

.modal-head-left {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--primary);
}

.modal-head-left h2 {
  margin: 0;
  font-size: 1.1rem;
  font-weight: 750;
  color: var(--text);
}

.modal-x {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.95rem;
  transition: all var(--transition);
}

.modal-x:hover {
  border-color: var(--border-strong);
  color: var(--text);
  background: var(--bg-soft);
}

.modal-body {
  padding: 20px 24px;
  display: grid;
  gap: 16px;
}

.modal-field-group {
  display: grid;
  gap: 8px;
}

.modal-field-group label {
  font-size: 0.82rem;
  font-weight: 650;
  color: var(--text-secondary);
}

.input-suffix {
  display: flex;
  gap: 8px;
}

.input-suffix-wrapper {
  position: relative;
  flex: 1;
  min-width: 0;
}

.input-suffix-wrapper input {
  width: 100%;
  padding-right: 40px;
  font-family: inherit;
}

.input-suffix-wrapper input[type="text"] {
  font-family: "Cascadia Code", "Fira Code", "Consolas", "SF Mono", monospace;
  font-size: 0.82rem;
  letter-spacing: 0.01em;
}

.btn-eye {
  position: absolute;
  right: 2px;
  top: 50%;
  transform: translateY(-50%);
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-eye:hover {
  color: var(--text);
  background: var(--bg-soft);
}

.eye-icon {
  display: block;
}

.modal-hint {
  margin: 0;
  font-size: 0.76rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.btn-primary-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: white;
  font-weight: 650;
  font-size: 0.84rem;
  padding: 8px 20px;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-primary-sm:hover {
  background: var(--primary-hover);
  box-shadow: var(--shadow-glow);
}

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

@keyframes scaleIn {
  from { opacity: 0; transform: scale(0.95) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ═══════════════════════════════════════════════
   Image Card
   ═══════════════════════════════════════════════ */

.image-card {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-soft);
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-slow);
  animation: cardEnter 0.35s ease both;
}

@keyframes cardEnter {
  from { opacity: 0; transform: translateY(12px) scale(0.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.image-card:hover {
  border-color: rgba(124, 58, 237, 0.4);
  box-shadow: var(--shadow-lg);
  transform: translateY(-4px);
}

/* Loading state */
.card-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  aspect-ratio: 9 / 16;
  background: linear-gradient(135deg, var(--gray-100), var(--gray-200));
  animation: shimmer 2s ease-in-out infinite;
}

@keyframes shimmer {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.spinner-ring {
  width: 36px;
  height: 36px;
  border: 3px solid var(--gray-300);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.card-loader-text {
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--text-muted);
}

.card-loader-time {
  margin-top: 4px;
  font-size: 0.74rem;
  font-weight: 500;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

.card-progress {
  width: min(72%, 120px);
  height: 6px;
  overflow: hidden;
  border-radius: var(--radius-full);
  background: rgba(148, 163, 184, 0.28);
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.08);
}

.card-progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: var(--gradient);
  transition: width 0.35s ease;
}

.card-progress-text {
  margin-top: -6px;
  font-size: 0.74rem;
  font-weight: 650;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

.image-card.is-loading .image-link,
.image-card.is-loading .image-meta { display: none; }
.image-card:not(.is-loading) .card-loader { display: none; }

/* Delete button */
.btn-card-del {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border: 0;
  border-radius: var(--radius-full);
  background: rgba(0, 0, 0, 0.5);
  color: white;
  font-size: 0.82rem;
  opacity: 0;
  transition: all var(--transition);
  backdrop-filter: blur(4px);
}

.image-card:hover .btn-card-del,
.image-card.is-loading .btn-card-del { opacity: 1; }

.btn-card-del:hover {
  background: var(--danger);
  transform: scale(1.1);
}

/* Error state */
.image-card.is-error .card-loader { animation: none; }
.image-card.is-error .spinner-ring { display: none; }
.image-card.is-error .card-loader-text { color: var(--danger); }
.image-card.is-error .image-link,
.image-card.is-error .image-meta { display: none; }

/* Image link */
.image-link {
  display: block;
  position: relative;
  overflow: hidden;
}

.image-link::after {
  content: "查看详情";
  position: absolute;
  inset: auto 8px 8px;
  border-radius: var(--radius-full);
  background: rgba(15, 23, 42, 0.72);
  color: white;
  font-size: 0.72rem;
  font-weight: 650;
  padding: 5px 10px;
  text-align: center;
  opacity: 0;
  transform: translateY(4px);
  transition: all var(--transition);
  pointer-events: none;
  backdrop-filter: blur(4px);
}

.image-card:hover .image-link::after {
  opacity: 1;
  transform: translateY(0);
}

.image-card img {
  display: block;
  width: 100%;
  aspect-ratio: 9 / 16;
  object-fit: cover;
  background: var(--bg-soft);
  transition: transform var(--transition-slow), filter var(--transition-slow);
}

.image-card video.card-video {
  display: block;
  width: 100%;
  aspect-ratio: 9 / 16;
  object-fit: cover;
  background: var(--bg-soft);
}

.image-card:hover img {
  filter: saturate(1.05) contrast(1.03);
  transform: scale(1.03);
}

/* Image meta */
.image-meta {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  min-height: 56px;
}

.image-card:not(.is-loading):not(.is-error) .image-meta {
  display: flex;
}

.image-meta-info {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.image-label {
  font-size: 0.8rem;
  font-weight: 650;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-time {
  font-size: 0.74rem;
  color: var(--text-muted);
}

.image-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.btn-image-dl,
.btn-image-copy {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 30px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.76rem;
  padding: 4px 12px;
  transition: all var(--transition);
}

.btn-image-dl {
  background: var(--gradient);
  border: 0;
  color: white;
  box-shadow: var(--shadow-glow);
}

.btn-image-dl:hover {
  box-shadow: var(--shadow-glow);
  transform: translateY(-1px);
}

.btn-image-copy:hover {
  border-color: var(--border-strong);
  background: var(--primary-bg);
  color: var(--primary);
}

/* ═══════════════════════════════════════════════
   Lightbox — Polished Detail View
   ═══════════════════════════════════════════════ */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.70);
  backdrop-filter: blur(12px) saturate(0.6);
  animation: lbFadeIn 0.25s ease;
}

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

.lightbox-panel {
  position: relative;
  z-index: 1;
  width: min(1100px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: 0 25px 60px rgba(15, 23, 42, 0.22), 0 0 0 1px rgba(15, 23, 42, 0.04);
  display: flex;
  flex-direction: column;
  animation: lbScaleIn 0.30s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

@keyframes lbScaleIn {
  from { opacity: 0; transform: scale(0.94) translateY(16px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

/* ── Header ──────────────────────────────────── */
.lb-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  flex-shrink: 0;
}

.lb-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--primary);
}

.lb-title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
}

.lb-close {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--text-muted);
  transition: all var(--transition);
  flex-shrink: 0;
}

.lb-close:hover {
  border-color: var(--danger);
  color: var(--danger);
  background: var(--danger-bg);
  transform: scale(1.05);
}

/* ── Body ────────────────────────────────────── */
.lightbox-body {
  display: grid;
  grid-template-columns: 1fr 340px;
  min-height: 0;
  flex: 1;
  overflow: hidden;
}

/* ── Image Area ──────────────────────────────── */
.lb-image-area {
  display: grid;
  grid-template-rows: 1fr auto auto;
  overflow: hidden;
  min-height: 0;
}

/* Viewport — the scroll/zoom container */
.lb-image-viewport {
  position: relative;
  overflow: hidden;
  cursor: grab;
  background:
    repeating-conic-gradient(var(--gray-200) 0% 25%, transparent 0% 50%) 50% / 20px 20px;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lb-image-viewport.grabbing {
  cursor: grabbing;
}

:root.dark .lb-image-viewport {
  background:
    repeating-conic-gradient(rgba(255,255,255,0.04) 0% 25%, transparent 0% 50%) 50% / 20px 20px;
}

/* Stage — the transform layer, centered by flex */
.lb-image-stage {
  transform-origin: center center;
  will-change: transform;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lb-image-stage.transitioning {
  transition: transform 0.25s cubic-bezier(0.25, 0.8, 0.25, 1.2);
}

.lb-image-stage img {
  display: block;
  max-width: 90vw;
  max-height: 65vh;
  object-fit: contain;
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 32px rgba(15, 23, 42, 0.14);
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.lb-image-viewport video {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 32px rgba(15, 23, 42, 0.14);
}

/* Zoom controls */
.lb-zoom-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 16px;
  border-top: 1px solid rgba(15, 23, 42, 0.05);
  background: rgba(15, 23, 42, 0.02);
}

:root.dark .lb-zoom-controls {
  border-top-color: rgba(255, 255, 255, 0.05);
  background: rgba(255, 255, 255, 0.02);
}

.lb-zoom-controls.video-hidden {
  display: none;
}

.lb-zoom-btn {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-secondary);
  transition: all var(--transition);
  flex-shrink: 0;
}

.lb-zoom-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-bg);
  box-shadow: var(--shadow-xs);
}

.lb-zoom-btn:disabled {
  opacity: 0.35;
  pointer-events: none;
  color: var(--text-muted);
}

.lb-zoom-value {
  min-width: 52px;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 650;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  user-select: none;
}

/* Image bottom bar */
.lb-image-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  border-top: 1px solid rgba(15, 23, 42, 0.06);
  background: rgba(0, 0, 0, 0.03);
}

:root.dark .lb-image-bar {
  border-top-color: rgba(255, 255, 255, 0.06);
  background: rgba(255, 255, 255, 0.03);
}

.lb-image-bar-label {
  font-size: 0.76rem;
  font-weight: 650;
  padding: 3px 10px;
  border-radius: var(--radius-full);
  background: var(--primary-bg);
  color: var(--primary);
}

.lb-image-bar-dims {
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ── Sidebar ─────────────────────────────────── */
.lb-sidebar {
  display: grid;
  grid-template-rows: auto 1fr auto auto auto;
  gap: 16px;
  padding: 20px;
  border-left: 1px solid var(--border);
  background: var(--bg-soft);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.lb-sidebar::-webkit-scrollbar { width: 4px; }
.lb-sidebar::-webkit-scrollbar-track { background: transparent; }
.lb-sidebar::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: var(--radius-full);
}

/* Prompt card */
.lb-card {
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  box-shadow: var(--shadow-xs);
}

.lb-card-label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.lb-card-prompt {
  margin: 0;
  font-size: 0.86rem;
  color: var(--text);
  line-height: 1.65;
  word-break: break-word;
  max-height: 160px;
  overflow-y: auto;
}

/* Info grid */
.lb-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.lb-info-item {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  display: grid;
  gap: 4px;
}

.lb-info-label {
  font-size: 0.69rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.lb-info-value {
  font-size: 0.84rem;
  font-weight: 650;
  color: var(--text);
}

/* Time row */
.lb-time-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 4px;
  color: var(--text-muted);
}

.lb-time-text {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
}

/* ── Actions ─────────────────────────────────── */
.lb-actions {
  display: grid;
  gap: 8px;
}

.lb-btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 46px;
  border: 0;
  border-radius: var(--radius-md);
  background: var(--gradient);
  color: white;
  font-weight: 700;
  font-size: 0.90rem;
  padding: 10px 20px;
  box-shadow: var(--shadow-glow);
  transition: all var(--transition);
}

.lb-btn-primary:hover {
  background: var(--gradient-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(124, 58, 237, 0.28);
}

.lb-btn-primary:active { transform: translateY(0); }

.lb-btn-outline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  min-height: 42px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--text-secondary);
  font-weight: 650;
  font-size: 0.86rem;
  padding: 9px 18px;
  transition: all var(--transition);
}

.lb-btn-outline:hover {
  border-color: var(--primary);
  background: var(--primary-bg);
  color: var(--primary);
  box-shadow: var(--shadow-sm);
}

/* ── Buttons (shared) ────────────────────────── */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  border: 0;
  border-radius: var(--radius-md);
  background: var(--gradient);
  color: white;
  font-weight: 700;
  font-size: 0.90rem;
  padding: 10px 20px;
  box-shadow: var(--shadow-glow);
  transition: all var(--transition);
}

.btn-primary:hover {
  background: var(--gradient-hover);
  transform: translateY(-1px);
}

.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-secondary);
  font-weight: 650;
  font-size: 0.88rem;
  padding: 9px 20px;
  transition: all var(--transition);
}

.btn-ghost:hover {
  border-color: var(--border-strong);
  background: var(--bg-soft);
  color: var(--text);
}

/* ═══════════════════════════════════════════════
   Responsive
   ═══════════════════════════════════════════════ */

/* Tablet: narrower sidebar */
@media (max-width: 1280px) {
  :root { --sidebar-width: 360px; }
  .gallery { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .main-content { padding: 20px 24px 40px; }
}

/* Small tablet / large phone: stack layout */
@media (max-width: 960px) {
  body { overflow: auto; }

  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    overflow: visible;
  }

  .sidebar {
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
  }

  .sidebar-scroll {
    max-height: 60vh;
    overflow-y: auto;
  }

  .main-content {
    overflow: visible;
    padding: 20px;
  }

  .gallery { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stats-bar { flex-direction: column; gap: 10px; }

  .lightbox-body {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
  }

  .lb-sidebar {
    border-left: 0;
    border-top: 1px solid var(--border);
    gap: 12px;
    padding: 16px;
    max-height: 45vh;
  }

  .lightbox-panel {
    max-height: calc(100vh - 32px);
    border-radius: var(--radius-lg);
  }

  .lb-image-viewport {
    min-height: 240px;
  }

  .lb-zoom-controls {
    padding: 6px 12px;
  }

  .lb-info-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* Phone */
@media (max-width: 640px) {
  :root { --sidebar-width: 100%; }

  .content-topbar {
    flex-direction: column;
    gap: 12px;
  }

  .sidebar-brand { padding: 16px; }
  .sidebar-scroll { padding: 16px; }
  .sidebar-footer { padding: 12px 16px; }

  .gallery {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .main-content { padding: 16px; }

  .params-row { grid-template-columns: 1fr; }
  .custom-size { grid-template-columns: 1fr 1fr; }

  .stats-bar { gap: 8px; }
  .stat-item { padding: 12px 16px; }
  .stat-value { font-size: 1.3rem; }

  .dropzone-content { flex-direction: column; text-align: center; }

  .gallery-pagination { flex-wrap: wrap; }
}
