/* 업무지원 웹 화면 — 좁은 사이드바(360~480px)가 기본, 넓은 화면은 확장 */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dde1e7;
  --text: #1c2027;
  --muted: #5f6875;
  --accent: #2459c9;
  --accent-weak: #e6edfb;
  --accent-text: #ffffff;
  --ok: #1d7a46;
  --ok-weak: #e3f4ea;
  --warn: #9a6200;
  --warn-weak: #fdf1dc;
  --bad: #b42318;
  --bad-weak: #fde8e6;
  --mark: #fff1a8;
  --add: #dff5e5;
  --del: #fde2e0;
  --radius: 8px;
  --shadow: 0 2px 10px rgba(0, 0, 0, .08);
  --font: "Pretendard", "Malgun Gothic", "맑은 고딕", "Apple SD Gothic Neo", system-ui, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "D2Coding", monospace;
  --tabbar-h: 56px;
  --header-h: 44px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181d;
    --surface: #1d2128;
    --surface-2: #262b33;
    --border: #353b45;
    --text: #e5e8ec;
    --muted: #9aa3ae;
    --accent: #7aa2f7;
    --accent-weak: #22304d;
    --accent-text: #0f1420;
    --ok: #5cc98b;
    --ok-weak: #1b3326;
    --warn: #e7b25a;
    --warn-weak: #3a2f1a;
    --bad: #f08a80;
    --bad-weak: #3d2220;
    --mark: #5a4f12;
    --add: #1d3a27;
    --del: #45231f;
    --shadow: 0 2px 12px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 var(--font);
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -9999px; top: 0; z-index: 100; background: var(--surface); padding: 8px; }
.skip-link:focus { left: 8px; }

/* ── 머리줄 · 탭 ───────────────────────────── */
.app-header {
  position: sticky; top: 0; z-index: 25; /* 탭 줄(20)보다 위: 머리줄의 작업 상태 창이 탭 줄에 가려지지 않게 */
  display: flex; align-items: center; gap: 8px;
  height: var(--header-h); padding: 0 12px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); }
.spacer { flex: 1; }
.helper-badge { font-size: 11px; padding: 1px 6px; border-radius: 10px; background: var(--accent-weak); color: var(--accent); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.tabbar a {
  flex: 1; min-width: 0; position: relative;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; color: var(--muted); text-decoration: none;
}
.tabbar a svg { width: 22px; height: 22px; }
.tabbar a[aria-current="page"] { color: var(--accent); font-weight: 600; }
.tabbar .badge { position: absolute; top: 4px; left: calc(50% + 6px); }
main { padding: 12px 12px calc(var(--tabbar-h) + 24px); max-width: 1400px; margin: 0 auto; outline: none; }
body.bare .tabbar, body.bare .job-indicator { display: none; }
body.bare main { padding-bottom: 24px; }

@media (min-width: 720px) {
  .tabbar {
    position: sticky; top: var(--header-h); bottom: auto; height: 42px; padding: 0 8px;
    border-top: 0; border-bottom: 1px solid var(--border); justify-content: flex-start;
  }
  .tabbar a { flex: 0 0 auto; flex-direction: row; gap: 6px; padding: 0 14px; font-size: 14px; }
  .tabbar a svg { width: 18px; height: 18px; }
  .tabbar a[aria-current="page"]::after { content: ""; position: absolute; left: 8px; right: 8px; bottom: 0; height: 2px; background: var(--accent); }
  .tabbar .badge { position: static; }
  main { padding: 16px 20px 32px; }
}

/* ── 공통 부품 ───────────────────────────── */
h1, h2, h3 { line-height: 1.3; margin: 0 0 8px; }
h1 { font-size: 18px; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.nowrap { flex-wrap: nowrap; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.break { overflow-wrap: anywhere; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.card + .card { margin-top: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 32px; padding: 4px 12px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn svg { width: 16px; height: 16px; flex: 0 0 16px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); }
.btn.small { min-height: 26px; padding: 2px 8px; font-size: 12px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; border-radius: 6px; border: 0; background: transparent; cursor: pointer; color: var(--muted); }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }

label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field { margin-bottom: 10px; }
input[type=text], input[type=password], input[type=search], input[type=date], input[type=number], input:not([type]), select, textarea {
  width: 100%; min-height: 34px; padding: 6px 10px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
textarea { min-height: 80px; resize: vertical; line-height: 1.5; }
textarea.code { font-family: var(--mono); font-size: 12px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; background: var(--surface); padding: 4px 12px; min-height: 30px; cursor: pointer; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--border); }
.seg button[aria-pressed="true"], .seg button[aria-selected="true"] { background: var(--accent-weak); color: var(--accent); font-weight: 600; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 12px 0; overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 8px 10px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; font-size: 11px; line-height: 18px; text-align: center; background: var(--bad); color: #fff; font-weight: 600; }
.tag { display: inline-block; padding: 0 6px; border-radius: 4px; font-size: 11px; line-height: 18px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.tag.ok { background: var(--ok-weak); color: var(--ok); }
.tag.warn { background: var(--warn-weak); color: var(--warn); }
.tag.bad { background: var(--bad-weak); color: var(--bad); }
.tag.info { background: var(--accent-weak); color: var(--accent); }

.state-box { padding: 24px 12px; text-align: center; color: var(--muted); }
.state-box.error { color: var(--bad); }
.state-box .btn { margin-top: 8px; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

.list { list-style: none; margin: 0; padding: 0; }
.list > li { border-bottom: 1px solid var(--border); }
.list > li:last-child { border-bottom: 0; }
.list-btn { display: block; width: 100%; text-align: left; padding: 8px 10px; border: 0; background: transparent; cursor: pointer; color: inherit; text-decoration: none; }
.list-btn:hover { background: var(--surface-2); }
.list-btn[aria-current="true"] { background: var(--accent-weak); }
.list-title { font-weight: 600; }
.list-meta { font-size: 12px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; }

dl.meta { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 8px 0; font-size: 13px; }
dl.meta dt { color: var(--muted); }
dl.meta dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabbar-h) + 16px); z-index: 50; display: flex; flex-direction: column; gap: 6px; width: min(92vw, 420px); pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 8px 12px; border-radius: 6px; box-shadow: var(--shadow); font-size: 13px; }
.toast.error { background: var(--bad); color: #fff; }
@media (min-width: 720px) { .toasts { bottom: 24px; } }

.progress { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }

/* ── 작업 상태 표시 ───────────────────────── */
.job-indicator { position: relative; }
.job-pill { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); background: var(--surface); border-radius: 14px; padding: 2px 10px; font-size: 12px; cursor: pointer; color: var(--muted); min-height: 26px; }
.job-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ok); }
.job-pill.busy { color: var(--accent); }
.job-pill.failed .dot { background: var(--bad); }
.job-pill.offline .dot { background: var(--muted); }
.job-pop { position: absolute; right: 0; top: calc(100% + 6px); width: 260px; z-index: 30; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px; font-size: 13px; }
.job-pop table { width: 100%; border-collapse: collapse; }
.job-pop td, .job-pop th { padding: 3px 4px; text-align: right; }
.job-pop td:first-child, .job-pop th:first-child { text-align: left; }
.job-pop .warn-msg { color: var(--warn); font-weight: 600; margin: 8px 0 2px; }
.job-pill.paused .dot { background: var(--warn); }

/* ── 로그인 ───────────────────────────── */
.auth-wrap { max-width: 380px; margin: 24px auto; }
.auth-wrap h1 { margin-bottom: 4px; }
.err-msg { color: var(--bad); font-size: 13px; margin: 6px 0; }
/* QR은 어두운 테마에서도 흰 바탕 그대로(찍히도록). 크기 고정, 좁은 사이드바에서도 줄어듦 */
.totp-qr-wrap { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.totp-qr { display: block; width: 200px; max-width: 100%; height: auto; aspect-ratio: 1; background: #fff; border-radius: 6px; image-rendering: pixelated; }
.secret { font-family: var(--mono); font-size: 15px; letter-spacing: 1px; background: var(--surface-2); padding: 8px; border-radius: 6px; overflow-wrap: anywhere; user-select: all; }

/* ── 질문 ───────────────────────────── */
.ask-box { position: sticky; top: var(--header-h); z-index: 10; background: var(--bg); padding: 4px 0 8px; }
@media (min-width: 720px) { .ask-box { top: calc(var(--header-h) + 42px); } }
.ask-input { display: flex; gap: 6px; }
.ask-input input { min-height: 40px; font-size: 15px; }
.ask-section-title { font-size: 12px; color: var(--muted); margin: 12px 0 4px; font-weight: 600; }
.snippet-text { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.snippet-text mark, .md mark { background: var(--mark); color: inherit; }
.answer { margin-top: 12px; }
.answer-q { font-weight: 600; margin-bottom: 6px; }
.cite-chip { display: inline-flex; align-items: center; border: 1px solid var(--accent); color: var(--accent); background: var(--accent-weak); border-radius: 9px; font-size: 11px; line-height: 16px; padding: 0 5px; margin: 0 1px; cursor: pointer; vertical-align: 1px; text-decoration: none; }
.cite-chip:hover { background: var(--accent); color: var(--accent-text); }
.cite-list { margin-top: 10px; font-size: 13px; }
.cite-list li { padding: 6px 0; }
.quote { border-left: 3px solid var(--border); padding-left: 8px; color: var(--muted); font-size: 12px; margin: 4px 0 0; overflow-wrap: anywhere; }

/* ── Markdown 본문 ───────────────────────── */
.md { overflow-wrap: anywhere; }
.md > :first-child { margin-top: 0; }
.md p { margin: 0 0 10px; }
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 { margin: 16px 0 8px; }
.md h1 { font-size: 17px; } .md h2 { font-size: 16px; } .md h3 { font-size: 15px; } .md h4, .md h5, .md h6 { font-size: 14px; }
.md ul, .md ol { padding-left: 22px; margin: 0 0 10px; }
.md pre { background: var(--surface-2); padding: 10px; border-radius: 6px; overflow-x: auto; font-size: 12px; }
.md code { font-family: var(--mono); font-size: 12px; background: var(--surface-2); padding: 0 3px; border-radius: 3px; }
.md pre code { background: none; padding: 0; }
.md blockquote { margin: 0 0 10px; padding-left: 10px; border-left: 3px solid var(--border); color: var(--muted); }
.md img { max-width: 100%; height: auto; border-radius: 4px; }
.md hr { border: 0; border-top: 1px solid var(--border); }
.table-wrap { overflow-x: auto; margin: 0 0 12px; max-width: 100%; }
.md table, .data-table { border-collapse: collapse; font-size: 12px; min-width: 100%; }
.md table { width: max-content; max-width: none; }
.md th, .md td { border: 1px solid var(--border); padding: 4px 6px; vertical-align: top; min-width: 2.5em; max-width: 24em; }
.md th { background: var(--surface-2); font-weight: 600; }
.md .figure-ph { display: block; padding: 6px 8px; border: 1px dashed var(--border); border-radius: 6px; color: var(--muted); font-size: 12px; margin: 0 0 10px; }
.blk-anchor { display: block; height: 0; }
.flash { animation: flash 2.4s ease-out; border-radius: 4px; }
@keyframes flash { 0%, 40% { background: var(--mark); box-shadow: 0 0 0 4px var(--mark); } 100% { background: transparent; box-shadow: none; } }
.page-mark { display: block; font-size: 11px; color: var(--muted); border-top: 1px dashed var(--border); margin: 12px 0 6px; padding-top: 2px; }

/* ── 보관함 ───────────────────────────── */
.lib { display: grid; grid-template-columns: 1fr; gap: 12px; }
.lib-tree, .lib-detail { display: none; }
.lib.show-tree .lib-tree { display: block; }
.lib.has-doc .lib-list { display: none; }
.lib.has-doc .lib-detail { display: block; }
.lib.has-doc.show-tree .lib-tree { display: none; }
@media (min-width: 1000px) {
  .lib { grid-template-columns: 240px minmax(300px, 380px) 1fr; align-items: start; }
  .lib-tree, .lib.has-doc .lib-tree, .lib.has-doc.show-tree .lib-tree { display: block; position: sticky; top: calc(var(--header-h) + 54px); max-height: calc(100vh - 110px); overflow: auto; }
  .lib-list, .lib.has-doc .lib-list { display: block; }
  .lib-detail { display: block; }
  .lib .only-narrow { display: none; }
}
.tree ul { list-style: none; margin: 0; padding-left: 14px; }
.tree > ul { padding-left: 0; }
.tree-row { display: flex; align-items: center; }
.tree-toggle { width: 22px; height: 26px; border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0; flex: 0 0 22px; }
.tree-toggle[disabled] { visibility: hidden; }
.tree-name { flex: 1; min-width: 0; text-align: left; border: 0; background: none; padding: 3px 6px; border-radius: 4px; cursor: pointer; color: inherit; display: flex; gap: 6px; }
.tree-name:hover { background: var(--surface-2); }
.tree-name[aria-current="true"] { background: var(--accent-weak); color: var(--accent); font-weight: 600; }
.tree-name .cnt { margin-left: auto; font-size: 11px; color: var(--muted); }
.drop-zone { position: relative; }
.drop-zone.dragging::after {
  content: attr(data-drop-label); position: absolute; inset: 0; z-index: 5;
  display: flex; align-items: center; justify-content: center; text-align: center; padding: 12px;
  background: color-mix(in srgb, var(--accent-weak) 88%, transparent); border: 2px dashed var(--accent); border-radius: var(--radius);
  color: var(--accent); font-weight: 600;
}
.upload-item { padding: 6px 0; font-size: 12px; }
.upload-item + .upload-item { border-top: 1px solid var(--border); }
.ver-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 6px 0; }
.ver-row + .ver-row { border-top: 1px solid var(--border); }
.ver-row.selected .ver-name { color: var(--accent); font-weight: 600; }
.content-view { max-height: none; }

/* ── 사업 · 값 표 ─────────────────────── */
.data-table th, .data-table td { border-bottom: 1px solid var(--border); padding: 6px; text-align: left; vertical-align: top; }
.data-table th { color: var(--muted); font-weight: 600; font-size: 12px; }
.data-table td.num { white-space: nowrap; }
.data-table tr.hist-row td { background: var(--surface-2); }
@media (max-width: 719px) {
  .data-table.responsive thead { display: none; }
  .data-table.responsive tr { display: block; border-bottom: 1px solid var(--border); padding: 6px 0; }
  .data-table.responsive td { display: inline-block; border: 0; padding: 1px 8px 1px 4px; vertical-align: middle; }
  .data-table.responsive td:empty { display: none; }
  .data-table.responsive td[data-label]::before { content: attr(data-label) " "; color: var(--muted); font-size: 11px; }
  .data-table.responsive td.item-name { display: block; font-weight: 600; }
  .data-table.responsive tr.hist-row td { display: block; }
}
.retracted { text-decoration: line-through; opacity: .6; }
.wiki-body { font-size: 14px; }

/* ── 확인 대기 · 차이 ───────────────────── */
.diff-table { width: 100%; border-collapse: collapse; font-size: 12px; margin: 6px 0; }
.diff-table th, .diff-table td { border: 1px solid var(--border); padding: 4px 6px; text-align: left; vertical-align: top; overflow-wrap: anywhere; }
.diff-table th { background: var(--surface-2); width: 28%; }
.diff-table .changed td.after { background: var(--add); }
.diff-table .changed td.before { background: var(--del); }
.diff-inline { font-size: 13px; line-height: 1.7; overflow-wrap: anywhere; white-space: pre-wrap; background: var(--surface-2); padding: 6px 8px; border-radius: 6px; }
ins { background: var(--add); text-decoration: none; }
del { background: var(--del); }

/* ── 상용구 ───────────────────────────── */
.snip-item { display: flex; align-items: flex-start; gap: 4px; }
.snip-item .list-btn { flex: 1; min-width: 0; }
.snip-body { font-size: 12px; color: var(--muted); white-space: pre-wrap; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.md .table-cap { font-size: 11px; color: var(--muted); margin: 8px 0 2px; }
.md .md-figure { margin: 0 0 12px; }
.md .md-figure img { display: block; max-height: 480px; object-fit: contain; background: var(--surface-2); }
.md .md-figure figcaption { font-size: 11px; color: var(--muted); margin-top: 2px; }
/* 넓은 표가 격자 칸을 밀어 화면 전체가 가로로 넘치지 않게 */
.lib > *, .card, .view, main { min-width: 0; }
.notice { padding: 6px 10px; border-radius: 6px; margin: 6px 0 0; background: var(--surface-2); }
.notice.warn { background: var(--warn-weak); color: var(--warn); }
.not-current { color: var(--muted); font-style: italic; }
/* 표 합계 검산: 불일치만 눈에 띄게, 반올림·불확실은 흐리게 */
.md .chk { font-size: 11px; white-space: nowrap; }
.md .chk-pass, .md .chk-single { color: var(--muted); opacity: .7; }
.md .chk-round, .md .chk-unknown { color: var(--muted); opacity: .55; }
.md .chk-fail { color: var(--bad); background: var(--bad-weak); padding: 0 5px; border-radius: 4px; font-weight: 600; opacity: 1; }
.md .chk-fail-table table { outline: 2px solid var(--bad); outline-offset: -1px; }
.md .chk-fail-cell { background: var(--bad-weak) !important; color: var(--bad); font-weight: 600; }
.md .chk-dim-cell { text-decoration: underline dotted var(--muted); text-underline-offset: 3px; }

/* 사업 카드 보기·수정 (projects.js) */
.card-sec { font-size: 15px; margin: 16px 0 6px; padding-top: 8px; border-top: 1px solid var(--border); }
.card-sub { font-size: 13px; margin: 10px 0 4px; color: var(--muted); }
.ov-block { margin: 4px 0 8px; }
.ov-title { font-weight: 600; font-size: 13px; }
.ov-items { margin: 2px 0 6px 18px; padding: 0; }
.ov-items li { margin: 1px 0; white-space: pre-wrap; }
fieldset.ov-edit { border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px 4px; margin: 0 0 8px; }
fieldset.ov-edit legend { font-size: 13px; font-weight: 600; padding: 0 4px; }
.ov-edit-line { align-items: flex-start; margin-bottom: 4px; }
textarea.ov-item { min-height: 34px; resize: none; overflow: hidden; }
.budget-table th[scope=row] { white-space: nowrap; color: var(--text); }
.budget-table td.num { text-align: right; }
.budget-table td.total { color: var(--muted); }
.budget-table th, .budget-table td { padding: 4px; }
.budget-table input { min-width: 64px; text-align: right; padding: 4px 6px; min-height: 30px; }
.card-edit [aria-invalid="true"] { border-color: var(--bad); outline: 2px solid var(--bad); outline-offset: -1px; }
details.adv-json { margin-top: 14px; }
details.adv-json summary { cursor: pointer; font-size: 13px; color: var(--muted); }
