:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1f2933;
  --muted: #6b7785;
  --line: #dde2e8;
  --brand: #1f3a5f;
  --brand-2: #2f5d8f;
  --accent: #2f6fdb;
  --ok: #1f8a4c;
  --warn: #b26a00;
  --danger: #c0392b;
  --chip: #eef2f7;
  --radius: 8px;
  font-size: 14px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", system-ui, sans-serif;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0 0 10px; }
h3 { font-size: 1rem; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.mono { font-family: ui-monospace, "SFMono-Regular", Consolas, monospace; font-size: 12.5px; }

/* 상단 메뉴 */
.topbar {
  display: flex; align-items: center; gap: 28px;
  background: var(--brand); color: #fff; padding: 0 24px; height: 52px;
}
.brand { color: #fff; font-weight: 700; font-size: 1.1rem; letter-spacing: .02em; }
.brand:hover { text-decoration: none; }
.modules { display: flex; gap: 4px; height: 100%; }
.modules a {
  display: flex; align-items: center; padding: 0 16px; color: #c9d6e6; font-weight: 600;
  border-bottom: 3px solid transparent;
}
.modules a:hover { color: #fff; text-decoration: none; }
.modules a.active { color: #fff; border-bottom-color: #8fb8ff; }

.subnav { background: var(--surface); border-bottom: 1px solid var(--line); padding: 0 24px; overflow-x: auto; }
.subnav ul { list-style: none; display: flex; gap: 2px; margin: 0; padding: 0; }
.subnav a {
  display: block; padding: 11px 14px; color: var(--muted); font-weight: 600; white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.subnav a:hover { color: var(--text); text-decoration: none; }
.subnav a.active { color: var(--brand-2); border-bottom-color: var(--brand-2); }

.container { max-width: 1440px; margin: 0 auto; padding: 20px 24px 60px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* 카드 */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat .label { color: var(--muted); font-size: 12px; }
.stat .value { font-size: 1.5rem; font-weight: 700; }
.stat .sub { color: var(--muted); font-size: 12px; }
.stat a { color: inherit; }

/* 버튼 */
.btn {
  display: inline-flex; align-items: center; gap: 4px; padding: 7px 13px; border-radius: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { text-decoration: none; border-color: #b8c2cf; background: #fafbfc; }
.btn.primary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.btn.primary:hover { background: var(--brand); }
.btn.danger { color: var(--danger); border-color: #e7b7b1; }
.btn.small { padding: 3px 8px; font-size: 12px; }
form.inline { display: inline; }

/* 표 */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { padding: 7px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.list th { background: #f0f3f7; font-weight: 600; font-size: 12.5px; color: #3e4c5b; position: sticky; top: 0; white-space: nowrap; }
table.list tbody tr:hover { background: #f7f9fc; }
table.list tr.closed td { color: var(--muted); }
table.list td.num, table.list th.num { text-align: right; white-space: nowrap; }
table.list tfoot td { font-weight: 600; background: #fafbfc; }
table.kv { border-collapse: collapse; width: 100%; }
table.kv th { width: 150px; text-align: left; color: var(--muted); font-weight: 600; padding: 6px 10px 6px 0; vertical-align: top; }
table.kv td { padding: 6px 0; }
table.kv td.pre { white-space: pre-wrap; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* 배지 */
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; background: var(--chip); color: #3e4c5b; white-space: nowrap; }
.badge.ok { background: #e3f4ea; color: var(--ok); }
.badge.warn { background: #fdf0db; color: var(--warn); }
.badge.danger { background: #fbe4e1; color: var(--danger); }
.badge.muted { background: #eceff3; color: var(--muted); }

/* 필터·폼 */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
input[type=text], input[type=date], input[type=search], input[type=number], select, textarea {
  font: inherit; padding: 6px 9px; border: 1px solid #c8d0da; border-radius: 6px; background: #fff; color: var(--text);
}
textarea { min-height: 70px; width: 100%; }
.filters input[type=search] { min-width: 240px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px 20px; }
.field label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.field .req { color: var(--danger); }
.field input, .field select, .field textarea { width: 100%; }
.field .help { color: var(--muted); font-size: 12px; margin-top: 3px; }
.field .error { color: var(--danger); font-size: 12px; margin-top: 3px; }
.field.has-error input, .field.has-error select { border-color: var(--danger); }
.field.wide { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 8px; margin-top: 18px; align-items: center; }
label.check { display: inline-flex; gap: 5px; align-items: center; font-weight: 500; }

/* 알림 */
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 12px; border: 1px solid; }
.flash.ok { background: #eaf6ef; border-color: #b9e0c8; color: #165c34; }
.flash.error { background: #fdecea; border-color: #f2c0ba; color: #8f2318; }
.flash.info { background: #eef3fb; border-color: #c8d7f0; color: #284a7a; }

/* 이력 */
.history { list-style: none; margin: 0; padding: 0; }
.history li { padding: 8px 0; border-bottom: 1px dashed var(--line); }
.history li:last-child { border-bottom: 0; }
.history .meta { color: var(--muted); font-size: 12px; }
.history .changes { margin: 4px 0 0; padding-left: 16px; font-size: 13px; }
.history del { color: var(--muted); }

/* 시작 화면 */
.modules-home { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; margin-top: 18px; }
.module-card { display: block; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 22px; color: var(--text); }
.module-card:hover { text-decoration: none; border-color: var(--brand-2); }
.module-card h2 { font-size: 1.2rem; }

/* 인쇄용 대장 */
.ledger-toolbar { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 16px; margin-bottom: 18px; }
.ledger-toolbar .row { display: flex; gap: 14px; flex-wrap: wrap; align-items: center; }
.ledger { background: #fff; padding: 18px 22px; margin-bottom: 24px; border: 1px solid var(--line); }
.ledger h1.title { text-align: center; font-size: 22px; letter-spacing: .5em; margin: 0 0 6px; }
.ledger .ledger-meta { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 6px; }
.ledger .heading { font-weight: 700; }
table.ledger-table { width: 100%; border-collapse: collapse; font-size: 11px; }
table.ledger-table th, table.ledger-table td { border: 1px solid #555; padding: 3px 4px; }
table.ledger-table th { background: #e5eaf2; text-align: center; white-space: pre-line; }
table.ledger-table td.center { text-align: center; }
table.ledger-table td.right { text-align: right; white-space: nowrap; }
.ledger .confirm { margin-top: 18px; font-size: 13px; }
.ledger .confirm p { margin: 4px 0; }

@media print {
  @page { size: A4 landscape; margin: 10mm; }
  body { background: #fff; font-size: 11px; }
  .no-print, .topbar, .subnav, .flash { display: none !important; }
  .container { max-width: none; padding: 0; }
  .ledger { border: 0; padding: 0; margin: 0; }
  .ledger + .ledger { page-break-before: always; }
  table.ledger-table thead { display: table-header-group; }
  table.ledger-table tr { page-break-inside: avoid; }
}

/* ── SPA 추가 ─────────────────────────────────────────── */
.topbar .userbox { margin-left: auto; display: flex; gap: 10px; align-items: center; color: #c9d6e6; font-size: 13px; }
.btn.ghost { background: transparent; color: #dfe8f3; border-color: rgba(255, 255, 255, .35); }
.btn.ghost:hover { background: rgba(255, 255, 255, .08); }
.btn.wide { width: 100%; justify-content: center; }
.btn:disabled { opacity: .55; cursor: default; }
.mt { margin-top: 12px; }
.spacer { flex: 1; }
input.short { width: 120px; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.stack label { font-weight: 600; font-size: 13px; }
.login { max-width: 460px; margin: 40px auto; }
.login h1 { margin-bottom: 8px; }
details summary { cursor: pointer; }
a.badge:hover { text-decoration: none; filter: brightness(.95); }
@media (max-width: 720px) {
  .topbar { gap: 12px; padding: 0 12px; }
  .topbar .userbox span { display: none; }
  .container { padding: 16px 12px 48px; }
  .grid.cols-2, .grid.cols-3 { grid-template-columns: 1fr; }
}
