/* dong 노트 — 개인 노트 서재.
   한 가지만 눈에 띄게: 답변이 인용한 노트는 형광펜 자국(--mark)으로 표시된다. 나머지는 조용하게. */

:root {
  --paper: #EEF1F4;
  --sheet: #F8FAFB;
  --ink: #1C2733;
  --ink-soft: #5A6878;
  --rule: #CDD5DD;
  --accent: #2E5E7E;
  --mark: #F3DA74;
  --mark-ink: #1C2733;
  --danger: #A8322D;
  --ok: #2F6B4F;

  --sans: "Pretendard", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
  --serif: "Noto Serif KR", "Nanum Myeongjo", "AppleMyungjo", "Batang", serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --step--1: 0.8125rem;
  --step-0: 0.9375rem;
  --step-1: 1.0625rem;
  --step-2: 1.375rem;
  --step-3: 1.75rem;

  --radius: 4px;
  --side: 17rem;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #15191E; --sheet: #1C2228; --ink: #DCE3EA; --ink-soft: #8C99A6; --rule: #2C353F;
    --accent: #86B3D1; --mark: #6B5A1C; --mark-ink: #F4ECCB; --danger: #E07A73; --ok: #7CC19C;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #15191E; --sheet: #1C2228; --ink: #DCE3EA; --ink-soft: #8C99A6; --rule: #2C353F;
  --accent: #86B3D1; --mark: #6B5A1C; --mark-ink: #F4ECCB; --danger: #E07A73; --ok: #7CC19C;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: var(--step-0)/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--ink-soft); }
.nowrap { white-space: nowrap; }
.mono { font-family: var(--mono); font-size: var(--step--1); }
.danger { color: var(--danger); }
.ok { color: var(--ok); }
[hidden] { display: none !important; }

/* ---------- 버튼·입력 ---------- */
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  border: 1px solid var(--rule); background: var(--sheet); color: var(--ink);
  border-radius: var(--radius); padding: .4rem .8rem; cursor: pointer;
}
.btn:hover { border-color: var(--ink-soft); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn-primary:hover { background: var(--accent); border-color: var(--accent); }
.btn-quiet { border-color: transparent; background: transparent; color: var(--ink-soft); padding: .3rem .5rem; }
.btn-quiet:hover { color: var(--ink); border-color: transparent; background: color-mix(in srgb, var(--rule) 45%, transparent); }
.btn-danger { color: var(--danger); }
input[type=text], input[type=password], input[type=search], input:not([type]), select, textarea {
  width: 100%; border: 1px solid var(--rule); background: var(--sheet);
  border-radius: var(--radius); padding: .5rem .65rem;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 25%, transparent); }
label { display: block; font-size: var(--step--1); color: var(--ink-soft); margin: 0 0 .3rem; }

/* ---------- 로그인 ---------- */
.login {
  min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 2rem 1rem;
}
.login form { margin-bottom: 8vh; }
.login form { width: min(22rem, 100%); }
.login h1 {
  font-family: var(--serif); font-weight: 600; font-size: var(--step-3); letter-spacing: -.01em;
  margin: 0 0 .25rem;
}
.login h1 .wordmark-mark { background: linear-gradient(transparent 58%, var(--mark) 58%, var(--mark) 92%, transparent 92%); padding: 0 .1em; }
.login p.lede { margin: 0 0 1.75rem; color: var(--ink-soft); }
.field { margin-bottom: 1rem; }
.login .btn-primary { width: 100%; justify-content: center; padding: .6rem; margin-top: .5rem; }
.form-error { color: var(--danger); min-height: 1.5em; margin: .75rem 0 0; font-size: var(--step--1); }
.otp { font-family: var(--mono); letter-spacing: .35em; font-size: var(--step-1); }

/* ---------- 앱 골격 ---------- */
.shell { display: grid; grid-template-columns: var(--side) 1fr; height: 100vh; height: 100dvh; }
.side {
  border-right: 1px solid var(--rule); background: var(--sheet);
  display: flex; flex-direction: column; min-height: 0;
}
.side-head { padding: 1rem 1rem .75rem; display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; }
.wordmark { font-family: var(--serif); font-weight: 600; font-size: var(--step-1); text-decoration: none; color: var(--ink); }
.side-nav { display: flex; gap: .25rem; padding: 0 .75rem .75rem; border-bottom: 1px solid var(--rule); }
.side-nav a {
  flex: 1; text-align: center; text-decoration: none; color: var(--ink-soft);
  padding: .35rem; border-radius: var(--radius);
}
.side-nav a[aria-current="page"] { color: var(--ink); background: var(--paper); font-weight: 600; }
.side-body { flex: 1; overflow-y: auto; padding: .5rem; }
.side-foot { border-top: 1px solid var(--rule); padding: .6rem .75rem; display: flex; justify-content: space-between; align-items: center; gap: .5rem; font-size: var(--step--1); }
.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.menu-toggle { display: none; }

/* 대화 목록 */
.conv-list { list-style: none; margin: .25rem 0 0; padding: 0; }
.conv-list li { position: relative; }
.conv-list a {
  display: block; padding: .45rem .6rem; border-radius: var(--radius);
  text-decoration: none; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  padding-right: 4.2rem;
}
.conv-list a:hover { background: var(--paper); }
.conv-list a[aria-current="page"] { background: var(--paper); font-weight: 600; }
.conv-list .conv-actions { position: absolute; right: .2rem; top: 50%; transform: translateY(-50%); display: none; }
.conv-list li:hover .conv-actions, .conv-list li:focus-within .conv-actions { display: flex; }
.conv-list .conv-actions button { font-size: var(--step--1); padding: .15rem .35rem; }
.conv-empty { padding: .6rem; color: var(--ink-soft); font-size: var(--step--1); }
.new-conv { width: 100%; justify-content: center; }

/* ---------- 채팅 ---------- */
.thread { flex: 1; overflow-y: auto; padding: 2rem 1.5rem 1rem; }
.turn { display: grid; grid-template-columns: minmax(0, 42rem) minmax(0, 15rem); gap: 0 2.5rem; margin: 0 auto 2.25rem; max-width: 60rem; }
.turn-q {
  grid-column: 1; justify-self: start; max-width: 100%;
  font-weight: 600; font-size: var(--step-1); line-height: 1.45;
  border-left: 3px solid var(--ink); padding: .1rem 0 .1rem .8rem; margin-bottom: 1rem; white-space: pre-wrap;
}
.turn-a { grid-column: 1; font-family: var(--serif); font-size: var(--step-1); line-height: 1.8; }
.turn-a > :first-child { margin-top: 0; }
.turn-a p { margin: 0 0 .9em; }
.turn-a h3, .turn-a h4 { font-family: var(--sans); font-size: var(--step-1); margin: 1.4em 0 .5em; }
.turn-a ul, .turn-a ol { padding-left: 1.3em; margin: 0 0 .9em; }
.turn-a li { margin: .2em 0; }
.turn-a blockquote { margin: 0 0 .9em; padding-left: .9em; border-left: 2px solid var(--rule); color: var(--ink-soft); }
.turn-a code { font-family: var(--mono); font-size: .85em; background: color-mix(in srgb, var(--rule) 45%, transparent); padding: .05em .3em; border-radius: 3px; }
.turn-a pre { font-size: var(--step--1); line-height: 1.5; background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius); padding: .75rem; overflow-x: auto; }
.turn-a pre code { background: none; padding: 0; }
.cite {
  font-family: var(--sans); font-size: .82em; color: var(--mark-ink);
  background: linear-gradient(transparent 12%, var(--mark) 12%, var(--mark) 88%, transparent 88%);
  padding: 0 .2em; border: 0; cursor: pointer; border-radius: 1px;
}
.cite:hover { text-decoration: underline; }
.caret::after { content: "▍"; color: var(--ink-soft); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .caret::after { animation: none; } }
.turn-meta { grid-column: 1; margin-top: .4rem; font-size: var(--step--1); color: var(--ink-soft); display: flex; gap: 1rem; flex-wrap: wrap; }
.turn-error { grid-column: 1; color: var(--danger); font-size: var(--step--1); margin-top: .5rem; }

/* 여백의 근거 노트 */
.margin { grid-column: 2; grid-row: 2 / span 3; align-self: start; font-size: var(--step--1); }
.margin-title { color: var(--ink-soft); margin: .2rem 0 .5rem; }
.margin ol { list-style: none; margin: 0; padding: 0; counter-reset: src; }
.margin li { counter-increment: src; margin-bottom: .55rem; }
.margin button {
  all: unset; cursor: pointer; display: block; line-height: 1.35;
}
.margin button .src-path {
  background: linear-gradient(transparent 55%, var(--mark) 55%, var(--mark) 90%, transparent 90%);
  color: var(--ink); word-break: break-all;
}
.margin button:hover .src-path { background: var(--mark); color: var(--mark-ink); }
.margin button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.margin .src-title { display: block; color: var(--ink-soft); }

.empty-thread { max-width: 34rem; margin: 18vh auto 0; text-align: left; }
.empty-thread h2 { font-family: var(--serif); font-weight: 600; font-size: var(--step-3); margin: 0 0 .5rem; }
.empty-thread p { color: var(--ink-soft); margin: 0 0 1.25rem; }
.suggestions { display: flex; flex-direction: column; gap: .4rem; align-items: flex-start; }

.composer { border-top: 1px solid var(--rule); background: var(--paper); padding: .85rem 1.5rem 1rem; }
.composer form { max-width: 60rem; margin: 0 auto; display: grid; grid-template-columns: 1fr auto; gap: .6rem; align-items: end; }
.composer textarea { resize: none; min-height: 2.75rem; max-height: 14rem; line-height: 1.5; padding: .6rem .75rem; }
.composer .hint { grid-column: 1 / -1; font-size: var(--step--1); color: var(--ink-soft); margin: 0; }

/* 노트 서랍 */
.drawer-backdrop { position: fixed; inset: 0; background: color-mix(in srgb, var(--ink) 30%, transparent); z-index: 20; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(40rem, 100%); z-index: 21;
  background: var(--sheet); border-left: 1px solid var(--rule); display: flex; flex-direction: column;
  animation: slide-in .18s ease-out;
}
@keyframes slide-in { from { transform: translateX(2rem); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .drawer { animation: none; } }
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; padding: 1rem 1.25rem .75rem; border-bottom: 1px solid var(--rule); }
.drawer-head h2 { margin: 0; font-family: var(--serif); font-size: var(--step-2); font-weight: 600; }
.drawer-body { overflow-y: auto; padding: 1rem 1.25rem 2rem; }

/* ---------- 관리 ---------- */
.admin { flex: 1; overflow-y: auto; padding: 1.75rem 2rem 3rem; }
.admin-inner { max-width: 64rem; }
.admin h1 { font-family: var(--serif); font-weight: 600; font-size: var(--step-3); margin: 0 0 1.5rem; }
.admin h2 { font-size: var(--step-1); margin: 2rem 0 .6rem; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.admin h2:first-of-type { margin-top: 0; }
.admin-nav { list-style: none; margin: .25rem 0 0; padding: 0; }
.admin-nav a { display: block; padding: .45rem .6rem; border-radius: var(--radius); text-decoration: none; color: var(--ink); }
.admin-nav a:hover { background: var(--paper); }
.admin-nav a[aria-current="page"] { background: var(--paper); font-weight: 600; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1.5rem; margin: 0; padding: .9rem 1rem; background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius); }
.facts dt { color: var(--ink-soft); }
.facts dd { margin: 0; word-break: break-word; }
.status-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(26rem, 1fr)); gap: 1.75rem 2rem; margin-bottom: 1rem; }
.status-grid h2 { margin-top: 0; min-height: 2.4rem; }
.inline-result { margin-top: .6rem; font-size: var(--step--1); }

table.data { width: 100%; border-collapse: collapse; font-size: var(--step--1); background: var(--sheet); border: 1px solid var(--rule); }
table.data th, table.data td { text-align: left; padding: .45rem .65rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
table.data th { color: var(--ink-soft); font-weight: 500; background: var(--paper); position: sticky; top: 0; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.data tr:last-child td { border-bottom: 0; }
.bar { display: block; height: .45rem; background: var(--accent); border-radius: 1px; min-width: 1px; }

.toolbar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: end; margin-bottom: .9rem; }
.toolbar .field { margin: 0; min-width: 9rem; }
.toolbar .grow { flex: 1; min-width: 12rem; }

.lvl { font-family: var(--mono); font-size: .75rem; padding: .05rem .35rem; border-radius: 3px; border: 1px solid var(--rule); }
.lvl-WARNING { color: #8A5A00; border-color: currentColor; }
.lvl-ERROR, .lvl-CRITICAL { color: var(--danger); border-color: currentColor; }
:root[data-theme="dark"] .lvl-WARNING { color: #E0B860; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .lvl-WARNING { color: #E0B860; } }
.log-row { cursor: pointer; }
.log-row:hover td { background: var(--paper); }
.log-detail pre { margin: 0; white-space: pre-wrap; word-break: break-word; font-family: var(--mono); font-size: .75rem; }

.notes-layout { display: grid; grid-template-columns: minmax(16rem, 22rem) 1fr; gap: 1.5rem; align-items: start; }
.note-list { list-style: none; margin: 0; padding: 0; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--sheet); max-height: 70vh; overflow-y: auto; }
.note-list li + li { border-top: 1px solid var(--rule); }
.note-list button { all: unset; display: block; width: 100%; box-sizing: border-box; padding: .5rem .7rem; cursor: pointer; }
.note-list button:hover, .note-list button[aria-current="true"] { background: var(--paper); }
.note-list button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.note-list .np { display: block; font-size: var(--step--1); color: var(--ink-soft); word-break: break-all; }
.note-reader { background: var(--sheet); border: 1px solid var(--rule); border-radius: var(--radius); padding: 1.25rem 1.5rem; min-height: 12rem; }
.note-reader h2.note-title { margin: 0 0 .25rem; font-family: var(--serif); font-size: var(--step-2); display: block; }
.tags { display: flex; flex-wrap: wrap; gap: .3rem; margin: .4rem 0 1rem; }
.tag { font-size: .75rem; border: 1px solid var(--rule); border-radius: 99px; padding: .05rem .5rem; color: var(--ink-soft); }
.linklist { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: .3rem .9rem; font-size: var(--step--1); }
.linklist button { all: unset; cursor: pointer; color: var(--accent); text-decoration: underline; }
.linklist .broken { color: var(--ink-soft); text-decoration: line-through; }
.wikilink { all: unset; cursor: pointer; color: var(--accent); text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
.wikilink:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.wikilink.broken { cursor: default; color: var(--ink-soft); text-decoration: line-through; }

.toast { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--paper); padding: .5rem 1rem; border-radius: var(--radius); font-size: var(--step--1); z-index: 30; }

/* ---------- 좁은 화면 ---------- */
@media (max-width: 60rem) {
  .turn { grid-template-columns: minmax(0, 1fr); }
  .margin { grid-column: 1; grid-row: auto; margin-top: .9rem; padding-top: .6rem; border-top: 1px dashed var(--rule); }
  .margin ol { display: flex; flex-wrap: wrap; gap: .4rem 1rem; }
  .margin .src-title { display: none; }
  .notes-layout { grid-template-columns: 1fr; }
  .status-grid { grid-template-columns: 1fr; }
}
@media (max-width: 44rem) {
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: min(var(--side), 85vw); z-index: 15; transform: translateX(-100%); transition: transform .18s; }
  .shell.menu-open .side { transform: none; box-shadow: 0 0 0 100vmax color-mix(in srgb, var(--ink) 30%, transparent); }
  .menu-toggle { display: inline-flex; margin: .5rem .75rem 0; align-self: flex-start; }
  .thread { padding: 1rem 1rem .5rem; }
  .composer { padding: .6rem 1rem .8rem; }
  .admin { padding: 1rem; }
  .facts { grid-template-columns: 1fr; }
  .facts dd { margin-bottom: .4rem; }
}
@media (prefers-reduced-motion: reduce) { .side { transition: none; } }
