/* ── Design tokens ─────────────────────────────────── */
:root {
  --bg: #0f1117;
  --bg-raised: #181b24;
  --bg-card: #1e2230;
  --bg-input: #252938;
  --border: rgba(255, 255, 255, 0.08);
  --border-focus: rgba(99, 134, 255, 0.5);
  --text: #e4e6ed;
  --text-muted: #8b90a0;
  --text-dim: #5c6070;
  --accent: #6386ff;
  --accent-glow: rgba(99, 134, 255, 0.15);
  --green: #34d399;
  --green-bg: rgba(52, 211, 153, 0.12);
  --orange: #fb923c;
  --orange-bg: rgba(251, 146, 60, 0.12);
  --red: #f87171;
  --red-bg: rgba(248, 113, 113, 0.12);
  --yellow: #fbbf24;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
  --sidebar-w: 220px;
  --topbar-h: 56px;
  --font-sans: "Inter", "Pretendard", "Noto Sans KR", -apple-system, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", "Fira Code", monospace;
  --font-serif: "Source Serif 4", "Noto Serif KR", Georgia, serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  display: flex;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Sidebar ──────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg-raised);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  z-index: 100;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  text-decoration: none;
  color: var(--text);
  margin-bottom: 28px;
}

.brand-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-serif);
  font-weight: 700;
  font-size: 18px;
  color: white;
}

.brand-text {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.2;
}

.brand-text small {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
}

.sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s;
}

.nav-item:hover { background: var(--bg-card); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--accent-glow); color: var(--accent); }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
}

.version-tag {
  font-size: 11px;
  color: var(--text-dim);
}

/* ── Main area ────────────────────────────────────── */
.main-area {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  height: var(--topbar-h);
  background: rgba(15, 17, 23, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  z-index: 50;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.topbar-title {
  font-size: 16px;
  font-weight: 600;
  font-family: var(--font-serif);
}

.page {
  padding: 24px 28px;
  max-width: 1400px;
  display: grid;
  gap: 20px;
}

/* ── Stats row ────────────────────────────────────── */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}

.stat-card.accent { border-color: rgba(52, 211, 153, 0.2); }
.stat-card.warn { border-color: rgba(251, 146, 60, 0.2); }

.stat-number {
  font-size: 28px;
  font-weight: 700;
  font-family: var(--font-mono);
  line-height: 1;
  margin-bottom: 4px;
}

.stat-card.accent .stat-number { color: var(--green); }
.stat-card.warn .stat-number { color: var(--orange); }

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ── Cards ────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 18px;
}

.card-header h2 {
  font-family: var(--font-serif);
  font-size: 18px;
  font-weight: 600;
}

.card-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ── Grid ─────────────────────────────────────────── */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

/* ── Badge ────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--accent-glow);
  color: var(--accent);
}

.badge.muted {
  background: rgba(139, 144, 160, 0.12);
  color: var(--text-muted);
}

.badge.pulse {
  background: var(--orange-bg);
  color: var(--orange);
  animation: pulse 2s infinite;
}

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

/* ── Status ───────────────────────────────────────── */
.status-pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.status-pill.status-completed,
.status-pill.status-approved { background: var(--green-bg); color: var(--green); }
.status-pill.status-failed,
.status-pill.status-needs_fix { background: var(--orange-bg); color: var(--orange); }
.status-pill.status-running,
.status-pill.status-queued { background: var(--accent-glow); color: var(--accent); }
.status-pill.status-pending { background: rgba(139, 144, 160, 0.12); color: var(--text-muted); }

.status-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
}

.status-dot.status-completed,
.status-dot.status-approved { background: var(--green); }
.status-dot.status-failed,
.status-dot.status-needs_fix { background: var(--orange); }
.status-dot.status-running,
.status-dot.status-queued { background: var(--accent); animation: pulse 1.5s infinite; }
.status-dot.status-pending { background: var(--text-dim); }

/* ── Forms ────────────────────────────────────────── */
.form-stack {
  display: grid;
  gap: 16px;
}

.field { display: grid; gap: 6px; }

.field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

input, select, textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  transition: border-color 0.15s;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

textarea { resize: vertical; font-size: 13px; }

/* ── File drop ────────────────────────────────────── */
.file-drop {
  position: relative;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 32px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}

.file-drop:hover {
  border-color: var(--accent);
  background: var(--accent-glow);
}

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

.file-drop-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  pointer-events: none;
}

.file-drop-label svg { stroke: var(--text-dim); }

/* ── Buttons ──────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: #5070e0; text-decoration: none; }

.btn-secondary { background: rgba(99, 134, 255, 0.12); color: var(--accent); }
.btn-secondary:hover { background: rgba(99, 134, 255, 0.2); text-decoration: none; }

.btn-warning { background: var(--orange-bg); color: var(--orange); }
.btn-warning:hover { background: rgba(251, 146, 60, 0.2); text-decoration: none; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 6px 12px;
}
.btn-ghost:hover { background: var(--bg-input); color: var(--text); text-decoration: none; }

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-full { width: 100%; }

/* ── Table ────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  font-size: 13px;
}

.data-table .clickable-row { cursor: pointer; transition: background 0.1s; }
.data-table .clickable-row:hover { background: rgba(99, 134, 255, 0.06); }

.mono { font-family: var(--font-mono); font-size: 12px; }
.center { text-align: center; }
.truncate { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.empty-state {
  padding: 40px;
  text-align: center;
  color: var(--text-dim);
}

.help-text {
  font-size: 12px;
  color: var(--text-dim);
}

.help-text code {
  background: var(--bg-input);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
}

/* ── Info bar ─────────────────────────────────────── */
.info-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.info-item {
  flex: 1;
  min-width: 140px;
  padding: 14px 18px;
  border-right: 1px solid var(--border);
}

.info-item:last-child { border-right: none; }

.info-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 4px;
}

.info-value {
  font-size: 13px;
  color: var(--text);
}

/* ── PDF grid ─────────────────────────────────────── */
.pdf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}

.pdf-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  transition: all 0.15s;
  text-decoration: none;
}

.pdf-card:hover {
  border-color: var(--accent);
  background: var(--accent-glow);
  text-decoration: none;
}

.pdf-card svg { flex-shrink: 0; stroke: var(--accent); }
.pdf-card span { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── Tabs ─────────────────────────────────────────── */
.tab-bar {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.tab {
  padding: 8px 16px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text-muted);
  font: inherit;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}

.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Filter bar ───────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
}

.filter-btn {
  padding: 5px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
}

.filter-btn:hover { border-color: var(--accent); color: var(--text); }
.filter-btn.active { background: var(--accent-glow); border-color: var(--accent); color: var(--accent); }

/* ── Scene grid ───────────────────────────────────── */
.scene-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.scene-card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color 0.15s;
}

.scene-card:hover { border-color: rgba(255, 255, 255, 0.15); }

.scene-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
}

.episode-tag {
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.scene-image-wrap {
  position: relative;
  aspect-ratio: 16 / 9;
  overflow: hidden;
}

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

.scene-image-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s;
}

.scene-image-wrap:hover .scene-image-overlay { opacity: 1; }

.scene-image-placeholder {
  aspect-ratio: 16 / 9;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-input);
  color: var(--text-dim);
  font-size: 13px;
}

.scene-card-body {
  padding: 12px 14px;
  flex: 1;
}

.scene-card-body h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 6px;
}

.scene-card-body .caption {
  font-size: 13px;
  color: var(--text-muted);
  font-style: italic;
  margin-bottom: 4px;
}

.scene-card-body .meta {
  font-size: 12px;
  color: var(--text-dim);
}

.scene-card-body .small { font-size: 11px; }

.prompt-details {
  margin-top: 8px;
}

.prompt-details summary {
  font-size: 12px;
  color: var(--accent);
  cursor: pointer;
}

.prompt-text {
  margin-top: 6px;
  padding: 10px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-family: var(--font-mono);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 200px;
  overflow-y: auto;
  color: var(--text-muted);
}

.scene-card-footer {
  padding: 10px 14px 14px;
  display: grid;
  gap: 8px;
  border-top: 1px solid var(--border);
}

/* ── Review form ──────────────────────────────────── */
.review-form {
  display: grid;
  gap: 8px;
}

.review-controls {
  display: flex;
  gap: 8px;
}

.review-controls select {
  flex: 1;
  padding: 6px 10px;
  font-size: 12px;
}

.review-controls .btn { flex-shrink: 0; }

.review-form textarea {
  padding: 8px 10px;
  font-size: 12px;
  min-height: 48px;
}

.review-summary {
  display: flex;
  gap: 12px;
  margin-top: 4px;
}

.review-count {
  font-size: 12px;
  font-weight: 500;
}

.review-count.approved { color: var(--green); }
.review-count.needs_fix { color: var(--orange); }
.review-count.pending { color: var(--text-dim); }
.review-count.total { color: var(--text-muted); }

/* ── Reference grid ───────────────────────────────── */
.ref-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.ref-card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: border-color 0.15s;
}

.ref-card:hover { border-color: rgba(255, 255, 255, 0.15); }

.ref-card img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  display: block;
}

.ref-card-label {
  padding: 8px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.ref-id {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
}

.ref-type-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(99, 134, 255, 0.1);
  color: var(--accent);
  text-transform: uppercase;
}

/* ── Log box ──────────────────────────────────────── */
.log-box {
  margin: 0;
  max-height: 500px;
  overflow: auto;
  padding: 16px;
  border-radius: var(--radius-sm);
  background: #0a0c10;
  color: #a5d6a7;
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-all;
}

/* ── Modal ────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 40px;
}

.modal-overlay.open { display: flex; }

.modal-content {
  position: relative;
  max-width: 95vw;
  max-height: 90vh;
}

.modal-content img {
  max-width: 100%;
  max-height: 85vh;
  border-radius: var(--radius);
  object-fit: contain;
}

.modal-close {
  position: absolute;
  top: -36px; right: 0;
  background: none;
  border: none;
  color: white;
  font-size: 28px;
  cursor: pointer;
  padding: 4px 8px;
}

/* ── Responsive ───────────────────────────────────── */
@media (max-width: 1024px) {
  .sidebar { display: none; }
  .main-area { margin-left: 0; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .info-bar { flex-direction: column; }
  .info-item { border-right: none; border-bottom: 1px solid var(--border); }
}

@media (max-width: 640px) {
  .stats-row { grid-template-columns: 1fr; }
  .scene-grid { grid-template-columns: 1fr; }
  .page { padding: 16px; }
  .tab-bar { gap: 0; }
  .tab { padding: 8px 10px; font-size: 12px; }
}
