/* AHIS 데이터 뷰어 — 토큰·근거는 docs/viewer-design.md (Carbon 밀도 + Mintlify 문서 탐색).
   CSP default-src 'self' — inline style 을 쓰지 않으므로 모든 모양은 이 파일에 둔다. */

@font-face {
  font-family: "Pretendard";
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  src: url("fonts/Pretendard-Regular.subset.woff2?v=1.3.9") format("woff2");
}
@font-face {
  font-family: "Pretendard";
  font-weight: 600;
  font-style: normal;
  font-display: swap;
  src: url("fonts/Pretendard-SemiBold.subset.woff2?v=1.3.9") format("woff2");
}

:root {
  --bg: #ffffff;
  --surface: #f4f4f4;
  --surface-2: #e8e8e8;
  --text: #161616;
  --text-2: #525252;
  --text-3: #5e5e5e;
  --line: #e0e0e0;
  --line-strong: #c6c6c6;
  --border-input: #8d8d8d;
  --accent: #0f62fe;
  --accent-hover: #0043ce;
  --warn-band: #f1c21b;
  --warn-bg: #fcf4d6;
  --danger: #da1e28;
  --font: "Pretendard", system-ui, -apple-system, "Malgun Gothic", sans-serif;
  --mono: ui-monospace, D2Coding, Consolas, "Courier New", monospace;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --radius: 4px;
  --header-h: 48px;
}

*, *::before, *::after { box-sizing: border-box; }
html { font-size: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 0.875rem;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  font-synthesis: none; /* 400·600 만 동봉 — 합성 굵기 금지 */
  -webkit-font-smoothing: antialiased;
}
strong, b { font-weight: 600; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
code { font-family: var(--mono); font-size: 0.8125rem; }

button, input { font: inherit; color: inherit; }
button {
  min-height: 32px;
  padding: 0 var(--s4);
  border: 1px solid var(--border-input);
  border-radius: var(--radius);
  background: var(--bg);
  cursor: pointer;
}
button:hover { background: var(--surface); }
input {
  min-height: 32px;
  padding: 0 var(--s3);
  border: 1px solid var(--border-input);
  border-radius: var(--radius);
  background: var(--bg);
}
input::placeholder { color: var(--text-3); }

/* --- 헤더 --------------------------------------------------------------------------------- */
.top {
  display: flex;
  align-items: center;
  gap: var(--s3);
  height: var(--header-h);
  padding: 0 var(--s4);
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.top strong { font-size: 1rem; }
.top span { color: var(--text-2); }
.top form { margin-left: auto; }
.tree-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border-input);
  border-radius: var(--radius);
  cursor: pointer;
  user-select: none;
}
.tree-btn:hover { background: var(--surface); }
.tree-toggle { position: absolute; opacity: 0; pointer-events: none; }
.tree-toggle:focus-visible + .layout .tree { outline: 2px solid var(--accent); outline-offset: -2px; }

/* --- 레이아웃: 트리(사이드바) + 상세 ------------------------------------------------------------ */
.layout { display: grid; grid-template-columns: auto 1fr; height: calc(100vh - var(--header-h)); }
.tree-toggle:checked ~ .layout { grid-template-columns: 1fr; }
.tree-toggle:checked ~ .layout .tree { display: none; }
/* 오른쪽 아래 모서리를 끌어 폭 조절(CSS resize) — 상태 기억은 viewer.js */
.tree {
  width: 22rem;
  min-width: 12rem;
  max-width: 70vw;
  resize: horizontal;
  overflow: auto;
  padding: var(--s2) 0;
  border-right: 1px solid var(--line);
  background: var(--bg);
}

.nodes, .records { list-style: none; margin: 0; padding: 0; }
.nodes .nodes, .nodes .records, .children > .warn, .children > .empty { margin-left: var(--s4); }
.tree summary {
  display: flex;
  align-items: baseline;
  gap: var(--s2);
  min-height: 28px;
  padding: var(--s1) var(--s4) var(--s1) var(--s2);
  border-left: 2px solid transparent;
  cursor: pointer;
  list-style: none;
}
.tree summary::-webkit-details-marker { display: none; }
.tree summary::before {
  content: "▸";
  flex: none;
  width: 1em;
  color: var(--text-3);
  font-size: 0.75rem;
  transition: transform 0.1s;
}
.tree details[open] > summary::before { transform: rotate(90deg); }
.tree summary:hover { background: var(--surface); }
.tree details[open] > summary { background: var(--surface); }
.tree > .nodes > li > details[open] > summary { border-left-color: var(--accent); }  /* 현재 위치 띠는 소스 단계 1개만 */
.src-name { font-weight: 600; }
.src-id { color: var(--text-3); font-family: var(--mono); font-size: 0.75rem; }
.range { color: var(--text); }
.n { margin-left: auto; color: var(--text-3); font-size: 0.75rem; font-variant-numeric: tabular-nums; }

.search { display: flex; gap: var(--s1); margin: var(--s1) var(--s4) var(--s2) var(--s5); }
.search input { flex: 1; min-width: 0; }

.records a {
  display: block;
  padding: var(--s1) var(--s4) var(--s1) var(--s5);
  color: var(--text);
  border-left: 2px solid transparent;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.records a:hover { background: var(--surface); color: var(--text); text-decoration: none; }
.records a[aria-current="true"] { background: var(--surface-2); border-left-color: var(--accent); }
.more { margin: var(--s1) var(--s4) var(--s2) var(--s5); }

/* --- 상세 --------------------------------------------------------------------------------- */
.detail { overflow: auto; padding: var(--s5) var(--s6); }
.detail h2 { margin: 0 0 var(--s4); font-size: 1.25rem; font-weight: 600; line-height: 1.3; }
.detail h2 small { margin-left: var(--s2); color: var(--text-2); font-size: 1rem; font-weight: 400; }

.meta {
  display: grid;
  grid-template-columns: max-content 1fr;
  margin: 0 0 var(--s5);
  border-top: 1px solid var(--line);
}
.meta dt, .meta dd { margin: 0; padding: var(--s1) var(--s3); border-bottom: 1px solid var(--line); }
.meta dt { color: var(--text-2); background: var(--surface); }
.meta dd { word-break: break-all; }

.tabs { display: flex; gap: 0; margin: 0 0 var(--s4); border-bottom: 1px solid var(--line); }
.tabs button {
  min-height: 36px;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--text-2);
}
.tabs button:hover { background: var(--surface); color: var(--text); }
.tabs button[aria-selected="true"] { border-bottom-color: var(--accent); color: var(--text); font-weight: 600; }

pre {
  margin: 0 0 var(--s4);
  padding: var(--s3) var(--s4);
  max-height: 70vh;
  overflow: auto;
  background: var(--surface);
  border-left: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 0.875rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-all;
}
.obj { margin: 0 0 var(--s5); }
.obj figcaption { display: flex; flex-wrap: wrap; align-items: baseline; gap: var(--s2); margin-bottom: var(--s2); }
.obj figcaption code { color: var(--text-2); }
.obj img, .obj video { display: block; max-width: 100%; max-height: 70vh; border: 1px solid var(--line); }

.warn {
  margin: 0 0 var(--s4);
  padding: var(--s2) var(--s3);
  background: var(--warn-bg);
  border-left: 3px solid var(--warn-band);
  color: var(--text);
}
.warn a { color: var(--accent-hover); text-decoration: underline; }  /* 경고 면 위 accent 4.54 → 7.07 */
.hint, .empty { color: var(--text-2); }
.empty { padding: var(--s1) var(--s4) var(--s1) var(--s5); }
.error { color: var(--danger); }

/* --- 로그인 -------------------------------------------------------------------------------- */
.login {
  display: grid;
  gap: var(--s4);
  max-width: 22rem;
  margin: 14vh auto;
  padding: var(--s6);
  border: 1px solid var(--line);
  background: var(--bg);
}
.login h1 { margin: 0; font-size: 1.25rem; font-weight: 600; }
.login form { display: grid; gap: var(--s3); }
.login label { display: grid; gap: var(--s1); color: var(--text-2); }
.login button[type="submit"] { min-height: 40px; border-color: var(--accent); background: var(--accent); color: #ffffff; }
.login button[type="submit"]:hover { border-color: var(--accent-hover); background: var(--accent-hover); }
