/* MOONZ WORKS 회계장부 — 화면 스타일 */
:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --line: #dde3ec;
  --text: #1a2233;
  --muted: #5d6b82;
  --accent: #1f4fd8;
  --accent-soft: #e8eefc;
  --danger: #c0392b;
  --danger-soft: #fdecea;
  --ok: #1e8e5a;
  --ok-soft: #e6f5ee;
  --warn: #b7791f;
  --warn-soft: #fdf3e1;
  --income: #1e8e5a;
  --expense: #c0392b;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.1);
  --font: -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Pretendard", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); color: var(--text); background: var(--bg); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.3; }
h1 { font-size: 20px; } h2 { font-size: 17px; } h3 { font-size: 15px; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.hidden { display: none !important; }
.income { color: var(--income); }
.expense { color: var(--expense); }

/* 레이아웃 */
.app { min-height: 100vh; display: grid; grid-template-columns: 220px 1fr; grid-template-rows: 56px 1fr; grid-template-areas: "top top" "nav main"; }
.topbar { grid-area: top; display: flex; align-items: center; gap: 14px; padding: 0 18px; background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; letter-spacing: 0.02em; white-space: nowrap; }
.brand img { width: 26px; height: 26px; border-radius: 6px; }
.brand .sub { font-weight: 500; color: var(--muted); font-size: 12px; }
.topbar .spacer { flex: 1; }
.env-badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); font-weight: 600; white-space: nowrap; }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.user-chip img { width: 26px; height: 26px; border-radius: 50%; }
.user-chip .role { font-size: 11px; color: var(--muted); white-space: nowrap; }
.nav-toggle { display: none; }
.sidenav { grid-area: nav; background: var(--surface); border-right: 1px solid var(--line); padding: 14px 10px; }
.sidenav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--text); font-weight: 500; }
.sidenav a:hover { background: var(--surface-2); text-decoration: none; }
.sidenav a.active { background: var(--accent-soft); color: var(--accent); }
.sidenav .icon { width: 18px; text-align: center; opacity: 0.8; }
main#view { grid-area: main; padding: 22px 26px 60px; min-width: 0; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.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; box-shadow: var(--shadow); }
.card + .card { margin-top: 14px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .label { font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.stat .value { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; }
.stat .hint { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* 버튼 */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 500; font-size: 13px; line-height: 1.2; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--danger); border-color: #f0c2bd; background: var(--danger-soft); }
.btn.small { padding: 4px 8px; font-size: 12px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.link { border: 0; background: transparent; color: var(--accent); padding: 2px 4px; }

/* 폼 */
.form-grid { display: grid; grid-template-columns: repeat(12, 1fr); gap: 10px 12px; }
.field { display: flex; flex-direction: column; gap: 4px; grid-column: span 4; min-width: 0; }
.field.span-2 { grid-column: span 2; } .field.span-3 { grid-column: span 3; } .field.span-6 { grid-column: span 6; } .field.span-8 { grid-column: span 8; } .field.span-12 { grid-column: span 12; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; }
.field input, .field select, .field textarea { padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; background: #fff; width: 100%; min-width: 0; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.field textarea { min-height: 64px; resize: vertical; }
.field .help { font-size: 11px; color: var(--muted); }
.field input.num { text-align: right; font-variant-numeric: tabular-nums; }
.inline-check { display: flex; align-items: center; gap: 6px; font-size: 13px; }
fieldset.group { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px 12px; margin: 0 0 12px; grid-column: span 12; }
fieldset.group legend { font-size: 12px; font-weight: 600; color: var(--muted); padding: 0 6px; }

/* 툴바(필터) */
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 12px; }
.toolbar .field { grid-column: auto; min-width: 120px; }
.toolbar .field input, .toolbar .field select { padding: 6px 8px; }
.toolbar .chips { display: flex; gap: 6px; }
.chip { padding: 4px 9px; border-radius: 999px; border: 1px solid var(--line); background: var(--surface); font-size: 12px; cursor: pointer; }
.chip.active, .chip:hover { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* 표 */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
table.data { border-collapse: collapse; width: 100%; font-size: 13px; }
table.data th, table.data td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
table.data th { background: var(--surface-2); color: var(--muted); font-weight: 600; font-size: 12px; white-space: nowrap; position: sticky; top: 0; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data tbody tr.clickable { cursor: pointer; }
table.data tbody tr.clickable:hover { background: #f3f6fd; }
table.data tfoot td { font-weight: 700; background: var(--surface-2); }
table.data td.ellipsis { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.data tr.deleted td { color: var(--muted); text-decoration: line-through; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* 뱃지 */
.badge { display: inline-block; padding: 2px 7px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.badge.income { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.badge.expense { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge.financing { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.transfer { background: #eef2f7; color: #4a5568; border-color: transparent; }
.badge.review { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.hold { background: #eee; color: #666; border-color: transparent; }
.badge.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }

/* 모달 */
.modal-backdrop { position: fixed; inset: 0; background: rgba(16, 24, 40, 0.45); display: flex; align-items: flex-start; justify-content: center; padding: 30px 12px; overflow-y: auto; z-index: 50; }
.modal { background: var(--surface); border-radius: 12px; width: min(920px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,0.25); }
.modal.narrow { width: min(560px, 100%); }
.modal header { display: flex; align-items: center; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal header h2 { margin: 0; }
.modal .body { padding: 16px 18px; }
.modal footer { display: flex; justify-content: space-between; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 12px 12px; }
.modal footer .left, .modal footer .right-group { display: flex; gap: 8px; }
.close-x { border: 0; background: transparent; font-size: 20px; cursor: pointer; color: var(--muted); }

/* 첨부 */
.dropzone { border: 1.5px dashed var(--line); border-radius: 8px; padding: 14px; text-align: center; color: var(--muted); background: var(--surface-2); cursor: pointer; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.attach-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.attach-list li { display: flex; align-items: center; gap: 10px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 7px; background: #fff; font-size: 12px; }
.attach-list li .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-list li .hash { font-family: var(--mono); color: var(--muted); }
.thumbs { display: flex; gap: 6px; flex-wrap: wrap; }
.thumbs img { width: 72px; height: 72px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }

/* 토스트 */
#toast-root { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: #1a2233; color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13px; box-shadow: var(--shadow); animation: fadein .2s ease; }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* 로그인 */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: radial-gradient(1200px 600px at 20% 0%, #e8eefc, transparent), var(--bg); }
.login-card { width: min(440px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 30px 28px; box-shadow: 0 10px 40px rgba(16,24,40,0.12); text-align: center; }
.login-card img { width: 56px; height: 56px; border-radius: 12px; margin-bottom: 10px; }
.login-card .msg { min-height: 20px; color: var(--danger); font-size: 13px; margin-top: 10px; }
.login-card .btn { width: 100%; justify-content: center; padding: 11px; font-size: 14px; margin-top: 14px; }

/* 상세 패널 */
.split { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 4px 10px; font-size: 13px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.summary-table td:first-child { color: var(--muted); }

/* 반응형 */
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-areas: "top" "main"; }
  .sidenav { position: fixed; top: 56px; left: 0; bottom: 0; width: 230px; transform: translateX(-100%); transition: transform .2s; z-index: 30; box-shadow: 0 0 30px rgba(0,0,0,0.15); }
  .sidenav.open { transform: none; }
  .nav-toggle { display: inline-flex; }
  main#view { padding: 16px 14px 60px; }
  .field { grid-column: span 6; }
  .field.span-2, .field.span-3 { grid-column: span 6; }
  .split { grid-template-columns: 1fr; }
  .user-chip .name, .user-chip .role, .brand .sub { display: none; }
  .topbar { gap: 8px; padding: 0 12px; }
}
@media (max-width: 520px) {
  .env-badge { font-size: 10px; padding: 2px 6px; }
  .field, .field.span-2, .field.span-3, .field.span-6, .field.span-8 { grid-column: span 12; }
  .cards { grid-template-columns: 1fr 1fr; }
  .stat .value { font-size: 17px; }
}
@media print {
  .topbar, .sidenav, .actions, .toolbar { display: none !important; }
  .app { display: block; }
  body { background: #fff; }
}

/* 복식부기: 전표 줄·종류 뱃지·분개 미리보기·인쇄 */
.jl { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; }
.jl .amt { font-variant-numeric: tabular-nums; white-space: nowrap; }
.badge.auto { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.reversal { background: #fde8e8; color: #b42318; border-color: transparent; }
.badge.adjust { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.badge.manual, .badge.opening, .badge.yearend { background: #eef2f7; color: #4a5568; border-color: transparent; }
table.data tr.reversed td { color: var(--muted); }
table.journal td { vertical-align: top; }
.card.preview { background: var(--surface-2); }
.card.preview table.data { background: #fff; }
@media print {
  .topbar, .sidenav, .toolbar, .chips, .page-head .actions, #toast-root, .modal-backdrop { display: none !important; }
  .app { display: block; }
  main#view { padding: 0; }
  .card, .table-wrap { box-shadow: none; border: 0; }
  body { background: #fff; }
}
.acct-map td:first-child { white-space: nowrap; }
.split > div { min-width: 0; }

/* 결산·재무제표 서식 */
.checklist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.checklist li { padding: 6px 8px; border: 1px solid var(--line); border-radius: 7px; background: #fff; font-size: 13px; }
.checklist li.block { border-color: #f0c2bd; background: var(--danger-soft); }
.stmt-preview .sheet { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 22px; margin-top: 8px; }
.sheet .fs-head { text-align: center; margin-bottom: 12px; }
.sheet .fs-company { font-weight: 700; font-size: 13px; color: var(--muted); }
.sheet .fs-company.big { font-size: 18px; color: var(--text); }
.sheet .fs-title { font-size: 20px; margin: 4px 0; }
.sheet .fs-sub { font-size: 12px; color: var(--muted); }
.sheet .fs-unit { text-align: right; font-size: 11px; color: var(--muted); }
.sheet .fs-foot { margin-top: 14px; font-size: 11px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 6px; }
table.fs { border-collapse: collapse; width: 100%; font-size: 13px; }
table.fs th, table.fs td { padding: 5px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.fs th { background: var(--surface-2); font-size: 12px; color: var(--muted); }
table.fs td.num, table.fs th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.fs tr.part td { font-weight: 700; background: var(--surface-2); }
table.fs tr.sub td { font-weight: 600; }
table.fs tr.sub2 td { font-weight: 600; padding-left: 16px; }
table.fs tr.item td:first-child { padding-left: 28px; }
table.fs tr.item2 td:first-child { padding-left: 44px; color: var(--muted); }
table.fs tr.total td { font-weight: 700; border-top: 2px solid var(--text); }
table.fs tr.total.grand td { background: var(--surface-2); }
table.fs tr.muted td { color: var(--muted); }
table.fs.small { font-size: 12px; }
table.fs td.ok { color: var(--ok); font-weight: 600; }
table.fs td.bad, .sheet p.bad { color: var(--danger); font-weight: 600; }
.sheet .note { margin: 10px 0; }
.sheet .note h4 { margin: 8px 0 4px; font-size: 14px; }
.sheet .note h5 { margin: 6px 0 2px; font-size: 12px; color: var(--muted); }
.sheet .note p { font-size: 13px; white-space: pre-wrap; }
.sheet h4.gl-acct { margin: 14px 0 4px; font-size: 13px; }
.cover-inner { text-align: center; padding: 60px 0; }
.cover-inner h1 { font-size: 26px; margin: 16px 0; }
table.sign { margin: 30px auto 16px; border-collapse: collapse; }
table.sign th, table.sign td { border: 1px solid var(--text); width: 90px; height: 28px; font-size: 12px; }
table.sign td { height: 64px; }
.print-bar { margin-bottom: 12px; }
.bundle .sheet { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 22px 26px; margin-bottom: 14px; position: relative; }
.bundle.archived .sheet::after { content: "정정 전 보관본 (현재 유효한 마감본 아님)"; position: absolute; top: 10px; right: 14px; font-size: 11px; color: var(--danger); border: 1px solid var(--danger); padding: 2px 6px; border-radius: 4px; }
.bundle.draft .sheet::after { content: "미확정 (마감 전 미리보기)"; position: absolute; top: 10px; right: 14px; font-size: 11px; color: var(--danger); border: 1px solid var(--danger); padding: 2px 6px; border-radius: 4px; }
@media print {
  @page { size: A4; margin: 14mm 12mm; }
  .print-bar, .stmt-preview .chips { display: none !important; }
  .bundle .sheet { border: 0; border-radius: 0; padding: 0; margin: 0; page-break-after: always; break-after: page; }
  .bundle .sheet:last-child { page-break-after: auto; }
  .sheet .fs-title { font-size: 18pt; }
  table.fs { font-size: 10pt; }
  table.fs.small { font-size: 8.5pt; }
  table.fs tr { page-break-inside: avoid; }
  table.fs thead { display: table-header-group; }
  .cover-inner { padding: 120px 0; }
}
