:root, :root[data-theme="light"] {
  --bg: #f4f6fb; --panel: #ffffff; --ink: #161b2e; --muted: #5b6478; --line: #dfe3ec;
  --brand: #2e3f94; --brand-l: #e7eaf7; --btn: #2e3f94; --btn-ink: #ffffff;
  --side: #1d2a6b; --side-ink: #e6e9ff; --side-muted: #9fabe3; --side-on: rgba(255,255,255,.16);
  --ok: #1a7f4b; --ok-l: #e3f4ea; --warn: #a55600; --warn-l: #fff1dc; --bad: #c0262d; --bad-l: #fde7e8;
  --new: #b3541e; --new-l: #fdeee4; --hl: #fff3a0; --sel-ink: #ffffff;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
  color-scheme: light;
}
:root[data-theme="mid"] {
  --bg: #dfe3ec; --panel: #eef1f6; --ink: #182033; --muted: #4a546b; --line: #c3cad8;
  --brand: #26378a; --brand-l: #d3d9ef; --btn: #2e3f94; --btn-ink: #ffffff;
  --side: #2b3450; --side-ink: #e9ecf5; --side-muted: #a9b1c9; --side-on: rgba(255,255,255,.14);
  --ok: #17693f; --ok-l: #d3eadc; --warn: #8f4a00; --warn-l: #f5e2c4; --bad: #a8212a; --bad-l: #f3d5d7;
  --new: #9a4515; --new-l: #f3dccd; --hl: #f5e27a; --sel-ink: #ffffff;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.08);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f1220; --panel: #181c2c; --ink: #e8eaf3; --muted: #a3aac0; --line: #2b3147;
  --brand: #a3b1ff; --brand-l: #262e55; --btn: #4659c8; --btn-ink: #ffffff;
  --side: #0a0d18; --side-ink: #dde1f3; --side-muted: #8791b4; --side-on: rgba(163,177,255,.16);
  --ok: #6fd39c; --ok-l: #173427; --warn: #f3b061; --warn-l: #3a2a14; --bad: #f2868b; --bad-l: #3d1c1f;
  --new: #f3a574; --new-l: #3b2517; --hl: #6b5d12; --sel-ink: #0f1220;
  --radius: 10px; --shadow: none;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif; background: var(--bg); color: var(--ink); font-size: 14px; line-height: 1.55; word-break: keep-all; overflow-wrap: anywhere; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.3; }
h2 { font-size: 20px; } h3 { font-size: 15px; }
.muted { color: var(--muted); }
button, .btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 8px; padding: 6px 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
button.primary, .btn.primary { background: var(--btn); border-color: var(--btn); color: var(--btn-ink); }
button:hover, .btn:hover { filter: brightness(.97); text-decoration: none; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; }

/* 로그인 */
.login-body { min-height: 100vh; display: grid; place-items: center; background: var(--side); padding: 16px; }
.login-card { color: var(--ink); background: var(--panel); border-radius: 16px; padding: 32px 28px; width: min(380px, 100%); text-align: center; box-shadow: 0 20px 50px rgba(0,0,0,.25); display: grid; gap: 12px; }
.login-logo { width: 200px; margin: 0 auto; }
.login-card h1 { font-size: 22px; margin: 0; }
.login-card h1 span { font-size: 15px; color: var(--muted); font-weight: 600; }
.login-card input { padding: 11px 12px; font-size: 15px; }
.login-card button { justify-content: center; padding: 11px; background: var(--btn); color: var(--btn-ink); border: 0; font-size: 15px; font-weight: 700; }
.err { color: var(--bad); min-height: 1.2em; margin: 0; }

/* 레이아웃 */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-ink); padding: 16px 12px; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.side .brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 16px; border-bottom: 1px solid rgba(255,255,255,.12); margin-bottom: 10px; }
.side .brand img { width: 52px; }
.side .brand b { color: var(--side-ink); display: block; font-size: 15px; }
.side .brand small { color: var(--side-muted); font-size: 11px; }
.side nav a { display: flex; align-items: center; gap: 10px; color: var(--side-ink); padding: 9px 10px; border-radius: 8px; font-weight: 500; }
.side nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.side nav a.on { background: var(--side-on); color: var(--side-ink); font-weight: 700; }
.side nav .num { width: 22px; height: 22px; border-radius: 6px; background: rgba(255,255,255,.14); display: inline-grid; place-items: center; font-size: 11px; font-weight: 700; flex: none; }
.side .sep { font-size: 11px; color: var(--side-muted); padding: 14px 10px 4px; letter-spacing: .04em; }
.side .foot { font-size: 11px; color: var(--side-muted); padding: 16px 10px 0; }
.main { min-width: 0; }
.top { position: sticky; top: 0; z-index: 5; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); padding: 10px 24px; display: flex; gap: 10px; align-items: center; }
.top .search { flex: 1; max-width: 560px; position: relative; }
.top .search input { width: 100%; padding: 8px 12px 8px 34px; }
.top .search::before { content: "⌕"; position: absolute; left: 11px; top: 5px; color: var(--muted); font-size: 18px; }
.top .role { margin-left: auto; font-size: 12px; }
.menu-btn { display: none; }
.content { padding: 22px 24px 60px; max-width: 1400px; }

.crumb { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .v { font-size: 26px; font-weight: 800; color: var(--brand); line-height: 1.2; }
.stat .l { color: var(--muted); font-size: 12px; }
.tile { display: block; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); color: var(--ink); }
.tile:hover { border-color: var(--brand); text-decoration: none; }
.tile .n { font-size: 12px; font-weight: 700; color: var(--brand); }
.tile h3 { margin: 4px 0; }
.tile p { margin: 0; color: var(--muted); font-size: 13px; }

table { border-collapse: collapse; width: 100%; }
th, td { border-bottom: 1px solid var(--line); padding: 7px 8px; text-align: left; vertical-align: top; }
th { background: var(--bg); font-size: 12px; color: var(--muted); font-weight: 700; position: sticky; top: 0; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--brand-l); }
.tbl-wrap { overflow-x: auto; }
.num-c { text-align: right; font-variant-numeric: tabular-nums; }

.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: var(--brand-l); color: var(--brand); white-space: nowrap; }
.tag.new { background: var(--new-l); color: var(--new); }
.tag.ok { background: var(--ok-l); color: var(--ok); }
.tag.warn { background: var(--warn-l); color: var(--warn); }
.tag.bad { background: var(--bad-l); color: var(--bad); }
.tag.gray { background: var(--bg); color: var(--muted); }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; font-weight: 600; white-space: nowrap; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { border: 0; background: none; border-bottom: 2px solid transparent; border-radius: 0; padding: 8px 12px; color: var(--muted); font-weight: 600; }
.tabs button.on { color: var(--brand); border-bottom-color: var(--brand); }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }

.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 12px; }
.kv dt { color: var(--muted); font-size: 12px; }
.kv dd { margin: 0; }

/* 프로세스 맵 */
.pmap { display: grid; grid-template-columns: 90px 1fr 90px; gap: 12px; align-items: stretch; }
.pmap .edge { writing-mode: vertical-rl; text-orientation: upright; display: grid; place-items: center; border-radius: var(--radius); font-weight: 700; letter-spacing: .1em; padding: 8px; }
.pmap .edge.in { background: var(--brand-l); color: var(--brand); }
.pmap .edge.out { background: var(--ok-l); color: var(--ok); }
.pmap .band { border: 1px dashed var(--line); border-radius: var(--radius); padding: 10px; margin-bottom: 10px; }
.pmap .band h4 { margin: 0 0 8px; font-size: 12px; color: var(--muted); }
.pmap .row { display: flex; gap: 8px; flex-wrap: wrap; }
.pbox { flex: 1 1 150px; background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--brand); border-radius: 8px; padding: 8px 10px; cursor: pointer; }
.pbox:hover { border-color: var(--brand); }
.pbox .c { font-size: 11px; color: var(--muted); }
.pbox b { display: block; font-size: 13px; }
.pbox .o { font-size: 11px; color: var(--brand); }
.band.cop .pbox { border-left-color: #2f8f6a; }
.band.sp .pbox { border-left-color: #b3541e; }
.arrow-row { text-align: center; color: var(--muted); font-size: 12px; margin: -4px 0 6px; }

/* 문서 트리 */
.tree details { border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; background: var(--panel); }
.tree summary { padding: 9px 12px; cursor: pointer; font-weight: 600; display: flex; gap: 8px; align-items: center; }
.tree .kids { padding: 0 12px 10px 28px; }
.tree .item { display: flex; gap: 8px; align-items: baseline; padding: 4px 0; border-bottom: 1px dashed var(--line); flex-wrap: wrap; }
.tree .item:last-child { border-bottom: 0; }

/* KPI */
.kpi-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.kpi-card h4 { margin: 0; font-size: 13px; }
.kpi-card .meta { font-size: 11px; color: var(--muted); }
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 10px; }
.kpi-input td input { width: 70px; padding: 3px 5px; text-align: right; }

/* 내부심사 */
.q { border-bottom: 1px solid var(--line); padding: 10px 0; display: grid; grid-template-columns: 70px 1fr 220px; gap: 10px; align-items: start; }
.q .no { font-weight: 700; color: var(--brand); font-size: 12px; }
.q .opts { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.q .opts button { padding: 3px 9px; font-size: 12px; }
.q .opts button.sel-ok { background: var(--ok); color: var(--sel-ink); border-color: var(--ok); }
.q .opts button.sel-warn { background: var(--warn); color: var(--sel-ink); border-color: var(--warn); }
.q .opts button.sel-bad { background: var(--bad); color: var(--sel-ink); border-color: var(--bad); }
.q .opts button.sel-na { background: var(--muted); color: var(--sel-ink); border-color: var(--muted); }
.q textarea { width: 100%; margin-top: 6px; min-height: 34px; font-size: 12px; }
.bar { height: 8px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); }

.org { display: grid; gap: 12px; justify-items: center; }
.org .box { background: var(--panel); border: 2px solid var(--brand); border-radius: 10px; padding: 8px 18px; text-align: center; min-width: 150px; }
.org .box small { display: block; color: var(--muted); }
.org .depts { display: grid; grid-template-columns: repeat(5, minmax(0,1fr)); gap: 10px; width: 100%; }
.org .dept { background: var(--panel); border: 1px solid var(--line); border-top: 4px solid var(--brand); border-radius: 10px; padding: 10px; cursor: pointer; }
.org .dept:hover { border-color: var(--brand); }
.org .dept ul { margin: 6px 0 0; padding-left: 16px; font-size: 12px; color: var(--muted); }
.flow { display: flex; gap: 6px; align-items: stretch; flex-wrap: wrap; }
.flow .st { flex: 1 1 160px; background: var(--bg); border-radius: 8px; padding: 8px 10px; font-size: 12px; position: relative; }
.flow .st b { display: block; font-size: 13px; color: var(--brand); }

.empty { text-align: center; padding: 40px; color: var(--muted); }
.notice { background: var(--warn-l); color: var(--warn); border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; font-size: 13px; }
iframe.preview { width: 100%; height: 70vh; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.hl { background: var(--hl); color: var(--ink); }

@media (max-width: 1100px) { .g4 { grid-template-columns: repeat(2, minmax(0,1fr)); } .org .depts { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .side { position: fixed; left: -260px; width: 250px; z-index: 20; transition: left .2s; }
  .side.open { left: 0; }
  .menu-btn { display: inline-flex; }
  .top { padding: 10px 16px; }
  .content { padding: 16px; }
  .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .pmap { grid-template-columns: 1fr; }
  .pmap .edge { writing-mode: horizontal-tb; }
  .q { grid-template-columns: 1fr; }
  .q .opts { justify-content: flex-start; }
  .kv { grid-template-columns: 90px 1fr; }
}
@media print { .side, .top { display: none; } .app { display: block; } .panel { box-shadow: none; break-inside: avoid; } }

.theme { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.theme button { border: 0; border-radius: 0; padding: 5px 10px; font-size: 12px; background: var(--panel); color: var(--muted); }
.theme button.on { background: var(--btn); color: var(--btn-ink); font-weight: 700; }

/* 표 정리 */
th { white-space: nowrap; }
td .tag, td .code { white-space: nowrap; }
table.kpi-input { table-layout: fixed; min-width: 1090px; }
.kpi-input col.c-name { width: 270px; } .kpi-input col.c-target { width: 130px; } .kpi-input col.c-owner { width: 64px; }
.kpi-input col.c-cycle { width: 70px; } .kpi-input col.c-m { width: 44px; } .kpi-input col.c-rate { width: 52px; }
.kpi-input td { vertical-align: middle; }
.kpi-input td:nth-child(3), .kpi-input td:nth-child(4) { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-input .sub { font-size: 11px; color: var(--muted); margin-top: 2px; line-height: 1.35; }
.kpi-input .sub .code { font-size: 11px; }
.kpi-input .sub-t { font-size: 12px; line-height: 1.35; }
.kpi-input td input { width: 100%; min-width: 0; padding: 3px 4px; text-align: right; font-size: 12px; }
.kpi-input td:nth-child(n+5) { padding-left: 3px; padding-right: 3px; }

/* 본문 가독성 */
.rt-wrap { padding: 6px 4px 10px; }
.rt { padding: 3px 0; line-height: 1.7; }
.rt .cl { color: var(--brand); font-variant-numeric: tabular-nums; margin-right: 2px; }
.rt-i { padding-left: 22px; text-indent: -14px; margin: 1px 0; }
details > summary { padding: 6px 0; }
table.sheet td, table.sheet th { font-size: 12.5px; white-space: normal; vertical-align: top; min-width: 70px; }
