/* ============================================
   bills-installments.css — Tagihan (Bills) & Cicilan (Installments):
   tabs, source/item cards, payment tables, Excel-style pivot spreadsheet
   view with frozen columns, stat cards, responsive card-list fallback.
   Part of the app.css split — must load AFTER expenses.css (overrides
   the shared .form-row for these modals' modal-body layout).
   ============================================ */

/* Tabs */
.bills-tabs {
  display: flex;
  gap: 4px;
  padding: 0 20px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.bills-tab {
  padding: 10px 18px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 6px;
}
.bills-tab:hover { color: var(--text-primary); }
.bills-tab.active {
  color: var(--gold);
  border-bottom-color: var(--gold);
}
.bills-tab i { font-size: 16px; }

.bills-tab-pane, .inst-tab-pane { padding: 0 20px 20px; }

/* Filter row */
.bills-filter-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.bills-filter-row-spread {
  justify-content: space-between;
}
.bills-year-label {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  min-width: 50px;
  text-align: center;
}

/* Tables */
.bills-table-wrap { overflow-x: auto; }
.bills-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.bills-table th {
  padding: 10px 12px;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.bills-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.bills-table tbody tr:hover { background: rgba(186,154,66,0.05); }
.bills-table .text-right { text-align: right; }
.bills-total-row td {
  border-top: 2px solid var(--gold);
  background: rgba(186,154,66,0.08);
}

/* Source dot */
.bills-source-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
}

/* Status badge */
.bills-status-badge {
  font-size: 11px;
  padding: 2px 8px;
  border: 1px solid;
  border-radius: 12px;
  white-space: nowrap;
}

/* Source cards */
.bills-source-list { display: flex; flex-direction: column; gap: 8px; }
.bills-source-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  transition: border-color 0.2s;
}
.bills-source-card:hover { border-color: var(--gold); }
.bills-source-dot-lg {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  flex-shrink: 0;
}
.bills-source-info { flex: 1; }
.bills-source-name { font-weight: 600; font-size: 14px; }
.bills-source-type { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.bills-source-actions { display: flex; gap: 4px; }

.bills-actions { display: flex; gap: 2px; }

/* Installment cards */
.inst-item-list { display: flex; flex-direction: column; gap: 14px; }
.inst-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
  display: flex;
}
.inst-card:hover { border-color: var(--gold); box-shadow: 0 2px 12px rgba(186,154,66,0.08); }
.inst-card-done { border-color: var(--success); }
.inst-card-done:hover { border-color: var(--success); box-shadow: 0 2px 12px rgba(76,175,80,0.1); }
.inst-card-inactive { opacity: 0.5; }
.inst-card-accent { width: 4px; flex-shrink: 0; border-radius: 4px 0 0 4px; }
.inst-card-body { flex: 1; padding: 16px 18px; min-width: 0; }
.inst-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 14px;
}
.inst-card-title strong { font-size: 15px; }
.inst-card-bank {
  display: inline-block;
  background: rgba(186,154,66,0.15);
  color: var(--gold);
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 11px;
  margin-left: 8px;
  font-weight: 500;
}
.inst-card-actions { display: flex; gap: 2px; }
.inst-card-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px 16px;
  margin-bottom: 14px;
  padding: 10px 14px;
  background: rgba(255,255,255,0.02);
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.04);
}
.inst-info-item { display: flex; flex-direction: column; gap: 2px; }
.inst-info-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); }
.inst-info-value { font-size: 13px; color: var(--text-primary); font-weight: 500; }
.inst-info-value i { font-size: 12px; margin-right: 2px; }
.inst-card-progress {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.inst-progress-bar {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.inst-progress-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s;
}
.inst-progress-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--gold);
  min-width: 36px;
  text-align: right;
}
.inst-card-footer {
  display: flex;
  gap: 24px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.inst-footer-item { display: flex; flex-direction: column; gap: 1px; }
.inst-footer-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); }
.inst-footer-value { font-size: 14px; font-weight: 600; }
.inst-card-detail {
  margin-top: 12px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}

/* Installment payment table rows */
.inst-payment-table { font-size: 12px; }
.inst-row-current { background: rgba(186,154,66,0.1) !important; }
.inst-row-paid td:first-child { border-left: 3px solid var(--success); }
.inst-row-overdue td:first-child { border-left: 3px solid var(--danger); }

/* Detail table */
.bills-table-detail { font-size: 12px; }

/* ── Excel Spreadsheet View ── */
.excel-source-btns { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 0; }
.excel-source-btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 20px; border: 1px solid var(--border); background: transparent; color: var(--text-secondary); font-size: 13px; cursor: pointer; transition: all 0.2s; }
.excel-source-btn:hover { border-color: var(--src-color, var(--gold)); color: var(--text-primary); background: rgba(255,255,255,0.04); }
.excel-source-btn.active { border-color: var(--src-color, var(--gold)); color: #fff; background: var(--src-color, var(--gold)); }
.excel-source-btn-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.excel-source-btn.active .excel-source-btn-dot { background: #fff !important; }
.excel-sheet { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; margin-top: 8px; }
.excel-sheet-header { padding: 10px 16px; font-weight: 700; font-size: 14px; color: #fff; display: flex; align-items: center; gap: 8px; }
.excel-sheet-body { overflow-x: auto; }
.excel-scroll { max-height: 80vh; overflow-y: auto; }
.excel-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.excel-table thead { position: sticky; top: 0; z-index: 2; }
.excel-table th { background: var(--bg-card); color: var(--text-secondary); font-weight: 600; padding: 8px 10px; border-bottom: 2px solid var(--border); white-space: nowrap; font-size: 11px; text-transform: uppercase; letter-spacing: 0.3px; }
.excel-table td { padding: 7px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.excel-table tbody tr:hover { background: rgba(186,154,66,0.06); }
.excel-table tfoot td { background: var(--bg-card); padding: 10px; border-top: 2px solid var(--gold); font-weight: 600; }

/* Pivot table month headers */
.excel-month-th { text-align: center !important; min-width: 80px; line-height: 1.3; }
.excel-month-current { background: rgba(186,154,66,0.2) !important; color: var(--gold) !important; }

/* Pivot cells */
.excel-cell { text-align: right; font-variant-numeric: tabular-nums; }
.excel-cell-desc { font-weight: 600; max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.excel-cell-paid { background: rgba(76,175,80,0.12); color: var(--success); }
.excel-cell-current { background: rgba(186,154,66,0.15); color: var(--gold); font-weight: 700; }
.excel-cell-overdue { background: rgba(244,67,54,0.12); color: var(--danger); }
.excel-cell-future { color: var(--text-muted); }
.excel-cell-na { text-align: center; color: var(--text-muted); opacity: 0.4; }
.excel-actions { white-space: nowrap; display: flex; gap: 2px; }

/* ── Frozen (sticky) first 2 columns ── */

/* Col 1: sticky left:0 — all rows including tfoot */
.excel-sticky-2 thead th:nth-child(1),
.excel-sticky-2 tbody td:nth-child(1),
.excel-sticky-2 tfoot td:nth-child(1) {
  position: sticky;
  left: 0;
  z-index: 2;
}
/* Col 2: sticky left:40px — thead + tbody only (tfoot uses colspan=2 cell) */
.excel-sticky-2 thead th:nth-child(2),
.excel-sticky-2 tbody td:nth-child(2) {
  position: sticky;
  left: 40px;
  z-index: 2;
}
/* Backgrounds */
.excel-sticky-2 thead th:nth-child(1),
.excel-sticky-2 thead th:nth-child(2) { z-index: 4; background: var(--bg-card); }
.excel-sticky-2 tbody td:nth-child(1),
.excel-sticky-2 tbody td:nth-child(2) { background: var(--bg-darkest); }
.excel-sticky-2 tfoot td:nth-child(1) { z-index: 3; background: var(--bg-card); }

/* Gap fix: col1 casts a solid shadow 4px to the RIGHT, sealing the sub-pixel gap.
   Col2 background (higher DOM order = on top) will cover this shadow in its area. */
.excel-sticky-2 thead th:nth-child(1) { box-shadow: 4px 0 0 var(--bg-card); }
.excel-sticky-2 tbody td:nth-child(1) { box-shadow: 4px 0 0 var(--bg-darkest); }

/* Freeze separator: dark drop-shadow on RIGHT edge of the frozen area */
.excel-sticky-2 thead th:nth-child(2) { box-shadow: 4px 0 10px rgba(0,0,0,0.7); }
.excel-sticky-2 tbody td:nth-child(2) { box-shadow: 4px 0 10px rgba(0,0,0,0.7); }
/* tfoot col1 = colspan-2 TOTAL cell = whole frozen area → separator on its right */
.excel-sticky-2 tfoot td:nth-child(1) { box-shadow: 4px 0 10px rgba(0,0,0,0.7); }

/* tfoot col2+: normal flow (col1 spans both frozen cols via colspan=2) */
.excel-sticky-2 tfoot td:nth-child(n+2) { position: static; box-shadow: none; }

/* Legend */
.excel-legend { display: flex; gap: 16px; padding: 10px 0; flex-wrap: wrap; margin-top: 8px; }
.excel-legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); }
.excel-legend-dot { width: 14px; height: 14px; border-radius: 3px; display: inline-block; }
.excel-legend-dot.excel-cell-paid { background: rgba(76,175,80,0.25); border: 1px solid var(--success); }
.excel-legend-dot.excel-cell-current { background: rgba(186,154,66,0.25); border: 1px solid var(--gold); }
.excel-legend-dot.excel-cell-overdue { background: rgba(244,67,54,0.25); border: 1px solid var(--danger); }
.excel-legend-dot.excel-cell-future { background: rgba(255,255,255,0.06); border: 1px solid var(--text-muted); }

/* Modal form-row (overrides the shared .form-row from base.css for these
   panels' modals — this specific variant wins because it loads last) */
.form-row { display: flex; gap: 12px; margin-bottom: 0; }
.form-row .form-group { margin-bottom: 12px; }

/* ── Stat Cards (Bills / Cicilan) ── */
.pomo-stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.pomo-stat-card .pomo-stat-val {
  font-size: clamp(1.05rem, 4.5vw, 1.7rem);
  font-weight: 800;
  color: var(--gold);
  line-height: 1.15;
  word-break: break-word;
}
.pomo-stat-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 500;
}
/* Space between stats grid and content below it in bills/cicilan tab panes */
.bills-tab-pane .pomo-stats-grid,
.inst-tab-pane .pomo-stats-grid {
  margin-bottom: 16px;
}

/* ── Responsive: Tagihan & Cicilan (≤768px) ── */
@media (max-width: 768px) {
  /* Tab bar: compact, no overflow-x needed (tabs fit in screen width) */
  .bills-tabs {
    padding: 0 4px;
    gap: 0;
  }
  .bills-tab {
    padding: 9px 11px;
    font-size: 12px;
    white-space: nowrap;
    flex-shrink: 0;
    gap: 4px;
  }
  .bills-tab i { font-size: 14px; }

  /* Tab pane: keep some side padding so cards don't touch screen edge */
  .bills-tab-pane, .inst-tab-pane { padding: 0 12px 20px; }

  /* Filter rows */
  .bills-filter-row { padding: 0; gap: 8px; }
  .bills-filter-row-spread {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .bills-filter-row-spread .btn {
    width: 100%;
    justify-content: center;
  }

  /* Year nav: center it */
  .bills-filter-row.bills-year-row { justify-content: center; }
  .bills-year-label { font-size: 16px; min-width: 60px; }

  /* Stat cards */
  .pomo-stats-grid { gap: 8px; }

  /* Inst card mobile */
  .inst-card-body { padding: 12px 14px; }
  .inst-card-head { margin-bottom: 10px; }
  .inst-card-title strong { font-size: 14px; }
  .inst-card-info-grid {
    grid-template-columns: 1fr 1fr;
    gap: 6px 10px;
    padding: 8px 10px;
    margin-bottom: 10px;
  }
  .inst-info-value {
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .inst-card-footer {
    gap: 0;
    justify-content: space-between;
    flex-wrap: nowrap;
  }
  .inst-footer-item { flex: 1; min-width: 0; }
  .inst-footer-value { font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
  .inst-footer-label { font-size: 9px; }
  .inst-card-progress { margin-bottom: 10px; }

  /* Bills table compact (non-rekap) */
  .bills-table:not(.bills-table-rekap) { font-size: 11px; }
  .bills-table:not(.bills-table-rekap) th,
  .bills-table:not(.bills-table-rekap) td { padding: 8px 6px; }

  /* Form row */
  .form-row { flex-direction: column; gap: 0; }
}

/* ── Bills Rekap table → card list (≤600px) ── */
@media (max-width: 600px) {
  /* Let wrapper scroll normally */
  .bills-table-wrap { overflow-x: visible; }

  /* Transform table to block */
  .bills-table-rekap { display: block; }
  .bills-table-rekap thead { display: none; }
  .bills-table-rekap tbody { display: flex; flex-direction: column; gap: 8px; }

  /* Each row → card */
  .bills-table-rekap tbody tr {
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 13px 14px;
    transition: border-color 0.2s;
  }
  .bills-table-rekap tbody tr:hover { border-color: var(--gold); background: var(--bg-card); }

  /* All cells → label: value row */
  .bills-table-rekap tbody td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 5px 0;
    white-space: normal;
    border: none;
    font-size: 13px;
    text-align: right;
  }
  .bills-table-rekap tbody td::before {
    content: attr(data-label);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-muted);
    font-weight: 600;
    flex-shrink: 0;
    text-align: left;
    margin-right: 8px;
  }

  /* First cell = period header */
  .bills-table-rekap tbody td:first-child {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-primary);
    border-bottom: 1px solid var(--border);
    padding-bottom: 9px;
    margin-bottom: 3px;
    justify-content: space-between;
    text-align: left;
  }
  .bills-table-rekap tbody td:first-child::before { display: none; }
  /* Show entry count next to period via data-entri attr */
  .bills-table-rekap tbody td:first-child::after {
    content: attr(data-entri);
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 400;
  }

  /* Hide the separate entri cell (shown in header via ::after) */
  .bills-table-rekap tbody .bills-entri-cell { display: none; }

  /* Footer total row */
  .bills-table-rekap tfoot { display: block; margin-top: 4px; }
  .bills-table-rekap tfoot tr {
    display: flex;
    background: rgba(186,154,66,0.08);
    border: 1px solid rgba(186,154,66,0.2);
    border-radius: 10px;
    padding: 12px 14px;
    gap: 4px;
  }
  .bills-table-rekap tfoot td {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 0;
    border: none;
    background: transparent !important;
    min-width: 0;
    text-align: left;
  }
  /* Hide first (TOTAL label) and last (empty Entri) */
  .bills-table-rekap tfoot td:first-child,
  .bills-table-rekap tfoot td:last-child { display: none; }
  .bills-table-rekap tfoot td::before {
    content: attr(data-label);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-muted);
    font-weight: 600;
    white-space: nowrap;
  }
  .bills-table-rekap tfoot td strong {
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
  }
  /* Override global .bills-total-row td */
  .bills-table-rekap .bills-total-row td {
    border-top: none;
    background: transparent !important;
  }
}
