/* 최종 성과보고서 협업 — 스타일. 단색, 8px 그리드, 모바일 우선(375px). */
:root {
  --navy: #1a2332;       /* Deep Navy */
  --fg: #1a2332;
  --muted: #4b5563;      /* 흰 배경 대비 7.5:1 */
  --line: #d1d5db;
  --line-strong: #9ca3af;
  --bg: #f3f4f6;
  --paper: #ffffff;
  --soft: #eef2f7;
  --accent: #1d4ed8;
  --danger: #b91c1c;
  --ok: #166534;
  --st-draft: #e5e7eb;
  --st-review: #bfdbfe;
  --st-done: #bbf7d0;
  --st-wait: #fed7aa;
  --mk-confirm: #fde68a;
  --mk-evid: #fecaca;
  --mk-warn: #fed7aa;
  --topbar-h: 56px;
}
* { box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  margin: 0; color: var(--fg); background: var(--bg); line-height: 1.6;
  font-family: system-ui, -apple-system, "Segoe UI", "Malgun Gothic", Roboto, sans-serif;
}
.hidden { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: #fff; color: var(--navy); padding: 8px 16px; z-index: 200; border-radius: 4px; }
.skip:focus { left: 8px; }
.muted { color: var(--muted); }
.nb { font-weight: normal; }
.spacer { flex: 1 1 auto; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.topbar :focus-visible, .toast :focus-visible { outline-color: #fff; }

/* ---------- 버튼·입력 ---------- */
.btn, button.btn, a.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  font: inherit; font-size: .9375rem; line-height: 1.2; min-height: 40px; padding: 8px 16px;
  border: 1px solid var(--line-strong); border-radius: 6px; background: #fff; color: var(--fg);
  cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--soft); }
.btn.primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn.primary:hover { background: #2b3a52; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn.sm { min-height: 32px; padding: 4px 8px; font-size: .875rem; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; }
.bar-btn { background: transparent; color: #fff; border-color: rgba(255,255,255,.55); }
.bar-btn:hover { background: rgba(255,255,255,.14); }
input[type=text], input[type=password], input:not([type]), select, textarea {
  font: inherit; font-size: 1rem; color: var(--fg); background: #fff;
  border: 1px solid var(--line-strong); border-radius: 6px; padding: 8px; width: 100%; min-height: 40px;
}
textarea { resize: vertical; }
label { display: block; font-size: .9375rem; font-weight: 600; margin: 8px 0 4px; }
label.chk { display: flex; align-items: center; gap: 8px; font-weight: normal; margin: 4px 0; min-height: 32px; }
label.chk input { width: 20px; height: 20px; margin: 0; }
.err { color: var(--danger); min-height: 24px; margin: 8px 0; font-size: .9375rem; }
.only-mobile { display: inline-flex; }

/* ---------- 로그인 ---------- */
.overlay { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 90; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 24px; width: 100%; max-width: 400px; }
.card h2 { margin: 0 0 8px; font-size: 1.25rem; }
.card .btn { width: 100%; margin-top: 8px; }

/* ---------- 상단 바 ---------- */
#app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 40; background: var(--navy); color: #fff; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px 16px; min-height: var(--topbar-h); }
.app-title { font-size: 1.125rem; margin: 0; font-weight: 700; }
.ver { font-size: .875rem; color: #e5e7eb; }
.who { font-size: .9375rem; }
.topbar .bar-btn { min-height: 40px; }

/* ---------- 레이아웃(모바일: 본문 → 패널 순서로 쌓기) ---------- */
.shell { flex: 1 1 auto; display: block; }
.content { padding: 16px; min-width: 0; background: var(--bg); outline: none; }
.panel { background: #fff; border-top: 2px solid var(--navy); padding: 16px; min-width: 0; }
.tree {
  position: fixed; left: 0; top: 0; bottom: 0; width: min(88vw, 340px); background: #fff; z-index: 60; overflow: auto;
  transform: translateX(-100%); visibility: hidden; transition: transform .2s ease, visibility .2s; padding: 16px 8px; border-right: 1px solid var(--line);
}
.tree.open { transform: none; visibility: visible; }
.shade { position: fixed; inset: 0; background: rgba(26,35,50,.5); z-index: 55; display: none; }
.shade.on { display: block; }

@media (min-width: 1024px) {
  #app { height: 100vh; }
  .shell { display: grid; grid-template-columns: 300px minmax(0, 1fr) 360px; min-height: 0; }
  .shell > .tree, .shell > .content, .shell > .panel { overflow: auto; min-height: 0; }
  .tree { position: static; transform: none; visibility: visible; width: auto; transition: none; z-index: auto; }
  .shade { display: none !important; }
  .panel { border-top: 0; border-left: 1px solid var(--line); }
  .only-mobile { display: none; }
  .content { padding: 24px; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* ---------- 트리 ---------- */
.tree-filters { padding: 0 8px 8px; border-bottom: 1px solid var(--line); margin-bottom: 8px; }
.tree-filters select { margin-bottom: 4px; }
#treeList ul { list-style: none; margin: 0; padding: 0 0 0 16px; }
#treeList > ul { padding-left: 0; }
.trow { display: flex; align-items: flex-start; gap: 0; border-radius: 6px; }
.trow.sel { background: var(--navy); color: #fff; }
.trow.sel .chip { outline: 1px solid #fff; }
.caret { flex: 0 0 32px; min-height: 40px; background: none; border: 0; color: inherit; cursor: pointer; font-size: .875rem; border-radius: 6px; }
.caret.none { visibility: hidden; }
.tlabel { flex: 1 1 auto; text-align: left; background: none; border: 0; color: inherit; font: inherit; font-size: .9375rem; line-height: 1.4; cursor: pointer; padding: 8px 4px; border-radius: 6px; min-height: 40px; }
.trow:not(.sel):hover { background: var(--soft); }
.tlabel .t { display: block; word-break: keep-all; overflow-wrap: anywhere; }
.tlabel .meta { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.lvl1 > .trow .t { font-weight: 700; }
.lvl-box .t { font-size: .875rem; }
.empty-tree { padding: 16px 8px; color: var(--muted); font-size: .9375rem; }

/* 배지·칩 */
.badge, .chip { display: inline-block; font-size: .75rem; line-height: 1.4; padding: 0 8px; border-radius: 999px; color: var(--navy); font-weight: 600; vertical-align: middle; }
.badge.st-초안, .st-초안 { background: var(--st-draft); }
.badge.st-검토중, .st-검토중 { background: var(--st-review); }
.badge.st-확정, .st-확정 { background: var(--st-done); }
.badge.st-증빙대기, .st-증빙대기 { background: var(--st-wait); }
.chip { background: #fff; border: 1px solid var(--line-strong); }
.chip.confirm { background: var(--mk-confirm); border-color: #d9b200; }
.chip.cmt { background: var(--st-review); border-color: #60a5fa; }
.chip.evid { background: var(--mk-evid); border-color: #f87171; }

/* ---------- 본문 영역 ---------- */
.crumb { font-size: .875rem; color: var(--muted); margin: 0 0 8px; }
.hint { color: var(--muted); font-size: .9375rem; }
.unit { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; margin: 0 0 16px; }
.unit.flash { outline: 3px solid var(--accent); }
.unit-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px 16px; border-bottom: 1px solid var(--line); background: var(--soft); border-radius: 8px 8px 0 0; }
.unit-bar .lbl { font-size: .875rem; color: var(--muted); font-weight: 600; }
.unit-bar .actions { margin-left: auto; display: flex; gap: 8px; }
.unit > .md, .unit > .md-wrap { padding: 8px 16px 16px; }

/* ---------- 렌더된 마크다운 ---------- */
.md { font-size: 1rem; line-height: 1.7; overflow-wrap: anywhere; }
.md h1 { font-size: 1.5rem; margin: 24px 0 16px; padding-bottom: 8px; border-bottom: 3px solid var(--navy); line-height: 1.35; }
.md h2 { font-size: 1.3125rem; margin: 24px 0 8px; line-height: 1.4; }
.md h3 { font-size: 1.125rem; margin: 16px 0 8px; line-height: 1.4; }
.md h4.box { font-size: 1.0625rem; margin: 16px 0 8px; padding: 8px 8px; background: var(--soft); border-left: 4px solid var(--navy); line-height: 1.4; }
.md h5, .md h6 { margin: 16px 0 8px; }
.md p { margin: 8px 0; }
.md p.l1 { padding-left: 1.25em; text-indent: -1.25em; }
.md ul, .md ol { margin: 4px 0 8px; padding-left: 1.75em; }
.md li { margin: 2px 0; }
.md blockquote { margin: 8px 0; padding: 8px 16px; background: var(--bg); border-left: 4px solid #64748b; }
.md blockquote p { margin: 4px 0; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.md code { font-family: ui-monospace, Consolas, monospace; font-size: .9em; background: var(--bg); padding: 0 4px; border-radius: 4px; }
.md pre { background: var(--bg); padding: 8px; overflow: auto; border-radius: 6px; }
.md img { max-width: 100%; height: auto; }
.md p.fig { text-align: center; }
.md .note { font-size: .8125rem; color: var(--muted); }
.md .unit-line { font-size: .8125rem; color: var(--muted); text-align: right; margin-bottom: 0; }
.md .img-missing { display: inline-block; padding: 8px; background: var(--mk-evid); border-radius: 4px; font-size: .875rem; }
.md .tw { overflow-x: auto; margin: 8px 0; -webkit-overflow-scrolling: touch; }
.md table { border-collapse: collapse; width: 100%; font-size: .875rem; line-height: 1.5; }
.md th, .md td { border: 1px solid var(--line-strong); padding: 4px 8px; vertical-align: top; text-align: left; }
.md th { background: #e5e7eb; text-align: center; font-weight: 700; vertical-align: middle; }
.md td table { margin: 4px 0; font-size: .8125rem; }
.md td table td, .md td table th { border-color: var(--line-strong); }
.md table[data-border="full"] td, .md table[data-border="full"] th { border: 1px solid var(--line-strong); }
.md td img { max-width: 100%; }
.md .badge { margin-left: 8px; }
.md mark { color: var(--fg); padding: 0 2px; border-radius: 2px; }
.md mark.mk-confirm, .md mark.mk-user { background: var(--mk-confirm); }
.md mark.mk-evid, .md mark.mk-photo { background: var(--mk-evid); }
.md mark.mk-warn { background: var(--mk-warn); }
.md .mermaid { text-align: center; margin: 16px auto; overflow-x: auto; }
.md .mermaid svg { max-width: 100%; height: auto; }
.md .mermaid.mm-err { background: var(--mk-evid); text-align: left; white-space: pre-wrap; font-family: ui-monospace, Consolas, monospace; font-size: .8125rem; padding: 8px; border-radius: 6px; }
.md .mermaid.mm-load { color: var(--muted); font-size: .875rem; }

/* ---------- 편집기 ---------- */
.editor { background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 16px; }
.editor h2 { font-size: 1.125rem; margin: 0 0 8px; }
.ed-fields { display: grid; grid-template-columns: 1fr; gap: 0 16px; }
.ed-panes { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; margin-top: 8px; }
.ed-panes textarea { min-height: 320px; font-family: ui-monospace, Consolas, "Malgun Gothic", monospace; font-size: .9375rem; line-height: 1.5; tab-size: 4; }
.ed-panes .preview { border: 1px solid var(--line); border-radius: 6px; padding: 8px 16px 16px; min-height: 160px; max-height: 70vh; overflow: auto; background: #fff; }
.ed-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; align-items: center; }
.ed-state { font-size: .875rem; color: var(--muted); }
.ed-note { font-size: .8125rem; color: var(--muted); margin: 4px 0; }
.preview [contenteditable="true"] { cursor: text; outline: 1px dashed transparent; }
.preview [contenteditable="true"]:hover { outline-color: var(--accent); background: #f8fafc; }
.preview [contenteditable="true"]:focus { outline: 2px solid var(--accent); background: #fff; }
.preview [data-locked="1"] { cursor: not-allowed; }
@media (min-width: 1280px) {
  .ed-fields { grid-template-columns: 1fr 1fr; }
  .ed-panes { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .ed-panes textarea { min-height: 60vh; }
  .ed-panes .preview { max-height: none; height: 60vh; min-height: 60vh; }
}

/* ---------- 패널(댓글·첨부) ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--line); margin-bottom: 8px; }
.tab { font: inherit; background: none; border: 0; border-bottom: 3px solid transparent; padding: 8px 16px; min-height: 40px; cursor: pointer; color: var(--muted); font-weight: 600; margin-bottom: -2px; }
.tab[aria-selected="true"] { color: var(--navy); border-bottom-color: var(--navy); }
.panel-target { font-size: .9375rem; font-weight: 700; margin: 8px 0; overflow-wrap: anywhere; }
.thread { border: 1px solid var(--line); border-radius: 8px; padding: 8px; margin: 8px 0; background: #fff; }
.thread.resolved { background: var(--bg); }
.cmt { padding: 4px 0; }
.cmt + .cmt { border-top: 1px dashed var(--line); margin-top: 8px; padding-top: 8px; }
.cmt .who2 { font-size: .8125rem; color: var(--muted); }
.cmt .body { white-space: pre-wrap; overflow-wrap: anywhere; margin: 4px 0; }
.cmt .row { display: flex; flex-wrap: wrap; gap: 4px; }
.replies { margin-left: 16px; border-left: 3px solid var(--line); padding-left: 8px; }
.form-stack textarea { min-height: 80px; }
.form-stack .btn { margin-top: 8px; }
details.resolved-box { margin: 8px 0; }
details.resolved-box > summary { cursor: pointer; padding: 8px 0; font-weight: 600; min-height: 40px; }
.agg-group h4 { margin: 16px 0 4px; font-size: .9375rem; }

.drop { border: 2px dashed var(--line-strong); border-radius: 8px; padding: 16px; text-align: center; background: var(--bg); margin: 8px 0; }
.drop.over { border-color: var(--accent); background: var(--soft); }
.att-list { list-style: none; padding: 0; margin: 8px 0; }
.att { display: flex; gap: 8px; border: 1px solid var(--line); border-radius: 8px; padding: 8px; margin: 8px 0; }
.att .thumb { flex: 0 0 72px; height: 72px; background: var(--bg); border-radius: 4px; display: flex; align-items: center; justify-content: center; overflow: hidden; font-weight: 700; color: var(--danger); text-decoration: none; }
.att .thumb img { width: 100%; height: 100%; object-fit: cover; }
.att .info { min-width: 0; flex: 1 1 auto; font-size: .875rem; overflow-wrap: anywhere; }
.att .info .row { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }

/* ---------- 모달·토스트 ---------- */
.modal-shade { position: fixed; inset: 0; background: rgba(26,35,50,.6); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 100; }
.modal { background: #fff; border-radius: 8px; width: 100%; max-width: 640px; max-height: calc(100vh - 32px); display: flex; flex-direction: column; }
.modal.wide { max-width: 1100px; }
.modal-head { display: flex; align-items: center; gap: 8px; padding: 16px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 1.125rem; flex: 1 1 auto; }
.modal-body { padding: 16px; overflow: auto; flex: 1 1 auto; }
.modal-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; padding: 16px; border-top: 1px solid var(--line); }
.cols2 { display: grid; grid-template-columns: 1fr; gap: 16px; }
@media (min-width: 768px) { .cols2 { grid-template-columns: 1fr 1fr; } }
.cols2 pre { margin: 0; }
pre.plain { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px; overflow: auto; max-height: 50vh; white-space: pre-wrap; overflow-wrap: anywhere; font-size: .8125rem; font-family: ui-monospace, Consolas, "Malgun Gothic", monospace; }
.hist-table { width: 100%; border-collapse: collapse; font-size: .9375rem; }
.hist-table th, .hist-table td { border-bottom: 1px solid var(--line); padding: 8px 4px; text-align: left; vertical-align: top; }
.hist-table .acts { display: flex; flex-wrap: wrap; gap: 4px; }
@media (max-width: 767px) {
  .hist-table thead { display: none; }
  .hist-table tr { display: block; border-bottom: 1px solid var(--line); padding: 8px 0; }
  .hist-table td { display: block; border: 0; padding: 2px 0; }
}
.diffbox { margin: 0 0 16px; }
.diffbox h3 { font-size: 1rem; margin: 0 0 4px; }
.diff { background: #fff; border: 1px solid var(--line); border-radius: 6px; overflow: auto; max-height: 40vh; font-family: ui-monospace, Consolas, "Malgun Gothic", monospace; font-size: .8125rem; margin: 0; }
.diff div { padding: 0 8px; white-space: pre-wrap; overflow-wrap: anywhere; min-height: 1.4em; }
.diff .add { background: #dcfce7; color: #14532d; }
.diff .del { background: #fee2e2; color: #7f1d1d; }
.diff .hunk { background: var(--soft); color: var(--muted); }
.slot-list { list-style: none; padding: 0; margin: 8px 0; }
.slot-list li { margin: 4px 0; }
.slot-list label { display: flex; gap: 8px; align-items: flex-start; font-weight: normal; padding: 8px; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; margin: 0; }
.slot-list input { width: 20px; height: 20px; margin-top: 2px; flex: 0 0 auto; }
.spinner { width: 32px; height: 32px; border: 4px solid var(--line); border-top-color: var(--navy); border-radius: 50%; animation: spin 1s linear infinite; margin: 0 auto 16px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation: none; border-top-color: var(--line); border-right-color: var(--navy); } }
.warn-list { color: #7c2d12; background: #fff7ed; border: 1px solid var(--st-wait); border-radius: 6px; padding: 8px 8px 8px 32px; }

#toasts { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 150; display: flex; flex-direction: column; gap: 8px; width: min(92vw, 560px); pointer-events: none; }
.toast { pointer-events: auto; background: var(--navy); color: #fff; padding: 8px 16px; border-radius: 8px; font-size: .9375rem; box-shadow: 0 4px 16px rgba(0,0,0,.35); display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toast.error { background: #7f1d1d; }
.toast .btn { background: #fff; color: var(--navy); min-height: 32px; padding: 4px 8px; }
.toast .x { margin-left: auto; background: none; border: 0; color: #fff; font-size: 1.25rem; cursor: pointer; min-height: 32px; min-width: 32px; }
