/**
 * @file docs/css/app.css
 * @description AtlasDesk 화면 틀 — WebApp Common GUI v0.5.9 「화면」 규칙(레일 60 · 패널 240 · 헤더 48 · 본문 최대 1640)과
 *   문서 본문(종이)·설정 줄·토스트·새 판 알림·오류 경계·좁은 화면 서랍. 색은 tokens.css 의 역할 토큰만 쓴다.
 *   보고서 본문(.slides-doc)은 slides.css · report.css, 지도는 geo.css, 자료 탭(흐름 트리 · 서류 · 확인 질문)과 상세 창은 data.css.
 *   이 파일 아래쪽의 서류 칩(.dc) · 단계 표(.tag) · 범례(.legend)는 여러 화면이 같이 쓰는 조각이다.
 */

/* ---------- 바탕 ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-size: calc(15px * var(--font-scale, 1));
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;            /* 페이지 전체가 아니라 본문 영역만 스크롤한다 */
}
button { font: inherit; color: inherit; }
a { color: var(--link); }
.mono { font-family: var(--font-mono); }
.muted { color: var(--muted); }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* 선형 아이콘: 24px 격자 · 선 1.75px · 둥근 끝. 레일 24px, 버튼 20px, 글자 옆 14px */
svg.ico { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.rail svg.ico { width: 24px; height: 24px; }
svg.ico.ico-sm { width: 14px; height: 14px; }

/* 스크롤바: 바탕 투명, 막대 자리 8px · 보이는 굵기 4px · 알약형 */
* { scrollbar-width: thin; scrollbar-color: var(--line) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-button { display: none; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: var(--r-pill); border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: padding-box; border: 2px solid transparent; }

/* ---------- 화면 구성 ---------- */
.app { display: flex; height: 100vh; height: 100dvh; }
.sidebar { display: flex; flex: none; height: 100%; z-index: 20; }
.rail {
  width: var(--rail-w); flex: none; display: flex; flex-direction: column; justify-content: space-between; align-items: center;
  padding: 10px 0; background: var(--sunken); border-right: 1px solid var(--line);
}
.rail-group { display: flex; flex-direction: column; gap: 8px; align-items: center; }
.rail-btn {
  position: relative; width: 42px; height: 42px; border-radius: var(--r-pill); border: 0; background: transparent;
  display: grid; place-items: center; cursor: pointer; color: var(--muted); transition: background var(--t-fast) ease, color var(--t-fast) ease;
}
.rail-btn:hover { background: var(--active); color: var(--fg); }
.rail-btn.on { background: var(--active); color: var(--fg); }
.rail-btn.on svg.ico { stroke-width: 2.25; }

.panel {
  width: var(--panel-w); flex: none; display: flex; flex-direction: column; overflow: hidden; background: var(--sunken);
  border-right: 1px solid var(--line); transition: width var(--t-base) ease, border-color var(--t-base) ease;
}
.app.panel-closed .panel { width: 0; border-right-color: transparent; }
.panel-head { height: var(--header-h); flex: none; display: flex; align-items: center; justify-content: space-between; padding: 0 8px 0 16px; border-bottom: 1px solid var(--line); min-width: var(--panel-w); }
.panel-title { font-weight: 700; font-size: 0.92rem; }
.panel-body { flex: 1; overflow: auto; padding: 8px 8px 16px; min-width: var(--panel-w); }
.panel-foot { flex: none; padding: 10px 16px 12px; border-top: 1px solid var(--line); font-size: 0.74rem; color: var(--muted); min-width: var(--panel-w); font-family: var(--font-mono); line-height: 1.5; }
.toc-group { margin: 6px 0 10px; }
.toc-head { font-size: 0.72rem; font-weight: 700; color: var(--muted); padding: 6px 10px 4px; letter-spacing: 0.02em; }
.toc a {
  display: block; padding: 6px 10px; border-radius: var(--r-md); text-decoration: none; color: var(--fg); font-size: 0.85rem; line-height: 1.4;
  transition: background var(--t-fast) ease;
}
.toc a:hover { background: var(--active); }
.toc a.on { background: var(--active); font-weight: 700; }
.toc a .no { font-family: var(--font-mono); font-size: 0.74rem; color: var(--muted); margin-right: 6px; }

.main-col { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ---------- 헤더 ---------- */
.header {
  position: relative; z-index: var(--z-header); height: var(--header-h); flex: none; display: flex; align-items: stretch; gap: 8px;
  padding: 0 10px; background: var(--sunken); border-bottom: 1px solid var(--line);
}
.h-left, .h-right { display: flex; align-items: center; gap: 4px; flex: none; }
.h-title { font-weight: 800; font-size: 0.98rem; text-decoration: none; color: var(--fg); white-space: nowrap; margin-left: 2px; letter-spacing: -0.01em; }
.icon-btn {
  position: relative; width: 32px; height: 32px; border: 0; border-radius: var(--r-md); background: transparent; color: var(--fg);
  display: grid; place-items: center; cursor: pointer; transition: background var(--t-fast) ease;
}
.icon-btn:hover { background: var(--active); }
.icon-btn[aria-expanded="true"], .icon-btn[aria-pressed="true"] { background: var(--fg); color: var(--bg); }
.icon-btn .dot { position: absolute; top: 5px; right: 5px; width: 7px; height: 7px; border-radius: 50%; background: var(--alert); }

.h-tabs { flex: 1; min-width: 0; display: flex; align-items: flex-end; justify-content: center; gap: 2px; }
.tabs {
  display: flex; gap: 3px; overflow-x: auto; scrollbar-width: none; align-items: flex-end; margin-bottom: -1px; max-width: 100%;
  scroll-behavior: smooth; cursor: default;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs.can-drag { cursor: grab; }
.tabs.dragging { cursor: grabbing; scroll-behavior: auto; }
.tab {
  flex: none; display: block; padding: 7px 20px 6px; font-size: 0.8em; font-weight: 700; white-space: nowrap; text-decoration: none;
  color: var(--muted); background: var(--active); border: 0; cursor: pointer;
  clip-path: polygon(9px 0, calc(100% - 9px) 0, 100% 100%, 0 100%);
  transition: background var(--t-fast) ease, color var(--t-fast) ease;
}
.tab:visited { color: var(--muted); }
.tab:hover { color: var(--fg); }
.tab.on, .tab.on:visited { background: var(--bg); color: var(--fg); padding-top: 10px; padding-bottom: 9px; }
.tab-nav { width: 22px; height: 30px; flex: none; border: 0; background: transparent; color: var(--fg); display: grid; place-items: center; cursor: pointer; padding: 0; margin-bottom: 2px; }
.tab-nav svg.ico { width: 16px; height: 16px; }
.tab-nav:disabled { opacity: 0.3; cursor: default; }

/* 헤더 아래로 펼쳐지는 패널 (필터 · 화면별 설정이 같은 자리를 쓴다) */
.header-drop {
  position: absolute; left: 0; right: 0; top: 100%; display: none; justify-content: center; padding: 0 16px;
}
.header-drop.is-open { display: flex; }
.drop-inner {
  width: 100%; max-width: var(--content-max); max-height: 70vh; overflow: auto; margin-top: 8px; padding: 14px 18px 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.14);
}

/* 설정 줄: 76px + 나머지, 사이 12px, 줄 사이 점선 */
.set-row { display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 12px; align-items: center; padding: 9px 0; border-bottom: 1px dashed var(--line); }
.set-row:last-child { border-bottom: 0; }
.set-row > .set-label { font-size: 0.8rem; font-weight: 700; }
.set-row > .set-ctrl { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-width: 0; }
.set-note { font-size: 0.85rem; color: var(--muted); padding: 4px 0 10px; }
.pill-btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--fg); border-radius: var(--r-pill); padding: 4px 12px;
  font-size: 0.82rem; cursor: pointer; transition: background var(--t-fast) ease; white-space: nowrap;
}
.pill-btn:hover { background: var(--active); }
.pill-btn[aria-pressed="true"] { background: var(--fg); color: var(--bg); border-color: var(--fg); font-weight: 700; }
.pill-btn:disabled { opacity: 0.45; cursor: default; }
.link-btn { border: 0; background: none; color: var(--link); cursor: pointer; padding: 0; text-decoration: underline; text-underline-offset: 2px; font-size: 0.85rem; }

/* ---------- 본문 ---------- */
.main { flex: 1; min-height: 0; overflow: auto; outline: none; }
.content { max-width: var(--content-max); margin: 0 auto; padding: 22px 24px 64px; }
.page-head { max-width: 52rem; margin: 4px 0 18px; }
.page-head h1 { font-size: 1.45rem; margin: 0 0 6px; letter-spacing: -0.01em; }
.page-head p { margin: 0; color: var(--muted); }

/* 문서 본문은 종이 위에 올린다: 밝은 테마는 흰색, 어두운 테마는 표면색 */
article.doc {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 28px clamp(16px, 3vw, 40px) 40px;
}
article.doc.is-report { background: var(--paper); }
/* 보고서의 스크립트·카드 잉크를 종이에 맞춘다 (어두운 테마에서도 읽히게) */
:root:is([data-skin="dark"], [data-skin="navy"]) .slides-doc {
  --c-bg: var(--paper); --c-fg: var(--fg); --c-muted: var(--muted); --c-line: var(--line); --c-sunken: var(--sunken); --c-mark: #6b5a16;
}
:root:is([data-skin="dark"], [data-skin="navy"]) .slides-doc .script mark { color: var(--fg); }
/* 장 번호: 묶음 제목 앞에 「장-묶음.」 (사이트의 제목 번호 매김과 같은 모양) */
.slides-doc { counter-reset: h2-no; }
.slides-doc > section > h2 { counter-increment: h2-no; }
.slides-doc > section > h2::before { content: var(--chap, "") "-" counter(h2-no) ". "; color: var(--muted); font-weight: 600; }
.doc-kicker { font-size: 0.78rem; color: var(--muted); font-family: var(--font-mono); margin-bottom: 4px; }

/* 문서 안의 일반 글 (자료 탭과 보조 페이지) */
.prose { max-width: 52rem; }
.prose h2 { font-size: 1.15rem; margin: 26px 0 8px; padding-bottom: 6px; border-bottom: 1px solid var(--line); }
.prose h3 { font-size: 1rem; margin: 18px 0 6px; }
.prose p, .prose li { font-size: 0.95rem; }

/* ---------- 카드 · 표 · 칩 (자료 탭) ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 18px 20px; margin: 16px 0; }
.card > h2 { font-size: 1.12rem; margin: 0 0 4px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card > .sub { color: var(--muted); font-size: 0.9rem; margin: 0 0 14px; max-width: 60rem; }
.tscroll { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-md); }
table.t { border-collapse: collapse; width: 100%; font-size: 0.86rem; background: var(--surface); }
table.t th, table.t td { border-bottom: 1px solid var(--line); padding: 7px 9px; text-align: left; vertical-align: top; }
table.t thead th { background: var(--sunken); font-size: 0.78rem; color: var(--muted); font-weight: 700; white-space: nowrap; position: sticky; top: 0; }
table.t tr:last-child td { border-bottom: 0; }
.mk { display: inline-block; font-size: 0.8rem; padding: 2px 6px; border-radius: var(--r-sm); background: var(--sunken); border: 1px solid var(--line); margin: 1px 0; white-space: nowrap; }
.mk b { margin-right: 3px; }
.mk.x { border-style: dashed; }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 0.76rem; padding: 2px 8px; border-radius: var(--r-pill); border: 1px solid var(--line); background: var(--sunken); color: var(--fg); white-space: nowrap; }
.tag.miss { border-style: dashed; }
.dc {
  display: inline-flex; align-items: center; gap: 5px; font: 600 0.76rem/1 var(--font-mono); padding: 4px 6px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: var(--surface); color: var(--fg); cursor: pointer; vertical-align: baseline;
}
.dc:hover { background: var(--active); }
.dc .t { font: 500 0.78rem/1.3 var(--font-body); color: var(--muted); }
.cl { font: 600 0.78rem/1 var(--font-mono); border: 0; background: none; color: var(--link); cursor: pointer; padding: 0; text-decoration: underline; text-underline-offset: 2px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 0.82rem; color: var(--muted); align-items: center; }

/* ---------- 토스트 · 새 판 알림 · 오류 경계 ---------- */
.toast {
  position: fixed; left: 50%; top: calc(var(--header-h) + 12px); transform: translateX(-50%); z-index: 200; padding: 8px 14px;
  background: var(--fg); color: var(--bg); border-radius: var(--r-md); font-size: 0.86rem; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}
.update-bar {
  position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 210; display: flex; align-items: center; gap: 10px;
  padding: 8px 8px 8px 16px; background: var(--fg); color: var(--bg); border-radius: var(--r-pill); box-shadow: 0 8px 26px rgba(0, 0, 0, 0.25); font-size: 0.88rem;
}
.update-bar .pill-btn { background: var(--bg); color: var(--fg); border-color: var(--bg); }
.update-bar .icon-btn { color: var(--bg); width: 28px; height: 28px; }
.update-bar .icon-btn:hover { background: rgba(255, 255, 255, 0.15); }
.error-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); padding: 22px 24px; max-width: 40rem; margin: 24px auto; }
.error-box h2 { margin: 0 0 6px; font-size: 1.1rem; }
.error-box p.mono { color: var(--muted); font-size: 0.82rem; word-break: break-all; }
.error-box .row { display: flex; gap: 8px; margin-top: 12px; }
.app-error { position: fixed; inset: 0; z-index: 300; background: var(--bg); display: grid; place-items: center; padding: 20px; }

/* ---------- 단축키 안내 배지 (Alt 를 누르고 있는 동안) ---------- */
.show-keys [data-kbd]::after {
  content: attr(data-kbd); position: absolute; right: -4px; bottom: -4px; width: 16px; height: 16px; display: grid; place-items: center;
  font: 700 10px/1 var(--font-mono); background: var(--fg); color: var(--bg); border-radius: var(--r-sm); text-transform: uppercase; pointer-events: none;
}
kbd { font: 600 0.78rem var(--font-mono); padding: 2px 6px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: var(--r-sm); background: var(--surface); }

/* ---------- 좁은 화면: 960px 아래에서는 레일과 패널을 한 덩어리 서랍으로 ---------- */
.backdrop { position: fixed; inset: 0; background: var(--scrim); z-index: var(--z-backdrop); opacity: 0; transition: opacity var(--t-slow) ease; }
.backdrop.is-open { opacity: 1; }
@media (max-width: 960px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: var(--z-drawer); transform: translateX(-100%);
    transition: transform var(--t-slow) ease; box-shadow: 8px 0 30px rgba(0, 0, 0, 0.18);
  }
  .app.drawer-open .sidebar { transform: none; }
  .app.panel-closed .panel { width: var(--panel-w); border-right-color: var(--line); }   /* 서랍 안에서는 항상 펼친다 */
  .h-tabs { justify-content: flex-start; }
  .content { padding: 16px 16px 56px; }
}
@media (max-width: 560px) {
  .h-title { display: none; }
  article.doc { padding: 18px 12px 28px; }
}

/* ---------- 움직임 줄이기 ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0s !important; animation-duration: 0s !important; scroll-behavior: auto !important; }
}

/* ---------- 인쇄 ---------- */
@media print {
  body { overflow: visible; }
  .sidebar, .header, .backdrop, .toast, .update-bar { display: none !important; }
  .app, .main-col, .main { display: block; height: auto; overflow: visible; }
  article.doc { border: 0; padding: 0; }
}
