/*
 * wiki.contextbio.ai — 내부 운영 위키.
 *
 * 회사 사이트(contextbio.css)와 색·서체를 일부러 다르게 잡았다. 내부 문서와 공개
 * 사이트가 같은 얼굴이면 지금 어디를 보고 있는지 헷갈리고, 내부 문서를 열어 둔 채
 * 화면을 공유하는 사고가 난다. 짙은 청록 + 고운바탕이 "여기는 내부" 표시다.
 *
 * 게이트 상태는 <html data-gate="..."> 하나로 통제한다 (wiki-gate.js).
 *   pending  인증 확인 중 — 본문도 로그인 패널도 내지 않는다
 *   signin   미로그인 — 로그인 패널
 *   denied   로그인했지만 권한 없음
 *   error    Firebase 에 닿지 못함
 *   open     통과 — 본문
 */

:root {
  --paper:        #F4F6F5;
  --surface:      #FFFFFF;
  --surface-sunk: #ECEFEE;
  --ink:          #12191A;
  --ink-soft:     #4A5654;
  --ink-faint:    #7C8886;
  --rule:         #D8DEDC;
  --rule-soft:    #E6EAE9;
  --accent:       #0E6B5C;
  --accent-deep:  #094B41;
  --accent-wash:  #E2EFEB;
  --amber:        #96650F;
  --amber-wash:   #F5EBD8;
  --danger:       #A33528;
  --shadow:       0 1px 2px rgba(18, 25, 26, .05), 0 8px 24px -16px rgba(18, 25, 26, .30);

  --f-display: "Gowun Batang", "Nanum Myeongjo", Georgia, serif;
  --f-body:    "IBM Plex Sans KR", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  --f-mono:    "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper:        #0E1415;
    --surface:      #151D1E;
    --surface-sunk: #101819;
    --ink:          #E7ECEA;
    --ink-soft:     #A6B2AF;
    --ink-faint:    #77837F;
    --rule:         #26312F;
    --rule-soft:    #1D2626;
    --accent:       #56BFA8;
    --accent-deep:  #8FD9C6;
    --accent-wash:  #16302B;
    --amber:        #D8A75A;
    --amber-wash:   #302716;
    --danger:       #E8897B;
    --shadow:       0 1px 2px rgba(0, 0, 0, .40), 0 8px 24px -16px rgba(0, 0, 0, .70);
  }
}

:root[data-theme="dark"] {
  --paper:        #0E1415;
  --surface:      #151D1E;
  --surface-sunk: #101819;
  --ink:          #E7ECEA;
  --ink-soft:     #A6B2AF;
  --ink-faint:    #77837F;
  --rule:         #26312F;
  --rule-soft:    #1D2626;
  --accent:       #56BFA8;
  --accent-deep:  #8FD9C6;
  --accent-wash:  #16302B;
  --amber:        #D8A75A;
  --amber-wash:   #302716;
  --danger:       #E8897B;
  --shadow:       0 1px 2px rgba(0, 0, 0, .40), 0 8px 24px -16px rgba(0, 0, 0, .70);
}

* { box-sizing: border-box; }

/* [hidden] 은 display 를 주는 규칙에 밀린다 — 명시적으로 이긴다. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: 16px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  word-break: keep-all;
}

/* ---------------------------------------------------------------- 게이트 */

/* 기본은 전부 감춤 — 상태가 정해질 때만 하나씩 연다(fail closed).
   본문은 data-gate="open" 에서만 나타난다. */
.gate-panel,
.wiki-page { display: none; }

[data-gate="pending"] .gate-pending,
[data-gate="signin"]  .gate-signin,
[data-gate="denied"]  .gate-denied,
[data-gate="error"]   .gate-error { display: block; }

[data-gate="open"] .wiki-page { display: block; }

.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 32px 20px;
}

[data-gate="open"] .gate { display: none; }

.gate-panel {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 6px;
  padding: 30px 28px 28px;
  box-shadow: var(--shadow);
  text-align: center;
}

.gate-mark {
  font-family: var(--f-mono);
  font-size: .64rem;
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--accent);
  margin: 0 0 14px;
}

.gate-panel h1 {
  font-family: var(--f-display);
  font-size: 1.5rem;
  font-weight: 700;
  margin: 0 0 8px;
  letter-spacing: -.01em;
}

.gate-panel p.say {
  margin: 0 0 20px;
  font-size: .89rem;
  color: var(--ink-soft);
  font-weight: 300;
  line-height: 1.65;
}

.btn:focus-visible,
.rail a:focus-visible,
.doc a:focus-visible,
.wiki-head a:focus-visible,
.wiki-head button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn {
  font-family: var(--f-body);
  font-size: .885rem;
  font-weight: 500;
  padding: 10px 16px;
  border-radius: 4px;
  border: 1px solid var(--rule);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  width: 100%;
  transition: border-color .14s ease, background .14s ease;
}

.btn:hover { border-color: var(--accent); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #FFFFFF;
}

:root[data-theme="dark"] .btn-primary,
.btn-primary { color: #FFFFFF; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn-primary { color: #08201C; }
}

:root[data-theme="dark"] .btn-primary { color: #08201C; }

.btn-primary:hover { background: var(--accent-deep); border-color: var(--accent-deep); }

.gate-foot {
  margin: 18px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--rule-soft);
  font-size: .78rem;
  color: var(--ink-faint);
}

.gate-foot a { color: var(--accent); }

.spinner {
  width: 22px;
  height: 22px;
  margin: 0 auto 14px;
  border: 2px solid var(--rule);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------- 머리글 */

.wiki-head {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
}

.wiki-head-in {
  max-width: 1180px;
  margin: 0 auto;
  padding: 11px 28px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.wiki-head .brand {
  font-family: var(--f-mono);
  font-size: .7rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--accent);
  text-decoration: none;
  white-space: nowrap;
}

.wiki-head .spacer { flex: 1; }

.wiki-head a.out,
.wiki-head button.out {
  font-family: var(--f-body);
  font-size: .8rem;
  color: var(--ink-soft);
  text-decoration: none;
  background: none;
  border: 0;
  padding: 3px 2px;
  cursor: pointer;
  white-space: nowrap;
}

.wiki-head a.out:hover,
.wiki-head button.out:hover { color: var(--accent); }

/* 로그인한 계정 — 누르면 계정 페이지(프로필 편집)로 간다. 눌리는 것이라
   눌릴 것처럼 보여야 하므로 점선 밑줄을 깔고 hover 에서 강조한다. */
.wiki-head .who {
  font-family: var(--f-mono);
  font-size: .715rem;
  color: var(--ink-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 34ch;
  text-decoration: none;
  border-bottom: 1px dotted var(--rule);
  padding-bottom: 1px;
  transition: color .14s ease, border-color .14s ease;
}

.wiki-head .who:hover {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* 비어 있을 때(인증 확인 전)는 밑줄만 뜨지 않도록 */
.wiki-head .who:empty { border-bottom: 0; }

/* ---------------------------------------------------------------- 레이아웃 */

.shell {
  max-width: 1180px;
  margin: 0 auto;
  padding: 0 28px 96px;
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
  gap: 56px;
  align-items: start;
}

.masthead {
  grid-column: 1 / -1;
  padding: 56px 0 34px;
  border-bottom: 1px solid var(--rule);
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px 40px;
}

.masthead h1 {
  font-family: var(--f-display);
  font-weight: 700;
  font-size: clamp(2.3rem, 5vw, 3.15rem);
  line-height: 1.15;
  letter-spacing: -.015em;
  margin: 0;
  text-wrap: balance;
}

.masthead h1 em { font-style: normal; color: var(--accent); }

.masthead .sub {
  margin: 12px 0 0;
  max-width: 46ch;
  color: var(--ink-soft);
  font-size: .965rem;
  font-weight: 300;
}

.stamp {
  font-family: var(--f-mono);
  font-size: .715rem;
  line-height: 1.9;
  color: var(--ink-faint);
  text-align: right;
  white-space: nowrap;
}

.stamp b {
  display: block;
  font-weight: 500;
  color: var(--ink-soft);
  letter-spacing: .04em;
  text-transform: uppercase;
  font-size: .68rem;
}

/* ---------------------------------------------------------------- 목차 레일 */

.rail {
  position: sticky;
  top: 74px;
  padding-top: 44px;
  font-size: .845rem;
}

.rail .eyebrow {
  font-family: var(--f-mono);
  font-size: .66rem;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin: 0 0 14px;
  padding-left: 13px;
}

.rail ol {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--rule);
}

.rail a {
  display: block;
  padding: 5px 0 5px 13px;
  margin-left: -1px;
  border-left: 2px solid transparent;
  color: var(--ink-soft);
  text-decoration: none;
  transition: color .14s ease, border-color .14s ease;
}

.rail a:hover { color: var(--accent); }

.rail a.on {
  color: var(--ink);
  border-left-color: var(--accent);
  font-weight: 500;
}

.rail .page-link {
  font-weight: 600;
  color: var(--ink);
  border-left-color: var(--rule);
}

/* ---------------------------------------------------------------- 본문 */

.doc { padding-top: 44px; min-width: 0; }

.doc section { scroll-margin-top: 74px; }

.doc section + section {
  margin-top: 60px;
  padding-top: 52px;
  border-top: 1px solid var(--rule-soft);
}

.doc h2 {
  font-family: var(--f-display);
  font-weight: 700;
  font-size: 1.72rem;
  line-height: 1.35;
  letter-spacing: -.01em;
  margin: 0 0 18px;
  text-wrap: balance;
  scroll-margin-top: 74px;
}

.doc h3 {
  font-family: var(--f-body);
  font-weight: 600;
  font-size: 1.015rem;
  margin: 38px 0 10px;
}

.doc .lede {
  margin: 0 0 26px;
  color: var(--ink-soft);
  font-weight: 300;
  max-width: 62ch;
}

.doc p { margin: 0 0 15px; max-width: 66ch; }

.doc > section > p:last-child { margin-bottom: 0; }

.doc ul { margin: 0 0 15px; padding-left: 0; list-style: none; max-width: 66ch; }

.doc ul li { position: relative; padding-left: 17px; margin-bottom: 7px; }

.doc ul li::before {
  content: "";
  position: absolute;
  left: 2px;
  top: .72em;
  width: 5px;
  height: 1px;
  background: var(--accent);
}

.doc ol { margin: 0 0 15px; padding-left: 20px; max-width: 66ch; }
.doc ol li { margin-bottom: 7px; }

.doc a { color: var(--accent); text-decoration-thickness: 1px; text-underline-offset: 2.5px; }

code {
  font-family: var(--f-mono);
  font-size: .855em;
  background: var(--surface-sunk);
  border: 1px solid var(--rule-soft);
  border-radius: 3px;
  padding: .06em .34em;
  word-break: break-all;
}

pre {
  font-family: var(--f-mono);
  font-size: .82rem;
  line-height: 1.72;
  background: var(--surface-sunk);
  border: 1px solid var(--rule-soft);
  border-left: 2px solid var(--accent);
  border-radius: 4px;
  padding: 15px 18px;
  margin: 0 0 18px;
  overflow-x: auto;
}

pre code { background: none; border: 0; padding: 0; font-size: 1em; word-break: normal; }

/* ---------------------------------------------------------------- 표 */

.tw { overflow-x: auto; margin: 0 0 18px; }

table {
  border-collapse: collapse;
  width: 100%;
  min-width: 460px;
  font-size: .875rem;
  font-variant-numeric: tabular-nums;
}

th, td {
  text-align: left;
  padding: 9px 16px 9px 0;
  border-bottom: 1px solid var(--rule-soft);
  vertical-align: top;
}

th {
  font-family: var(--f-mono);
  font-size: .68rem;
  font-weight: 500;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--ink-faint);
  border-bottom-color: var(--rule);
  white-space: nowrap;
}

td code { white-space: nowrap; }
tr:last-child td { border-bottom: 0; }

td .meta {
  display: block;
  font-family: var(--f-mono);
  font-size: .68rem;
  color: var(--ink-faint);
  letter-spacing: .04em;
}

/* ---------------------------------------------------------------- 서비스 카드 */

.services {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(232px, 1fr));
  gap: 14px;
  margin: 0 0 20px;
}

.svc {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 5px;
  padding: 17px 18px 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.svc-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }

.svc h3 {
  font-family: var(--f-display);
  font-size: 1.16rem;
  font-weight: 700;
  margin: 0;
  letter-spacing: .01em;
}

.svc p { margin: 0; font-size: .845rem; line-height: 1.62; color: var(--ink-soft); font-weight: 300; }

.svc .where {
  font-family: var(--f-mono);
  font-size: .72rem;
  color: var(--ink-faint);
  margin-top: auto;
  padding-top: 9px;
  border-top: 1px dashed var(--rule-soft);
  word-break: break-all;
}

.tag {
  font-family: var(--f-mono);
  font-size: .625rem;
  letter-spacing: .08em;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 100px;
  white-space: nowrap;
  flex-shrink: 0;
}

.tag.live { background: var(--accent-wash); color: var(--accent-deep); }
.tag.soon { background: var(--amber-wash);  color: var(--amber); }

:root[data-theme="dark"] .tag.live,
:root[data-theme="dark"] .tag.soon { color: var(--ink); }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .tag.live,
  :root:not([data-theme="light"]) .tag.soon { color: var(--ink); }
}

/* ---------------------------------------------------------------- 콜아웃 */

.note {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-left: 2px solid var(--accent);
  border-radius: 4px;
  padding: 14px 18px;
  margin: 0 0 18px;
  font-size: .885rem;
  max-width: 68ch;
}

.note.warn { border-left-color: var(--amber); }

.note .label {
  font-family: var(--f-mono);
  font-size: .66rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--accent);
  display: block;
  margin-bottom: 5px;
}

.note.warn .label { color: var(--amber); }
.note p { margin: 0 0 10px; max-width: none; }
.note p:last-child { margin-bottom: 0; }

/* ---------------------------------------------------------------- 구성도 */

figure {
  margin: 0 0 20px;
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 5px;
  padding: 22px 20px 16px;
  box-shadow: var(--shadow);
}

figure .fw { overflow-x: auto; }
figure svg { display: block; width: 100%; min-width: 560px; height: auto; }

figcaption {
  font-size: .795rem;
  color: var(--ink-faint);
  margin-top: 12px;
  padding-top: 11px;
  border-top: 1px solid var(--rule-soft);
  line-height: 1.6;
}

.sv-box  { fill: var(--surface-sunk); stroke: var(--rule); }
.sv-key  { fill: var(--accent-wash);  stroke: var(--accent); }
.sv-t    { fill: var(--ink); font-family: var(--f-body); font-size: 12.5px; font-weight: 500; }
.sv-s    { fill: var(--ink-faint); font-family: var(--f-mono); font-size: 10px; }
.sv-lbl  { fill: var(--ink-faint); font-family: var(--f-mono); font-size: 9.5px; letter-spacing: .1em; }
.sv-line { stroke: var(--rule); stroke-width: 1.2; fill: none; }
.sv-line.hot { stroke: var(--accent); stroke-dasharray: 3 3; }

/* ---------------------------------------------------------------- 체크리스트 */

.doc ul.todo { display: flex; flex-direction: column; gap: 11px; margin: 0 0 18px; max-width: 68ch; }

.doc ul.todo li {
  background: var(--surface);
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 13px 16px 13px 0;
  margin: 0;
  display: grid;
  grid-template-columns: 30px 1fr;
  align-items: start;
  font-size: .885rem;
}

.doc ul.todo li::before { display: none; }

.todo .box {
  width: 13px;
  height: 13px;
  border: 1.5px solid var(--amber);
  border-radius: 2px;
  margin: 5px 0 0 12px;
}

.todo b { font-weight: 600; display: block; margin-bottom: 2px; }
.todo span.d { color: var(--ink-soft); font-weight: 300; }

/* ---------------------------------------------------------------- 꼬리말 */

.colophon {
  grid-column: 1 / -1;
  margin-top: 72px;
  padding-top: 22px;
  border-top: 1px solid var(--rule);
  font-family: var(--f-mono);
  font-size: .715rem;
  color: var(--ink-faint);
  display: flex;
  flex-wrap: wrap;
  gap: 8px 26px;
  justify-content: space-between;
}

/* ---------------------------------------------------------------- 좁은 화면 */

@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); gap: 0; padding: 0 20px 72px; }
  .wiki-head-in { padding: 10px 20px; }
  .wiki-head .who { max-width: 18ch; }
  .masthead { padding-top: 40px; }

  .rail {
    position: static;
    padding: 32px 0 22px;
    border-bottom: 1px solid var(--rule-soft);
  }

  .rail ol { flex-direction: row; flex-wrap: wrap; gap: 4px 6px; border-left: 0; }
  .rail .eyebrow { padding-left: 0; }

  .rail a {
    border: 1px solid var(--rule);
    border-radius: 100px;
    padding: 3px 11px;
    margin: 0;
    font-size: .8rem;
  }

  .rail a.on { border-color: var(--accent); }
  .doc { padding-top: 34px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

html { scroll-behavior: smooth; }

/* ── 웹 편집 (wiki-edit.js) ─────────────────────────────── */
.wiki-editor {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(18, 25, 26, .45);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.wiki-editor[hidden] { display: none; }
.wiki-editor-in {
  width: min(1100px, 100%); height: min(92vh, 100%);
  display: flex; flex-direction: column; gap: 10px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--rule); border-radius: 10px;
  box-shadow: var(--shadow); padding: 16px;
}
.wiki-editor-head { display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; }
.wiki-editor-path { font-family: var(--f-mono); font-size: 13px; color: var(--ink-faint); }
.wiki-editor-hint { margin: 0; font-size: 13px; color: var(--ink-soft); }
.wiki-editor textarea {
  flex: 1; min-height: 0; width: 100%; resize: none;
  font: 14px/1.6 var(--f-mono); color: var(--ink);
  background: var(--surface-sunk); border: 1px solid var(--rule); border-radius: 6px;
  padding: 12px;
}
.wiki-editor-foot { display: flex; gap: 8px; align-items: center; justify-content: flex-end; flex-wrap: wrap; }
.wiki-editor-note { flex: 1; min-width: 200px; font-size: 13px; color: var(--ink-soft); }
