/* ==========================================================================
   RT DIGITAL - UI COMPONENTS (TERANG, WARM, GELAP)
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Header & Navigation Bar
   -------------------------------------------------------------------------- */
.top-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-subtle);
  padding: 0.65rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  flex-shrink: 0;
}

.brand-icon img {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  object-fit: cover;
}

.brand-info h1 {
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: var(--text-main);
}

.brand-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--primary);
}

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--primary);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* --------------------------------------------------------------------------
   2. Theme Switcher Component [ ☀️ Terang | ☕ Warm | 🌙 Gelap ]
   -------------------------------------------------------------------------- */
.theme-switcher {
  display: inline-flex;
  align-items: center;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  padding: 2px;
  gap: 2px;
}

.theme-btn {
  border: none;
  background: transparent;
  padding: 0.3rem 0.65rem;
  border-radius: var(--radius-pill);
  font-size: 0.75rem;
  font-weight: 600;
  font-family: inherit;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  transition: all var(--transition-fast);
}

.theme-btn:hover {
  color: var(--text-main);
}

.theme-btn.active {
  background: var(--bg-surface);
  color: var(--text-main);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-highlight);
}

/* User & Mode Badges */
.user-badge {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.7rem;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pill);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  transition: var(--transition-fast);
}

.user-badge:hover {
  border-color: var(--border-focus);
}

.user-badge.role-rt {
  background: var(--status-income-bg);
  border-color: var(--status-income-border);
  color: var(--status-income);
}

.user-badge.role-warga {
  background: var(--accent-kkw-bg);
  border-color: var(--accent-kkw-border);
  color: var(--accent-kkw);
}

/* --------------------------------------------------------------------------
   3. Bottom Navigation Bar (Mobile-First)
   -------------------------------------------------------------------------- */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding: 0.45rem 0.5rem calc(0.45rem + env(safe-area-inset-bottom, 0px));
  max-width: 600px;
  margin: 0 auto;
  box-shadow: var(--shadow-md);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
  padding: 0.4rem 0.75rem;
  color: var(--text-muted);
  font-size: 0.72rem;
  font-weight: 600;
  text-decoration: none;
  border-radius: var(--radius-md);
  transition: all var(--transition-fast);
  cursor: pointer;
  border: none;
  background: transparent;
  flex: 1;
}

.nav-item svg {
  width: 20px;
  height: 20px;
  stroke-width: 2;
  transition: transform var(--transition-fast);
}

.nav-item:hover, .nav-item.active {
  color: var(--primary);
}

.nav-item.active svg {
  stroke: var(--primary);
}

.nav-item.active::after {
  content: '';
  width: 14px;
  height: 3px;
  background: var(--primary);
  border-radius: var(--radius-pill);
}

.desktop-nav {
  display: none;
}

/* --------------------------------------------------------------------------
   4. Cards & Clean Widgets
   -------------------------------------------------------------------------- */
.content-area {
  padding: 1.25rem;
  padding-bottom: 6.5rem;
  min-height: calc(100vh - 120px);
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 1.15rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.85rem;
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-main);
}

/* Banner Pengumuman & Info RT (Live dari Google Sheet) */
.info-banner {
  background: var(--primary-light);
  border: 1px solid var(--primary-border);
  border-radius: var(--radius-lg);
  padding: 0.9rem 1.1rem;
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.info-banner-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.info-banner-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.info-banner-content {
  font-size: 0.85rem;
  color: var(--text-main);
  line-height: 1.45;
}

/* Stat Grid */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.stat-card-full {
  grid-column: span 2;
}

.stat-card {
  padding: 1rem;
  border-radius: var(--radius-lg);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 95px;
}

.stat-card.primary {
  background: var(--status-income-bg);
  border-color: var(--status-income-border);
}

.stat-card.income {
  background: var(--status-income-bg);
  border-color: var(--status-income-border);
}

.stat-card.expense {
  background: var(--status-expense-bg);
  border-color: var(--status-expense-border);
}

.stat-card.kkw {
  background: var(--accent-kkw-bg);
  border-color: var(--accent-kkw-border);
}

.stat-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.stat-value {
  font-size: 1.35rem;
  font-weight: 800;
  margin-top: 0.35rem;
  letter-spacing: -0.01em;
  color: var(--text-main);
}

.stat-subtext {
  font-size: 0.72rem;
  color: var(--text-dim);
  margin-top: 0.2rem;
}

/* --------------------------------------------------------------------------
   5. Buttons & Form Controls
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.6rem 1rem;
  font-size: 0.88rem;
  font-weight: 600;
  font-family: inherit;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
}

.btn-sm {
  padding: 0.35rem 0.7rem;
  font-size: 0.78rem;
  border-radius: var(--radius-sm);
}

.btn-lg {
  padding: 0.75rem 1.25rem;
  font-size: 0.95rem;
  border-radius: var(--radius-md);
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
}
.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--bg-surface-elevated);
  border-color: var(--border-subtle);
  color: var(--text-main);
}
.btn-secondary:hover {
  background: var(--border-highlight);
}

.btn-wa {
  background: #16a34a;
  color: #ffffff;
}
.btn-wa:hover {
  background: #15803d;
}

.btn-danger {
  background: var(--status-expense-bg);
  border-color: var(--status-expense-border);
  color: var(--status-expense);
}
.btn-danger:hover {
  background: var(--status-expense);
  color: #ffffff;
}

/* Filter Pills Bar */
.filter-pills-bar {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  overflow-x: auto;
  padding: 0.2rem 0;
  margin-bottom: 0.85rem;
  scrollbar-width: none;
}
.filter-pills-bar::-webkit-scrollbar {
  display: none;
}

.pill-btn {
  white-space: nowrap;
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-pill);
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.pill-btn:hover {
  color: var(--text-main);
  border-color: var(--border-highlight);
}

.pill-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

/* Search Box */
.search-box {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.5rem 0.85rem;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
}

.search-box:focus-within {
  border-color: var(--border-focus);
}

.search-box input {
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-main);
  font-size: 0.88rem;
  width: 100%;
  font-family: inherit;
}

/* Form Groups & Inputs */
.form-group {
  margin-bottom: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.form-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.form-control {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.8rem;
  font-size: 0.88rem;
  color: var(--text-main);
  outline: none;
  font-family: inherit;
  width: 100%;
}

.form-control:focus {
  border-color: var(--border-focus);
}

/* --------------------------------------------------------------------------
   6. Accordion (Database Warga per-KK dengan TTL & Umur)
   -------------------------------------------------------------------------- */
.kk-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  margin-bottom: 0.75rem;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.kk-card.open {
  border-color: var(--border-highlight);
}

.kk-header {
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
}

.kk-header:hover {
  background: var(--bg-surface-elevated);
}

.kk-header-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.kk-avatar {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: var(--primary);
  flex-shrink: 0;
}

.kk-arrow {
  transition: transform var(--transition-normal);
  color: var(--text-dim);
}

.kk-card.open .kk-arrow {
  transform: rotate(180deg);
  color: var(--primary);
}

.kk-content {
  display: none;
  padding: 0.85rem 1rem;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-surface-elevated);
}

.kk-card.open .kk-content {
  display: block;
}

/* --------------------------------------------------------------------------
   6b. Collapsible Card (generik, dipakai mis. Tanda Tangan Digital)
   -------------------------------------------------------------------------- */
.collapsible-header {
  cursor: pointer;
  user-select: none;
}

.collapsible-arrow {
  transition: transform var(--transition-normal);
  color: var(--text-dim);
  display: inline-flex;
}

.collapsible-card.open .collapsible-arrow {
  transform: rotate(180deg);
  color: var(--primary);
}

.collapsible-body {
  display: none;
}

.collapsible-card.open .collapsible-body {
  display: block;
}

.member-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.65rem;
}

.member-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.85rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  gap: 0.5rem;
}

/* Status Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  font-weight: 700;
}

.badge-aktif {
  background: var(--status-income-bg);
  color: var(--status-income);
  border: 1px solid var(--status-income-border);
}

.badge-lahir {
  background: var(--accent-kkw-bg);
  color: var(--accent-kkw);
  border: 1px solid var(--accent-kkw-border);
}

.badge-meninggal {
  background: var(--status-expense-bg);
  color: var(--status-expense);
  border: 1px solid var(--status-expense-border);
}

.badge-pindah {
  background: var(--accent-amber-bg);
  color: var(--accent-amber);
  border: 1px solid var(--accent-amber-border);
}

/* --------------------------------------------------------------------------
   7. Matriks Tunggakan KKW Table
   -------------------------------------------------------------------------- */
.matrix-table-container {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  margin-top: 0.5rem;
}

.matrix-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  text-align: left;
}

.matrix-table th {
  background: var(--bg-surface-elevated);
  padding: 0.65rem 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}

.matrix-table td {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-main);
  white-space: nowrap;
}

.matrix-table tr:last-child td {
  border-bottom: none;
}

.matrix-table tr:hover {
  background: var(--bg-surface-elevated);
}

/* --------------------------------------------------------------------------
   8. Signature Pad Canvas di Pengaturan
   -------------------------------------------------------------------------- */
.signature-box {
  background: #ffffff;
  border: 2px dashed var(--border-highlight);
  border-radius: var(--radius-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 0.5rem;
  position: relative;
}

#signature-pad {
  width: 100%;
  max-width: 360px;
  height: 140px;
  background: #ffffff;
  touch-action: none;
  cursor: crosshair;
}

.signature-preview-img {
  max-height: 55px;
  max-width: 110px;
  object-fit: contain;
}

/* --------------------------------------------------------------------------
   9. Kwitansi Digital Resmi RT & Tanda Tangan
   -------------------------------------------------------------------------- */
.receipt-paper {
  background: #ffffff !important;
  color: #1e293b !important;
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
  border: 1px solid #cbd5e1;
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  margin: 0 auto;
  max-width: 440px;
}

.receipt-header {
  text-align: center;
  border-bottom: 2px dashed #cbd5e1;
  padding-bottom: 0.75rem;
  margin-bottom: 0.85rem;
}

.receipt-row {
  display: flex;
  justify-content: space-between;
  padding: 0.28rem 0;
  font-size: 0.85rem;
}

.receipt-amount-box {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-md);
  padding: 0.7rem;
  margin: 0.75rem 0;
  text-align: center;
}

.receipt-terbilang {
  font-style: italic;
  font-size: 0.78rem;
  color: #64748b;
  margin-top: 0.2rem;
}

.receipt-footer {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid #e2e8f0;
}

.receipt-signature-area {
  text-align: center;
  position: relative;
  min-width: 110px;
}

.receipt-stamp {
  width: 76px;
  height: 76px;
  border: 2px solid #dc2626;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #dc2626;
  font-size: 0.62rem;
  font-weight: 800;
  transform: rotate(-10deg);
  opacity: 0.9;
  position: absolute;
  top: -15px;
  left: -20px;
  pointer-events: none;
}

/* --------------------------------------------------------------------------
   10. Modals & Viewfinder
   -------------------------------------------------------------------------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-sheet {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  width: 100%;
  max-width: 580px;
  max-height: 88vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 1.25rem;
  padding-bottom: 2rem;
  transform: translateY(100%);
  transition: transform var(--transition-normal);
}

.modal-overlay.active .modal-sheet {
  transform: translateY(0);
}

.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--border-highlight);
  border-radius: var(--radius-pill);
  margin: -0.25rem auto 0.85rem auto;
}

.ocr-camera-box {
  position: relative;
  width: 100%;
  height: 220px;
  background: #000;
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--primary);
  margin-bottom: 0.85rem;
}

.ocr-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.ocr-laser-line {
  position: absolute;
  left: 5%;
  right: 5%;
  height: 2px;
  background: var(--primary);
  box-shadow: 0 0 8px var(--primary);
  animation: scanLaser 2s infinite ease-in-out alternate;
}

@keyframes scanLaser {
  0% { top: 10%; }
  100% { top: 90%; }
}

.ocr-progress-track {
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--bg-surface-elevated);
  overflow: hidden;
}

.ocr-progress-bar {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width 0.2s ease;
}

/* Toast */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  left: 1rem;
  max-width: 420px;
  margin: 0 auto;
  z-index: 120;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-main);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-size: 0.85rem;
  animation: fadeIn 0.2s ease forwards;
  pointer-events: auto;
}

.toast.success {
  border-color: var(--status-income-border);
  background: var(--status-income-bg);
  color: var(--status-income);
}

.toast.error {
  border-color: var(--status-expense-border);
  background: var(--status-expense-bg);
  color: var(--status-expense);
}
