:root {
  /* ===== Design Tokens (B2-0a / docs/design/README.md) ===== */
  /* Surfaces */
  --page: #EEF1F5;
  --card: #FFFFFF;
  --subtle: #FAFBFC;
  --subtle2: #F5F7FA;
  --subtle3: #F2F4F8;
  --chip-track: #E6EAF1;
  /* Borders */
  --border-card: #E2E7EE;
  --hairline: #EDF0F4;
  --border-input: #DCE1E9;
  --border-strong: #D4DAE3;
  /* Text */
  --text-primary: #1B2430;
  --text-secondary: #5A6677;
  --text-muted: #8A94A3;
  --text-faint: #9AA4B2;
  /* Primary (indigo-blue) */
  --indigo: #3A56D4;
  --indigo-weak: #EEF1FD;
  --indigo-deep: #2B41AE;
  --indigo-border: #C0CCF5;
  /* Status — 승인/확정 (green) */
  --green: #15803D;
  --green-bg: #E6F4EA;
  --green-border: #C6E6D0;
  /* Status — 반송/대표 (amber) */
  --amber: #B45309;
  --amber-bg: #FBF4E6;
  --amber-border: #ECDABA;
  /* Status — 반려 (red) */
  --red: #C0392B;
  --red-bg: #FBEEEE;
  --red-border: #EBC4C4;
  --danger-strong: #DC2626;
  /* Brand gradient (로고에만) */
  --brand-grad: linear-gradient(135deg,#14B9C4 0%,#1AC2A6 52%,#46D877 100%);

  /* ===== Legacy aliases — 기존 컴포넌트 변수명 유지, 값만 디자인 토큰으로 ===== */
  --primary: var(--indigo);
  --primary-hover: var(--indigo-deep);
  --primary-light: var(--indigo-weak);
  --danger: var(--red);
  --danger-light: var(--red-bg);
  --warning: var(--amber);
  --warning-light: var(--amber-bg);
  --info: var(--indigo);
  --info-light: var(--indigo-weak);
  --bg: var(--page);
  --surface: var(--card);
  --surface2: var(--subtle);
  --border: var(--border-card);
  --border2: var(--border-input);
  --text: var(--text-primary);
  --text2: var(--text-secondary);
  --muted: var(--text-muted);
  --shadow: 0 1px 4px rgba(0,0,0,.06);
  --radius: 14px;

  /* 수입/확정은 회계 의미상 green 유지 (indigo로 바뀌지 않게) */
  --income: var(--green);
  --income-light: var(--green-bg);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; font-family: 'Noto Sans KR', 'Noto Sans TC', system-ui, -apple-system, 'Segoe UI', sans-serif; font-size: 14px; color: var(--text); background: var(--bg); line-height: 1.55; }

/* ===== App Shell ===== */
#app { display: flex; height: 100vh; overflow: hidden; }

/* Sidebar (236px 고정) */
#sidebar { width: 236px; flex-shrink: 0; background: var(--card); border-right: 1px solid var(--border-card); display: flex; flex-direction: column; }
.sb-logo { height: 60px; flex-shrink: 0; display: flex; align-items: center; gap: 10px; padding: 0 16px; border-bottom: 1px solid var(--hairline); }
.logo-mark { width: 30px; height: 30px; flex-shrink: 0; border-radius: 8px; background: var(--brand-grad); display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 17px; }
.logo-text { line-height: 1.25; min-width: 0; }
.logo-brand { font-size: 14px; font-weight: 700; letter-spacing: .04em; color: var(--text-primary); }
.logo-sub { font-size: 11px; color: var(--text-muted); }

.sb-nav { flex: 1; overflow-y: auto; padding: 14px 12px; display: flex; flex-direction: column; gap: 4px; }
.sb-section { font-size: 11px; font-weight: 700; letter-spacing: .06em; color: var(--text-faint); padding: 4px 12px 8px; }
.nav-item { display: flex; align-items: center; height: 42px; padding: 0 12px; width: 100%; border: none; background: none; border-radius: 10px; cursor: pointer; color: var(--text-secondary); font-size: 14px; font-weight: 500; text-align: left; font-family: inherit; transition: background .12s, color .12s; }
.nav-item:hover { background: var(--subtle3); }
.nav-item.active { background: var(--indigo-weak); color: var(--indigo); font-weight: 700; }
.nav-item.hidden { display: none; }
.nav-label { display: inline-flex; align-items: baseline; gap: 6px; }
.nav-tc { font-size: 11px; font-weight: 500; color: var(--text-muted); }
.nav-item.active .nav-tc { color: var(--indigo); }

/* 결재 그룹 래퍼: display:contents 로 sb-nav flex 간격 유지, staff 숨김 시 그룹 전체 제거 */
#nav-appr-group { display: contents; }
#nav-appr-group.hidden { display: none; }

.sb-user { margin-top: auto; flex-shrink: 0; display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--hairline); }
.sb-avatar { width: 34px; height: 34px; flex-shrink: 0; border-radius: 50%; background: var(--text-primary); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; }
.sb-user-meta { min-width: 0; line-height: 1.3; }
.sb-user-name { font-size: 13px; font-weight: 700; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-user-role { font-size: 11px; }

/* Main column */
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#topbar { height: 60px; flex-shrink: 0; background: var(--card); border-bottom: 1px solid var(--border-card); display: flex; align-items: center; padding: 0 22px; gap: 18px; }
.tb-title { line-height: 1.3; }
#pageTitle { font-size: 16px; font-weight: 700; color: var(--text-primary); }
.tb-sub { font-size: 12px; color: var(--text-muted); }
.tb-right { margin-left: auto; display: flex; align-items: center; gap: 12px; flex: 0 0 auto; }
.logout-btn { background: var(--subtle3); border: 1px solid var(--border-input); color: var(--text-secondary); cursor: pointer; padding: .4rem .85rem; border-radius: 9px; font-size: .8rem; font-weight: 500; font-family: inherit; transition: background .12s; }
.logout-btn:hover { background: var(--chip-track); }

/* Content */
#content { flex: 1; overflow-y: auto; padding: 24px 28px; }
.tab-panel { display: none; max-width: 1400px; margin: 0 auto; }
.tab-panel.active { display: block; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.card-title { font-weight: 600; font-size: .95rem; margin-bottom: 1rem; padding-bottom: .6rem; border-bottom: 1px solid var(--border); }
.card-title .badge { font-size: .7rem; font-weight: 500; }

/* Summary cards */
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.summary-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; text-align: center; }
.summary-card .label { font-size: .75rem; color: var(--muted); margin-bottom: .3rem; }
.summary-card .value { font-size: 1.4rem; font-weight: 700; }
.summary-card.income .value { color: var(--income); }
.summary-card.expense .value { color: var(--danger); }
.summary-card.profit .value { color: var(--info); }
.summary-card.tax .value { color: var(--warning); }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-label { display: block; font-size: .8rem; font-weight: 600; color: var(--text2); margin-bottom: .35rem; }
.form-input, .form-select, .form-textarea {
  width: 100%; padding: .5rem .75rem; border: 1px solid var(--border2); border-radius: 6px;
  font-size: .875rem; color: var(--text); background: var(--surface);
  transition: border-color .15s;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light);
}
.form-textarea { resize: vertical; min-height: 70px; }
.form-row { display: grid; gap: .75rem; }
.form-row.col2 { grid-template-columns: 1fr 1fr; }
.form-row.col3 { grid-template-columns: 1fr 1fr 1fr; }
.form-row.col4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: .4rem; padding: .5rem 1rem; border-radius: 6px; border: none; cursor: pointer; font-size: .875rem; font-weight: 500; transition: all .15s; text-decoration: none; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--surface2); color: var(--text2); border: 1px solid var(--border2); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-sm { padding: .3rem .65rem; font-size: .8rem; }
.btn-xs { padding: .2rem .45rem; font-size: .75rem; }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { background: var(--surface2); font-size: .78rem; font-weight: 600; text-align: left; padding: .6rem .75rem; border-bottom: 1px solid var(--border2); white-space: nowrap; color: var(--text2); }
td { padding: .55rem .75rem; border-bottom: 1px solid var(--border); font-size: .85rem; vertical-align: middle; }
tr:hover td { background: var(--primary-light); }
tr.clickable { cursor: pointer; }

/* Badges */
.badge { display: inline-block; padding: .15rem .5rem; border-radius: 99px; font-size: .72rem; font-weight: 600; }
.badge-income { background: var(--income-light); color: var(--income); }
.badge-expense { background: var(--danger-light); color: var(--danger); }
.badge-pending { background: var(--warning-light); color: var(--warning); }
.badge-confirmed { background: var(--income-light); color: var(--income); }
.badge-admin { background: #f3e8ff; color: #7c3aed; }
.badge-staff { background: var(--info-light); color: var(--info); }

/* Filter bar */
.filter-bar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end; margin-bottom: 1rem; }
.filter-bar .form-group { margin-bottom: 0; }
.filter-bar .form-input, .filter-bar .form-select { font-size: .82rem; padding: .4rem .65rem; }

/* Input tab layout */
.input-layout { display: grid; grid-template-columns: 1fr 340px; gap: 1rem; }
@media (max-width: 900px) { .input-layout { grid-template-columns: 1fr; } }

/* Drop zone */
.drop-zone {
  border: 2px dashed var(--border2); border-radius: var(--radius); padding: 1.5rem;
  text-align: center; cursor: pointer; color: var(--muted); transition: all .15s;
  background: var(--surface2); margin-bottom: 1rem;
}
.drop-zone:hover, .drop-zone.drag-over { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
.drop-zone .drop-icon { font-size: 2rem; margin-bottom: .5rem; }
.drop-zone p { font-size: .85rem; }
.ocr-preview { width: 100%; max-height: 200px; object-fit: contain; border-radius: 6px; margin-bottom: .75rem; border: 1px solid var(--border); }

/* Tax preview */
.tax-preview { background: var(--surface2); border: 1px solid var(--border); border-radius: 6px; padding: .75rem 1rem; font-size: .85rem; margin-top: .5rem; }
.tax-preview .row { display: flex; justify-content: space-between; padding: .2rem 0; }
.tax-preview .row.total { font-weight: 700; border-top: 1px solid var(--border2); margin-top: .25rem; padding-top: .4rem; }

/* Pagination */
.pagination { display: flex; gap: .25rem; align-items: center; margin-top: 1rem; justify-content: center; }
.page-btn { padding: .3rem .6rem; border: 1px solid var(--border2); border-radius: 4px; background: var(--surface); cursor: pointer; font-size: .8rem; }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-btn:hover:not(.active) { background: var(--surface2); }

/* Modal */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 100; align-items: center; justify-content: center; }
.modal-overlay.open { display: flex; }
.modal { background: var(--surface); border-radius: var(--radius); width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto; box-shadow: 0 8px 40px rgba(0,0,0,.18); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); }
.modal-header h3 { font-size: 1rem; font-weight: 600; }
.modal-close { background: none; border: none; cursor: pointer; font-size: 1.2rem; color: var(--muted); line-height: 1; }
.modal-body { padding: 1.25rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: .5rem; padding: .75rem 1.25rem; border-top: 1px solid var(--border); }

/* Alert */
.alert { padding: .65rem 1rem; border-radius: 6px; font-size: .85rem; margin-bottom: .75rem; }
.alert-success { background: var(--primary-light); color: var(--primary); border: 1px solid #a7f3d0; }
.alert-error { background: var(--danger-light); color: var(--danger); border: 1px solid #fca5a5; }
.alert-info { background: var(--info-light); color: var(--info); border: 1px solid #93c5fd; }

/* Empty state */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--muted); }
.empty-state p { font-size: .9rem; }

/* Loading */
.loading { text-align: center; padding: 2rem; color: var(--muted); }

/* Report table */
.report-table td:last-child { text-align: right; font-weight: 500; }
.report-table tr.highlight td { background: var(--primary-light); font-weight: 700; }

/* Responsive */
@media (max-width: 640px) {
  .form-row.col2, .form-row.col3, .form-row.col4 { grid-template-columns: 1fr; }
  #content { padding: 16px; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
}

/* Utility */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--muted); }
.text-income { color: var(--income); }
.text-expense { color: var(--danger); }
.font-bold { font-weight: 700; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.gap-1 { gap: .5rem; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.w-full { width: 100%; }
