:root {
  --bg: #e8eef8;
  --bg-soft: #f4f7fc;
  --glass: rgba(255, 255, 255, 0.58);
  --glass-strong: rgba(255, 255, 255, 0.78);
  --glass-border: rgba(255, 255, 255, 0.72);
  --glass-border-soft: rgba(148, 163, 184, 0.22);
  --glass-inset: rgba(255, 255, 255, 0.42);
  --text: #1e293b;
  --text-muted: #64748b;
  --accent: #6b7cff;
  --accent-2: #9b8afb;
  --accent-soft: rgba(107, 124, 255, 0.14);
  --accent-glow: rgba(107, 124, 255, 0.22);
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --running: #2563eb;
  --radius: 22px;
  --radius-sm: 14px;
  --shadow: 0 8px 32px rgba(100, 120, 180, 0.12), 0 2px 8px rgba(100, 120, 180, 0.06);
  --shadow-lg: 0 24px 56px rgba(90, 110, 180, 0.18);
  --font: "DM Sans", "Noto Sans SC", system-ui, -apple-system, "SF Pro Text", "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --sidebar: 260px;
  --blur: 20px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: linear-gradient(155deg, #e4ecf8 0%, #efe8f8 42%, #e4f2fb 78%, #f0eaf6 100%);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  position: relative;
  min-height: 100%;
  overflow-x: hidden;
}

.ambient {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
}
.orb {
  position: absolute;
  border-radius: 50%;
  will-change: transform;
  opacity: 0.6;
  filter: blur(2px);
}
.orb-a {
  width: 46vw; height: 46vw; max-width: 560px; max-height: 560px;
  left: -10%; top: -14%;
  background: radial-gradient(circle, rgba(167, 180, 255, 0.6) 0%, rgba(167, 180, 255, 0) 70%);
  animation: floatA 28s ease-in-out infinite;
}
.orb-b {
  width: 38vw; height: 38vw; max-width: 460px; max-height: 460px;
  right: -8%; top: 18%;
  background: radial-gradient(circle, rgba(210, 185, 255, 0.55) 0%, rgba(200, 180, 255, 0) 70%);
  animation: floatB 34s ease-in-out infinite;
}
.orb-c {
  width: 32vw; height: 32vw; max-width: 400px; max-height: 400px;
  left: 28%; bottom: -12%;
  background: radial-gradient(circle, rgba(170, 220, 255, 0.5) 0%, rgba(180, 220, 255, 0) 70%);
  animation: floatC 32s ease-in-out infinite;
}
@keyframes floatA {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(6%, 8%) scale(1.05); }
}
@keyframes floatB {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(-8%, -5%) scale(1.08); }
}
@keyframes floatC {
  0%, 100% { transform: translate(0, 0); }
  50% { transform: translate(5%, -10%); }
}

@media (prefers-reduced-motion: reduce) {
  .orb { animation: none !important; }
  .view.active { animation: none !important; }
  .status-running::before { animation: none !important; }
  .toast { animation: none !important; }
  .glass-card::after { animation: none !important; display: none; }
  .gallery-item:hover { transform: none; }
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
code {
  font-family: var(--mono);
  font-size: 0.84em;
  background: rgba(107, 124, 255, 0.1);
  padding: 0.12em 0.45em;
  border-radius: 6px;
  color: #4f5fd6;
}
.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.req { color: var(--danger); }

.glass-card,
.glass-panel {
  background: var(--glass);
  backdrop-filter: blur(var(--blur)) saturate(1.4);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(1.4);
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.glass-card::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    105deg,
    transparent 38%,
    rgba(255, 255, 255, 0.38) 50%,
    transparent 62%
  );
  background-size: 220% 100%;
  pointer-events: none;
  opacity: 0.32;
  animation: shimmer 12s ease-in-out infinite;
}
@keyframes shimmer {
  0%, 100% { background-position: 100% 0; }
  50% { background-position: 0% 0; }
}
.glass-card > *,
.glass-panel > * { position: relative; z-index: 1; }

.glass-inset {
  background: var(--glass-inset);
  border: 1px solid var(--glass-border-soft);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}

.logo-mark {
  width: 48px; height: 48px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(107,124,255,0.22), rgba(155,138,251,0.18)),
    rgba(255,255,255,0.75);
  border: 1px solid var(--glass-border-soft);
  position: relative;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(107, 124, 255, 0.18);
}
.logo-mark::before {
  content: "";
  position: absolute;
  inset: 12px;
  border: 2px solid transparent;
  border-image: linear-gradient(135deg, var(--accent), var(--accent-2)) 1;
  clip-path: polygon(50% 0%, 0% 100%, 100% 100%);
  opacity: 0.95;
}
.logo-mark.sm { width: 38px; height: 38px; border-radius: 12px; }
.logo-mark.sm::before { inset: 9px; border-width: 1.5px; }

.login-screen {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 24px;
  position: relative;
  z-index: 1;
}
.login-card {
  width: min(420px, 100%);
  border-radius: 28px;
  padding: 40px 36px;
}
.login-brand {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 28px;
}
.login-brand h1 {
  margin: 0;
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.login-brand p { margin: 4px 0 0; font-size: 0.85rem; }
.login-hint { margin-top: 20px; font-size: 0.8rem; }

label {
  display: block;
  font-size: 0.85rem;
  font-weight: 560;
  margin-bottom: 8px;
  color: var(--text-muted);
}
.label-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.label-row label { margin-bottom: 0; }

input[type="text"],
input[type="password"],
input[type="number"],
input[type="url"],
textarea,
select {
  width: 100%;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid var(--glass-border-soft);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  color: var(--text);
}
input:focus, textarea:focus, select:focus {
  border-color: rgba(107, 124, 255, 0.55);
  box-shadow: 0 0 0 3px var(--accent-glow);
  background: rgba(255, 255, 255, 0.95);
}
textarea { resize: vertical; min-height: 128px; line-height: 1.55; }
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2364748b' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}
.field { margin-bottom: 20px; }
.field-row.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.field-hint { margin: 8px 0 0; font-size: 0.75rem; line-height: 1.45; }
.tip-box {
  margin-top: 10px;
  padding: 10px 12px;
  background: rgba(107, 124, 255, 0.08);
  border: 1px solid rgba(107, 124, 255, 0.16);
  border-radius: 12px;
  color: var(--text-muted);
}
.tip-box strong { color: var(--text); font-weight: 600; }
.form-error { color: var(--danger); font-size: 0.85rem; min-height: 1.2em; margin: 10px 0 0; }
.form-msg { font-size: 0.85rem; color: var(--success); margin-left: 12px; max-width: 360px; }
.form-msg.error { color: var(--danger); }

.prompt-helpers {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip-btn {
  border: 1px solid rgba(107, 124, 255, 0.22);
  background: rgba(255, 255, 255, 0.7);
  color: #4f5fd6;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.72rem;
  font-weight: 560;
  transition: background 0.15s, border-color 0.15s;
}
.chip-btn:hover {
  background: var(--accent-soft);
  border-color: rgba(107, 124, 255, 0.4);
}

.ref-help {
  margin-bottom: 12px;
  font-size: 0.82rem;
  line-height: 1.5;
}
.ref-help p { margin: 0 0 6px; }
.ref-help p:last-child { margin-bottom: 0; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--glass-border-soft);
  background: rgba(255, 255, 255, 0.7);
  color: var(--text);
  border-radius: 14px;
  padding: 10px 16px;
  font-weight: 580;
  transition: background 0.15s, border-color 0.15s, transform 0.1s, box-shadow 0.15s;
}
.btn:hover {
  background: rgba(255, 255, 255, 0.95);
  border-color: rgba(107, 124, 255, 0.3);
}
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: linear-gradient(135deg, #6b7cff, #9b8afb);
  border: none;
  color: #fff;
  box-shadow: 0 8px 22px rgba(107, 124, 255, 0.38);
}
.btn-primary:hover {
  filter: brightness(1.06);
  background: linear-gradient(135deg, #6b7cff, #9b8afb);
  color: #fff;
}
.btn-lg {
  padding: 13px 22px;
  font-size: 0.98rem;
  border-radius: 16px;
  min-width: 140px;
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
}
.btn-ghost:hover {
  background: var(--accent-soft);
  border-color: transparent;
}
.btn-danger {
  background: rgba(220, 38, 38, 0.08);
  border-color: rgba(220, 38, 38, 0.25);
  color: var(--danger);
}
.btn-sm { padding: 6px 10px; font-size: 0.8rem; border-radius: 10px; }
.btn-block { width: 100%; margin-top: 8px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.app {
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  border-radius: 0;
  border-top: none;
  border-bottom: none;
  border-left: none;
  display: flex;
  flex-direction: column;
  padding: 22px 14px;
  background: rgba(255, 255, 255, 0.48);
}
.sidebar-brand {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 6px 10px 22px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 1rem; letter-spacing: -0.02em; }
.brand-text span { font-size: 0.72rem; color: var(--text-muted); }
.nav { display: flex; flex-direction: column; gap: 5px; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  padding: 12px 14px;
  border-radius: 16px;
  font-weight: 520;
  transition: background 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.nav-item:hover {
  background: rgba(255, 255, 255, 0.6);
  color: var(--text);
}
.nav-item.active {
  background: linear-gradient(100deg, rgba(107,124,255,0.18), rgba(155,138,251,0.1));
  border-color: rgba(107,124,255,0.24);
  color: var(--text);
  box-shadow: 0 4px 14px rgba(107, 124, 255, 0.1);
}
.nav-icon { width: 1.2em; opacity: 0.85; }
.badge-count {
  margin-left: auto;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  min-width: 1.4em;
  padding: 2px 7px;
  border-radius: 999px;
  text-align: center;
}
.sidebar-footer {
  border-top: 1px solid var(--glass-border-soft);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.stats-mini { font-size: 0.75rem; line-height: 1.45; padding: 0 6px; }

.main {
  padding: 30px 36px 52px;
  max-width: 1320px;
  width: 100%;
}
.view { display: none; }
.view.active { display: block; animation: fadeIn 0.28s ease; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
.view-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 26px;
}
.view-header h2 {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: -0.03em;
  font-weight: 700;
  color: #0f172a;
}
.view-header p { margin: 6px 0 0; font-size: 0.9rem; }
.toolbar { display: flex; gap: 10px; align-items: center; }

.panel {
  border-radius: var(--radius);
  padding: 24px;
}
.panel h3 {
  margin: 0 0 16px;
  font-size: 1.02rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.generate-grid {
  display: grid;
  grid-template-columns: 1.45fr 1fr;
  gap: 22px;
  align-items: start;
}
.segmented {
  display: inline-flex;
  background: rgba(255, 255, 255, 0.55);
  border: 1px solid var(--glass-border-soft);
  border-radius: 14px;
  padding: 4px;
  gap: 2px;
  flex-wrap: wrap;
}
.seg {
  border: none;
  background: transparent;
  color: var(--text-muted);
  padding: 8px 16px;
  border-radius: 11px;
  font-size: 0.85rem;
  font-weight: 540;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
.seg.active {
  background: rgba(255, 255, 255, 0.95);
  color: var(--text);
  box-shadow: 0 2px 10px rgba(100, 120, 180, 0.14);
}

.custom-size-wrap {
  margin-top: 12px;
  padding-top: 4px;
}

.ref-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; }
.ref-row {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  background: rgba(255, 255, 255, 0.45);
  border: 1px solid var(--glass-border-soft);
  border-radius: 16px;
}
.ref-num {
  width: 36px;
  height: 36px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 0.85rem;
  color: #4f5fd6;
  background: linear-gradient(135deg, rgba(107,124,255,0.18), rgba(155,138,251,0.14));
  border: 1px solid rgba(107,124,255,0.2);
  flex-shrink: 0;
}
.ref-main { min-width: 0; }
.ref-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 4px;
  letter-spacing: 0.01em;
}
.ref-main input {
  padding: 9px 12px;
  font-size: 0.88rem;
}
.ref-preview {
  width: 52px;
  height: 52px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--glass-border-soft);
  background: rgba(255,255,255,0.7);
  flex-shrink: 0;
  display: grid;
  place-items: center;
}
.ref-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.ref-preview.empty,
.ref-preview.broken {
  background: rgba(148, 163, 184, 0.12);
}
.ref-preview-ph {
  font-size: 0.65rem;
  color: var(--text-muted);
}
.ref-preview.broken::after {
  content: "!";
  font-size: 0.85rem;
  color: var(--warning);
  font-weight: 700;
}
.ref-preview.broken img { display: none; }
.ref-remove { white-space: nowrap; }

.form-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
  padding-top: 6px;
}
.code-block {
  font-family: var(--mono);
  font-size: 0.75rem;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid var(--glass-border-soft);
  border-radius: 14px;
  padding: 14px;
  overflow: auto;
  max-height: 380px;
  white-space: pre-wrap;
  word-break: break-word;
  color: #4f46a8;
  margin: 0;
}
.pricing-card {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--glass-border-soft);
}
.pricing-card h4 { margin: 0 0 8px; font-size: 0.9rem; }
.preview-panel { position: sticky; top: 24px; }

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.job-list { display: flex; flex-direction: column; gap: 12px; }
.job-card {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 16px;
  align-items: center;
  background: var(--glass);
  backdrop-filter: blur(var(--blur)) saturate(1.3);
  -webkit-backdrop-filter: blur(var(--blur)) saturate(1.3);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.job-card .thumb {
  width: 68px; height: 68px;
  border-radius: 14px;
  object-fit: cover;
  background: rgba(255,255,255,0.6);
  border: 1px solid var(--glass-border-soft);
}
.job-card .thumb.placeholder {
  display: grid;
  place-items: center;
  color: var(--text-muted);
  font-size: 1.2rem;
}
.job-meta h4 {
  margin: 0 0 4px;
  font-size: 0.95rem;
  font-weight: 600;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.job-meta .sub { font-size: 0.78rem; color: var(--text-muted); }
.job-actions { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.72rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid transparent;
}
.status-pending {
  background: rgba(217, 119, 6, 0.12);
  color: var(--warning);
  border-color: rgba(217, 119, 6, 0.28);
}
.status-running {
  background: rgba(37, 99, 235, 0.12);
  color: var(--running);
  border-color: rgba(37, 99, 235, 0.28);
}
.status-running::before {
  content: "";
  width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
  animation: pulse 1.2s ease infinite;
}
.status-success {
  background: rgba(5, 150, 105, 0.12);
  color: var(--success);
  border-color: rgba(5, 150, 105, 0.28);
}
.status-failed {
  background: rgba(220, 38, 38, 0.1);
  color: var(--danger);
  border-color: rgba(220, 38, 38, 0.28);
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.7); }
}

.empty-state {
  text-align: center;
  padding: 64px 24px;
  border-radius: var(--radius);
  border-style: dashed;
}
.empty-icon {
  font-size: 2rem;
  opacity: 0.7;
  margin-bottom: 8px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.empty-state h3 { margin: 0 0 6px; }

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}
.gallery-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: 18px;
  overflow: hidden;
  border: 1px solid var(--glass-border);
  background: var(--glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  cursor: pointer;
  transition: transform 0.18s, box-shadow 0.18s, border-color 0.18s;
  box-shadow: var(--shadow);
}
.gallery-item:hover {
  transform: translateY(-3px);
  border-color: rgba(107, 124, 255, 0.4);
  box-shadow: var(--shadow-lg);
}
.gallery-item img {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
}
.gallery-item .cap {
  position: absolute;
  inset: auto 0 0 0;
  padding: 28px 12px 12px;
  background: linear-gradient(transparent, rgba(30, 41, 59, 0.72));
  font-size: 0.72rem;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.pager {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 16px;
  margin-top: 20px;
}

.table-wrap { overflow: auto; padding: 0; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
.data-table th, .data-table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--glass-border-soft);
  vertical-align: middle;
}
.data-table th {
  color: var(--text-muted);
  font-weight: 560;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: rgba(255, 255, 255, 0.45);
  position: sticky;
  top: 0;
}
.data-table tr:hover td { background: rgba(107, 124, 255, 0.04); }
.prompt-cell {
  max-width: 280px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 18px;
}
.kv {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 10px 12px;
  margin: 0;
  font-size: 0.9rem;
}
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; font-family: var(--mono); font-size: 0.82rem; word-break: break-word; }

.ref-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.ref-thumb {
  display: block;
  position: relative;
  width: 72px;
  height: 72px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--glass-border-soft);
  background: rgba(255,255,255,0.7);
  flex-shrink: 0;
  transition: transform 0.15s, box-shadow 0.15s;
}
.ref-thumb:hover {
  transform: scale(1.04);
  box-shadow: 0 4px 14px rgba(107, 124, 255, 0.2);
}
.ref-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.ref-thumb-badge {
  position: absolute;
  top: 4px;
  left: 4px;
  z-index: 1;
  background: rgba(30, 41, 59, 0.7);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 6px;
}
.ref-thumb-fallback {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  font-size: 0.65rem;
  color: var(--text-muted);
  padding: 4px;
  text-align: center;
  word-break: break-all;
}
.ref-link-list {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  font-size: 0.78rem;
  width: 100%;
}
.ref-link-list li {
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(232, 238, 248, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: grid;
  place-items: center;
  padding: 24px;
}
.lightbox-shell {
  width: min(1080px, 100%);
  max-height: min(90vh, 900px);
  border-radius: 24px;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.lightbox-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--glass-border-soft);
  flex-shrink: 0;
}
.lightbox-header h3 { margin: 0; font-size: 1rem; font-weight: 650; }
.lightbox-body {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 0;
  min-height: 0;
  flex: 1;
  overflow: hidden;
}
.lightbox-media {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(255, 255, 255, 0.25);
  min-height: 280px;
  overflow: auto;
  position: relative;
}
.lightbox-media img {
  max-width: 100%;
  max-height: calc(90vh - 100px);
  border-radius: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--glass-border-soft);
  object-fit: contain;
  background: #fff;
}
.lightbox-loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 0.9rem;
}
.lightbox-side {
  padding: 18px 20px 20px;
  overflow: auto;
  border-left: 1px solid var(--glass-border-soft);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.lb-section h4 {
  margin: 0 0 8px;
  font-size: 0.78rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.lb-section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}
.lb-section-head h4 { margin: 0; }
.lb-prompt {
  margin: 0;
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.65);
  border: 1px solid var(--glass-border-soft);
  border-radius: 14px;
  font-family: var(--font);
  font-size: 0.88rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 180px;
  overflow: auto;
  user-select: text;
  cursor: text;
  color: var(--text);
}
.lb-params {
  grid-template-columns: 110px 1fr;
  font-size: 0.85rem;
}
.lightbox-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: auto;
  padding-top: 8px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(232, 238, 248, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: grid;
  place-items: center;
  padding: 24px;
}
.modal-card {
  width: min(600px, 100%);
  border-radius: 22px;
  box-shadow: var(--shadow-lg);
  max-height: 85vh;
  overflow: auto;
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--glass-border-soft);
}
.modal-header h3 { margin: 0; font-size: 1rem; }
.modal-body { padding: 20px; font-size: 0.9rem; }
.modal-body p { margin: 0 0 10px; }
.modal-body .err {
  background: rgba(220, 38, 38, 0.08);
  border: 1px solid rgba(220, 38, 38, 0.22);
  color: var(--danger);
  padding: 10px 12px;
  border-radius: 12px;
  font-family: var(--mono);
  font-size: 0.78rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  padding: 12px 18px;
  border-radius: 14px;
  font-size: 0.9rem;
  animation: fadeIn 0.2s ease;
  max-width: min(380px, calc(100vw - 48px));
}

@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: relative;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
  }
  .nav { flex-direction: row; flex-wrap: wrap; flex: 1; }
  .sidebar-footer {
    width: 100%;
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
  .generate-grid { grid-template-columns: 1fr; }
  .preview-panel { position: static; }
  .field-row.two { grid-template-columns: 1fr; }
  .main { padding: 20px 16px 40px; }
  .job-card { grid-template-columns: 1fr; }
  .lightbox-body { grid-template-columns: 1fr; }
  .lightbox-side { border-left: none; border-top: 1px solid var(--glass-border-soft); }
  .lightbox-media img { max-height: 40vh; }
  .lightbox-shell { max-height: 92vh; }
  .ref-row {
    grid-template-columns: auto 1fr;
    grid-template-areas:
      "num main"
      "prev rem";
  }
  .ref-num { grid-area: num; }
  .ref-main { grid-area: main; }
  .ref-preview { grid-area: prev; }
  .ref-remove { grid-area: rem; justify-self: start; }
}
