: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; }

/* ---------- 상단 바 ---------- */
.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; }
.toolbar { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; margin-left: auto; }
.toolbar.disabled { opacity: .45; pointer-events: none; }
.group { display: flex; align-items: center; gap: 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;
}
.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.icon { width: 32px; height: 32px; padding: 0; font-size: 15px; }
.btn.small { padding: 3px 8px; font-size: 12px; }

.page-input { width: 56px; text-align: center; }
.page-input, select {
  height: 32px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text); font: inherit; padding: 0 6px;
}
.page-total { color: var(--muted); min-width: 40px; }

/* ---------- 레이아웃 ---------- */
.layout { flex: 1; display: flex; min-height: 0; }
.sidebar {
  width: 280px; flex-shrink: 0; display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border); min-height: 0;
}
.panel { display: flex; flex-direction: column; min-height: 0; }
.files-panel { max-height: 45%; border-bottom: 1px solid var(--border); }
.thumbs-panel { flex: 1; }
.panel-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; font-weight: 600; font-size: 13px;
}
.summary { font-weight: 400; color: var(--muted); font-size: 12px; }
.files-panel .panel-head { flex-direction: column; align-items: flex-start; gap: 2px; }
.panel-tools { display: flex; gap: 6px; padding: 0 12px 8px; flex-wrap: wrap; align-items: center; }
.check { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; margin-right: auto; }

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

/* 실제 포맷 종류 태그 */
.kind {
  display: inline-block; min-width: 34px; text-align: center; margin-right: 6px;
  border-radius: 3px; padding: 0 4px; font-size: 10px; font-weight: 700; color: #fff; vertical-align: 1px;
}
.kind-tiff { background: #0d9488; }
.kind-pdf { background: #dc2626; }
.kind-image { background: #7c3aed; }
.kind-other { background: #6b7280; }
.small-select { height: 24px; font-size: 12px; margin-right: auto; padding: 0 4px; }

.thumbs { overflow-y: auto; padding: 4px 12px 12px; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.thumb { cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.thumb-box {
  width: 120px; background: #fff; border: 2px solid transparent; outline: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.thumb-box canvas { display: block; max-width: 100%; max-height: 100%; }
.thumb.active .thumb-box { border-color: var(--accent); }
.thumb-num { font-size: 11px; color: var(--muted); }
.thumb.active .thumb-num { color: var(--accent); font-weight: 600; }

/* ---------- 본문 ---------- */
.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.unknown, .notice.unsupported { background: var(--err-bg); color: var(--err); }
.notice.ok { background: var(--ok-bg); color: var(--ok); }
.notice-text { flex: 1; }

.viewer { flex: 1; overflow: auto; background: var(--viewer-bg); position: relative; outline: none; }
.page-wrap { min-height: 100%; display: flex; align-items: flex-start; justify-content: center; padding: 16px; width: max-content; min-width: 100%; }
.page-wrap canvas { display: block; box-shadow: 0 2px 10px rgba(0,0,0,.25); background: #fff; }
.page-wrap.loading::after {
  content: "불러오는 중…"; position: absolute; top: 12px; right: 16px;
  background: var(--surface); color: var(--muted); padding: 4px 10px; border-radius: 4px; font-size: 12px;
}
.page-error { margin-top: 40px; color: var(--err); background: var(--err-bg); padding: 16px 20px; border-radius: 8px; }
.page-error .office-link { display: inline-block; margin-left: 12px; text-decoration: none; }

.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: 560px; 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);
}
[hidden] { display: none !important; }

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; max-height: 38%; border-right: 0; border-bottom: 1px solid var(--border); }
  .thumbs-panel { display: none; }
  .files-panel { max-height: none; flex: 1; border-bottom: 0; }
  .toolbar { margin-left: 0; }
}
