/* 색·글꼴·간격은 tokens.css 의 변수만 쓴다. */

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  min-height: 100vh; background: var(--bg); color: var(--ink);
  font-family: var(--font-sans); font-size: 14px; line-height: 1.55;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
mark.hit { background: var(--match-bg); color: var(--match-ink); border-radius: 2px; padding: 0 1px; }
.ell { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mono { font-family: var(--font-mono); }

/* ---------- 버튼·입력 ---------- */
.btn {
  border: 1px solid var(--line-strong); background: var(--surface); border-radius: var(--radius-md);
  padding: 4px 10px; font-size: 12.5px; cursor: pointer; color: var(--ink);
}
.btn:hover { border-color: var(--accent); }
.btn.primary { border-color: var(--accent); background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.small { padding: 1px 10px; font-size: 12px; }
.btn.quiet { border-color: transparent; background: transparent; color: var(--muted); }
.btn.quiet:hover { color: var(--stale); border-color: transparent; text-decoration: underline; }
.navbtn {
  border: 1px solid var(--line); background: transparent; border-radius: var(--radius-md);
  padding: 4px 10px; font-size: 12.5px; cursor: pointer; color: var(--muted);
}
.navbtn:hover { border-color: var(--accent-line); color: var(--accent); }
.navbtn.on { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.iconbtn {
  display: grid; place-items: center; width: 30px; height: 28px; border: 1px solid var(--line);
  background: transparent; border-radius: var(--radius-md); cursor: pointer; color: var(--muted);
}
.iconbtn:hover { border-color: var(--accent-line); color: var(--accent); }
.fld {
  min-width: 0; border: 1px solid var(--line-strong); background: var(--surface);
  border-radius: var(--radius-md); padding: 4px 8px;
}
.fld:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius-pill);
  padding: 0 8px; font: var(--text-chip); cursor: pointer; color: var(--muted); white-space: nowrap;
}
.chip.on { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- 상단 ---------- */
.top {
  display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap;
  padding: 10px var(--space-4); background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: var(--space-2); font-weight: 700; letter-spacing: -0.01em; margin-right: var(--space-3); }
.logo {
  width: 20px; height: 20px; border-radius: var(--radius-md); background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
}
.grow { flex-grow: 1; }
.keys { font-size: 12px; color: var(--faint); font-family: var(--font-mono); }

/* ---------- 배치 ---------- */
.layout { display: flex; flex-wrap: wrap; align-items: flex-start; }
.side {
  flex: 1 1 240px; max-width: 260px; min-width: 220px; align-self: stretch; min-height: calc(100vh - 50px);
  background: var(--surface); border-right: 1px solid var(--line); padding: 14px 10px;
  display: flex; flex-direction: column; gap: 10px;
}
.main { flex: 999 1 560px; min-width: 0; display: flex; justify-content: center; padding: 40px var(--space-4) 64px; }
.col { width: 100%; max-width: 760px; display: flex; flex-direction: column; }

/* ---------- 분류 패널 ---------- */
.tree { display: flex; flex-direction: column; gap: 1px; }
.facet {
  display: flex; align-items: center; gap: var(--space-2); border: 1px solid transparent; background: transparent;
  border-radius: var(--radius-md); padding: 5px 8px; font-size: 13px; cursor: pointer; text-align: left; color: var(--ink);
}
.facet.top { font-weight: 600; }
.facet.child { padding-left: 22px; }
.facet.zero { color: var(--faint); }
.facet:hover { border-color: var(--accent-line); color: var(--accent); }
.facet.on { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.facet .name { flex-grow: 1; }
.facet .n, .grp-n { font-family: var(--font-mono); font-size: 11px; color: var(--faint); }
.dashed {
  border: 1px dashed var(--line-strong); background: transparent; border-radius: var(--radius-md);
  padding: 6px; font-size: 12.5px; cursor: pointer; color: var(--muted);
}
.dashed:hover { color: var(--accent); border-color: var(--accent); }
.cat-form { display: flex; flex-direction: column; gap: 6px; }
.cat-form-btns { display: flex; gap: 6px; }
.side-head { display: flex; align-items: center; gap: var(--space-2); padding: 0 0 8px 8px; border-bottom: 1px solid var(--line); }
.side-head .label { flex-grow: 1; font-size: 12px; line-height: 18px; font-weight: 600; color: var(--muted); }
.navbtn.small { flex: none; padding: 1px 8px; font-size: 12px; line-height: 18px; }
/* 편집 상태: 패널 폭(약 200px)을 넘지 않게 버튼은 26px 아이콘이고, 이름이 길면 이름만 줄바꿈한다 */
.facet-edit {
  display: flex; align-items: flex-start; gap: 2px; border: 1px solid transparent;
  border-radius: var(--radius-md); padding: 2px 2px 2px 8px; font-size: 13px; color: var(--ink);
}
.facet-edit:not(.rename):hover, .facet-edit:not(.rename):focus-within { background: var(--surface-2); }
.facet-edit.top { font-weight: 600; }
.facet-edit.child { padding-left: 22px; }
.facet-edit .name { flex-grow: 1; min-width: 0; padding-top: 3px; overflow-wrap: anywhere; }
.facet-edit.rename { align-items: center; flex-wrap: wrap; row-gap: 4px; }
/* 설명칸은 이름칸 아래, 오른쪽 아이콘 두 개(56px)만큼 비운다 */
.facet-edit.rename .fld.desc { flex: 0 0 calc(100% - 56px); font-size: 12px; font-weight: 400; }
.facet-edit.rename .fld { flex: 1 1 0; min-width: 0; padding: 3px 6px; font-size: 13px; font-weight: inherit; }
.ibtn {
  flex: none; display: grid; place-items: center; width: 26px; height: 26px; padding: 0;
  border: 1px solid transparent; background: transparent; border-radius: var(--radius-md); color: var(--muted); cursor: pointer;
}
.ibtn.rn:hover { color: var(--accent); }
.ibtn.del:hover { color: var(--stale); }
.ibtn.cp:hover, .ibtn.dl:hover { color: var(--accent); }
.dline .ibtn { align-self: center; margin: -3px 0; }
.ibtn.ok { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.ibtn.ok:hover { color: var(--accent-ink); filter: brightness(1.08); }
.ibtn.no:hover { color: var(--ink); border-color: var(--line-strong); }
.ibtn:focus-visible { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- 검색창·요약 ---------- */
.search {
  position: relative; cursor: text;
  display: flex; align-items: center; gap: 10px; height: 48px; padding: 0 var(--space-2) 0 14px;
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-1); transition: border-color .15s, box-shadow .15s;
}
.search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.search > svg { color: var(--faint); flex: none; }
.search input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font: var(--text-search); color: var(--ink);
}
.search input::-webkit-search-cancel-button { display: none; }
.ibtn.help { cursor: pointer; }
.ibtn.help:hover, .ibtn.help[aria-expanded="true"] { color: var(--accent); }
/* 검색 문법 팝오버: 검색창 오른쪽 아래에 붙는다 */
.help-pop {
  position: absolute; top: calc(100% + 6px); right: 0; z-index: 3; cursor: default;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md); box-shadow: var(--shadow-1);
  padding: 8px 12px; font-size: 12.5px; color: var(--muted);
}
.help-pop table { border-collapse: collapse; }
.help-pop td { padding: 2px 0; vertical-align: baseline; }
.help-pop td:first-child { padding-right: var(--space-4); white-space: nowrap; }
.help-pop code { font-family: var(--font-mono); font-size: 12px; color: var(--ink); }
.help-pop code + code { margin-left: 6px; }
.summary { display: flex; align-items: center; gap: var(--space-2); padding: 10px 4px 6px; font-size: 12px; color: var(--muted); min-height: 38px; }
.summary b { color: var(--ink); font-weight: 600; }
.summary .note { color: var(--stale); }
.summary .ms { margin-left: auto; font-family: var(--font-mono); color: var(--faint); }

/* ---------- 결과 묶음 ---------- */
.grp { display: flex; flex-direction: column; margin-top: 10px; }
.grp.out { display: none; }
.grp-head {
  position: sticky; top: 0; z-index: 1; width: 100%; border: 0; background: var(--bg); cursor: pointer; text-align: left;
  display: flex; align-items: center; gap: 6px; padding: 8px 4px 6px; font: var(--text-label); color: var(--muted);
}
.grp-head:hover, .grp-head:hover .chev { color: var(--ink); }
.grp-head .chev { flex: none; width: 12px; display: inline-grid; place-items: center; font-size: 9px; color: var(--faint); transition: transform .2s ease; }
.grp.shut .chev { transform: rotate(-90deg); }
.grp-head .top-name { color: var(--faint); font-weight: 500; }
.grp-head .rule { flex-grow: 1; height: 1px; background: var(--line); margin: 0 6px; }
/* 묶음 접기: 높이와 투명도를 함께 줄인다 */
.gbody { display: grid; grid-template-rows: 1fr; opacity: 1; transition: grid-template-rows .22s ease, opacity .18s ease; }
.grp.shut .gbody { grid-template-rows: 0fr; opacity: 0; pointer-events: none; }
.gin { overflow: hidden; min-height: 0; padding: 0 4px; margin: 0 -4px; }
.grp-rows { display: flex; flex-direction: column; }

/* 걸러진 항목은 높이를 접으며 사라진다 */
.row { display: grid; grid-template-rows: 1fr; opacity: 1; transition: grid-template-rows .2s ease, opacity .16s ease; }
.row.out { grid-template-rows: 0fr; opacity: 0; pointer-events: none; }
.row > .in { overflow: hidden; min-height: 0; }
/* 행 사이는 가는 줄. 묶음 마지막 행에는 긋지 않는다 */
.item { border-bottom: 1px solid var(--line); }
.row.last .item { border-bottom-color: transparent; }
.row.sel .item, .item.editing {
  background: var(--surface); border: 1px solid var(--accent-line); border-radius: 8px; box-shadow: var(--shadow-1); margin: 2px 0;
}

.rowbtn {
  width: 100%; display: flex; align-items: flex-start; gap: var(--space-3); border: 0; background: transparent;
  border-radius: 8px; padding: 10px 14px; text-align: left; cursor: pointer; transition: background .12s;
}
.rowbtn:hover { background: var(--surface-2); }
.row.sel .rowbtn:hover { background: transparent; }
.qa { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.line { display: flex; align-items: baseline; gap: var(--space-2); width: 100%; }
.tag-q, .tag-a { font-family: var(--font-mono); font-size: 11px; font-weight: 500; flex: none; width: 12px; }
.tag-q { color: var(--accent); }
.tag-a { color: var(--faint); }
.qtext { font: var(--text-question); color: var(--ink); overflow-wrap: anywhere; min-width: 0; }
.atext { font: var(--text-answer); color: var(--ink); white-space: pre-wrap; overflow-wrap: anywhere; min-width: 0; }
.clamp2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.date { flex: none; padding-top: 3px; font: var(--text-meta); color: var(--faint); white-space: nowrap; }

/* 펼침: 근거·연결·이력 각 한 줄. 박스 없이 가는 줄 아래 작은 글자 */
.detail {
  display: flex; flex-direction: column; gap: 4px; padding: 8px 14px 12px 34px;
  border-top: 1px solid var(--line); font-size: 12.5px; line-height: 20px;
}
.dline { display: flex; gap: 10px; align-items: baseline; min-width: 0; }
.dline .label { flex: none; width: 28px; font-size: 11px; font-weight: 600; color: var(--faint); }
.dline .val { flex: 1; min-width: 0; }
.dline .val.ell { cursor: pointer; }
.dline .val.wrap { white-space: normal; overflow-wrap: anywhere; }
.ev { display: flex; align-items: baseline; gap: 6px; font: var(--text-evidence); color: var(--muted); }
.ev.wrap { flex-wrap: wrap; }
.ev .kind, .ev .sep, .ev .none { flex: none; color: var(--faint); }
.ev .none { font-family: var(--font-sans); }
.ev .dir { min-width: 0; flex: 0 1000 auto; color: var(--faint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; direction: rtl; text-align: left; }
.ev.wrap .dir { direction: ltr; white-space: normal; }
.ev .file { flex: none; color: var(--muted); }
/* 근거 경로 링크는 상자 없이 폴더·파일 칸을 그대로 둔다(줄임 배치 유지). 마우스를 올리면 accent 밑줄 */
.ev a.evlink { display: contents; color: inherit; }
.ev a.evlink:hover .file, .ev a.evlink:hover .target, .ev .target a.evlink:hover { color: var(--accent); text-decoration: underline; }
.ev .target, .ev .anchor { min-width: 0; flex: 0 1 auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ev.wrap .target, .ev.wrap .anchor { white-space: normal; }
.hist { display: flex; align-items: baseline; gap: 6px; font-family: var(--font-mono); font-size: 11.5px; color: var(--faint); }
.hist > span { min-width: 0; }
.more {
  flex: none; border: 1px solid var(--line); background: transparent; border-radius: var(--radius-pill);
  padding: 0 6px; font: inherit; font-size: 11px; line-height: 16px; cursor: pointer; color: var(--muted);
}
.more:hover { color: var(--accent); border-color: var(--accent-line); }
.links { display: flex; gap: var(--space-3); }
.links a { min-width: 0; }

/* 편집 폼 */
.edit { display: flex; flex-direction: column; gap: var(--space-2); padding: 12px 14px; }
.eline { display: flex; align-items: center; gap: var(--space-2); }
.eline.multi { align-items: flex-start; }
.eline .tag-q, .eline .tag-a { padding-top: 0; }
.eline.multi .tag-a, .eline.multi .count { padding-top: 7px; }
.edit .fq { flex: 1; font: var(--text-question); padding: 5px 9px; }
.edit .fa { flex: 1; font: var(--text-answer); padding: 5px 9px; resize: vertical; overflow-y: auto; }
.count { font-family: var(--font-mono); font-size: 11px; color: var(--faint); width: 52px; text-align: right; flex: none; }
.count.over { color: var(--stale); font-weight: 600; }
.erow {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin-left: 20px; padding-top: 10px;
  border-top: 1px solid var(--line); font-size: 12.5px;
}
.erow select.fld { flex: none; padding: 4px 6px; max-width: 240px; }
.erow .fe { flex: 1 1 220px; font: var(--text-evidence); }
.erow .spacer { flex-grow: 1; }
.emsg { padding-left: 20px; font-size: 12.5px; color: var(--stale); }
.emsg:empty { display: none; }
.similar { padding: 4px 0 0 20px; display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; }
.similar:empty { display: none; }
.similar .head { color: var(--muted); }
.similar a { display: block; }
.similar .sub { color: var(--faint); font-family: var(--font-mono); font-size: 11.5px; }

/* 새 질문 폼: 결과 위 카드 */
.newform {
  border: 1px solid var(--accent-line); border-radius: var(--radius-lg); margin: 4px 0 12px;
  background: var(--surface); box-shadow: var(--shadow-1);
}

/* 0건 */
.empty {
  padding: 48px var(--space-4) 16px; text-align: center; color: var(--faint); font-size: 13px;
  display: flex; flex-direction: column; align-items: center; gap: var(--space-3);
}

/* 0건일 때 단어 하나를 뺀 질의 칩 */
.relaxed { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.relaxed:empty { display: none; }
.chip:hover { border-color: var(--accent-line); color: var(--accent); }
.relaxed code { font-family: var(--font-mono); color: var(--ink); }

/* 알림 */
.toast {
  position: fixed; right: var(--space-4); bottom: var(--space-4); max-width: 520px; display: flex; gap: var(--space-3);
  align-items: center; padding: 8px 12px; border-radius: var(--radius-md); background: var(--ink); color: var(--bg);
  opacity: 0; transition: opacity .2s; pointer-events: none; font-size: 13px; box-shadow: var(--shadow-1);
}
.toast.on { opacity: 1; pointer-events: auto; }
.toast.err { background: var(--stale); color: var(--accent-ink); }
.toast button { border: 1px solid currentColor; background: transparent; color: inherit; border-radius: var(--radius-sm); padding: 0 8px; cursor: pointer; }

@media (max-width: 720px) {
  .keys { display: none; }
  .side { max-width: none; min-height: 0; border-right: 0; border-bottom: 1px solid var(--line); }
  .main { padding-top: var(--space-4); }
}

/* ---------- 원격 모드: 계정·로그인 ---------- */
.account { display: flex; align-items: center; gap: var(--space-2); }
.account-name { max-width: 160px; font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.login {
  max-width: 360px; margin: 96px auto 0; padding: var(--space-6); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-1);
  display: flex; flex-direction: column; gap: var(--space-3);
}
.login-title { margin: 0; font-size: 18px; line-height: 26px; font-weight: 700; }
.login-note { margin: 0; font-size: 13px; color: var(--muted); word-break: keep-all; }
.login-btns { display: flex; flex-direction: column; gap: var(--space-2); }
.login-btn { display: block; padding: 8px 12px; font-size: 14px; text-align: center; }
.login-btn:hover { text-decoration: none; }
.login-err { margin: 0; font-size: 13px; color: var(--stale); word-break: keep-all; }
@media (max-width: 420px) { .login { margin: 48px var(--space-4) 0; } }

/* 연결: 개인 토큰과 설치 명령 */
.connect {
  margin: 0 0 var(--space-4); padding: var(--space-4); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius-lg); display: flex; flex-direction: column; gap: var(--space-3);
}
.connect .label { font-size: 12px; font-weight: 600; color: var(--muted); }
.connect-head { display: flex; align-items: center; }
.connect-head .label { flex-grow: 1; }
.connect-note { margin: 0; font-size: 12.5px; color: var(--muted); word-break: keep-all; }
.connect-form { display: flex; gap: var(--space-2); }
.connect-form .fld { flex: 1 1 auto; }
.token-made {
  display: flex; flex-direction: column; gap: var(--space-2); padding: var(--space-3); font-size: 12.5px;
  background: var(--accent-soft); border: 1px solid var(--accent-line); border-radius: var(--radius-md);
}
.token-made p { margin: 0; }
.token-row { display: flex; align-items: center; gap: var(--space-2); }
.token-value { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; font-size: 12px; }
.token-list { list-style: none; margin: 0; padding: 0; }
.token-item { display: flex; align-items: center; gap: var(--space-2); padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.token-item:last-child { border-bottom: 0; }
.token-item .name { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.token-item .meta { font-size: 11.5px; color: var(--faint); }
.token-item.expired .name { color: var(--faint); }
.connect-cmd { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--space-2); align-items: start; }
.connect-cmd .label, .connect-cmd .shell-tabs, .connect-cmd .connect-note { grid-column: 1 / -1; }
.shell-tabs { display: flex; flex-wrap: wrap; gap: var(--space-1); }
.connect-export, .connect-login { display: flex; flex-direction: column; align-items: flex-start; gap: var(--space-2); }
.connect-login .connect-form { flex-wrap: wrap; }
.connect-export .btn:hover { text-decoration: none; }
.connect-leave { display: flex; flex-direction: column; gap: var(--space-2); padding-top: var(--space-3); border-top: 1px solid var(--line); }
.btn.danger { color: var(--stale); border-color: var(--stale); }
.btn.danger:hover { background: var(--stale-soft); }
.connect-cmd pre {
  margin: 0; padding: var(--space-2) var(--space-3); background: var(--surface-2); border-radius: var(--radius-md);
  font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere;
}
