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

/* ---------- 상단 바 ---------- */
.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; text-decoration: none;
}
.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; }

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

/* ---------- 레이아웃 ---------- */
.layout { flex: 1; display: flex; min-height: 0; }
.sidebar {
  width: 260px; 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; padding: 0 12px 8px; }

.file-list { list-style: none; margin: 0; padding: 0 6px 8px; overflow-y: auto; flex: 1; }
.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.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-xlsx { background: #15803d; }
.kind-pptx { background: #c2410c; }
.kind-other { background: #6b7280; }

/* ---------- 본문 ---------- */
.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.ok { background: var(--ok-bg); color: var(--ok); }
.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: 580px; line-height: 1.6;
}
.empty-title { font-size: 18px; font-weight: 700; margin-bottom: 8px; }
.muted { color: var(--muted); font-size: 12px; }

.sheet-tabs {
  display: flex; gap: 2px; overflow-x: auto; padding: 0 8px; background: var(--surface);
  border-top: 1px solid var(--border); flex-shrink: 0;
}
.sheet-tab {
  border: 0; border-bottom: 3px solid transparent; background: none; color: var(--muted);
  padding: 7px 14px; font: inherit; font-size: 13px; cursor: pointer; white-space: nowrap;
}
.sheet-tab:hover { color: var(--text); }
.sheet-tab.active { color: var(--ok); border-bottom-color: var(--ok); font-weight: 600; }
.sheet-tab.hidden-sheet { font-style: italic; opacity: .7; }

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

/* ---------- XLSX ---------- */
.xlsx-sheet { background: #fff; color: #000; display: inline-block; box-shadow: 0 2px 10px rgba(0,0,0,.2); }
.xlsx-empty { padding: 40px 60px; color: #666; }
.xlsx-table {
  border-collapse: collapse; table-layout: fixed; width: max-content;
  font-family: "Malgun Gothic", "맑은 고딕", sans-serif; font-size: 11pt;
}
.xlsx-table th {
  background: #f1f3f5; color: #555; font-weight: 400; font-size: 11px; border: 1px solid #d0d4d9;
  position: sticky; z-index: 2; padding: 0 4px;
}
.xlsx-table thead th { top: 0; height: 22px; }
.xlsx-table tbody th { left: 0; z-index: 1; text-align: center; }
.xlsx-table th.xlsx-corner { left: 0; z-index: 3; }
.xlsx-table td {
  padding: 1px 3px; overflow: hidden; white-space: nowrap; text-overflow: clip; vertical-align: bottom;
  background-image: linear-gradient(to right, transparent calc(100% - 1px), #e2e5e9 0),
                    linear-gradient(to bottom, transparent calc(100% - 1px), #e2e5e9 0);
}
.xlsx-table.no-grid td, .xlsx-table td.filled { background-image: none; }
.xlsx-table td.wrap { white-space: pre-wrap; overflow-wrap: anywhere; }

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