/* 젠업 재무 대시보드. 디자인 토큰 + 레이아웃 + 컴포넌트. 라이트 테마 고정 (다크 토큰은 자리만 준비) */
:root {
  color-scheme: light;
  --page: #f7f7f8;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --ink: #111318;
  --ink-2: #5b616e;
  --ink-3: #8b909c;
  --line: #e6e7ea;
  --line-2: #eef0f2;
  --accent: #2a78d6;
  --accent-soft: #eaf2fc;
  --pos: #006300;
  --neg: #d03b3b;
  --warn: #fab219;
  --warn-soft: #fff6dc;
  --neg-soft: #fdecec;
  --pos-soft: #e6f4e6;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s1-light: #86b6ef;
  --radius-card: 12px;
  --radius-ctl: 8px;
  --shadow: 0 1px 2px rgba(17, 19, 24, .04), 0 0 0 1px var(--line);
  --sidebar-w: 232px;
  --topbar-h: 56px;
  --font: "Pretendard Variable", Pretendard, system-ui, -apple-system, "Segoe UI", "Malgun Gothic", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: var(--font); font-size: 14px; line-height: 1.5; color: var(--ink); background: var(--page); -webkit-font-smoothing: antialiased; }
a { color: inherit; text-decoration: none; }
h1, h2, h3, h4, p { margin: 0; }
h1 { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
h2 { font-size: 16px; font-weight: 700; }
h3 { font-size: 13px; font-weight: 600; color: var(--ink-2); }
code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--ink-3); }
.small { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.num.pos { color: var(--pos); }
.num.neg { color: var(--neg); }
.num.zero { color: var(--ink-3); }
.right { text-align: right; }
.stack { display: grid; gap: 12px; }
.row { display: flex; align-items: center; gap: 8px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.grow { flex: 1; }
[hidden] { display: none !important; }
.icon { flex: none; vertical-align: -3px; }

/* ---------- 앱 셸 ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; width: var(--sidebar-w); flex: none; background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 14px 12px; }
.brand { display: flex; align-items: center; gap: 8px; padding: 6px 8px 14px; font-weight: 700; font-size: 15px; }
.brand-mark { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 7px; background: var(--ink); color: #fff; font-size: 13px; font-weight: 700; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-group { font-size: 11px; font-weight: 600; color: var(--ink-3); letter-spacing: .02em; padding: 14px 10px 4px; }
.nav-item { display: flex; align-items: center; gap: 9px; padding: 7px 10px; border-radius: var(--radius-ctl); color: var(--ink-2); font-size: 13.5px; font-weight: 500; transition: background .12s, color .12s; }
.nav-item:hover { background: var(--surface-2); color: var(--ink); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item .icon { color: inherit; opacity: .9; }
.nav-count { margin-left: auto; font-style: normal; font-size: 11px; font-weight: 600; background: var(--warn-soft); color: #8a5a00; padding: 1px 7px; border-radius: 999px; font-variant-numeric: tabular-nums; }
.sidebar-foot { border-top: 1px solid var(--line-2); padding-top: 10px; margin-top: 8px; display: grid; gap: 6px; }
.sidebar-note { display: flex; gap: 6px; align-items: center; font-size: 11.5px; color: #8a5a00; background: var(--warn-soft); padding: 6px 8px; border-radius: 6px; }
.sidebar-env { display: flex; justify-content: space-between; align-items: center; padding: 0 8px; font-size: 11px; color: var(--ink-3); }
.sidebar-env a { display: inline-flex; padding: 4px; border-radius: 6px; color: var(--ink-3); }
.sidebar-env a:hover { background: var(--surface-2); color: var(--ink); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 20; height: var(--topbar-h); display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 0 28px; background: rgba(247, 247, 248, .85); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar-title { font-weight: 600; font-size: 14px; color: var(--ink-2); white-space: nowrap; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.content { width: 100%; max-width: 1280px; margin: 0 auto; padding: 24px 28px 64px; display: grid; gap: 20px; align-content: start; }
.content-wide { max-width: none; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; }
.page-head p { margin-top: 4px; font-size: 13px; }
.page-actions { display: flex; gap: 8px; align-items: center; }

/* ---------- 카드 / 그리드 ---------- */
.card { background: var(--surface); border-radius: var(--radius-card); box-shadow: var(--shadow); padding: 18px 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card-head h2 { font-size: 14px; }
.card-flush { padding: 0; overflow: hidden; }
.card-flush .card-head { padding: 16px 20px 0; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-main, .grid-3 { grid-template-columns: 1fr; } }
/* 모바일 드로어 사이드바 */
.topbar .topbar-menu, .sidebar .sidebar-close, .sidebar-back { display: none; }
@media (max-width: 720px) {
  .grid-4, .grid-2 { grid-template-columns: 1fr; }
  .content { padding: 16px; }
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar .topbar-menu { display: inline-flex; flex: none; }
  .topbar-right { overflow-x: auto; min-width: 0; }
  .period-label { display: none; }
  .sidebar { position: fixed; top: 0; left: 0; bottom: 0; height: 100dvh; z-index: 110; transform: translateX(-100%); transition: transform .2s ease; box-shadow: none; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(17,19,24,.25); }
  .sidebar .sidebar-close { display: inline-flex; margin-top: 2px; }
  .sidebar-back { display: block; position: fixed; inset: 0; z-index: 100; background: rgba(17,19,24,.35); }
  .sidebar-back[hidden] { display: none; }
  body.sidebar-locked { overflow: hidden; }
}
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }

/* KPI */
.kpi { display: grid; gap: 12px; align-content: start; }
.kpi-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.kpi-value { font-size: 20px; font-weight: 700; letter-spacing: -.01em; }
.kpi-bar { display: flex; height: 6px; border-radius: 3px; overflow: hidden; gap: 2px; background: var(--line-2); }
.kpi-bar i { display: block; height: 100%; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.legend-row .legend-label { flex: 1; color: var(--ink-2); }
.legend-row .legend-value { font-weight: 600; }
.bar-dot { display: inline-block; width: 3px; height: 14px; border-radius: 2px; flex: none; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: none; }

/* 배너 / 알림 / 빈 상태 */
.banner { display: flex; align-items: center; gap: 14px; padding: 14px 18px; border-radius: var(--radius-card); background: var(--accent-soft); color: var(--ink); }
.banner .icon { color: var(--accent); }
.banner-warn { background: var(--warn-soft); }
.banner-warn .icon { color: #b07a00; }
.banner-ok { background: var(--pos-soft); }
.banner-ok .icon { color: var(--pos); }
.banner-text { display: flex; flex-direction: column; flex: 1; }
.banner-text b { font-size: 14px; }
.banner-text span { font-size: 12.5px; color: var(--ink-2); }
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius-ctl); font-size: 13px; }
.alert-error { background: var(--neg-soft); color: #8a1f1f; }
.alert-warn { background: var(--warn-soft); color: #7a5200; }
.alert-ok { background: var(--pos-soft); color: var(--pos); }
.empty { display: grid; justify-items: center; gap: 6px; padding: 40px 20px; text-align: center; color: var(--ink-2); }
.empty .icon { color: var(--ink-3); }
.empty b { color: var(--ink); }
.empty p { font-size: 13px; max-width: 42ch; }
.empty .btn { margin-top: 8px; }

/* 칩 / 배지 */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px 2px 7px; border-radius: 999px; background: var(--surface-2); font-size: 12px; font-weight: 500; color: var(--ink); white-space: nowrap; }
.chip-warn { background: var(--warn-soft); color: #8a5a00; }
.badge { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.badge-accent { background: var(--accent-soft); color: var(--accent); }
.badge-ok { background: var(--pos-soft); color: var(--pos); }
.badge-warn { background: var(--warn-soft); color: #8a5a00; }
.badge-neg { background: var(--neg-soft); color: var(--neg); }
.badge-fixed { background: #eef2f7; color: #3a4a63; }
.badge-variable { background: #eef7f2; color: #1c6b4a; }

/* ---------- 폼 컨트롤 ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 36px; padding: 0 14px; border-radius: var(--radius-ctl); border: 1px solid var(--line); background: var(--surface); color: var(--ink); font: inherit; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; transition: background .12s, transform .06s, border-color .12s; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn-primary:hover { background: #2a2d35; }
.btn-danger { color: var(--neg); }
.btn-danger:hover { background: var(--neg-soft); border-color: #f3c4c4; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }
.btn-sm { height: 30px; padding: 0 10px; font-size: 12.5px; }
.btn-xs { height: 26px; padding: 0 8px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-icon { width: 30px; padding: 0; }
.input, .select, textarea.input { height: 36px; padding: 0 10px; border: 1px solid var(--line); border-radius: var(--radius-ctl); background: var(--surface); font: inherit; font-size: 13px; color: var(--ink); min-width: 0; }
.input:focus, .select:focus, textarea.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.input::placeholder { color: var(--ink-3); }
.input-sm, .select-sm { height: 30px; font-size: 12.5px; padding: 0 8px; }
.select { padding-right: 26px; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%235b616e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6l6 -6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 7px center; }
textarea.input { height: auto; padding: 8px 10px; resize: vertical; }
.field { display: grid; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.field .input, .field .select { width: 100%; }
.field-help { font-weight: 400; color: var(--ink-3); font-size: 12px; }
.check { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }
.check input { width: 15px; height: 15px; accent-color: var(--accent); margin: 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.search { position: relative; }
.search .icon { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); color: var(--ink-3); }
.search .input { padding-left: 30px; }

/* 기간 선택 */
.period { display: flex; align-items: center; gap: 8px; }
.period-icon { display: inline-flex; color: var(--ink-3); }
.period-range { display: inline-flex; gap: 6px; align-items: center; }
.period-label { font-size: 12.5px; font-variant-numeric: tabular-nums; }

/* 탭 */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); }
.tab { padding: 8px 12px; margin-bottom: -1px; border-bottom: 2px solid transparent; font-size: 13.5px; font-weight: 500; color: var(--ink-2); cursor: pointer; }
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); border-bottom-color: var(--ink); font-weight: 600; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: var(--radius-ctl); padding: 3px; gap: 2px; }
.seg a, .seg button { padding: 4px 10px; border-radius: 6px; font-size: 12.5px; font-weight: 500; color: var(--ink-2); border: 0; background: transparent; font-family: inherit; cursor: pointer; }
.seg .active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(17,19,24,.08); font-weight: 600; }

/* ---------- 테이블 ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line-2); vertical-align: middle; white-space: nowrap; }
.table th { font-size: 12px; font-weight: 600; color: var(--ink-3); background: var(--surface); position: sticky; top: 0; z-index: 1; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: #fafafb; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table .wrap { white-space: normal; }
.table .actions { text-align: right; }
.table .actions .btn { opacity: .55; }
.table tr:hover .actions .btn { opacity: 1; }
.table-compact th, .table-compact td { padding: 7px 10px; }

/* 손익표 */
.pl { font-size: 13px; }
.pl th:first-child, .pl td:first-child { position: sticky; left: 0; background: var(--surface); z-index: 2; min-width: 190px; }
.pl th:first-child { z-index: 3; }
.pl th.num.total, .pl td.num.total { background: var(--surface-2); font-weight: 600; }
.pl tr.group td { font-weight: 700; }
.pl tr.group td:first-child { cursor: pointer; user-select: none; }
.pl tr.group .icon { transition: transform .15s; color: var(--ink-3); margin-right: 4px; }
.pl tr.group.collapsed .icon { transform: rotate(-90deg); }
.pl tr.child td:first-child { padding-left: 34px; font-weight: 400; color: var(--ink-2); }
.pl tr.child td { color: var(--ink-2); }
.pl tr.subtotal td { font-weight: 700; background: #fbfbfc; }
.pl tr.subtotal.key td { background: var(--accent-soft); font-size: 13.5px; border-top: 1px solid #cfe0f6; border-bottom: 1px solid #cfe0f6; }
.pl tr.subtotal.key td:first-child { color: var(--accent); }
.pl tr.ratio td { color: var(--ink-3); font-size: 12px; }
.pl .code-color { display: inline-block; width: 3px; height: 12px; border-radius: 2px; margin-right: 8px; vertical-align: -2px; }

/* 차트 */
.chart-box { position: relative; width: 100%; height: 260px; }
.chart-box.tall { height: 320px; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12px; color: var(--ink-2); justify-content: center; margin-top: 10px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }

/* 스켈레톤 */
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, #eaebee 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: shimmer 1.4s ease infinite; border-radius: 6px; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: 0 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } .btn, .nav-item { transition: none; } }

/* 토스트 */
.toast-host { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: grid; gap: 8px; }
.toast { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 10px; background: var(--ink); color: #fff; font-size: 13px; box-shadow: 0 6px 20px rgba(17,19,24,.18); animation: toast-in .18s ease-out; max-width: 380px; }
.toast-error { background: var(--neg); }
.toast-ok .icon { color: #7ee2a0; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* 모달 */
.modal-back { position: fixed; inset: 0; z-index: 90; background: rgba(17,19,24,.35); display: grid; place-items: center; padding: 20px; }
.modal { width: 100%; max-width: 520px; background: var(--surface); border-radius: 14px; padding: 22px 24px; box-shadow: 0 20px 60px rgba(17,19,24,.25); display: grid; gap: 14px; }
.modal h2 { font-size: 16px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.modal-wide { max-width: 960px; }

/* 계정과목 선택 팝오버 */
.picker { position: fixed; z-index: 120; width: 300px; background: var(--surface); border-radius: 12px; box-shadow: 0 12px 40px rgba(17,19,24,.18), 0 0 0 1px var(--line); display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; max-height: 420px; overflow: hidden; }
.picker-search { padding: 10px 10px 6px; }
.picker-search .input { width: 100%; }
.picker-tabs { display: flex; flex-wrap: wrap; gap: 2px; padding: 0 10px; border-bottom: 1px solid var(--line-2); }
.picker-tab { flex: none; border: 0; background: none; font: inherit; font-size: 12.5px; font-weight: 500; color: var(--ink-2); padding: 6px 8px; margin-bottom: -1px; border-bottom: 2px solid transparent; cursor: pointer; }
.picker-tab.active { color: var(--ink); border-bottom-color: var(--ink); font-weight: 600; }
.picker-list { overflow-y: auto; padding: 6px; }
.picker-group { font-size: 11px; color: var(--ink-3); padding: 8px 8px 4px; }
.picker-item { display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: none; font: inherit; font-size: 13px; color: var(--ink); padding: 7px 8px; border-radius: 8px; cursor: pointer; text-align: left; }
.picker-item:hover { background: var(--surface-2); }
.picker-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.picker-empty { padding: 20px; text-align: center; font-size: 12.5px; color: var(--ink-3); }
.picker-foot { display: grid; gap: 4px; padding: 8px 12px 10px; border-top: 1px solid var(--line-2); font-size: 12.5px; }
.pick-btn { display: inline-flex; align-items: center; gap: 4px; border: 1px solid transparent; background: none; padding: 0; border-radius: 999px; cursor: pointer; font: inherit; }
.pick-btn:hover .chip { box-shadow: 0 0 0 1px var(--line); }
.pick-btn .icon { color: var(--ink-3); }
tr.pld-changed td { background: var(--accent-soft) !important; }

/* 손익표 금액 셀 드릴다운 */
.cell-link { cursor: pointer; }
.cell-link:hover { text-decoration: underline; text-decoration-color: var(--line); }

/* 진행 바 */
.progress { height: 6px; border-radius: 3px; background: var(--line-2); overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }

/* 정의 리스트 */
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 13px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; font-weight: 500; }

/* 계정과목 색 */
.code-cell { display: inline-flex; align-items: center; gap: 8px; }

/* 로그인 */
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); padding: 28px; display: grid; gap: 12px; }
.login-card .brand { padding: 0 0 6px; }
.login-card h1 { font-size: 20px; }
