/* Wi.VIEWER 공통 틀: 색 토큰, 상단 도구줄, 탐색창, 보기 영역, 메뉴, 대화상자, 알림, 접근성(KWCAG 2.2), 인쇄에서 틀 감추기.
   형식별 화면은 viewer-doc.css, viewer-ppt.css, viewer-excel.css, viewer-md.css 가 이 위에 덧붙인다(열린 문서의 형식에 맞는 것 하나만 불러온다). */

/* ---------------------------------------------------------------- 토큰 */
:root {
  font-family: -apple-system, BlinkMacSystemFont, "Pretendard", "Noto Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
  color-scheme: dark;
  --top: #1b1d21; --sidebar: #24262c; --canvas: #33363c; --surface: #292c32; --surface-hover: #383b42; --line: #3b3e45;
  --text: #eceef3; --muted: #bbc2cf; --subtle: #a8b1bf; --input: #202228;
  --accent: #8eb5ff; --accent-bg: rgba(101, 145, 248, .13);
  --shadow: 0 20px 65px rgba(0, 0, 0, .25); --page-shadow: 0 5px 18px rgba(0, 0, 0, .24);
  --focus: #f9c848; --sel: rgba(142, 181, 255, .4);
}
html[data-theme="light"] {
  color-scheme: light;
  --top: #fff; --sidebar: #fff; --canvas: #eff1f5; --surface: #fff; --surface-hover: #f1f3f7; --line: #e5e7ed;
  --text: #232935; --muted: #586373; --subtle: #647081; --input: #f5f6f9;
  --accent: #2755ad; --accent-bg: rgba(65, 108, 227, .09);
  --shadow: 0 20px 65px rgba(31, 41, 61, .18); --page-shadow: 0 8px 25px rgba(38, 49, 73, .13);
  --sel: rgba(39, 85, 173, .3);
}

/* ---------------------------------------------------------------- 바탕 */
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
button, input { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; opacity: .38; }
svg { display: block; flex: none; }
body { background: var(--canvas); color: var(--text); font-size: 13px; letter-spacing: -.025em; }
[hidden] { display: none !important; }
:where(button, input, [tabindex], a):focus-visible { outline: 3px solid var(--focus) !important; outline-offset: 2px !important; }
.skip-link { position: fixed; top: -100px; left: 14px; z-index: 200; background: #ffe083; color: #171717; padding: 13px 17px; border-radius: 6px; font-size: 14px; font-weight: 700; text-decoration: none; }
.skip-link:focus { top: 8px; }
.sr-only { position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important; white-space: nowrap !important; border: 0 !important; }

/* ---------------------------------------------------------------- 상단 도구줄 */
.app { height: 100dvh; min-height: 350px; display: flex; flex-direction: column; position: relative; overflow: hidden; }
.topbar { height: 62px; flex: none; display: grid; grid-template-columns: minmax(250px, 1fr) auto minmax(250px, 1fr); align-items: center; padding: 0 19px; background: var(--top); border-bottom: 1px solid var(--line); position: relative; z-index: 20; gap: 14px; }
.top-left, .top-right, .tool-group { display: flex; align-items: center; min-width: 0; }
.top-left { gap: 12px; }
.top-right { justify-content: flex-end; gap: 8px; }
.tool-group { gap: 3px; }
/* 가운데 도구: 쪽 이동 | 확대(화면 한가운데) | 맞춤. 형식마다 보이는 묶음이 다르다(viewer-*.css). */
.top-center { display: grid; grid-template-columns: minmax(0, 1fr) 1px auto 1px minmax(0, 1fr); align-items: center; justify-content: stretch; gap: 9px; min-width: 0; }
.top-center > .tool-group:first-child { justify-self: end; }
.top-center > .tool-group:nth-child(3) { justify-self: center; }
.top-center > .mode-toggle { justify-self: start; }
.top-center > .toolbar-divider { margin: 0; }
.icon-btn { display: inline-grid; place-items: center; border: none; border-radius: 9px; background: transparent; color: var(--muted); width: 34px; height: 34px; min-width: 36px; min-height: 36px; transition: background .15s, color .15s; position: relative; }
.icon-btn:hover:not(:disabled) { background: var(--surface-hover); color: var(--text); }
.icon-btn.active { background: var(--accent-bg); color: var(--accent); }
.icon-btn svg { height: 18px; width: 18px; stroke-width: 1.8; }
.brandline { height: 24px; width: 1px; background: var(--line); }
.doc-identity { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.doc-identity .docname { font-size: 13px; font-weight: 660; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 370px; }
.file-sub { font-size: 10px; color: var(--muted); font-weight: 500; display: flex; gap: 8px; align-items: center; }
.toolbar-divider { height: 22px; width: 1px; background: var(--line); margin: 0 5px; }
.page-field { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.num-input { height: 31px; width: 42px; border-radius: 6px; border: 1px solid var(--line); background: var(--input); color: var(--text); text-align: center; padding: 0 3px; font-size: 12px; outline: none; }
.num-input:focus { border-color: var(--accent); }
.zoom-label { color: var(--text); font-size: 12px; min-width: 43px; text-align: center; font-variant-numeric: tabular-nums; }
.mode-toggle { display: flex; align-items: center; padding: 3px; background: var(--input); border: 1px solid var(--line); border-radius: 9px; gap: 1px; }
.mode-toggle button { height: 27px; min-height: 30px; padding: 0 10px; border-radius: 6px; border: 0; background: transparent; color: var(--muted); font-size: 12px; white-space: nowrap; font-weight: 550; }
.mode-toggle button.active { text-decoration: underline; background: var(--surface-hover); color: var(--text); box-shadow: 0 1px 2px rgba(0, 0, 0, .1); }
.button-light { font-size: 12px; font-weight: 600; border: 1px solid var(--line); color: var(--text); background: var(--surface); border-radius: 8px; padding: 7px 11px; }
.button-light:hover { background: var(--surface-hover); }
.button-primary { font-size: 13px; font-weight: 750; border: 0; color: #101726; background: var(--accent); border-radius: 9px; padding: 11px 20px; min-height: 40px; }
.button-primary:hover { filter: brightness(1.08); }
html[data-theme="light"] .button-primary { color: #fff; }
/* 문서를 열기 전에는 가운데 도구를 감춘다 */
html[data-viewer="none"] .top-center { visibility: hidden; }

/* ---------------------------------------------------------------- 탐색창 */
.workspace { flex: 1; min-height: 0; display: flex; position: relative; }
.sidebar { width: 272px; flex: none; display: flex; flex-direction: column; background: var(--sidebar); border-right: 1px solid var(--line); min-height: 0; transition: width .22s, transform .22s; z-index: 15; visibility: visible; }
.sidebar.closed { width: 0; overflow: hidden; border-right: 0; visibility: hidden; }
.sidebar-top { padding: 21px 18px 13px; flex: none; width: 272px; }
.side-heading { display: flex; align-items: center; justify-content: space-between; margin-bottom: 17px; }
.side-heading strong { font-size: 14px; font-weight: 700; }
.side-heading span { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; }
.search-box { position: relative; display: flex; align-items: center; height: 36px; border: 1px solid var(--line); background: var(--input); border-radius: 8px; padding: 0 10px; gap: 8px; }
.search-box:focus-within { border-color: var(--accent); }
.search-box svg { height: 15px; width: 15px; color: var(--muted); }
.search-box input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); font-size: 12px; appearance: none; -webkit-appearance: none; }
.search-box input::placeholder { color: var(--subtle); }
.search-box input[type="search"]::-webkit-search-cancel-button, .search-box input[type="search"]::-webkit-search-decoration { display: none; -webkit-appearance: none; appearance: none; }
.kbd { font-size: 10px; color: var(--subtle); border: 1px solid var(--line); border-radius: 4px; padding: 1px 4px; }
.clear-search { border: 0; background: transparent; color: var(--muted); display: none; min-width: 28px; min-height: 28px; width: 28px; height: 28px; padding: 7px; flex: none; border-radius: 6px; }
.clear-search svg { width: 14px; height: 14px; }
.clear-search:hover { background: var(--surface-hover); color: var(--text); }
.side-tabs { display: flex; width: 272px; padding: 0 9px; border-bottom: 1px solid var(--line); gap: 20px; flex: none; justify-content: center; text-align: center; }
.side-tab { border: none; background: transparent; color: var(--muted); font-weight: 600; font-size: 12px; padding: 11px 2px 13px; position: relative; white-space: nowrap; text-align: center; }
.side-tab.active { color: var(--text); }
.side-tab.active:after { content: ""; position: absolute; bottom: -1px; left: 0; right: 0; height: 2px; background: var(--accent); border-radius: 2px; }
.side-content { overflow-y: auto; overflow-x: hidden; flex: 1; min-height: 0; width: 272px; scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
/* 미리보기(쪽 그림) */
.thumbs { padding: 20px 12px 28px; display: grid; grid-template-columns: minmax(0, 1fr); justify-content: center; justify-items: center; row-gap: 20px; }
.thumbs:focus { outline-offset: -3px; }
.thumbnail-item { display: flex; flex-direction: column; align-items: center; width: 100%; max-width: 220px; margin: 0 auto; gap: 9px; padding: 5px 3px; border: 0; background: transparent; color: var(--muted); font-size: 11px; border-radius: 9px; }
.thumbnail-paper { height: 139px; width: 98px; background: white; color: #1d1d1d; display: block; position: relative; border: 4px solid transparent; border-radius: 2px; box-shadow: 0 3px 9px rgba(0, 0, 0, .18); overflow: hidden; transition: border-color .15s, box-shadow .15s; }
.thumbnail-paper img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; user-select: none; -webkit-user-drag: none; }
.thumbnail-item.active .thumbnail-paper { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(89, 137, 244, .22), 0 3px 9px rgba(0, 0, 0, .12); }
.thumbnail-item.active .thumb-number { color: var(--accent); font-weight: 700; }
.thumbnail-item:hover .thumbnail-paper { border-color: var(--accent); }
.thumb-number { font-variant-numeric: tabular-nums; }
/* 검색 결과와 목차 */
.results { width: 100%; display: flex; flex-direction: column; align-items: stretch; justify-content: flex-start; padding: 17px 12px; }
.result-meta { font-size: 11px; color: var(--muted); padding: 0 10px 13px; line-height: 1.6; text-align: left; }
.result-item { width: 100%; text-align: left; border: 0; background: transparent; border-radius: 8px; padding: 12px 11px; display: flex; flex-direction: column; align-items: stretch; gap: 7px; color: var(--text); margin: 0; }
.result-item:hover { background: var(--surface-hover); }
.result-item .result-page { color: var(--accent); font-weight: 700; font-size: 11px; }
.result-item .excerpt { font-size: 12px; line-height: 1.7; color: var(--muted); overflow-wrap: anywhere; text-align: left; }
.result-item mark { background: #ead36a; color: #252313; border-radius: 2px; padding: 0 1px; }
.empty-result { width: 100%; padding: 50px 20px; text-align: center; color: var(--muted); font-size: 12px; line-height: 1.8; }
.empty-result svg { height: 24px; width: 24px; margin: 0 auto 15px; color: var(--subtle); }
.outline-list { list-style: none; margin: 0; padding: 0; }
.outline-list .outline-list { padding-left: 14px; }
.outline-list a { display: block; padding: 8px 11px; border-radius: 8px; color: var(--text); text-decoration: none; font-size: 12px; line-height: 1.5; overflow-wrap: anywhere; }
.outline-list a:hover { background: var(--surface-hover); }
.outline-list .outline-page { color: var(--muted); font-size: 11px; margin-left: 6px; font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------- 보기 영역 */
.viewer-area { min-width: 0; min-height: 0; flex: 1; position: relative; display: flex; flex-direction: column; background: var(--canvas); }
.canvas-scroll { flex: 1; min-height: 0; overflow: auto; scrollbar-width: thin; scrollbar-color: #8886 transparent; scroll-behavior: auto; scrollbar-gutter: stable; position: relative; outline: none; }
.canvas-scroll:focus-visible { outline-offset: -3px !important; }
.spinner { height: 28px; width: 28px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.file-drop { display: none; position: absolute; z-index: 30; inset: 14px; border: 2px dashed var(--accent); border-radius: 15px; background: var(--accent-bg); backdrop-filter: blur(12px); align-items: center; justify-content: center; flex-direction: column; gap: 12px; pointer-events: none; color: var(--text); font-weight: 700; font-size: 17px; text-align: center; padding: 0 20px; }
.viewer-area.dragover .file-drop { display: flex; }
/* 문서를 열기 전 안내 */
.empty-state { position: absolute; inset: 0; z-index: 5; display: flex; align-items: center; justify-content: center; padding: 24px; overflow: auto; }
.empty-card { width: min(520px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow); padding: 34px 32px 30px; text-align: center; }
.empty-card .empty-icon { width: 46px; height: 46px; margin: 0 auto 16px; color: var(--accent); }
.empty-card h2 { margin: 0 0 10px; font-size: 19px; font-weight: 760; }
.empty-card p { margin: 0 0 18px; color: var(--muted); font-size: 13px; line-height: 1.75; }
.empty-card .empty-hint { font-size: 11px; color: var(--subtle); margin: 14px 0 0; }
.url-form { margin-top: 18px; text-align: left; }
.url-form label { display: block; margin-bottom: 7px; font-size: 12px; font-weight: 700; color: var(--muted); }
.url-row { display: flex; gap: 8px; }
.url-row input { flex: 1; min-width: 0; height: 40px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--input); color: var(--text); font-size: 13px; }
.url-row .button-light { min-height: 40px; padding: 0 16px; }
.server-docs { margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--line); text-align: left; }
.server-docs h3 { margin: 0 0 8px; font-size: 12px; font-weight: 700; color: var(--muted); }
.server-docs ul { list-style: none; margin: 0; padding: 0; max-height: 190px; overflow: auto; }
.server-docs button { display: flex; justify-content: space-between; gap: 12px; width: 100%; border: 0; background: transparent; color: var(--text); text-align: left; padding: 8px 10px; border-radius: 8px; font-size: 12px; }
.server-docs button:hover { background: var(--surface-hover); }
.server-docs .doc-size { color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }

/* ---------------------------------------------------------------- 더보기 메뉴 */
.more-holder { position: relative; }
.menu-pop { position: absolute; right: 0; top: 44px; width: 254px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 8px; z-index: 50; display: none; visibility: hidden; }
.menu-pop.open { display: block; visibility: visible; animation: pop .12s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }
.menu-row { display: flex; justify-content: space-between; align-items: center; width: 100%; min-height: 39px; border: 0; border-radius: 7px; padding: 8px 10px; color: var(--text); background: transparent; text-align: left; font-size: 12px; }
.menu-row:hover { background: var(--surface-hover); }
.menu-row .menu-title { display: flex; align-items: center; gap: 11px; }
.menu-row svg { width: 17px; height: 17px; color: var(--muted); }
.menu-heading { font-size: 10px; color: var(--muted); padding: 11px 10px 5px; font-weight: 700; }
.menu-sep { height: 1px; background: var(--line); margin: 6px 2px; }
.switch { width: 31px; height: 18px; background: var(--line); border-radius: 100px; display: inline-flex; align-items: center; padding: 2px; transition: background .2s; }
.switch:after { content: ""; display: block; width: 14px; height: 14px; background: #fff; border-radius: 50%; box-shadow: 0 1px 2px #0002; transition: transform .2s; }
.switch.on { background: var(--accent); }
.switch.on:after { transform: translateX(13px); }

/* ---------------------------------------------------------------- 대화상자, 알림 */
.modal-backdrop { position: fixed; inset: 0; z-index: 70; background: rgba(10, 13, 19, .62); backdrop-filter: blur(3px); display: none; align-items: center; justify-content: center; padding: 20px; }
.modal-backdrop.visible { display: flex; }
.modal { max-width: 95vw; width: 450px; max-height: min(650px, 88vh); overflow: auto; background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 15px; box-shadow: var(--shadow); }
.modal-header { padding: 21px 24px 17px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--line); }
.modal-header h2 { font-size: 16px; font-weight: 760; margin: 0; }
.modal-body { padding: 22px 24px 25px; }
.modal-footer { padding: 15px 24px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; }
.meta-list { display: grid; grid-template-columns: 100px 1fr; margin: 0; gap: 16px 14px; }
.meta-list dt { font-size: 12px; color: var(--muted); }
.meta-list dd { font-size: 12px; margin: 0; min-width: 0; word-break: break-word; line-height: 1.55; }
.modal-lead { font-size: 13px; color: var(--muted); line-height: 1.75; margin: 9px 0 18px; }
.about-logo { font-size: 23px; font-weight: 850; letter-spacing: .02em; }
.about-logo span { color: var(--accent); }
.about-version { display: inline-block; border: 1px solid var(--line); padding: 4px 7px; border-radius: 5px; color: var(--muted); font-size: 11px; margin-top: 7px; }
.about-brand-row { display: flex; align-items: flex-end; justify-content: flex-start; gap: 12px; flex-wrap: wrap; }
.about-brand-row .about-logo { line-height: 1.15; }
.about-brand-row .about-version { margin: 0 0 2px; flex: none; }
.shortcut-grid { display: grid; grid-template-columns: 1fr auto; gap: 13px 12px; color: var(--muted); font-size: 12px; }
.shortcut-grid kbd { color: var(--text); font-family: inherit; background: var(--input); border: 1px solid var(--line); padding: 3px 7px; border-radius: 5px; font-size: 11px; }
.toast { position: fixed; z-index: 85; bottom: 25px; left: 50%; transform: translate(-50%, 15px); background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: 9px; padding: 11px 15px; box-shadow: var(--shadow); font-size: 12px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: 90vw; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------------------------------------------------------- 좁은 화면 */
@media (max-width: 1200px) {
  .topbar { grid-template-columns: minmax(160px, 1fr) auto minmax(145px, 1fr); gap: 7px; padding: 0 10px; }
  .doc-identity .docname { max-width: 200px; }
  .top-left { gap: 7px; }
  .top-center { gap: 5px; }
  .top-right { gap: 4px; }
  .mode-toggle button { padding: 0 7px; }
  .toolbar-divider { margin: 0 2px; }
}
/* 가운데 도구가 화면 한가운데에 오도록: 쪽 이동과 맞춤이 양옆에서 균형을 잡는다 */
@media (min-width: 901px) {
  .topbar { grid-template-columns: minmax(0, 1fr) 510px minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .topbar { height: 58px; grid-template-columns: minmax(0, 1fr) auto; row-gap: 0; }
  .top-center { position: absolute; top: 58px; left: 0; right: 0; height: 48px; background: var(--top); border-bottom: 1px solid var(--line); z-index: 9; }
  .workspace { padding-top: 48px; }
  .sidebar { position: absolute; top: 48px; bottom: 0; left: 0; box-shadow: 15px 0 28px rgba(0, 0, 0, .18); }
  .sidebar.closed { transform: translateX(-100%); width: 272px; }
  .doc-identity .docname { max-width: 37vw; }
  .brandline { display: none; }
  .sidebar-top { padding-top: 17px; }
  .mode-toggle { margin: 0 4px; }
}
@media (max-width: 480px) {
  .topbar { padding: 0 7px; }
  .doc-identity .docname { max-width: 39vw; font-size: 11px; }
  .top-right { gap: 1px; }
  .top-right > .icon-btn, .more-holder > .icon-btn { width: 30px; min-width: 30px; }
  .num-input { width: 33px; }
  .top-center { gap: 2px; }
  .top-center .icon-btn { width: 32px; height: 32px; }
  .mode-toggle button { padding: 0 5px; font-size: 10px; min-height: 28px; }
  .toolbar-divider { margin: 0 1px; }
}
@media (max-width: 420px) {
  .top-center > .tool-group:first-child { gap: 1px; }
  .top-center > .tool-group:first-child .icon-btn { width: 28px; min-width: 28px; height: 32px; min-height: 32px; }
  .top-center .page-field { gap: 3px; }
  .top-center .num-input { width: 28px; }
  .top-center .mode-toggle { margin: 0; }
  .top-center .mode-toggle button { padding-inline: 4px; }
}
@media (max-width: 340px) {
  .top-center > .tool-group:nth-child(3) { gap: 1px; }
  .top-center > .tool-group:nth-child(3) .icon-btn { width: 28px; min-width: 28px; height: 32px; min-height: 32px; }
  .top-center .zoom-label { min-width: 36px; }
  .top-center .mode-toggle button { padding-inline: 3px; }
}

/* ---------------------------------------------------------------- 접근성 설정 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; }
}
@media (forced-colors: active) {
  .side-tab.active:after, .switch, .thumbnail-item.active .thumbnail-paper { border: 2px solid Highlight; }
  .icon-btn.active, .side-tab.active, .mode-toggle button.active { color: Highlight; }
  .thumbnail-item.active .thumbnail-paper { border-width: 4px; }
}

/* ---------------------------------------------------------------- 인쇄: 틀은 종이에 나가지 않는다(종이 배치는 형식별 CSS) */
@media print {
  html, body, .app { overflow: visible !important; height: auto !important; background: #fff !important; color: #000 !important; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
  .skip-link, .sr-only, .topbar, .sidebar, .file-drop, .toast, .modal-backdrop, .password-overlay, .empty-state, #fullscreenCloseBar { display: none !important; }
  .workspace, .viewer-area, .canvas-scroll { display: block !important; position: static !important; height: auto !important; overflow: visible !important; }
}
