/* 재무 현황(메인 `/`, 관리자 전용) — 건강 판정 · 핵심 6칸 · 월말 예상 잔고 · 부채 · 월별 현금흐름 · 자본 */
.finance-page {
  --fin-good: #027a48;
  --fin-good-bg: #ecfdf3;
  --fin-warn: #b54708;
  --fin-warn-bg: #fffaeb;
  --fin-danger: #b42318;
  --fin-danger-bg: #fef3f2;
  --fin-in: #2a78d6;
  --fin-out: #e07a2f;
  --fin-cash: #2a78d6;
  --fin-inventory: #7a5af8;
  --fin-receivable: #12b0a0;
  --fin-debt: #e07a2f;
  --fin-surface: #fff;
  --fin-soft: #f6f8fc;
}

.finance-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
}

.finance-head-actions {
  display: grid;
  justify-items: end;
  gap: 6px;
}

.finance-head-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.finance-updated {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.finance-skeleton {
  display: grid;
  gap: 14px;
}

.finance-skeleton span {
  display: block;
  height: 120px;
  border-radius: 18px;
  background: linear-gradient(90deg, #eef1f6 0%, #f8fafc 50%, #eef1f6 100%);
  background-size: 220% 100%;
  animation: finance-loading 1.2s linear infinite;
}

@keyframes finance-loading {
  to { background-position: -220% 0; }
}

/* ① 건강 판정 */
.finance-health {
  display: grid;
  gap: 16px;
  margin-bottom: 18px;
  padding: 20px 22px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--fin-surface);
  box-shadow: var(--surface-shadow);
}

.finance-health.is-good { border-color: #abefc6; }
.finance-health.is-warning { border-color: #fedf89; }
.finance-health.is-danger { border-color: #fecdca; }

.finance-health-verdict {
  display: flex;
  align-items: center;
  gap: 16px;
}

.finance-health-verdict h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -.03em;
}

.finance-health-verdict p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.finance-grade {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.finance-grade b {
  display: inline-grid;
  width: 16px;
  height: 16px;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  font-size: 11px;
}

.finance-grade.is-good { background: var(--fin-good-bg); color: var(--fin-good); }
.finance-grade.is-good b { background: var(--fin-good); }
.finance-grade.is-warning { background: var(--fin-warn-bg); color: var(--fin-warn); }
.finance-grade.is-warning b { background: var(--fin-warn); }
.finance-grade.is-danger { background: var(--fin-danger-bg); color: var(--fin-danger); }
.finance-grade.is-danger b { background: var(--fin-danger); }

.finance-grade.is-large {
  padding: 8px 16px;
  font-size: 18px;
}

.finance-grade.is-large b {
  width: 24px;
  height: 24px;
  font-size: 14px;
}

.finance-checks {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.finance-check {
  display: grid;
  align-content: start;
  gap: 5px;
  min-width: 0;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--fin-soft);
}

.finance-check-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: #475467;
  font-size: 13px;
  font-weight: 750;
}

.finance-check strong {
  font-size: 22px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.035em;
}

.finance-check p {
  margin: 0;
  color: #344054;
  font-size: 13px;
  line-height: 1.45;
}

.finance-check small {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

/* ② 핵심 6칸 */
.finance-kpis {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.finance-kpi {
  display: grid;
  min-width: 0;
  position: relative;
  align-content: start;
  gap: 6px;
  overflow: hidden;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--fin-surface);
  color: var(--ink);
  box-shadow: var(--surface-shadow);
  text-decoration: none;
}

.finance-kpi::before {
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: #6d8bff;
  content: "";
}

.finance-kpi:hover { border-color: #bdc9ed; color: var(--ink); }
.finance-kpi.is-warning::before { background: var(--fin-warn); }
.finance-kpi.is-focus { background: linear-gradient(180deg, #f3f6ff, #fff); border-color: #c7d4fe; }
.finance-kpi.is-focus::before { background: var(--accent); }
.finance-kpi.is-danger::before { background: var(--fin-danger); }

.finance-kpi-label {
  color: #667085;
  font-size: 13px;
  font-weight: 750;
}

.finance-kpi-label em {
  margin-left: 4px;
  color: #98a2b3;
  font-style: normal;
  font-weight: 650;
}

.finance-kpi strong {
  overflow-wrap: anywhere;
  font-size: clamp(24px, 2vw, 32px);
  font-variant-numeric: tabular-nums;
  letter-spacing: -.045em;
}

.finance-kpi small {
  color: #667085;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  line-height: 1.5;
}

.finance-delta { font-weight: 750; }
.finance-delta.is-up { color: var(--fin-good); }
.finance-delta.is-down { color: var(--fin-danger); }
.finance-delta.is-neutral { color: var(--muted); }

/* 패널 공통 */
.finance-grid {
  display: grid;
  gap: 18px;
  margin-bottom: 18px;
}

.finance-grid--main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
.finance-grid--second { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }

.finance-panel {
  min-width: 0;
  margin: 0;
}

.finance-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 12px;
}

.finance-panel-head h2 {
  margin: 0;
  font-size: 18px;
  letter-spacing: -.025em;
}

.finance-panel-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.finance-panel-head > a {
  flex: none;
  font-size: 12px;
  font-weight: 750;
}

.finance-kicker {
  margin: 0 0 4px !important;
  color: var(--accent-text) !important;
  font-size: 11px !important;
  font-weight: 800;
  letter-spacing: .08em;
}

.finance-subhead {
  margin: 16px 0 8px;
  font-size: 14px;
}

.finance-subhead small {
  margin-left: 6px;
  color: var(--muted);
  font-weight: 600;
}

/* 그래프 */
.finance-chart-host { min-height: 170px; }
.finance-chart { display: block; overflow: visible; }
.finance-chart text { font-family: inherit; }
.finance-axis { fill: #667085; font-size: 11px; font-variant-numeric: tabular-nums; }
.finance-grid-line { stroke: #eef1f6; stroke-width: 1; }
.finance-zero { stroke: #98a2b3; stroke-width: 1; }
.finance-line { fill: none; stroke: var(--fin-in); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.finance-line.is-live { stroke-dasharray: 4 4; }
.finance-area { fill: rgba(42, 120, 214, .08); stroke: none; }
.finance-threshold { stroke: var(--fin-danger); stroke-width: 1.5; stroke-dasharray: 6 4; }
.finance-threshold-label { fill: var(--fin-danger); font-size: 11px; font-weight: 700; }
.finance-month-end { stroke: #344054; stroke-width: 1; stroke-dasharray: 2 3; }
.finance-month-end-label { fill: #111827; font-size: 12px; font-weight: 800; }
.finance-min-dot { fill: #fff; stroke: var(--fin-danger); stroke-width: 2; }
.finance-cross { stroke: #98a2b3; stroke-width: 1; }
.finance-hover-dot, .finance-dot { fill: var(--fin-in); stroke: #fff; stroke-width: 2; }
.finance-live-dot { fill: #fff; stroke: var(--fin-in); stroke-width: 2.5; }
.finance-hit { fill: transparent; cursor: crosshair; }
.finance-hit:focus-visible, .finance-month:focus-visible, .finance-dot:focus-visible, .finance-live-dot:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.finance-band { fill: transparent; }
.finance-month:hover .finance-band { fill: rgba(51, 92, 255, .05); }
.finance-bar-in { fill: var(--fin-in); }
.finance-bar-out { fill: var(--fin-out); }
.finance-month.is-partial .finance-bar-in, .finance-month.is-partial .finance-bar-out { opacity: .55; }
.finance-net-dot { fill: #111827; stroke: #fff; stroke-width: 2; }
.finance-net-label { font-size: 11px; font-weight: 750; font-variant-numeric: tabular-nums; }
.finance-net-label.is-up { fill: var(--fin-good); }
.finance-net-label.is-down { fill: var(--fin-danger); }

.finance-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
  margin: 8px 0 0;
  padding: 0;
  color: #475467;
  font-size: 12px;
  list-style: none;
}

.finance-legend li { display: inline-flex; align-items: center; gap: 6px; }
.finance-legend i { display: inline-block; width: 14px; height: 10px; border-radius: 3px; }
.finance-legend i.is-line { height: 2px; background: var(--fin-in); }
.finance-legend i.is-threshold { height: 0; border-top: 2px dashed var(--fin-danger); }
.finance-legend i.is-min { width: 10px; height: 10px; border: 2px solid var(--fin-danger); border-radius: 50%; }
.finance-legend i.is-in { background: var(--fin-in); }
.finance-legend i.is-out { background: var(--fin-out); }
.finance-legend i.is-net { width: 10px; height: 10px; border-radius: 50%; background: #111827; }

.finance-tooltip {
  position: fixed;
  left: var(--tip-x, 0);
  top: var(--tip-y, 0);
  z-index: 50;
  min-width: 180px;
  max-width: 300px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 12px 32px #1018282e;
  font-size: 12px;
  pointer-events: none;
}

.finance-tooltip[hidden] { display: none; }
.finance-tooltip strong { display: block; margin-bottom: 4px; font-size: 13px; }
.finance-tooltip p { margin: 0; }
.finance-tooltip ul { display: grid; gap: 3px; margin: 6px 0 0; padding: 0; list-style: none; }
.finance-tooltip li { display: flex; justify-content: space-between; gap: 10px; }
.finance-tooltip i { color: var(--fin-warn); font-style: normal; font-weight: 700; }
.finance-tooltip dl { display: grid; grid-template-columns: auto auto; gap: 2px 14px; margin: 4px 0 0; }
.finance-tooltip dt { color: var(--muted); }
.finance-tooltip dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }

/* 목록 */
.finance-events, .finance-debts, .finance-composition {
  display: grid;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.finance-events li, .finance-debts li {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 8px 4px;
  border-bottom: 1px solid #f0f2f6;
  font-size: 13px;
}

.finance-events time { min-width: 38px; color: var(--muted); font-variant-numeric: tabular-nums; }
.finance-events small, .finance-debts small { display: block; color: var(--muted); font-size: 11px; }
.finance-events b, .finance-debts b, .finance-composition b { font-variant-numeric: tabular-nums; white-space: nowrap; }
.finance-events li.is-in b { color: var(--fin-good); }
.finance-events li.is-out b { color: #344054; }

.finance-split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 10px;
}

.finance-split > div {
  display: grid;
  gap: 2px;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--fin-soft);
}

.finance-split span { color: #667085; font-size: 12px; font-weight: 700; }
.finance-split strong { font-size: 18px; font-variant-numeric: tabular-nums; letter-spacing: -.03em; }
.finance-split small { color: var(--muted); font-size: 11px; }

.finance-kind {
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 750;
  white-space: nowrap;
}

.finance-kind.is-payment { background: #eef2ff; color: #2447d8; }
.finance-kind.is-planned { background: #fff4ed; color: #b93815; }
.finance-overdue { color: var(--fin-danger); }

.finance-note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.finance-stack {
  display: flex;
  height: 14px;
  gap: 2px;
  overflow: hidden;
  margin-bottom: 10px;
  border-radius: 999px;
}

.finance-stack-part { flex: 0 0 calc(var(--share, 0) * 1%); min-width: 2px; }
.finance-stack-part.is-cash, .finance-composition i.is-cash { background: var(--fin-cash); }
.finance-stack-part.is-inventory, .finance-composition i.is-inventory { background: var(--fin-inventory); }
.finance-stack-part.is-receivable, .finance-composition i.is-receivable { background: var(--fin-receivable); }
.finance-composition i.is-debt { background: var(--fin-debt); }

.finance-composition li {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto 44px;
  align-items: center;
  gap: 10px;
  padding: 6px 2px;
  font-size: 13px;
}

.finance-composition i { width: 10px; height: 10px; border-radius: 3px; }
.finance-composition small { color: var(--muted); font-size: 11px; text-align: right; }
.finance-composition li.is-minus b { color: var(--fin-danger); }
.finance-composition li.is-total { margin-top: 4px; padding-top: 10px; border-top: 1px solid var(--line); font-weight: 800; }
.finance-composition li.is-total b { font-size: 16px; }

.finance-table { margin-top: 12px; }
.finance-table summary { cursor: pointer; color: var(--accent-text); font-size: 12px; font-weight: 750; }
.finance-table table { width: 100%; margin-top: 8px; font-size: 12px; font-variant-numeric: tabular-nums; }
.finance-table td { text-align: right; }

/* 2026-10-31: 누르면 상세(모달) · 차입금 · 6개월 예상 · 월별 손익 */
.finance-kpi { width: 100%; font: inherit; text-align: left; cursor: pointer; }
.finance-kpi:focus-visible, .finance-check-button:focus-visible, .finance-split button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.finance-kpi-more { color: var(--accent-text); font-size: 12px; font-weight: 750; }
.finance-check { padding: 0; }
.finance-check-button {
  display: grid;
  align-content: start;
  gap: 5px;
  width: 100%;
  height: 100%;
  min-width: 0;
  padding: 14px 16px;
  border: 0;
  border-radius: 14px;
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.finance-check-button:hover { background: #eef2fb; }
.finance-check-button strong { font-size: 22px; font-variant-numeric: tabular-nums; letter-spacing: -.035em; }
.finance-check-detail { color: #344054; font-size: 13px; line-height: 1.45; }
.finance-check-button small { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.finance-split--three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.finance-split button {
  display: grid;
  gap: 2px;
  min-width: 0;
  padding: 12px 14px;
  border: 0;
  border-radius: 12px;
  background: var(--fin-soft);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.finance-split button:hover { background: #eef2fb; }
.finance-split button.is-loan { background: #fff6ed; }
.finance-kind.is-loan { background: #fff4ed; color: #b93815; }
.finance-composition i.is-loan { background: #b93815; }

.finance-alert {
  margin: 0 0 10px;
  padding: 10px 12px;
  border: 1px solid #fecdca;
  border-radius: 10px;
  background: var(--fin-danger-bg);
  color: var(--fin-danger);
  font-size: 13px;
}
.finance-risk-band { fill: rgba(180, 35, 24, .07); }
.finance-legend i.is-risk { background: rgba(180, 35, 24, .18); }
.finance-left-line { fill: none; stroke: #475467; stroke-width: 1.5; stroke-dasharray: 3 3; }
.finance-month[role="button"] { cursor: pointer; }
.finance-month-table { margin-top: 12px; }
.finance-month-table table, .finance-detail-table table { width: 100%; font-size: 12px; font-variant-numeric: tabular-nums; }
/* 공용 표 최소 폭(680px)은 모달·좁은 칸에서 넘친다 — 좁은 화면에서만 칸 안 가로 스크롤 */
.finance-month-table table, .finance-detail-table table { min-width: 420px; }
.finance-detail-table th[scope="row"] { color: var(--ink); text-transform: none; letter-spacing: 0; font-size: 12px; white-space: nowrap; }
.finance-month-table td, .finance-detail-table td { text-align: right; white-space: nowrap; }
.finance-month-table tr.is-risk th, .finance-month-table tr.is-risk td { background: var(--fin-danger-bg); }
.finance-row-button { min-height: 0; padding: 0; font-weight: 750; }
.finance-month-table th, .finance-month-table td { padding-top: 6px; padding-bottom: 6px; }
.finance-grid--wide { grid-template-columns: minmax(0, 1fr); }

.finance-detail-dialog { --dialog-width: 760px; }
.finance-detail-dialog .erp-dialog-body { align-content: start; grid-auto-rows: max-content; }
.finance-detail-dialog .finance-subhead { margin: 4px 0 0; }
.finance-detail-dialog .finance-note { margin: 0; }
.finance-facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
  margin: 0;
}
.finance-facts div { padding: 10px 12px; border-radius: 10px; background: var(--fin-soft); }
.finance-facts dt { color: #667085; font-size: 12px; font-weight: 700; }
.finance-facts dd { margin: 2px 0 0; font-size: 15px; font-variant-numeric: tabular-nums; }

.finance-empty { margin: 0; padding: 24px 0; color: var(--muted); text-align: center; }
.finance-no-access { padding: 32px; text-align: center; }

/* 세금 일정·세금 넣은 예상 잔고(2026-11-24) — 응답에 세금 칸이 있을 때만 그려진다 */
.finance-tax-line { fill: none; stroke: var(--fin-out); stroke-width: 2; stroke-dasharray: 5 4; stroke-linejoin: round; }
.finance-tax-dot { fill: var(--fin-out); stroke: #fff; stroke-width: 1.5; }
.finance-legend i.is-tax-line { height: 0; border-top: 2px dashed var(--fin-out); border-radius: 0; }
.finance-tax-cell small { display: block; color: var(--muted); font-size: 11px; font-weight: 600; }
.finance-tax-cell.is-same span { color: var(--muted); }
.finance-month-table td.finance-tax-cell.is-risk { background: var(--fin-danger-bg); }
.finance-tax-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.finance-tax-card {
  display: grid;
  align-content: start;
  gap: 2px;
  min-width: 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--fin-soft);
}
.finance-tax-card span { color: #667085; font-size: 12px; font-weight: 700; }
.finance-tax-card strong { font-size: 18px; font-variant-numeric: tabular-nums; letter-spacing: -.03em; overflow-wrap: anywhere; }
.finance-tax-card small { color: var(--muted); font-size: 12px; line-height: 1.5; }
.finance-tax-card.is-soon { background: var(--fin-warn-bg); }
.finance-tax-card.is-danger { background: var(--fin-danger-bg); }
.finance-tax-card.is-danger strong { color: var(--fin-danger); }
.finance-tax-table table { width: 100%; min-width: 640px; font-size: 13px; font-variant-numeric: tabular-nums; }
.finance-tax-table th, .finance-tax-table td { padding-top: 8px; padding-bottom: 8px; }
.finance-tax-table th[scope="row"] { color: var(--ink); text-transform: none; letter-spacing: 0; font-size: 13px; white-space: nowrap; }
.finance-tax-table td.is-num { text-align: right; white-space: nowrap; }
.finance-tax-table thead th:nth-child(3), .finance-tax-table thead th:nth-child(6) { text-align: right; }
.finance-tax-table td small { color: var(--muted); font-size: 11px; }
.finance-tax-table tr.is-soon th, .finance-tax-table tr.is-soon td { background: var(--fin-warn-bg); }
.finance-tax-soon { color: var(--fin-warn); }
.finance-kind.is-tax-in { background: #eef1f6; color: #475467; }
.finance-kind.is-tax-new { background: #fff4ed; color: #b93815; }

@media (max-width: 1180px) {
  .finance-checks { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .finance-grid--main, .finance-grid--second { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 900px) {
  .finance-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .finance-month-table table, .finance-detail-table table { min-width: 0; }
  .finance-month-table td, .finance-detail-table td { white-space: normal; }
  .finance-head { align-items: flex-start; flex-direction: column; }
  .finance-head-actions { justify-items: start; }
  .finance-health-verdict { align-items: flex-start; flex-direction: column; gap: 10px; }
  .finance-checks, .finance-kpis, .finance-split, .finance-split--three { grid-template-columns: minmax(0, 1fr); }
  .finance-tax-cards { grid-template-columns: minmax(0, 1fr); }
  /* 세금 칸이 더해지면 6칸이라 폰에서 글자가 세로로 쪼개진다 — 이때만 표 안쪽에서 옆으로 민다 */
  .finance-month-table.has-tax table { min-width: 560px; }
  .finance-month-table.has-tax td { white-space: nowrap; }
}

@media (prefers-reduced-motion: reduce) {
  .finance-skeleton span { animation: none; }
}

@media (forced-colors: active) {
  .finance-kpi, .finance-health, .finance-check, .finance-split button { border: 1px solid CanvasText; }
}
