/* ==================================================================
   Investigation Copilot — "조사 대장(field ledger)" 테마
   종이 위의 기록: 잉크 본문, 절제된 teal 상호작용, 모노스페이스 메타데이터.
   ================================================================== */

:root {
  color-scheme: light;
  --paper: #f5f3ec;
  --surface: #fffefa;
  --inset: #f0ede2;
  --ink: #20282b;
  --muted: #6c7674;
  --line: #dcd8ca;
  --line-soft: rgb(220 216 202 / 60%);
  --accent: #14655a;
  --accent-dark: #0d4a41;
  --accent-soft: #e3efe9;
  --ok: #1e7a4f;
  --ok-soft: #e0eee5;
  --warn: #96620a;
  --warn-soft: #f5ebd1;
  --bad: #9d3a2e;
  --bad-soft: #f7e6e1;
  --shadow-soft: 0 1px 2px rgb(41 48 46 / 5%), 0 8px 24px rgb(41 48 46 / 6%);
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI",
    "Apple SD Gothic Neo", "Malgun Gothic", sans-serif;
}

* { box-sizing: border-box; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
}

a { color: inherit; }
h1, h2, h3, p { margin-top: 0; }

/* 기록 메타데이터(시각·ID·건수)는 페이지 공통으로 모노스페이스 */
time {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: .74rem;
  letter-spacing: -.01em;
}

/* ------------------------------------------------------------------ */
/* 공통 크롬: 상단 바                                                  */
/* ------------------------------------------------------------------ */

.topbar {
  min-height: 56px;
  padding: 0 4vw;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--line);
  background: rgb(255 254 250 / 90%);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  font-weight: 800;
  font-size: .95rem;
  letter-spacing: -.02em;
  text-decoration: none;
}
.brand::before {
  content: "";
  width: .62em;
  height: .62em;
  border-radius: 2px;
  background: var(--accent);
}

.eyebrow {
  color: rgb(20 101 90 / 72%);
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .13em;
}

.mode-badge {
  padding: .32rem .6rem;
  border: 1px solid rgb(20 101 90 / 35%);
  border-radius: 999px;
  color: var(--accent-dark);
  font-family: var(--font-mono);
  font-size: .68rem;
  font-weight: 700;
  letter-spacing: 0;
  white-space: nowrap;
}
.mode-badge.live { color: #fff; background: var(--accent); border-color: var(--accent); }
.topbar-context { display: flex; align-items: center; justify-content: flex-end; gap: .65rem; min-width: 0; }
.principal-label { max-width: 18rem; overflow: hidden; color: var(--muted); font-size: .75rem; text-overflow: ellipsis; white-space: nowrap; }
.logout-form { display: block; }
.logout-button { padding: .4rem .6rem; color: var(--accent-dark); background: transparent; font-size: .75rem; }
.logout-button:hover { color: #fff; }

.page-shell { width: min(1500px, 92vw); margin: 0 auto; padding: 2.5rem 0 5rem; }

/* ------------------------------------------------------------------ */
/* 공통 부품: 카드, 버튼, 폼, 처리 상태                                */
/* ------------------------------------------------------------------ */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}

button, .secondary-button {
  justify-self: start;
  border: 0;
  border-radius: 8px;
  padding: .7rem 1rem;
  color: #fff;
  background: var(--accent);
  font: inherit;
  font-size: .92rem;
  font-weight: 750;
  text-decoration: none;
  cursor: pointer;
}
button:hover { background: var(--accent-dark); }
button:disabled { cursor: wait; opacity: .68; background: var(--accent); }
button:focus-visible, .secondary-button:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 3px solid rgb(20 101 90 / 30%);
  outline-offset: 1px;
}
.secondary-button {
  color: var(--accent-dark);
  background: transparent;
  border: 1px solid rgb(20 101 90 / 45%);
}
.secondary-button:hover { border-color: var(--accent-dark); background: var(--accent-soft); }

form { display: grid; gap: .7rem; }
label { font-weight: 750; }
textarea {
  width: 100%;
  resize: vertical;
  border: 1px solid #c3bfae;
  border-radius: 10px;
  padding: .85rem .95rem;
  background: #fff;
  color: var(--ink);
  font: inherit;
  line-height: 1.6;
}
textarea:focus { outline: 3px solid rgb(20 101 90 / 18%); border-color: var(--accent); }
form[aria-busy="true"] textarea[readonly] { color: #4f5d61; background: var(--inset); cursor: wait; }
.reasoning-effort-field {
  display: grid;
  grid-template-columns: auto minmax(6.5rem, 8rem) 1fr;
  align-items: center;
  gap: .45rem .65rem;
  width: min(100%, 31rem);
}
.reasoning-effort-field label { color: var(--muted); font-size: .78rem; }
.reasoning-effort-field select {
  border: 1px solid #c3bfae;
  border-radius: 8px;
  padding: .45rem .65rem;
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-size: .85rem;
}
.reasoning-effort-field small { color: var(--muted); font-size: .74rem; }

.processing-status {
  display: flex;
  align-items: center;
  gap: .7rem;
  width: fit-content;
  padding: .55rem .75rem;
  border: 1px solid rgb(20 101 90 / 25%);
  border-radius: 10px;
  color: var(--accent-dark);
  background: var(--accent-soft);
}
.processing-status[hidden] { display: none; }
.processing-status > span:last-child { display: grid; gap: .1rem; }
.processing-status strong { font-size: .85rem; }
.processing-status small { color: var(--muted); font-size: .74rem; }
.processing-spinner {
  width: 1rem;
  height: 1rem;
  flex: 0 0 auto;
  border: 2px solid rgb(20 101 90 / 22%);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: processing-spin .8s linear infinite;
}
@keyframes processing-spin { to { transform: rotate(360deg); } }

.empty-state, .muted { color: var(--muted); }
details summary { cursor: pointer; font-weight: 700; }
pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.55;
  font-family: var(--font-mono);
}

/* 섹션 헤딩 문법: 좌측 제목, 우측 모노 건수, 베이스라인 헤어라인 */
.section-heading {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  padding-bottom: .5rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: .9rem;
}
.section-heading h2 { margin: 0; font-size: 1.02rem; letter-spacing: -.01em; }
.section-heading span { color: var(--muted); font-family: var(--font-mono); font-size: .76rem; }

/* ------------------------------------------------------------------ */
/* 목록 페이지: 작업대 홈 — 새 기록이 첫 동작                          */
/* ------------------------------------------------------------------ */

.hero, .new-case, .case-list-section { max-width: 56rem; margin-inline: auto; }

.hero { margin-bottom: 1.6rem; }
.hero h1 {
  margin: .3rem 0 .5rem;
  font-size: clamp(1.5rem, 3vw, 2.1rem);
  line-height: 1.2;
  letter-spacing: -.03em;
}
.hero p:last-child { margin: 0; color: var(--muted); font-size: .92rem; }

.new-case { padding: 1.2rem 1.3rem 1.3rem; margin-bottom: 2.4rem; box-shadow: var(--shadow-soft); }
.new-case h2 { margin-bottom: .8rem; font-size: 1.02rem; }
.new-case label { font-size: .8rem; color: var(--muted); }

.case-list { display: grid; gap: .55rem; }
.case-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  text-decoration: none;
}
.case-row:hover { border-color: var(--accent); background: #fdfcf6; }
.case-row span:first-child { display: grid; gap: .22rem; min-width: 0; }
.case-row strong {
  font-size: .92rem;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.case-row small, .case-meta {
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: .72rem;
  letter-spacing: -.01em;
}
.case-meta { flex: none; text-align: right; }

.auth-card { width: min(34rem, 100%); margin: 8vh auto 0; padding: 2rem; }
.auth-card h1 { margin: .35rem 0 .7rem; font-size: clamp(1.5rem, 4vw, 2.2rem); }
.auth-card > p:not(.eyebrow) { color: var(--muted); line-height: 1.65; }
.auth-actions { display: flex; gap: .7rem; margin-top: 1.4rem; }
.auth-actions .auth-primary { color: #fff; background: var(--accent); }

/* ------------------------------------------------------------------ */
/* Case 화면: 대화가 주인공, 조사 상태는 보조 레일 (구조 유지)          */
/* ------------------------------------------------------------------ */

body:has(.case-screen) {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
body:has(.case-screen) .topbar { flex: none; }
body:has(.case-screen) .page-shell {
  flex: 1;
  min-height: 0;
  display: flex;
  width: min(1200px, 94vw);
  padding: 0;
}

.case-screen {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.case-topline {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
  padding: .8rem .1rem .75rem;
  border-bottom: 1px solid var(--line);
}
.case-topline-info { min-width: 0; }
.case-idline {
  margin: 0 0 .22rem;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: .72rem;
  letter-spacing: -.01em;
}
.case-idline time { font-size: .72rem; }
.case-id { color: var(--accent-dark); }
.case-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.4;
  letter-spacing: -.015em;
  overflow-wrap: anywhere;
}
.quiet-button { padding: .46rem .72rem; border-color: var(--line); color: var(--muted); font-size: .8rem; white-space: nowrap; }
.quiet-button:hover { border-color: var(--accent); color: var(--accent-dark); background: transparent; }

.case-layout {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 320px);
}

.conversation-panel {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding-right: 1.5rem;
}

.panel-heading { padding: .8rem .1rem .55rem; }
.panel-heading .eyebrow { margin: 0; font-size: .56rem; letter-spacing: .16em; color: rgb(20 101 90 / 55%); }
.panel-heading h2 { margin: .12rem 0 0; font-size: .95rem; letter-spacing: -.01em; }

/* 스레드: 내부 스크롤, 최신 답변이 입력창 바로 위에 보이도록 아래에서 시작 */
.thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column-reverse;
}
.messages {
  display: grid;
  gap: .8rem;
  width: 100%;
  max-width: 47rem;
  margin: 0 auto;
  padding: .5rem .15rem 1rem;
}

.message {
  max-width: 94%;
  padding: .85rem 1rem .7rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
}
.message.user {
  justify-self: end;
  max-width: 82%;
  background: var(--accent-soft);
  border-color: #c3d8cf;
  border-bottom-right-radius: 4px;
}
.message.assistant {
  justify-self: start;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px rgb(41 48 46 / 5%);
}
.message-role { margin-bottom: .35rem; font-size: .62rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.message.assistant .message-role { color: var(--accent); }
.message.user .message-role { color: #5c7a6d; }
.message-content { font-size: .95rem; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.62; }
.message time { display: block; margin-top: .55rem; font-size: .68rem; }
.message.user time { text-align: right; }

.inline-checks { margin: .85rem 0 0; padding: .8rem 0 0 1.3rem; border-top: 1px solid var(--line-soft); }
.inline-checks > li { margin-top: .6rem; font-size: .92rem; font-weight: 650; line-height: 1.5; }
.inline-checks > li:first-child { margin-top: 0; }
.inline-checks > li::marker { color: var(--accent); font-weight: 800; }
.inline-check-reason { margin: .25rem 0 0; color: var(--muted); font-size: .84rem; font-weight: 400; }
.check-how { margin: .35rem 0 0; font-weight: 400; }
.check-how > summary { color: var(--accent-dark); font-size: .8rem; font-weight: 700; }
.check-how > p { margin: .4rem 0 .2rem; font-size: .86rem; white-space: pre-wrap; overflow-wrap: anywhere; font-family: inherit; }
.check-how ul { margin: .2rem 0 0; padding-left: 1.15rem; color: #4a5a57; font-size: .84rem; }
.check-how ul li { margin-top: .25rem; }

/* 하단 도크: 스크롤과 무관하게 항상 보이는 알림·입력 */
.conversation-dock { flex: none; border-top: 1px solid var(--line); padding: .3rem .15rem .9rem; }
.conversation-dock > * { width: 100%; max-width: 47rem; margin-left: auto; margin-right: auto; }

.follow-up-form { display: grid; gap: .45rem; padding-top: .55rem; }
.follow-up-form label { color: var(--muted); font-size: .78rem; }
.follow-up-form textarea { padding: .7rem .85rem; }
.composer-actions { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; }
.composer-actions button { padding: .6rem .95rem; font-size: .88rem; }
.composer-actions .processing-status { padding: .3rem .2rem; border: 0; background: transparent; }

.turn-status {
  display: grid;
  gap: .4rem;
  margin: .65rem auto .25rem;
  padding: .8rem 1rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
}
.turn-status .eyebrow { font-size: .6rem; }
.turn-status p { margin: 0; font-size: .88rem; line-height: 1.55; }
.turn-status.pending, .turn-status.plan-note { border-color: #e3c88f; background: var(--warn-soft); }
.turn-status.pending .eyebrow, .turn-status.plan-note .eyebrow { color: var(--warn); }
.turn-status.failed { border-color: #e0b0a7; background: var(--bad-soft); }
.turn-status.failed .eyebrow { color: var(--bad); }
.turn-status.plan-note p { font-size: .82rem; }
.turn-status .secondary-button { justify-self: start; padding: .45rem .7rem; font-size: .8rem; }
.recovery-form { display: grid; gap: .5rem; margin: .3rem 0; }
.recovery-form button { width: fit-content; }
.recovery-form .processing-status { padding: .45rem .6rem; border: 0; background: transparent; }

/* 조사 상태 레일: 카드 없이 명세처럼 */
.workspace-panel {
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  padding: 0 .15rem 1.5rem 1.5rem;
  border-left: 1px solid var(--line);
}
.workspace-panel .panel-heading { padding-left: 0; padding-right: 0; }

.state-rejection-badge {
  margin: .35rem 0 .5rem;
  padding: .55rem .7rem;
  border: 1px solid #e0b0a7;
  border-radius: 8px;
  color: #7d3029;
  background: var(--bad-soft);
  font-size: .76rem;
  font-weight: 600;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.workspace-card { padding: .85rem 0 1rem; }
.workspace-card + .workspace-card { border-top: 1px solid var(--line); }
.workspace-card-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .75rem;
  margin: 0 0 .3rem;
  font-size: .8rem;
}
.workspace-card-heading small { color: var(--muted); font-family: var(--font-mono); font-size: .72rem; font-weight: 700; }
.workspace-card.uncertainty:has(.state-item) .workspace-card-heading small { color: var(--warn); }
.workspace-card.conflict .workspace-card-heading small { color: var(--bad); }
.workspace-card .muted { margin: .25rem 0 0; font-size: .8rem; }

/* 역할 구분 라벨: finding과 answered uncertainty를 같은 카드 안에서 분리한다 */
.state-group-label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: .5rem;
  margin: .75rem 0 0;
  color: var(--muted);
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .02em;
}
.state-group-label:first-of-type { margin-top: .35rem; }
.state-group-label span { font-family: var(--font-mono); font-size: .68rem; }
.state-group-label + .state-item { padding-top: .35rem; }

.recheck-flag {
  display: inline-block;
  margin-left: .1rem;
  padding: .06rem .34rem;
  border-radius: 4px;
  color: #74510a;
  background: var(--warn-soft);
  font-size: .62rem;
  font-weight: 750;
  white-space: nowrap;
}

.state-item { padding-top: .6rem; }
.state-item + .state-item { margin-top: .6rem; border-top: 1px solid var(--line-soft); }
.state-item p { margin: 0 0 .3rem; font-size: .82rem; line-height: 1.55; overflow-wrap: anywhere; }
.state-item p:only-child { margin-bottom: 0; }
.state-item-meta { display: flex; min-width: 0; align-items: center; gap: .3rem .4rem; flex-wrap: wrap; }
.state-item-meta small { color: var(--muted); min-width: 0; font-size: .68rem; overflow-wrap: anywhere; }

.state-badge {
  display: inline-flex;
  align-items: center;
  padding: .14rem .42rem;
  border-radius: 4px;
  font-size: .62rem;
  font-weight: 750;
  line-height: 1.3;
}
.category-badge { color: var(--accent-dark); background: var(--accent-soft); }
.status-badge { color: #435158; background: #e8e7df; }
.status-open, .status-partial, .status-currently_unavailable { color: #74510a; background: var(--warn-soft); }
.status-contested { color: #7d3029; background: var(--bad-soft); }
.status-answered, .status-active, .status-strengthened { color: #1c5e40; background: var(--ok-soft); }

.workspace-more { margin-top: .7rem; }
.workspace-more > summary { color: var(--accent-dark); font-size: .78rem; }
.workspace-more > div { margin-top: .2rem; }

.unresolved-checks { margin: .1rem 0 0; padding: 0; list-style: none; }
.unresolved-checks li {
  position: relative;
  margin-top: .5rem;
  padding-left: 1.2rem;
  font-size: .82rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.unresolved-checks li:first-child { margin-top: .3rem; }
.unresolved-checks li::before {
  content: "";
  position: absolute;
  left: 0;
  top: .3em;
  width: .58em;
  height: .58em;
  border: 1.5px solid #9fb0a8;
  border-radius: 2px;
}

/* ------------------------------------------------------------------ */
/* Audit: 요약 먼저, 원본은 펼쳐서 — 대장 그 자체                       */
/* ------------------------------------------------------------------ */

.case-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.case-header p { color: var(--muted); }
.case-header h1 { margin: .2rem 0 .4rem; font-size: clamp(1.4rem, 2.5vw, 1.8rem); letter-spacing: -.025em; }
.audit-header .eyebrow { font-family: var(--font-mono); letter-spacing: .04em; }
.audit-header p:last-child { margin: 0; font-size: .88rem; }

.audit-overview {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) minmax(15rem, auto);
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  padding: .95rem 1.1rem;
}
.audit-overview > div { display: grid; gap: .15rem; }
.audit-overview strong {
  color: var(--accent-dark);
  font-family: var(--font-mono);
  font-size: 1.45rem;
  line-height: 1;
}
.audit-overview span, .audit-overview p { color: var(--muted); font-size: .78rem; }
.audit-overview p { margin: 0; text-align: right; }

.audit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
.audit-card, .ledger-section { padding: 1rem 1.1rem; }
.ledger-section { margin-top: 1rem; }

.audit-section-heading {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 1rem;
  padding-bottom: .55rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: .35rem;
}
.audit-section-heading h2 { margin-bottom: .15rem; font-size: 1rem; }
.audit-section-heading > span { color: var(--muted); font-family: var(--font-mono); font-size: .76rem; }
.audit-section-heading p:last-child { margin-bottom: 0; color: var(--muted); font-size: .82rem; }
.audit-section-heading .eyebrow { font-size: .6rem; }

.audit-entry { padding: .75rem 0; border-top: 1px solid var(--line-soft); }
.audit-entry:first-of-type { border-top: 0; }
.audit-entry small { color: var(--muted); font-family: var(--font-mono); font-size: .7rem; }
.audit-entry pre {
  max-height: 30rem;
  overflow: auto;
  margin: .6rem 0 0;
  padding: .75rem;
  border-radius: 8px;
  background: var(--inset);
  font-size: .74rem;
}
.audit-entry-heading { display: flex; justify-content: space-between; align-items: start; gap: 1rem; }
.audit-entry-heading strong { font-family: var(--font-mono); font-size: .8rem; letter-spacing: -.01em; }
.audit-entry-heading time, .revision-entry > summary time, .ledger-event > summary time { font-size: .7rem; font-weight: 500; }

.evidence-text {
  margin: .55rem 0;
  padding: .7rem .8rem;
  border-radius: 8px;
  background: var(--inset);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.55;
  font-size: .88rem;
}

.revision-entry > summary, .ledger-event > summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  list-style-position: outside;
}
.revision-entry > summary > span, .ledger-event > summary > span { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.revision-entry > summary > span { display: grid; gap: .18rem; }
.revision-entry > summary strong { font-size: .88rem; }
.audit-change-list { margin: .8rem 0; padding-left: 1.25rem; font-size: .88rem; }
.audit-change-list li + li { margin-top: .4rem; }

.raw-data-disclosure {
  margin-top: .75rem;
  padding: .6rem .75rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfaf4;
}
.raw-data-disclosure > summary { color: var(--muted); font-size: .8rem; }
.raw-data-disclosure pre { margin-bottom: 0; }

.ledger-disclosure { margin-top: .75rem; border-top: 1px solid var(--line-soft); padding-top: .9rem; }
.ledger-disclosure > summary { display: grid; gap: .2rem; color: var(--accent-dark); }
.ledger-disclosure > summary small { color: var(--muted); font-weight: 500; font-size: .78rem; }

.ledger-toolbar {
  display: flex;
  align-items: center;
  gap: .65rem;
  margin: 1rem 0 .25rem;
  padding: .65rem .75rem;
  border-radius: 8px;
  background: var(--inset);
}
.ledger-toolbar label { font-size: .8rem; }
.ledger-toolbar select {
  min-width: 11rem;
  padding: .45rem .6rem;
  border: 1px solid #c3bfae;
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  font: inherit;
  font-size: .85rem;
}
.ledger-toolbar [data-ledger-count] { margin-left: auto; font-family: var(--font-mono); font-size: .74rem; }
.ledger-list { display: grid; }
.ledger-list > [hidden] { display: none; }
.ledger-event > summary strong { font-family: var(--font-mono); font-size: .78rem; }
.ledger-event small { color: var(--muted); font-weight: 500; }

.event-type-badge {
  padding: .2rem .45rem;
  border-radius: 4px;
  color: var(--accent-dark);
  background: var(--accent-soft);
  font-size: .7rem;
  font-weight: 800;
}
.event-type-badge.outcome-committed, .event-type-badge.outcome-no_change { color: #1c5e40; background: var(--ok-soft); }
.event-type-badge.outcome-rejected { color: #7d3029; background: var(--bad-soft); }
.event-type-badge.outcome-not_attempted { color: #74510a; background: var(--warn-soft); }

/* ------------------------------------------------------------------ */
/* 오류 페이지                                                         */
/* ------------------------------------------------------------------ */

.error-card {
  max-width: 34rem;
  margin: 9vh auto 0;
  padding: 1.4rem 1.5rem 1.5rem;
  border-top: 3px solid var(--bad);
}
.error-card .eyebrow { color: var(--bad); font-family: var(--font-mono); letter-spacing: .05em; }
.error-card h1 { margin: .35rem 0 .5rem; font-size: clamp(1.25rem, 3vw, 1.6rem); letter-spacing: -.02em; line-height: 1.3; }
.error-card p { color: var(--muted); line-height: 1.6; }
.error-card pre { margin: 1rem 0 1.25rem; padding: .9rem; border-radius: 8px; background: var(--bad-soft); color: var(--bad); }

/* ------------------------------------------------------------------ */
/* 반응형                                                              */
/* ------------------------------------------------------------------ */

@media (max-width: 900px) {
  .audit-grid { grid-template-columns: 1fr; }
  .audit-overview { grid-template-columns: repeat(3, 1fr); }
  .audit-overview p { grid-column: 1 / -1; text-align: left; }
  .case-header { align-items: start; }

  /* 좁은 화면: 셸을 풀고 문서 흐름으로 — 대화 먼저, 조사 상태는 뒤에 */
  body:has(.case-screen) { height: auto; display: block; overflow: visible; }
  body:has(.case-screen) .page-shell { display: block; padding: 1.25rem 0 3.5rem; }
  .case-screen { display: block; }
  .case-layout { display: block; }
  .case-topline { align-items: start; }
  .conversation-panel { display: block; padding-right: 0; }
  .thread { display: block; overflow: visible; }
  .messages { max-width: none; padding: .5rem 0 .75rem; }
  .conversation-dock { padding: .35rem 0 0; }
  .conversation-dock > * { max-width: none; }
  .workspace-panel {
    margin-top: 1.75rem;
    padding: .25rem 0 0;
    border-left: 0;
    border-top: 1px solid var(--line);
    overflow: visible;
  }
}

@media (max-width: 620px) {
  .page-shell { width: min(94vw, 100%); padding-top: 1.75rem; }
  .topbar { padding: 0 3vw; }
  .mode-badge { font-size: .6rem; padding: .26rem .5rem; }
  .case-header, .case-row { align-items: start; flex-direction: column; }
  .case-meta { text-align: left; }
  .revision-entry > summary, .ledger-event > summary { align-items: start; flex-direction: column; }
  .ledger-toolbar { align-items: stretch; flex-direction: column; }
  .ledger-toolbar [data-ledger-count] { margin-left: 0; }

  .case-topline { flex-direction: column; align-items: start; gap: .6rem; }
  .message { max-width: 100%; }
  .message.user { max-width: 92%; }
  .composer-actions { align-items: start; flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  .processing-spinner { animation: none; }
}
