/* ===================================================
   📁 파일 위치: /영일전기철물2/sections/cash/cash_stats.css
   ✅ 덮어쓰기 지시: cash_stats 현대 대시보드 UI v8.0
   =================================================== */

/* ─────────────────────────────────────────────
   변수
───────────────────────────────────────────── */
.cs-page {
  --cs-income:  #059669;
  --cs-income-bg: #ecfdf5;
  --cs-income-border: #a7f3d0;
  --cs-expense: #dc2626;
  --cs-expense-bg: #fef2f2;
  --cs-expense-border: #fecaca;
  --cs-profit:  #2563eb;
  --cs-profit-bg: #eff6ff;
  --cs-profit-border: #bfdbfe;
  --cs-profit-neg: #dc2626;

  --cs-border: #e5e7eb;
  --cs-row-hover: #f9fafb;
  --cs-head-bg: #f3f4f6;
  --cs-text: #111827;
  --cs-muted: #6b7280;
  --cs-ink: #1f2937;
  --cs-radius: 10px;
  --cs-shadow: 0 1px 4px rgba(0,0,0,.08);
}

/* ─────────────────────────────────────────────
   페이지 루트
───────────────────────────────────────────── */
.cs-page {
  box-sizing: border-box;
  width: 100%;
  padding: 16px 20px 40px;
  font-family: 'Pretendard', 'Apple SD Gothic Neo', 'Noto Sans KR', sans-serif;
  color: var(--cs-text);
  font-size: 14px;
  line-height: 1.5;
  background: transparent;
}

.cs-page *, .cs-page *::before, .cs-page *::after {
  box-sizing: border-box;
}

/* ─────────────────────────────────────────────
   페이지 헤더
───────────────────────────────────────────── */
.cs-header {
  margin-bottom: 16px;
}

.cs-page-title {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 800;
  color: var(--cs-ink);
  letter-spacing: -.3px;
}

.cs-page-sub {
  margin: 0;
  font-size: 13px;
  color: var(--cs-muted);
}

/* ─────────────────────────────────────────────
   상단 영역 (기간 + KPI)
───────────────────────────────────────────── */
.cs-top-area {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

/* 기간 선택 바 */
.cs-period-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  background: #fff;
  border: 1px solid var(--cs-border);
  border-radius: var(--cs-radius);
  padding: 10px 14px;
  box-shadow: var(--cs-shadow);
}

.cs-period-dates {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.cs-period-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--cs-muted);
  white-space: nowrap;
}

.cs-period-sep {
  color: var(--cs-muted);
  font-size: 13px;
}

.cs-date-input {
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--cs-border);
  border-radius: 6px;
  font-size: 13px;
  color: var(--cs-ink);
  background: #fff;
  outline: none;
}
.cs-date-input:focus {
  border-color: #6366f1;
  box-shadow: 0 0 0 2px rgba(99,102,241,.15);
}

.cs-period-chips {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: nowrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.cs-period-chips::-webkit-scrollbar { display: none; }

.cs-chip {
  flex: 0 0 auto;
  height: 30px;
  padding: 0 11px;
  border: 1px solid var(--cs-border);
  border-radius: 6px;
  background: #fff;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--cs-ink);
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s, border-color .15s;
}
.cs-chip:hover {
  background: #f3f4f6;
  border-color: #d1d5db;
}
.cs-chip.active, .cs-chip.is-active {
  background: #1f2937;
  color: #fff;
  border-color: #1f2937;
}

/* KPI 카드 */
.cs-kpi-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.cs-kpi-card {
  border-radius: var(--cs-radius);
  border: 1px solid transparent;
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: var(--cs-shadow);
}

.cs-kpi-income {
  background: var(--cs-income-bg);
  border-color: var(--cs-income-border);
}
.cs-kpi-expense {
  background: var(--cs-expense-bg);
  border-color: var(--cs-expense-border);
}
.cs-kpi-profit {
  background: var(--cs-profit-bg);
  border-color: var(--cs-profit-border);
}

.cs-kpi-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--cs-muted);
  text-transform: uppercase;
  letter-spacing: .3px;
}

.cs-kpi-income .cs-kpi-label { color: #065f46; }
.cs-kpi-expense .cs-kpi-label { color: #991b1b; }
.cs-kpi-profit .cs-kpi-label  { color: #1e40af; }

.cs-kpi-value {
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -.5px;
  line-height: 1.1;
}

.cs-kpi-income .cs-kpi-value { color: var(--cs-income); }
.cs-kpi-expense .cs-kpi-value { color: var(--cs-expense); }
.cs-kpi-profit .cs-kpi-value  { color: var(--cs-profit); }
.cs-kpi-profit .cs-kpi-value.is-neg { color: var(--cs-profit-neg); }

.cs-kpi-sub {
  font-size: 11.5px;
  color: var(--cs-muted);
  min-height: 16px;
}

/* ─────────────────────────────────────────────
   메인 2컬럼 레이아웃
───────────────────────────────────────────── */
.cs-body {
  display: grid;
  grid-template-columns: 1fr 500px;
  gap: 16px;
  align-items: start;
}

/* 우측 상세 패널: viewport sticky + flex 컬럼으로 높이 채움 */
.cs-detail-col {
  position: sticky;
  top: calc(var(--app-header-h, 52px) + 8px);
  max-height: calc(100vh - var(--app-header-h, 52px) - 24px);
  display: flex;
  flex-direction: column;
}

.cs-detail-col .cs-card {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ─────────────────────────────────────────────
   카드
───────────────────────────────────────────── */
.cs-card {
  background: #fff;
  border: 1px solid var(--cs-border);
  border-radius: var(--cs-radius);
  box-shadow: var(--cs-shadow);
  overflow: hidden;
}

.cs-card-head {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--cs-border);
  background: #fafafa;
}

.cs-card-title {
  font-size: 14px;
  font-weight: 800;
  color: var(--cs-ink);
  white-space: nowrap;
}

.cs-card-hint {
  font-size: 12px;
  color: var(--cs-muted);
}

/* ─────────────────────────────────────────────
   탭
───────────────────────────────────────────── */
.cs-tab-bar {
  display: flex;
  gap: 4px;
  margin-bottom: 10px;
  background: #f3f4f6;
  border-radius: 8px;
  padding: 3px;
}

.cs-tab-btn {
  flex: 1;
  height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  font-size: 13px;
  font-weight: 700;
  color: var(--cs-muted);
  cursor: pointer;
  transition: background .15s, color .15s, box-shadow .15s;
}
.cs-tab-btn:hover {
  background: #e5e7eb;
  color: var(--cs-ink);
}
.cs-tab-btn.active {
  background: #fff;
  color: var(--cs-ink);
  box-shadow: 0 1px 3px rgba(0,0,0,.1);
}

.cs-tab-panel {
  display: none;
}
.cs-tab-panel.active {
  display: block;
}

/* ─────────────────────────────────────────────
   테이블
───────────────────────────────────────────── */
.cs-table-wrap {
  overflow-x: auto;
}

.cs-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 13px;
}

.cs-table thead th {
  background: var(--cs-head-bg);
  border-bottom: 1px solid var(--cs-border);
  padding: 8px 10px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--cs-muted);
  white-space: nowrap;
}

.cs-table tbody tr {
  border-bottom: 1px solid #f0f0f0;
  transition: background .1s;
}
.cs-table tbody tr:hover {
  background: var(--cs-row-hover);
}
.cs-table tbody td {
  padding: 7px 10px;
  vertical-align: middle;
  line-height: 1.3;
}

.cs-table tfoot th, .cs-table tfoot td {
  background: #f8f9fa;
  border-top: 2px solid var(--cs-border);
  padding: 8px 10px;
  font-weight: 800;
  font-size: 12.5px;
}

.cs-table-empty,
.cash-table-empty {
  text-align: center;
  color: var(--cs-muted);
  padding: 20px 10px;
  font-size: 13px;
}

/* 클릭 선택 셀 */
td.cs-picked {
  outline: 2px solid #6366f1;
  outline-offset: -2px;
  background: #eff6ff;
}

/* 클릭 가능한 금액 버튼 */
.cs-link {
  background: none;
  border: none;
  padding: 0;
  color: #2563eb;
  font-size: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.cs-link:hover {
  color: #1d4ed8;
}

/* 월 헤더 행 */
.cs-month-row td {
  background: #f3f4f6;
  padding: 0 !important;
}
.cs-month-toggle {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: none;
  padding: 6px 10px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--cs-ink);
  cursor: pointer;
}
.cs-month-toggle:hover {
  background: #e5e7eb;
}

/* ─────────────────────────────────────────────
   구분별 그리드
───────────────────────────────────────────── */
.cs-bykind-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}

.cs-bykind-section {
  border-right: 1px solid var(--cs-border);
  padding: 12px;
}
.cs-bykind-section:last-child {
  border-right: 0;
}

.cs-bykind-title {
  margin: 0 0 4px;
  font-size: 13px;
  font-weight: 700;
  color: var(--cs-ink);
}

.cs-bykind-sub {
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--cs-muted);
}

/* 사이드 패널 내부: 카드 헤더/필터/서머리/미니는 고정, 테이블만 늘어남 */
.cs-detail-col .cs-card-head,
.cs-detail-col .cs-detail-filters,
.cs-detail-col .cs-detail-summary,
.cs-detail-col .cs-detail-mini {
  flex-shrink: 0;
}

/* ─────────────────────────────────────────────
   상세내역 필터
───────────────────────────────────────────── */
.cs-detail-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--cs-border);
  background: #fafafa;
}

.cs-filter-label {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 600;
  color: var(--cs-muted);
  white-space: nowrap;
}

.cs-filter-label--wide {
  flex: 1 1 auto;
}

.cs-filter-label--search {
  width: 100%;
}

.cs-select {
  height: 30px;
  padding: 0 6px;
  border: 1px solid var(--cs-border);
  border-radius: 6px;
  font-size: 12.5px;
  color: var(--cs-ink);
  background: #fff;
  outline: none;
}
.cs-select:focus {
  border-color: #6366f1;
}

.cs-date-input--sm {
  height: 30px;
  font-size: 12px;
}

.cs-mini-btn {
  height: 28px;
  padding: 0 9px;
  border: 1px solid var(--cs-border);
  border-radius: 5px;
  background: #fff;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--cs-muted);
  cursor: pointer;
}
.cs-mini-btn:hover {
  background: #f3f4f6;
}

.cs-search-input {
  width: 100%;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--cs-border);
  border-radius: 6px;
  font-size: 13px;
  outline: none;
  background: #fff;
}
.cs-search-input:focus {
  border-color: #6366f1;
  box-shadow: 0 0 0 2px rgba(99,102,241,.1);
}

.cs-detail-summary {
  margin: 0;
  padding: 6px 14px;
  font-size: 12px;
  color: var(--cs-muted);
  border-bottom: 1px solid #f0f0f0;
}

/* ─────────────────────────────────────────────
   상세 mini 카드
───────────────────────────────────────────── */
.cs-detail-mini {
  margin: 6px 12px 0;
  padding: 10px 12px;
  background: #f8fafc;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.4;
}
.cs-detail-mini .mini-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
}
.cs-detail-mini .mini-item { color: #374151; white-space: nowrap; }
.cs-detail-mini .mini-amount { color: #059669; font-weight: 700; }
.cs-detail-mini .mini-memo { white-space: normal; }

/* 상세 테이블 스크롤 영역 */
.cs-detail-table-wrap {
  overflow-y: auto;
}

/* 사이드 패널에서는 남은 높이 전부 사용 */
.cs-detail-col .cs-detail-table-wrap {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

/* ─────────────────────────────────────────────
   상세내역 테이블 컬럼
───────────────────────────────────────────── */
.cash-detail-table {
  table-layout: fixed;
  width: 100%;
}

.cash-detail-table th, .cash-detail-table td {
  font-size: 12.5px;
  line-height: 1.3;
  padding: 6px 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cash-detail-table td.col-memo {
  white-space: normal;
}

/* 기본 컬럼 폭 (모달용) */
.cash-detail-table .col-date    { width: 90px; }
.cash-detail-table .col-type    { width: 52px; text-align: center; }
.cash-detail-table .col-kind    { width: 76px; text-align: center; }
.cash-detail-table .col-project { width: 130px; }
.cash-detail-table .col-customer{ width: 100px; }
.cash-detail-table .col-method  { width: 76px; text-align: center; }
.cash-detail-table .col-memo    { width: auto; }
.cash-detail-table .col-amount  { width: 100px; text-align: right; font-variant-numeric: tabular-nums; }
.cash-detail-table .col-detail  { width: 52px; text-align: center; }

/* 사이드 패널: 설명(메모)·입금수단·상세 컬럼 숨김 */
.cs-detail-col .cash-detail-table .col-memo,
.cs-detail-col .cash-detail-table th.col-memo   { display: none; }
.cs-detail-col .cash-detail-table .col-method,
.cs-detail-col .cash-detail-table th.col-method { display: none; }
.cs-detail-col .cash-detail-table .col-detail,
.cs-detail-col .cash-detail-table th.col-detail { display: none; }

/* 사이드 패널 셀 padding 축소 */
.cs-detail-col .cash-detail-table th,
.cs-detail-col .cash-detail-table td {
  padding: 5px 6px;
  font-size: 12px;
}

/* 사이드 패널 컬럼 폭: 6컬럼 합계 ≈ 500px */
.cs-detail-col .cash-detail-table .col-date    { width: 88px; }
.cs-detail-col .cash-detail-table .col-type    { width: 46px; }
.cs-detail-col .cash-detail-table .col-kind    { width: 72px; }
.cs-detail-col .cash-detail-table .col-project { width: 120px; }
.cs-detail-col .cash-detail-table .col-customer{ width: 82px; }
.cs-detail-col .cash-detail-table .col-amount  { width: 92px; }

/* ─────────────────────────────────────────────
   모달
───────────────────────────────────────────── */
.cs-modal {
  display: none;
}
.cs-modal.is-open {
  display: block;
  position: fixed;
  inset: 0;
  z-index: 99999;
}

.cs-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.45);
}

.cs-modal-panel {
  position: absolute;
  left: 50%;
  top: 4vh;
  transform: translateX(-50%);
  width: min(1200px, 96vw);
  height: 92vh;
  background: #fff;
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0,0,0,.22);
  display: flex;
  flex-direction: column;
}

.cs-modal-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--cs-border);
  background: #fafafa;
}

.cs-modal-title {
  font-size: 15px;
  font-weight: 800;
  color: var(--cs-ink);
}

.cs-modal-x {
  width: 36px;
  height: 36px;
  border: 0;
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
  color: var(--cs-muted);
  transition: background .15s;
}
.cs-modal-x:hover {
  background: #f3f4f6;
  color: var(--cs-ink);
}

.cs-modal-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 10px 14px;
}

body.modal-lock { overflow: hidden; }

/* 모달 안 상세카드 */
#cs-detail-card.cs-in-modal {
  margin: 0;
  border: 0;
  box-shadow: none;
  flex: unset;         /* sticky panel flex 해제 */
  min-height: unset;
  display: block;
  overflow: visible;
}
#cs-detail-card.cs-in-modal .cs-card-head {
  display: none;
}
#cs-detail-card.cs-in-modal .cash-detail-table tbody {
  display: table-row-group !important;
  height: auto !important;
  overflow: visible !important;
}
#cs-detail-card.cs-in-modal .cs-detail-table-wrap {
  flex: unset;
  max-height: none;
  overflow: visible;
}

/* ─────────────────────────────────────────────
   반응형
───────────────────────────────────────────── */

/* 1300px 이하: 우측 패널 숨기고 모달만 */
@media (max-width: 1299px) {
  .cs-body {
    grid-template-columns: 1fr;
  }
  .cs-detail-col {
    display: none;
  }
}

/* 900px 이하: KPI 1열 */
@media (max-width: 899px) {
  .cs-kpi-row {
    grid-template-columns: 1fr;
  }
  .cs-page {
    padding: 12px 14px 30px;
  }
  .cs-bykind-grid {
    grid-template-columns: 1fr;
  }
  .cs-bykind-section {
    border-right: 0;
    border-bottom: 1px solid var(--cs-border);
  }
  .cs-bykind-section:last-child {
    border-bottom: 0;
  }
}

/* 600px 이하: 기간바 세로 */
@media (max-width: 599px) {
  .cs-period-bar {
    flex-direction: column;
    align-items: flex-start;
  }
  .cs-period-chips {
    width: 100%;
  }
  .cs-kpi-value {
    font-size: 20px;
  }
}

/* ─────────────────────────────────────────────
   프린트
───────────────────────────────────────────── */
@media print {
  .cs-modal { display: none !important; }
  body.modal-lock { overflow: visible !important; }
  .cs-detail-col { display: none !important; }
}
