:root {
  --bg: #0b0d12;
  --bg-alt: #10131a;
  --surface: #151922;
  --surface-2: #1b202b;
  --border: #262c39;
  --text: #eef1f6;
  --text-dim: #9aa3b5;
  --text-faint: #626b80;
  --accent: #6ea8ff;
  --accent-2: #7ef0c9;
  --accent-grad: linear-gradient(135deg, #6ea8ff 0%, #8b7cff 55%, #7ef0c9 100%);
  --accent-ink: #0b0d12;
  --danger: #ff6b6b;
  --warn: #ffb454;
  --ok: #4ade80;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.35);
  --bg-radial: radial-gradient(circle at 15% -10%, #171d2c 0%, #0b0d12 55%);
  font-size: 16px;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f3f4f8;
  --bg-alt: #eceef4;
  --surface: #ffffff;
  --surface-2: #f4f5f9;
  --border: #e2e5ee;
  --text: #171a21;
  --text-dim: #5b6272;
  --text-faint: #8991a3;
  --accent-ink: #10131a;
  --shadow: 0 8px 26px rgba(30, 41, 59, 0.08);
  --bg-radial: radial-gradient(circle at 15% -10%, #eef1fb 0%, #f3f4f8 55%);
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg-radial) fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Pretendard", "Apple SD Gothic Neo",
    "Noto Sans KR", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  transition: background-color .15s ease, color .15s ease;
}

.app { width: 100%; padding: 14px 16px 40px; }

/* ---------------- topbar ---------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 4px 18px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--accent-grad);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; letter-spacing: -0.5px; color: var(--accent-ink); font-size: 15px;
  box-shadow: 0 6px 18px rgba(110, 168, 255, 0.25);
  flex-shrink: 0;
}
.brand-text h1 { font-size: 19px; margin: 0; font-weight: 700; letter-spacing: -0.2px; }
.brand-text .sub { margin: 2px 0 0; font-size: 12.5px; color: var(--text-dim); }

.topbar-right { display: flex; align-items: center; gap: 10px; }

.conn-status {
  display: flex; align-items: center; gap: 8px;
  font-size: 12.5px; color: var(--text-dim);
  background: var(--surface); border: 1px solid var(--border);
  padding: 7px 12px; border-radius: 999px;
}
.conn-status .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); }
.conn-status.online .dot { background: var(--ok); box-shadow: 0 0 8px rgba(74, 222, 128, 0.7); }
.conn-status.offline .dot { background: var(--danger); }

/* ---------------- settings button / popover ---------------- */
.settings-wrap { position: relative; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-dim); display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: border-color .15s ease, color .15s ease, transform .1s ease;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn[aria-expanded="true"] { color: var(--accent); border-color: var(--accent); }

.settings-popover {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 50;
  min-width: 220px; padding: 12px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
}
.settings-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.settings-row > span { font-size: 12.5px; color: var(--text-dim); font-weight: 600; }

.theme-switch {
  display: flex; gap: 3px; padding: 3px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
}
.theme-opt {
  display: flex; align-items: center; gap: 5px;
  border: none; background: transparent; color: var(--text-dim);
  font-size: 12px; font-weight: 600; padding: 6px 11px; border-radius: 999px;
  cursor: pointer; transition: background .15s ease, color .15s ease;
}
.theme-opt.active { background: var(--accent-grad); color: var(--accent-ink); }

/* ---------------- two-column layout ---------------- */
.layout {
  display: grid;
  grid-template-columns: minmax(300px, 360px) 1fr;
  gap: 16px;
  align-items: start;
}
.sidebar {
  display: flex; flex-direction: column; gap: 22px;
  position: sticky; top: 14px;
  max-height: calc(100vh - 28px);
  overflow-y: auto;
  overflow-x: hidden;
  padding: 2px 4px 2px 2px;
}
.sidebar::-webkit-scrollbar, .results-main::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }
.results-main { min-width: 0; }

/* ---------------- panels ---------------- */
.panel {
  background: linear-gradient(180deg, var(--surface) 0%, var(--bg-alt) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 20px 24px;
  box-shadow: var(--shadow);
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.panel h2 {
  font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-dim); margin: 0 0 14px; font-weight: 700;
  display: flex; align-items: center; gap: 10px;
}
/* "h2 + h2"는 두 제목 사이에 .model-choices/.dropzone 같은 콘텐츠 div가 끼어 있어서
   실제로는 한 번도 매치되지 않았다 — 그래서 "이미지 업로드" 제목이 위 블록에 그대로
   붙어 보였다. 형제 h2가 아니라 "패널 안 첫 번째가 아닌 모든 h2"를 기준으로 잡는다. */
.panel h2:not(:first-of-type) { margin-top: 30px; }
.step-no {
  width: 20px; height: 20px; border-radius: 6px; background: var(--surface-2);
  border: 1px solid var(--border); display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; color: var(--accent); font-weight: 800; flex-shrink: 0;
}
.queue-meta { font-size: 11.5px; color: var(--text-faint); margin: 0 0 16px; }

/* ---------------- model choices ---------------- */
.model-choices { display: flex; flex-direction: column; gap: 10px; }
.model-card {
  display: block; cursor: pointer;
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  padding: 13px 15px; background: var(--surface-2);
  transition: border-color .15s ease, background .15s ease, transform .1s ease;
}
.model-card:hover { border-color: #7d8aa8; transform: translateY(-1px); }
.model-card input { position: absolute; opacity: 0; pointer-events: none; }
.model-card:has(input:checked) {
  border-color: var(--accent);
  background: linear-gradient(180deg, rgba(110,168,255,0.14), rgba(110,168,255,0.04));
  box-shadow: 0 0 0 1px rgba(110,168,255,0.25) inset;
}
.model-card-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; row-gap: 6px; }
.model-label { font-weight: 700; font-size: 13.5px; line-height: 1.4; }
.model-sub { display: block; margin-top: 7px; font-size: 11.5px; color: var(--text-dim); line-height: 1.55; }
.badge {
  font-size: 9.5px; font-weight: 800; letter-spacing: 0.03em; text-transform: uppercase;
  background: var(--accent-grad); color: var(--accent-ink); padding: 4px 8px; border-radius: 999px;
  white-space: nowrap; flex-shrink: 0;
}

/* ---------------- dropzone ---------------- */
.dropzone {
  border: 1.5px dashed var(--border); border-radius: var(--radius);
  padding: 28px 16px; text-align: center; cursor: pointer;
  background: var(--surface-2); transition: border-color .15s ease, background .15s ease;
  outline: none;
}
.dropzone:hover, .dropzone:focus-visible { border-color: var(--accent); }
.dropzone.dragover {
  border-color: var(--accent-2); background: rgba(126, 240, 201, 0.06);
}
.dropzone-inner { color: var(--text-dim); display: flex; flex-direction: column; align-items: center; gap: 7px; }
.dropzone-inner svg { color: var(--accent); margin-bottom: 2px; }
.dropzone-inner p { margin: 0; font-size: 13px; line-height: 1.5; }
.dropzone-inner p strong { color: var(--text); }
.dropzone-inner .hint { font-size: 11px; color: var(--text-faint); }
.upload-error {
  margin-top: 12px; padding: 10px 14px; border-radius: var(--radius-sm);
  background: rgba(255,107,107,0.1); border: 1px solid rgba(255,107,107,0.35);
  color: #ff8f8f; font-size: 12.5px;
}

/* ---------------- queue (sidebar, stacked) ---------------- */
.queue-col + .queue-col { margin-top: 22px; }
.queue-col h3 {
  font-size: 12px; color: var(--text-dim); font-weight: 700; margin: 0 0 11px;
  display: flex; align-items: center; gap: 8px;
}
.queue-col .dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot-processing { background: var(--accent); box-shadow: 0 0 8px rgba(110,168,255,0.7); animation: pulse 1.4s infinite; }
.dot-queued { background: var(--warn); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

.job-list { display: flex; flex-direction: column; gap: 10px; }
.job-list .empty { color: var(--text-faint); font-size: 12.5px; margin: 2px 0; }

/* ---------------- job card ---------------- */
.job-card {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); padding: 12px 13px;
}
.job-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; border-radius: 8px; margin: -4px; padding: 4px; transition: background .12s ease; }
.job-card-head:hover { background: rgba(255,255,255,0.03); }
.job-card-title { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 auto; }
.job-toggle {
  flex-shrink: 0; width: 24px; height: 24px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-dim); display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: transform .18s ease, color .15s ease, border-color .15s ease;
}
.job-toggle:hover { color: var(--accent); border-color: var(--accent); }
.job-toggle.collapsed svg { transform: rotate(-90deg); }
.job-toggle svg { transition: transform .18s ease; }
.job-filename {
  font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; max-width: 100%;
}
.job-model { font-size: 11px; color: var(--text-faint); }
.status-badge {
  font-size: 10px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.03em;
  padding: 3px 9px; border-radius: 999px; white-space: nowrap; flex-shrink: 0;
}
.status-badge.queued { background: rgba(255,180,84,0.15); color: var(--warn); }
.status-badge.processing { background: rgba(110,168,255,0.15); color: var(--accent); }
.status-badge.done { background: rgba(74,222,128,0.15); color: var(--ok); }
.status-badge.failed { background: rgba(255,107,107,0.15); color: var(--danger); }

.job-step { margin-top: 7px; font-size: 12px; color: var(--text-dim); }
.job-progress { margin-top: 8px; height: 4px; border-radius: 999px; background: var(--border); overflow: hidden; }
.job-progress-bar {
  height: 100%; width: 40%; border-radius: 999px; background: var(--accent-grad);
  animation: indeterminate 1.3s ease-in-out infinite;
}
.job-card:not(.is-processing) .job-progress { display: none; }
@keyframes indeterminate {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(250%); }
}
.job-error {
  margin-top: 9px; font-size: 12px; color: #ff8f8f;
  background: rgba(255,107,107,0.08); border: 1px solid rgba(255,107,107,0.3);
  border-radius: 8px; padding: 8px 10px;
}

/* ---------------- results (right column, done cards) ---------------- */
.results-panel { min-height: 200px; }
.results-list { gap: 16px; }
.results-list .job-card { padding: 16px 18px; }
.job-body { margin-top: 14px; display: flex; flex-direction: column; gap: 16px; }
/* `display:flex`가 클래스 선택자라 [hidden]의 UA 기본 display:none보다 우선순위가
   높아져(author > user-agent) `body.hidden = true`를 줘도 실제로는 안 숨었다 —
   더 구체적인 선택자로 hidden일 때의 display를 명시해 되찾는다. */
.job-body[hidden] { display: none; }
.results-list .job-filename { font-size: 14.5px; max-width: 60vw; }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 8px; }
.gallery figure { margin: 0; position: relative; border-radius: 10px; overflow: hidden; background: #000; cursor: zoom-in; border: 1px solid var(--border); }
.gallery img { display: block; width: 100%; height: 140px; object-fit: cover; transition: transform .2s ease; }
.gallery figure:hover img { transform: scale(1.04); }
.gallery figcaption {
  position: absolute; left: 0; right: 0; bottom: 0; padding: 5px 8px;
  font-size: 10.5px; color: #fff; background: linear-gradient(0deg, rgba(0,0,0,0.75), rgba(0,0,0,0));
}

.scorebox { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.scorebox-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 13px; background: var(--surface); border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.scorebox-head .integrity {
  font-size: 12px; font-weight: 700; color: var(--accent-ink); background: var(--accent-grad);
  padding: 4px 10px; border-radius: 999px;
}
.summary-chips { display: flex; gap: 8px; flex-wrap: wrap; font-size: 12px; color: var(--text-dim); }
.summary-chips b { color: var(--text); }

.score-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.score-table td { padding: 8px 13px; border-top: 1px solid var(--border); vertical-align: middle; }
.score-table td.name { color: var(--text-dim); width: 46%; }
.score-table td.val { text-align: right; font-variant-numeric: tabular-nums; width: 66px; color: var(--text); }
.score-bar-cell { width: 100%; }
.score-bar { height: 6px; border-radius: 999px; background: var(--border); overflow: hidden; }
.score-bar-fill { height: 100%; background: var(--accent-grad); border-radius: 999px; }

.boxes-list { padding: 10px 13px; font-size: 12px; color: var(--text-dim); border-top: 1px solid var(--border); }
.boxes-list code { color: var(--text); background: var(--surface); padding: 1px 5px; border-radius: 5px; }

.job-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-size: 12.5px; font-weight: 600; padding: 8px 14px;
  border-radius: 999px; cursor: pointer; text-decoration: none; display: inline-flex;
  align-items: center; gap: 6px; transition: border-color .15s ease, background .15s ease;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent-grad); color: var(--accent-ink); border: none; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-ghost { color: var(--text-faint); }
.btn-ghost:hover { color: var(--danger); border-color: var(--danger); }

/* ---------------- lightbox ---------------- */
.lightbox {
  position: fixed; inset: 0; background: rgba(6, 7, 10, 0.92); backdrop-filter: blur(4px);
  display: none; align-items: center; justify-content: center; flex-direction: column;
  z-index: 100; padding: 24px;
}
.lightbox.open { display: flex; }
.lightbox img { max-width: min(92vw, 1100px); max-height: 78vh; border-radius: 10px; box-shadow: 0 20px 60px rgba(0,0,0,0.6); }
.lightbox-caption { margin-top: 14px; color: var(--text-dim); font-size: 13px; }
.lightbox-close {
  position: absolute; top: 18px; right: 22px; width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 22px; line-height: 1; cursor: pointer; z-index: 2;
}
.lightbox-nav {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 46px; height: 46px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  transition: border-color .15s ease, color .15s ease, background .15s ease;
  z-index: 2;
}
.lightbox-nav:hover { border-color: var(--accent); color: var(--accent); }
.lightbox-prev { left: 14px; }
.lightbox-next { right: 14px; }
@media (max-width: 640px) {
  .lightbox-nav { width: 40px; height: 40px; }
  .lightbox-prev { left: 6px; }
  .lightbox-next { right: 6px; }
}

.foot { text-align: center; color: var(--text-faint); font-size: 11.5px; padding: 24px 0 4px; }

/* ---------------- responsive / mobile ---------------- */
@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; max-height: none; overflow: visible; }
}

@media (max-width: 640px) {
  .app { padding: 10px 10px 32px; }
  .topbar { padding-bottom: 14px; }
  .brand-text h1 { font-size: 16px; }
  .brand-mark { width: 38px; height: 38px; }
  .panel { padding: 14px 13px 16px; border-radius: 12px; }
  .gallery { grid-template-columns: repeat(2, 1fr); }
  .gallery img { height: 108px; }
  .results-list .job-filename { max-width: 55vw; }
  .scorebox-head { flex-direction: column; align-items: flex-start; }
  .lightbox-close { top: 10px; right: 10px; }
  .settings-popover { right: -40px; }
}
