:root {
  --bg: #f3f4f6;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --border: #d9dde3;
  --text: #1f2937;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --viewer-bg: #e5e7eb;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --err: #b91c1c;
  --err-bg: #fee2e2;
  --selected: #dbeafe;
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", "Segoe UI", sans-serif;
  font-size: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111827;
    --surface: #1f2937;
    --surface-2: #273244;
    --border: #374151;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --accent: #3b82f6;
    --viewer-bg: #0b1220;
    --ok: #4ade80;
    --ok-bg: #14532d;
    --warn: #fbbf24;
    --warn-bg: #451a03;
    --err: #f87171;
    --err-bg: #450a0a;
    --selected: #1e3a8a;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); display: flex; flex-direction: column; overflow: hidden; }
a { color: var(--accent); }
[hidden] { display: none !important; }

/* ---------- 상단 바 ---------- */
.topbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 16px; margin-right: 4px; }
.brand-sub { font-weight: 400; font-size: 12px; color: var(--muted); margin-left: 4px; }

.btn {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 6px; padding: 6px 12px; cursor: pointer; font: inherit; line-height: 1.2; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.small { padding: 3px 8px; font-size: 12px; }
.btn.wide { width: 100%; padding: 9px 12px; font-weight: 600; }

select {
  height: 30px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 13px; padding: 0 6px; min-width: 0;
}

/* ---------- 레이아웃 ---------- */
.layout { flex: 1; display: flex; min-height: 0; }
.sidebar {
  width: 320px; flex-shrink: 0; display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border); min-height: 0;
}
.panel-head {
  display: flex; flex-direction: column; gap: 2px;
  padding: 8px 12px; font-weight: 600; font-size: 13px;
}
.summary { font-weight: 400; color: var(--muted); font-size: 12px; }
.panel-tools { display: flex; gap: 6px; align-items: center; padding: 0 12px 8px; }
.check-all { display: flex; align-items: center; gap: 4px; font-size: 12px; margin-right: auto; cursor: pointer; }

.file-list { list-style: none; margin: 0; padding: 0 6px 8px; overflow-y: auto; flex: 1; min-height: 80px; }
.file-item {
  padding: 6px 8px; border-radius: 6px; cursor: pointer; display: flex; gap: 8px; align-items: flex-start;
}
.file-item:hover { background: var(--surface-2); }
.file-item.active { background: var(--selected); }
.file-item input { margin-top: 3px; flex-shrink: 0; }
.file-body { display: flex; flex-direction: column; gap: 3px; min-width: 0; flex: 1; }
.file-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; font-size: 11px; color: var(--muted); }
.file-save { font-size: 11px; }
.badge { border-radius: 4px; padding: 1px 6px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.badge.ok, .badge.done { color: var(--ok); background: var(--ok-bg); }
.badge.mismatch, .badge.working { color: var(--warn); background: var(--warn-bg); }
.badge.unsupported, .badge.error { color: var(--err); background: var(--err-bg); }
.badge.pending { color: var(--muted); background: var(--surface-2); }

.kind {
  display: inline-block; min-width: 38px; text-align: center; margin-right: 6px;
  border-radius: 3px; padding: 0 4px; font-size: 10px; font-weight: 700; color: #fff; vertical-align: 1px;
}
.kind-hwpx { background: #0284c7; }
.kind-docx { background: #1d4ed8; }
.kind-pptx { background: #c2410c; }
.kind-other { background: #6b7280; }

/* ---------- 변환 옵션 ---------- */
.options {
  border-top: 1px solid var(--border); padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 8px;
  background: var(--surface-2); flex-shrink: 0; max-height: 60%; overflow-y: auto;
}
.option-title { font-weight: 600; font-size: 13px; }
.radio { display: flex; gap: 8px; align-items: flex-start; cursor: pointer; font-size: 13px; }
.radio input { margin-top: 3px; flex-shrink: 0; }
.radio span { display: flex; flex-direction: column; gap: 2px; }
.radio small { color: var(--muted); font-size: 11.5px; line-height: 1.45; }
.option-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.option-row > span { width: 64px; flex-shrink: 0; color: var(--muted); }
.option-row select { flex: 1; }
.option-hint { margin: 0; font-size: 11.5px; color: var(--muted); line-height: 1.45; }

.progress { display: flex; flex-direction: column; gap: 6px; }
.progress-bar { height: 6px; border-radius: 3px; background: var(--border); overflow: hidden; }
.progress-bar span { display: block; height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.progress-text { font-size: 12px; color: var(--muted); }
.progress .btn { align-self: flex-start; }
.result {
  font-size: 12.5px; line-height: 1.5; padding: 8px 10px; border-radius: 6px;
  background: var(--ok-bg); color: var(--ok); display: flex; flex-direction: column; gap: 6px;
}
.result.error { background: var(--err-bg); color: var(--err); }
.result .btn { align-self: flex-start; }

/* ---------- 미리보기 ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.notice {
  display: flex; align-items: center; gap: 12px; padding: 8px 14px; font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.notice.mismatch { background: var(--warn-bg); color: var(--warn); }
.notice.error, .notice.unsupported { background: var(--err-bg); color: var(--err); }
.notice.info { background: var(--surface-2); color: var(--muted); }
.notice-text { flex: 1; }

.viewer { flex: 1; overflow: auto; background: var(--viewer-bg); position: relative; outline: none; }
.stage { padding: 16px; width: max-content; min-width: 100%; }
.stage.loading::after {
  content: "미리보기를 불러오는 중…"; position: fixed; top: 64px; right: 24px;
  background: var(--surface); color: var(--muted); padding: 4px 10px; border-radius: 4px; font-size: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.doc-host { margin: 0 auto; color: #000; }
.page-error { margin: 40px auto 0; max-width: 640px; color: var(--err); background: var(--err-bg); padding: 16px 20px; border-radius: 8px; line-height: 1.6; }

.empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; }
.empty-box {
  text-align: center; border: 2px dashed var(--border); border-radius: 12px; padding: 40px 32px;
  background: var(--surface); max-width: 600px; line-height: 1.6;
}
.empty-title { font-size: 18px; font-weight: 700; margin-bottom: 8px; }
.muted { color: var(--muted); font-size: 12px; }

.statusbar {
  display: flex; gap: 18px; flex-wrap: wrap; padding: 5px 12px; font-size: 12px; color: var(--muted);
  background: var(--surface); border-top: 1px solid var(--border); min-height: 26px;
}
.statusbar b { color: var(--text); font-weight: 600; }

.drop-overlay {
  position: fixed; inset: 0; background: rgba(37, 99, 235, .15); border: 4px dashed var(--accent);
  display: flex; align-items: center; justify-content: center; z-index: 50; pointer-events: none;
  font-size: 22px; font-weight: 700; color: var(--accent);
}

/* ---------- 변환 작업 영역 ----------
   화면에서는 보이지 않는 곳에 원래 크기로 그린다(display:none 이면 글꼴·그림 배치가 계산되지 않는다). */
.work { position: absolute; left: -100000px; top: 0; width: max-content; background: #fff; color: #000; }
.work .pdf-page { box-shadow: none !important; margin: 0 !important; }
.work .docx-wrapper { background: none !important; padding: 0 !important; display: block !important; }
.work .hwpx-doc { display: block; }
.work .pptx-preview-wrapper { background: none !important; height: auto !important; overflow: visible !important; }

@media print {
  html, body { height: auto; overflow: visible; display: block; background: #fff; }
  body > :not(.work) { display: none !important; }
  .work { position: static; left: auto; width: auto; }
  .work .pdf-page {
    height: var(--print-height, auto); min-height: 0 !important; overflow: hidden; break-inside: avoid;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  .work .pdf-page.break { break-after: page; }
}

@media (max-width: 760px) {
  .layout { flex-direction: column; overflow-y: auto; }
  .sidebar { width: 100%; border-right: 0; border-bottom: 1px solid var(--border); }
  .file-list { max-height: 200px; }
  .options { max-height: none; }
  .main { min-height: 60vh; }
}
