:root {
  color-scheme: dark;
  --bg: #07111d;
  --bg-layer: rgba(11, 20, 36, 0.88);
  --bg-darker: #060a0f;
  --panel: rgba(12, 24, 43, 0.84);
  --panel-strong: rgba(15, 29, 52, 0.94);
  --panel-soft: rgba(255, 255, 255, 0.035);
  --panel-border: rgba(117, 163, 255, 0.16);
  --panel-border-strong: rgba(125, 214, 255, 0.28);
  --text: #eff5ff;
  --muted: #94a8cb;
  --primary: #5ed6ff;
  --primary-strong: #8ff6ff;
  --primary-glow: rgba(88, 219, 255, 0.28);
  --success: #31cf90;
  --warn: #ffb856;
  --danger: #ff6f82;
  --shadow-lg: 0 28px 80px rgba(0, 0, 0, 0.34);
  --shadow-md: 0 18px 44px rgba(0, 0, 0, 0.24);
  --radius-xl: 30px;
  --radius-lg: 22px;
  --radius-md: 18px;
  --radius-sm: 14px;
  --nav-height: 70px;
  --sidebar-width: 340px;
  --sidebar-history-width: 320px;
  --font-main: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }

html, body { 
  margin: 0; 
  height: 100vh; 
  overflow: hidden; 
  font-family: var(--font-main);
  background:
    radial-gradient(circle at top left, rgba(42, 135, 255, 0.2), transparent 30%),
    radial-gradient(circle at 85% 15%, rgba(0, 217, 189, 0.1), transparent 25%),
    linear-gradient(180deg, #06101a 0%, #091423 100%);
  color: var(--text);
}

[hidden] { display: none !important; }

/* App Container */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: relative;
  z-index: 1;
}

/* Top Nav */
.top-nav {
  height: var(--nav-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 30px;
  background: var(--bg-layer);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--panel-border);
  z-index: 100;
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.3);
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 15px;
  min-width: 0;
}

.brand-logo {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  object-fit: cover;
  flex-shrink: 0;
  box-shadow: 0 0 20px rgba(94, 214, 255, 0.18);
}

.brand-copy {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.brand-tag {
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-strong) 100%);
  color: #000;
  padding: 3px 10px;
  border-radius: 999px;
  box-shadow: 0 0 15px var(--primary-glow);
}

.nav-brand h1 {
  font-size: 22px;
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-site-link {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-site-link:hover {
  color: var(--primary-strong);
  text-decoration: underline;
}

.nav-user-area {
  display: flex;
  align-items: center;
  gap: 20px;
}

.nav-credit-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--panel-border);
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 14px;
}

.nav-credit-chip .label { color: var(--muted); }

.nav-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--panel-border);
  color: var(--text);
  padding: 8px 20px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.nav-btn:hover { 
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--primary);
  transform: translateY(-1px);
}

.nav-btn.primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-strong) 100%);
  border-color: transparent;
  color: #000;
  box-shadow: 0 10px 20px var(--primary-glow);
}

/* Workbench Layout */
.workbench-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  padding: 20px;
  gap: 20px;
}

/* Sidebar Common */
aside {
  background: var(--panel);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-xl);
  display: flex;
  flex-direction: column;
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.sidebar-header {
  padding: 20px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--panel-border);
}

.sidebar-header h2 {
  font-size: 15px;
  margin: 0;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 2px;
  font-weight: 800;
}

.sidebar-title {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.history-tip {
  margin: 0;
  color: rgba(148, 168, 203, 0.8);
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0;
  text-transform: none;
  line-height: 1.25;
}

.sidebar-collapse-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 4px;
  font-size: 18px;
  transition: color 0.2s;
}

.sidebar-collapse-btn:hover { color: var(--primary); }

/* Sidebar Params */
.sidebar-params {
  width: var(--sidebar-width);
  flex-shrink: 0;
}

body.sidebar-collapsed .sidebar-params {
  width: 0;
  margin-right: -20px;
  opacity: 0;
  pointer-events: none;
}

.params-form {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.param-section {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.param-section h3 {
  font-size: 15px;
  margin: 0;
  color: var(--primary);
  font-weight: 700;
}

textarea {
  width: 100%;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  color: var(--text);
  padding: 16px;
  font-size: 15px;
  line-height: 1.6;
  resize: none;
  outline: none;
  transition: border-color 0.3s, box-shadow 0.3s;
}

textarea:focus { 
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-glow);
}

.ref-info-area {
  width: 100%;
}

.ref-dashed-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 8px;
}

.ref-dashed-box {
  border: 1px dashed rgba(125, 214, 255, 0.42);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.02);
  padding: 8px 8px;
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: hidden;
  position: relative;
  cursor: pointer;
}

.ref-slot-content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}

.ref-slot-placeholder {
  color: rgba(148, 168, 203, 0.85);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  line-height: 1.2;
  padding: 6px;
}

.ref-slot-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: calc(var(--radius-md) - 2px);
  display: block;
}

.ref-dashed-box .ref-title {
  font-size: 11px;
  color: var(--muted);
  font-weight: 800;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.ref-dashed-box .ref-body {
  font-size: 12px;
  color: var(--text);
  line-height: 1.35;
  word-break: break-word;
  white-space: pre-line;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  overflow: hidden;
}

.ref-dashed-box textarea {
  width: 100%;
  min-height: 32px;
  background: transparent;
  border: none;
  color: var(--text);
  padding: 0;
  font-size: 12px;
  line-height: 1.35;
  outline: none;
  resize: vertical;
}

.ref-dashed-box textarea::placeholder {
  color: rgba(148, 168, 203, 0.7);
}

.ref-dashed-add {
  border: 1px dashed rgba(125, 214, 255, 0.6);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.02);
  aspect-ratio: 1;
  cursor: pointer;
  color: var(--primary);
  font-size: 22px;
  font-weight: 900;
  letter-spacing: 1px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.ref-slot-close {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  border: 1px solid rgba(117, 163, 255, 0.22);
  background: rgba(0, 0, 0, 0.35);
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ref-slot-close:hover {
  border-color: rgba(255, 111, 130, 0.55);
  color: var(--danger);
}

.ref-dashed-box.is-dragging,
.ref-dashed-add.is-dragging {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-glow);
}

.ref-preview-modal {
  position: fixed;
  inset: 0;
  z-index: 1100;
}

.ref-preview-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(10px);
}

.ref-preview-card {
  position: absolute;
  inset: 16px;
  border-radius: var(--radius-xl);
  border: 1px solid var(--panel-border-strong);
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.ref-preview-card img {
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--radius-lg);
  border: 1px solid var(--panel-border);
  background: #000;
}

.ref-preview-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.ref-preview-close:hover {
  border-color: var(--primary);
}

.ref-dashed-add:hover {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-glow);
}

.choice-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.choice-block label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

.choice-group {
  display: flex;
  gap: 10px;
}

.choice-group.wrap {
  flex-wrap: wrap;
}

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

.choice-group.mini .chip {
  padding: 9px 12px;
  font-size: 13px;
}

.ratio-grid {
  width: 100%;
}

.custom-inputs {
  display: flex;
  align-items: center;
  gap: 10px;
}

.custom-inputs input {
  width: 100%;
  min-width: 0;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  color: var(--text);
  padding: 12px 14px;
  outline: none;
}

.custom-inputs input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-glow);
}

.status-indicator .text {
  color: var(--muted);
}

.chip {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--panel-border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.2s;
  text-align: center;
}

.chip:hover:not(:disabled) { 
  border-color: var(--primary);
  background: rgba(255, 255, 255, 0.08);
}

.chip.active {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-strong) 100%);
  border-color: transparent;
  color: #000;
  font-weight: 700;
  box-shadow: 0 8px 16px var(--primary-glow);
}

.chip:disabled, .chip.is-disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

details {
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: rgba(255, 255, 255, 0.02);
}

summary {
  padding: 14px 18px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  user-select: none;
}

details > summary {
  list-style: none;
}

details > summary::-webkit-details-marker {
  display: none;
}

.section-content {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  background: rgba(0, 0, 0, 0.15);
  border-top: 1px solid var(--panel-border);
}

.reference-actions {
  display: flex;
  gap: 12px;
}

.btn-sm {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  cursor: pointer;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
}

.btn-sm.ghost {
  background: transparent;
  color: var(--muted);
}

.reference-list {
  min-height: 96px;
  border: 1px dashed rgba(125, 214, 255, 0.38);
  border-radius: var(--radius-md);
  background: rgba(255, 255, 255, 0.03);
  padding: 12px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.reference-list.is-dragging {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-glow);
}

.reference-list .empty-hint {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.5px;
  min-height: 72px;
}

.ref-thumb {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid rgba(125, 214, 255, 0.22);
  background: #000;
  cursor: pointer;
  position: relative;
  transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.ref-thumb:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
  box-shadow: 0 8px 18px rgba(0,0,0,0.35);
}

.ref-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.ref-remove {
  position: absolute;
  right: 8px;
  top: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(255, 111, 130, 0.35);
  background: rgba(255, 111, 130, 0.14);
  color: var(--danger);
  font-weight: 800;
  cursor: pointer;
  opacity: 0;
  transform: translateY(-2px);
  transition: opacity 0.15s, transform 0.15s, background 0.15s;
}

.ref-thumb:hover .ref-remove {
  opacity: 1;
  transform: translateY(0);
}

.ref-remove:hover {
  background: rgba(255, 111, 130, 0.28);
}

.result-placeholder {
  width: 100%;
  max-width: 720px;
  min-height: 260px;
  border: 1px dashed rgba(125, 214, 255, 0.28);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.02);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-weight: 700;
  letter-spacing: 0.4px;
  text-align: center;
  padding: 24px;
}

.viewer-loader {
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  border: 1px solid var(--panel-border);
  border-radius: 999px;
  padding: 10px 14px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.result-thumbs-strip {
  width: 100%;
  max-width: 980px;
  display: flex;
  gap: 10px;
  margin-top: 18px;
  overflow-x: auto;
  padding: 8px 4px;
}

.thumb {
  width: 84px;
  height: 84px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(125, 214, 255, 0.18);
  background: rgba(0, 0, 0, 0.35);
  padding: 0;
  cursor: pointer;
  overflow: hidden;
  flex: 0 0 auto;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumb.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.meta-panel {
  border-top: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.02);
}

.meta-header {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--panel-border);
}

.meta-header h3 {
  margin: 0;
  font-size: 14px;
  color: var(--muted);
  letter-spacing: 1px;
  text-transform: uppercase;
  font-weight: 800;
}

.meta-body {
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.meta-item {
  display: flex;
  gap: 10px;
  align-items: baseline;
  font-size: 13px;
  line-height: 1.4;
}

.meta-item .label {
  color: var(--muted);
  flex: 0 0 auto;
}

.meta-item .val {
  color: var(--text);
  word-break: break-word;
}

.close-btn {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.close-btn:hover {
  border-color: var(--primary);
}

.history-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
  color: var(--muted);
  font-weight: 700;
}

.tab-switch {
  display: flex;
  gap: 10px;
  padding: 0 30px 16px;
}

.tab-btn {
  flex: 1;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-weight: 800;
  cursor: pointer;
}

.tab-btn.active {
  color: #000;
  border-color: transparent;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-strong) 100%);
}

.btn.full {
  width: 100%;
}

.btn.ghost {
  background: transparent;
  color: var(--muted);
}

.btn.danger-link {
  background: transparent;
  border-color: rgba(255, 111, 130, 0.35);
  color: var(--danger);
}

.btn.danger-link:hover {
  background: rgba(255, 111, 130, 0.12);
}

.feedback {
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  color: var(--muted);
  font-size: 13px;
}

.feedback.error {
  border-color: rgba(255, 111, 130, 0.35);
  color: var(--danger);
}

.feedback.success {
  border-color: rgba(49, 207, 144, 0.35);
  color: var(--success);
}

.modal-actions {
  display: flex;
  gap: 12px;
}

.package-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.loading {
  color: var(--muted);
  font-weight: 700;
  padding: 10px 0;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(6px);
  z-index: 180;
}

.params-footer {
  margin-top: auto;
  padding-top: 24px;
  border-top: 1px solid var(--panel-border);
}

.preview-stats {
  display: flex;
  gap: 15px;
}

.stat-item {
  flex: 1;
  background: rgba(255, 255, 255, 0.04);
  padding: 12px;
  border-radius: var(--radius-md);
  text-align: center;
  border: 1px solid var(--panel-border);
}

.stat-item span {
  display: block;
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
}

.stat-item strong { 
  font-size: 16px; 
  color: var(--primary);
}

/* Main Preview */
.main-preview {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-xl);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.preview-header {
  padding: 16px 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid var(--panel-border);
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 15px;
}

.badge {
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.badge.idle { background: rgba(255, 255, 255, 0.1); color: var(--muted); }
.badge.running { background: var(--primary); color: #000; animation: pulse-glow 2s infinite; }
.badge.success { background: var(--success); color: #000; }
.badge.error { background: var(--danger); color: #fff; }

@keyframes pulse-glow {
  0% { box-shadow: 0 0 5px var(--primary-glow); }
  50% { box-shadow: 0 0 20px var(--primary-glow); }
  100% { box-shadow: 0 0 5px var(--primary-glow); }
}

.preview-actions {
  display: flex;
  gap: 15px;
}

.inline-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.04);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.3px;
  color: var(--muted);
  user-select: none;
}

.inline-progress-percent {
  color: var(--primary);
  min-width: 42px;
  text-align: right;
}

@media (max-width: 520px) {
  .inline-progress-text { display: none; }
  .inline-progress { padding: 10px 12px; }
}

.action-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 24px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  cursor: pointer;
  border: none;
  font-size: 15px;
  transition: all 0.3s;
}

.action-btn.primary { background: linear-gradient(135deg, var(--primary) 0%, var(--primary-strong) 100%); color: #000; }
.action-btn.danger { background: rgba(255, 82, 82, 0.1); color: var(--danger); border: 1px solid rgba(255, 82, 82, 0.3); }
.action-btn:disabled { opacity: 0.3; cursor: not-allowed; }

.preview-stage {
  flex: 1;
  padding: 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  position: relative;
}

.progress-container {
  width: 100%;
  max-width: 500px;
  position: absolute;
  top: 30px;
}

.progress-bar {
  height: 6px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--panel-border);
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width 0.5s ease;
  box-shadow: 0 0 15px var(--primary-glow);
}

.progress-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
  font-size: 13px;
  color: var(--muted);
}

.image-viewer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 25px;
  max-width: 100%;
}

.viewer-content {
  background: #000;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--panel-border-strong);
}

.viewer-content img {
  display: block;
  max-width: 100%;
  transition: width 0.3s ease;
}

.viewer-toolbar {
  display: flex;
  align-items: center;
  gap: 30px;
  background: var(--panel-strong);
  padding: 10px 24px;
  border-radius: 999px;
  backdrop-filter: blur(15px);
  border: 1px solid var(--panel-border-strong);
}

.zoom-tool {
  display: flex;
  align-items: center;
  gap: 15px;
}

.zoom-tool input[type="range"] {
  width: 140px;
  accent-color: var(--primary);
}

.icon-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--panel-border);
  padding: 8px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  color: var(--text);
  letter-spacing: 0.5px;
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: var(--primary);
  transform: translateY(-1px);
}

.icon-btn.danger {
  border-color: rgba(255, 111, 130, 0.35);
  color: var(--danger);
}

.icon-btn.danger:hover {
  border-color: rgba(255, 111, 130, 0.65);
  background: rgba(255, 111, 130, 0.14);
}

/* Sidebar History */
.sidebar-history {
  width: var(--sidebar-history-width);
  flex-shrink: 0;
  border-left: 1px solid var(--panel-border);
}

.history-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 15px;
}

.history-item {
  aspect-ratio: 1;
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  border: 2px solid transparent;
  background: #000;
  transition: transform 0.2s;
}

.history-item:hover { border-color: var(--primary); transform: scale(1.05); }

.history-item img { width: 100%; height: 100%; object-fit: cover; }

/* Modals */
.modal-shell {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(10px);
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 500px;
  background: var(--panel-strong);
  border: 1px solid var(--panel-border-strong);
  border-radius: var(--radius-xl);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.modal-head {
  padding: 25px 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--panel-border);
}

.modal-body { padding: 30px; }

.modal-body input {
  width: 100%;
  background: rgba(0, 0, 0, 0.4);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  color: var(--text);
  padding: 14px 18px;
  margin-bottom: 20px;
  outline: none;
}

.btn {
  padding: 14px 28px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  cursor: pointer;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
}

.btn.primary { background: linear-gradient(135deg, var(--primary) 0%, var(--primary-strong) 100%); color: #000; border: none; }

/* Mobile Footer */
.mobile-footer {
  display: none;
  height: 70px;
  background: var(--bg-layer);
  backdrop-filter: blur(20px);
  border-top: 1px solid var(--panel-border);
  padding: 0 20px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 200;
}

.footer-btn {
  flex: 1;
  height: 48px;
  border-radius: 999px;
  border: 1px solid var(--panel-border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--muted);
  font-weight: 800;
  cursor: pointer;
}

.footer-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.footer-btn.primary {
  flex: 2;
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-strong) 100%);
  color: #000;
  height: 48px;
  border-radius: 999px;
  font-weight: 800;
}

.footer-btn.danger {
  flex: 1;
  border-color: rgba(255, 111, 130, 0.35);
  color: var(--danger);
  background: rgba(255, 111, 130, 0.12);
}

/* Responsive */
@media (max-width: 1400px) {
  :root {
    --sidebar-width: 300px;
    --sidebar-history-width: 280px;
  }
}

@media (max-width: 1200px) {
  .sidebar-history { display: none; }
}

@media (max-width: 768px) {
  .top-nav {
    padding: 0 14px;
    gap: 10px;
  }
  .nav-brand {
    flex: 1;
    min-width: 0;
  }
  .brand-logo {
    width: 38px;
    height: 38px;
    border-radius: 12px;
  }
  .nav-brand h1 {
    font-size: 17px;
  }
  .brand-site-link {
    font-size: 11px;
  }
  .nav-user-area {
    gap: 10px;
    flex-shrink: 0;
  }
  .ref-dashed-grid {
    grid-template-columns: repeat(auto-fill, minmax(82px, 1fr));
  }
  html, body {
    height: 100%;
    overflow: auto;
  }
  .app-container {
    height: auto;
    min-height: 100vh;
  }
  .nav-btn { display: none; }
  .nav-btn.primary { display: block; }
  .nav-btn.recharge { display: block; }
  .mobile-footer { display: flex; }
  .preview-actions { display: none; }
  .preview-stage { padding-bottom: 90px; }
  .workbench-layout {
    flex-direction: column;
    padding: 12px;
    gap: 12px;
    overflow: visible;
    padding-bottom: calc(90px + env(safe-area-inset-bottom, 0px));
  }
  .sidebar-params {
    display: flex;
    width: auto;
  }
  .params-form {
    max-height: none;
  }
  .reference-list {
    grid-template-columns: repeat(2, 1fr);
  }
  .preview-header {
    padding: 14px 14px;
    flex-wrap: wrap;
    gap: 10px;
  }
  .status-indicator {
    flex-wrap: wrap;
    gap: 10px;
  }
  .preview-stage {
    padding: 18px 14px;
    justify-content: flex-start;
    overflow: visible;
  }
  .mobile-footer {
    padding-bottom: calc(env(safe-area-inset-bottom, 0px));
    height: calc(70px + env(safe-area-inset-bottom, 0px));
  }
  body.mobile-history-open .sidebar-history {
    display: flex;
    position: fixed;
    inset: 90px 12px 92px 12px;
    width: auto;
    z-index: 190;
  }
}

@media (hover: none) and (pointer: coarse) {
  .ref-remove {
    opacity: 1;
    transform: translateY(0);
  }
}
