:root {
  --ink: #1b2836;
  --muted: #4d5e6e;
  --faint: #6d7e8d;
  --line: #c5d0da;
  --line-strong: #b4c0cb;
  --panel: #ffffff;
  --stage: #e6edf2;
  --desktop: #d3dde5;
  --head: #e5eef5;
  --label: #e7eef4;
  --edit: #fffdf6;
  --lock: #f3f6f8;
  --navy: #12324d;
  --navy-2: #0d2438;
  --select: #d7e7f6;
  --hover: #f2f7fb;
  --focus: #1d5f99;
  --ok: #1c6b45;
  --wait: #8a5d00;
  --stop: #8f3030;
  --draft: #1d5f99;
  --row: 30px;
  --font: "Segoe UI", "Malgun Gothic", "맑은 고딕", sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  font-size: 13px;
  color: var(--ink);
  background: var(--desktop);
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }

.app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--desktop);
}

.topbar {
  height: 36px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 10px 0 8px;
  background: var(--navy-2);
  color: #e7eef4;
}
.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }
.mark {
  width: 28px;
  height: 22px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(231, 238, 244, 0.45);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.brand-text { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
.brand-text strong { font-size: 13px; font-weight: 650; letter-spacing: 0; }
.crumb { color: #b7c9d8; font-size: 12px; }
.crumb::before { content: "/"; margin-right: 8px; color: #6e8798; }
.session {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #d5e0e8;
  white-space: nowrap;
}
.session strong { font-weight: 650; color: #fff; }
.session-key { color: #8eabbf; }
.session-btn {
  height: 22px;
  padding: 0 8px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: transparent;
  color: #fff;
}
.session-btn:hover { background: rgba(255, 255, 255, 0.08); }
html.boot .app { visibility: hidden; }
.login {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--desktop);
}
.login[hidden] { display: none; }
.login-card {
  width: min(360px, calc(100% - 32px));
  background: #fff;
  border: 1px solid var(--line-strong);
}
.login-card h1 {
  margin: 0;
  height: 40px;
  display: flex;
  align-items: center;
  padding: 0 14px;
  background: var(--navy);
  color: #fff;
  font-size: 14px;
  font-weight: 650;
}
.login-card label {
  display: grid;
  gap: 4px;
  margin: 12px 14px 0;
  color: #31485b;
  font-size: 12px;
}
.login-card label[hidden] { display: none !important; }
.login-card input {
  height: 28px;
  border: 1px solid #b7c3ce;
  padding: 0 8px;
  background: var(--edit);
}
.notice {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(18, 50, 77, 0.35);
}
.notice[hidden] { display: none; }
.notice-card {
  width: min(420px, calc(100% - 32px));
  background: #fff;
  border: 1px solid var(--line-strong);
}
.notice-card p {
  margin: 0;
  padding: 18px 16px 8px;
  line-height: 1.5;
}
.notice-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 8px 14px 14px; }
.login-error {
  min-height: 18px;
  margin: 8px 14px 0;
  color: var(--stop);
  font-size: 12px;
}
.login-card .btn { margin: 8px 14px 0; }
.login-help {
  margin: 10px 14px 14px;
  padding: 10px 10px 8px;
  border-top: 1px solid var(--line);
  color: #4a5d6e;
  font-size: 12px;
  line-height: 1.55;
}
.login-help p { margin: 0 0 6px; }
.login-help p:last-child { margin-bottom: 0; }
.sep { width: 1px; height: 12px; background: rgba(255, 255, 255, 0.22); }

.body { flex: 1; min-height: 0; display: flex; }
.nav {
  width: 132px;
  flex: none;
  display: flex;
  flex-direction: column;
  background: #f6f9fb;
  border-right: 1px solid var(--line-strong);
  padding-top: 8px;
}
.nav-label, .nav-foot {
  margin: 0;
  padding: 0 12px;
  font-size: 11px;
  color: var(--faint);
}
.nav-label { margin-bottom: 4px; }
.nav-foot { margin-top: auto; padding-bottom: 10px; }
.nav-item {
  height: 34px;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 0 12px;
  border: 0;
  border-left: 3px solid transparent;
  background: transparent;
  color: #2d4254;
  text-align: left;
}
.nav-item svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  flex: none;
}
.nav-badge {
  margin-left: auto;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: #c4473a;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}
.nav-badge[hidden] { display: none !important; }
.nav-item:hover { background: #eaf1f6; }
.nav-item.is-active {
  background: #dceaf6;
  border-left-color: var(--navy);
  color: var(--navy);
  font-weight: 700;
}

.stage {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--stage);
}
.command {
  height: 36px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  background: #f3f7fa;
  border-bottom: 1px solid var(--line);
}
.btn {
  height: 26px;
  padding: 0 10px;
  border: 1px solid #b7c3ce;
  background: #fff;
  color: var(--ink);
  line-height: 24px;
}
.btn:hover:not(:disabled) { background: #f7fbfe; border-color: #8ea4b6; }
.btn:focus-visible, .nav-item:focus-visible, .grid th button:focus-visible, .val input:focus-visible, .cell-input:focus-visible, .criteria input:focus-visible, .criteria select:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: -2px;
}
.btn.primary { background: var(--navy); border-color: var(--navy); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #1a4466; }
.btn.danger { color: var(--stop); }
.btn.danger:hover:not(:disabled) { background: #fbf6f6; }
.btn:disabled { color: #8b9aab; background: #eef2f5; border-color: #d5dee4; }
.link-btn {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--navy);
  text-decoration: underline;
  cursor: pointer;
  font: inherit;
  text-align: left;
}
.link-btn:hover { color: #1a4466; }
.sep-v { width: 1px; height: 16px; background: #c9d3dc; margin: 0 2px; }

.criteria {
  min-height: 36px;
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  padding: 4px 8px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.field { display: flex; align-items: center; gap: 6px; min-width: 0; }
.field span { color: var(--muted); font-size: 12px; white-space: nowrap; }
.criteria input, .criteria select {
  height: 26px;
  border: 1px solid #b7c3ce;
  background: var(--edit);
  padding: 0 6px;
}
.criteria input:focus, .criteria select:focus { border-color: var(--focus); outline: none; }
.criteria input[type="date"] { width: 132px; }
.criteria input[type="search"] { width: 220px; }
.criteria .vendor { width: 140px; }
.tilde { color: var(--faint); }

.doc-tab {
  height: 26px;
  flex: none;
  display: flex;
  align-items: flex-end;
  padding: 0 8px;
  background: var(--stage);
}
.doc-tab span {
  height: 24px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-bottom: 0;
  color: var(--navy);
  font-size: 12px;
  font-weight: 650;
}

.composite {
  flex: 1;
  min-height: 0;
  display: flex;
  padding: 0 6px 6px;
}
.pane {
  background: var(--panel);
  border: 1px solid var(--line-strong);
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.list-pane { flex: 0 0 42%; }
.detail-pane { flex: 1 1 auto; overflow: visible; }
.audit-pane { flex: 1 1 auto; }
.splitter {
  width: 6px;
  flex: none;
  cursor: col-resize;
  position: relative;
}
.splitter::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 2px;
  width: 2px;
  background: transparent;
}
.splitter:hover::after, .splitter.is-drag::after { background: #7ea4c4; }

.pane-cap {
  height: 28px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 8px;
  background: #f5f8fb;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  font-weight: 700;
  color: #24384a;
}
.cap-title { display: inline-flex; align-items: center; gap: 6px; min-width: 0; }
.cap-title i { width: 8px; height: 8px; background: var(--navy); display: inline-block; flex: none; }
.cap-meta { font-weight: 500; color: var(--muted); }

.form {
  flex: none;
  overflow: visible;
  display: grid;
  grid-template-columns: 76px minmax(110px, 1.35fr) 76px minmax(78px, 0.8fr) 76px minmax(100px, 1fr) 76px minmax(72px, 0.75fr);
  border-bottom: 1px solid var(--line);
}
.lab, .val { min-width: 0; min-height: var(--row); border-bottom: 1px solid #e1e8ee; border-right: 1px solid #e1e8ee; }
.lab {
  display: flex;
  align-items: center;
  padding: 0 8px;
  background: var(--label);
  color: #31485b;
  font-size: 12px;
}
.val { display: flex; background: var(--lock); position: relative; }
.val.edit { background: var(--edit); }
.val input, .val select {
  width: 100%;
  min-width: 0;
  height: 100%;
  border: 0;
  background: transparent;
  padding: 0 8px;
  font: inherit;
}
.val input:focus, .val select:focus { outline: none; background: #fff; box-shadow: inset 0 0 0 2px var(--focus); }
.val input[readonly] { color: var(--ink); }
.val.span { grid-column: 2 / -1; }
.lookup {
  position: relative;
  width: 100%;
  min-width: 0;
  height: 100%;
  z-index: 5;
}
.lookup > input { width: 100%; height: 100%; }
.lookup-list {
  position: absolute;
  left: 0;
  right: 0;
  top: 100%;
  z-index: 20;
  max-height: 220px;
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line-strong);
  box-shadow: 0 8px 18px rgba(20, 40, 60, 0.12);
}
.lookup-option {
  display: block;
  width: 100%;
  border: 0;
  border-bottom: 1px solid #eef2f5;
  background: #fff;
  text-align: left;
  padding: 7px 8px;
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.lookup-option:hover,
.lookup-option.is-active { background: var(--select); }
.lookup-empty {
  padding: 8px;
  color: var(--muted);
  font-size: 12px;
}
.line-lookup {
  min-height: 28px;
}
.line-lookup > input {
  border: 0;
  background: transparent;
  padding: 0 6px;
  font: inherit;
}
.line-lookup .lookup-list {
  z-index: 40;
}

.grid-scroll { flex: 1; min-height: 0; overflow: auto; }
.grid-scroll::-webkit-scrollbar { width: 10px; height: 10px; }
.grid-scroll::-webkit-scrollbar-thumb { background: #c5d0d8; border: 2px solid #fff; }
.grid-scroll::-webkit-scrollbar-track { background: #fff; }

.grid {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.grid th, .grid td {
  height: var(--row);
  padding: 0 8px;
  border-bottom: 1px solid #e6edf2;
  border-right: 1px solid #f0f4f7;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
}
.grid th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--head);
  border-bottom-color: #c5d3df;
  box-shadow: inset 0 -1px 0 #c5d3df;
  font-size: 12px;
  font-weight: 700;
  color: #2a4154;
}
.grid th button {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  font: inherit;
  font-weight: 700;
  color: inherit;
  text-align: inherit;
}
.grid th.num, .grid th.num button, .grid td.num { text-align: right; }
.grid th.num button { justify-content: flex-end; }
.grid th .mark-sort { color: #9aabba; font-size: 9px; }
.grid th[aria-sort="ascending"] .mark-sort, .grid th[aria-sort="descending"] .mark-sort { color: var(--navy); }
.grid tbody tr { cursor: pointer; }
.grid tbody tr:hover td { background: var(--hover); }
.grid tbody tr.is-selected td { background: var(--select); box-shadow: inset 0 -1px 0 #c5d8ea; }
.grid tbody tr.is-selected td:first-child { box-shadow: inset 2px 0 0 var(--focus), inset 0 -1px 0 #c5d8ea; }
.grid tfoot td {
  position: sticky;
  bottom: 0;
  z-index: 1;
  background: #f4f7fa;
  border-top: 1px solid #c5d0da;
  border-bottom: 0;
  font-weight: 700;
}
.cell-input {
  width: 100%;
  height: 26px;
  border: 0;
  background: var(--edit);
  padding: 0 6px;
  text-align: inherit;
  font-variant-numeric: tabular-nums;
}
.cell-input:focus { outline: none; box-shadow: inset 0 0 0 2px var(--focus); background: #fff; }
.empty { text-align: center; color: var(--faint); cursor: default; height: 48px; }

.state { display: inline-flex; align-items: center; gap: 6px; }
.state::before {
  content: "";
  width: 7px;
  height: 7px;
  background: var(--draft);
  flex: none;
}
.state.wait::before { background: var(--wait); }
.state.ok::before { background: var(--ok); }
.state.stop::before { background: var(--stop); }
.state.mute::before { background: #8b9aab; }

.statusbar {
  height: 24px;
  flex: none;
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(0, 1.4fr) minmax(140px, 1fr);
  align-items: center;
  gap: 12px;
  padding: 0 8px;
  background: #e7eef3;
  border-top: 1px solid var(--line-strong);
  color: var(--muted);
  font-size: 12px;
}
.statusbar .msg { color: var(--navy); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.statusbar .msg.is-alert { color: #a33b30; font-weight: 650; }
.statusbar .hint { text-align: right; }

.print-root { display: none; }

@media (max-width: 1100px) {
  .form { grid-template-columns: 72px 1fr 64px 1fr; }
  .val.span { grid-column: 2 / -1; }
  .session-key { display: none; }
}
@media (max-width: 860px) {
  .body { flex-direction: column; }
  .nav {
    width: auto;
    height: 40px;
    flex-direction: row;
    align-items: stretch;
    padding: 0;
    border-right: 0;
    border-bottom: 1px solid var(--line-strong);
    overflow-x: auto;
  }
  .nav-label, .nav-foot { display: none; }
  .nav-item { width: auto; border-left: 0; border-bottom: 3px solid transparent; padding: 0 14px; }
  .nav-item.is-active { border-bottom-color: var(--navy); border-left-color: transparent; }
  .composite { flex-direction: column; }
  .splitter { display: none; }
  .list-pane { flex: none; height: 34vh; }
  .criteria input[type="search"] { width: 140px; }
}

@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; }
  .app, .login, .notice { display: none !important; }
  .print-root { display: block; color: #000; }
  .print-root h1 { margin: 0 0 4px; text-align: center; font-size: 22px; letter-spacing: 0.4em; font-weight: 700; }
  .print-meta { display: flex; justify-content: space-between; margin: 0 0 8px; font-size: 12px; }
  .print-root table { width: 100%; border-collapse: collapse; font-size: 11px; margin-bottom: 8px; }
  .print-root th, .print-root td { border: 1px solid #222; padding: 4px 6px; text-align: left; }
  .print-root td.num, .print-root th.num { text-align: right; font-variant-numeric: tabular-nums; }
  .print-sign { display: flex; justify-content: flex-end; gap: 0; margin-top: 12px; }
  .print-sign div { width: 90px; height: 72px; border: 1px solid #222; border-left: 0; text-align: center; font-size: 12px; padding-top: 4px; }
  .print-sign div:first-child { border-left: 1px solid #222; }
  .print-note { margin-top: 8px; font-size: 10px; color: #333; }
  .print-root.statement h1 { letter-spacing: 0.55em; }
  .print-parties { margin-bottom: 8px; }
  .print-parties th { text-align: center; background: #f3f3f3; }
  .print-parties td.lab { width: 72px; background: #fafafa; white-space: nowrap; }
}
