/* Google Fonts (Inter, Noto Sans JP) dimuat non-blocking lewat pwa_head() di app/Core/pwa.php */

* { box-sizing: border-box; }
html { scroll-padding-top: env(safe-area-inset-top, 0px); overflow-x: hidden; width: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--surface-alt);
  color: var(--text);
  font-variant-numeric: tabular-nums;
  padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  width: 100%;
  touch-action: pan-y; /* allow vertical scroll/swipe, block pinch-zoom gestures */
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }

.app-header {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: calc(var(--space-3) + env(safe-area-inset-top,0px)) var(--space-4) var(--space-3);
  display: flex; align-items: center; justify-content: space-between;
}
.app-header h1 { font-size: 17px; font-weight: 700; margin: 0; }
.icon-btn {
  width: 36px; height: 36px; border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  background: var(--surface-alt); border: 1px solid var(--border); color: var(--text);
  transition: background var(--transition-fast);
}
.icon-btn:hover { background: var(--indigo-100); }
.icon-btn.danger { color: var(--red); }
.icon-btn.danger:hover { background: var(--red-bg); }

.container { max-width: 480px; margin: 0 auto; padding: var(--space-4); }
@media (min-width: 900px) { .container { max-width: 960px; } }

.balance-card {
  background: var(--gradient-balance);
  color: #fff; border-radius: var(--radius-lg);
  padding: var(--space-5); box-shadow: var(--shadow-md);
  margin-bottom: var(--space-5);
}
.balance-card .label { font-size: 13px; opacity: 0.85; margin-bottom: var(--space-2); }
.balance-card .amount { font-size: 32px; font-weight: 800; letter-spacing: -0.02em; }
.balance-card .sub { display: flex; gap: var(--space-5); margin-top: var(--space-4); font-size: 13px; }
.balance-card .sub b { display:block; font-size: 15px; font-weight: 700; }

.menu-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-3);
  margin-bottom: var(--space-5);
}
.menu-item {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-2); display: flex; flex-direction: column; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 600; text-align: center; transition: transform var(--transition-fast), background var(--transition-fast);
}
.menu-item i { font-size: 20px; color: var(--indigo); }
.menu-item:active { transform: scale(0.96); background: var(--indigo-100); }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: var(--space-4); box-shadow: var(--shadow-sm); margin-bottom: var(--space-4);
}
.card h2 { font-size: 14px; font-weight: 700; margin: 0 0 var(--space-3); }

.tx-item {
  display: flex; align-items: center; gap: var(--space-3); padding: var(--space-3) 0;
  border-bottom: 1px solid var(--border);
}
.tx-item:last-child { border-bottom: none; }
.tx-icon { width: 36px; height: 36px; border-radius: 50%; display:flex; align-items:center; justify-content:center; flex-shrink:0; }
.tx-icon.in { background: var(--green-bg); color: var(--green); }
.tx-icon.out { background: var(--red-bg); color: var(--red); }
.tx-info { flex: 1; min-width: 0; }
.tx-info .cat { font-weight: 600; font-size: 14px; }
.tx-info .meta { font-size: 12px; color: var(--text-muted); }
.tx-amount { font-weight: 700; font-size: 14px; white-space: nowrap; }
.tx-amount.in { color: var(--green); }
.tx-amount.out { color: var(--red); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: var(--radius-md); padding: 13px 20px; font-weight: 700; font-size: 14px;
  border: 1px solid transparent; transition: background var(--transition-fast), transform var(--transition-fast);
  width: 100%;
}
.btn-primary { background: var(--indigo); color: #fff; }
.btn-primary:hover { background: var(--indigo-600); }
.btn-primary:active { transform: scale(0.98); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-danger { background: var(--red); color: #fff; }
.btn-sm { width: auto; padding: 8px 14px; font-size: 13px; }

.form-group { margin-bottom: var(--space-4); }
.form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text-muted); }
.form-control {
  width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-md);
  font-size: 15px; background: var(--surface); color: var(--text); font-family: inherit;
}
.form-control:focus { outline: none; border-color: var(--indigo); box-shadow: 0 0 0 3px var(--indigo-100); }

/* Reset native select rendering (iOS/Android draw their own widget otherwise,
   which ignores our border/radius/font and looks inconsistent) and draw a
   custom chevron so every select matches the rest of the form controls. */
select.form-control,
.filter-bar select,
.filter-field select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%235B6B82' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  background-size: 14px;
  padding-right: 38px;
}
.filter-bar select { padding-right: 30px; background-position: right 10px center; background-size: 12px; }

.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-around;
  padding: 8px 0 calc(8px + env(safe-area-inset-bottom,0px));
  transform: translateZ(0); /* own compositing layer -> no jitter while scrolling on Android */
}
.bottom-nav a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10px; color: var(--text-muted); font-weight: 600; padding: 4px 8px; }
.bottom-nav a.active { color: var(--indigo); }
.bottom-nav a i { font-size: 20px; }
.fab {
  width: 56px; height: 56px; border-radius: 50%; background: var(--indigo); color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 18px rgba(99,91,255,0.45), 0 0 0 4px var(--surface);
  margin-top: -30px; border: none;
  transition: transform var(--transition-fast), background var(--transition-fast);
}
.fab:active { background: var(--indigo-600); transform: scale(0.94); }
.fab-plus {
  font-family: -apple-system, BlinkMacSystemFont, sans-serif; /* not the icon webfont — always renders */
  font-size: 28px; font-weight: 400; line-height: 1; color: #fff;
  margin-top: -2px; /* optical centering of the glyph */
}

.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge.active { background: var(--green-bg); color: var(--green); }
.badge.inactive { background: var(--red-bg); color: var(--red); }
.badge.invited { background: var(--indigo-100); color: var(--indigo); }
.badge.role-owner { background: var(--indigo-100); color: var(--indigo); }
.badge.role-admin { background: var(--surface-alt); color: var(--text-muted); border: 1px solid var(--border); }

.empty-state { text-align: center; padding: var(--space-6) var(--space-4); color: var(--text-muted); }
.empty-state .grad-icon {
  width: 80px; height: 80px; border-radius: 50%; background: var(--gradient-atmos);
  display: flex; align-items: center; justify-content: center; margin: 0 auto var(--space-4);
  font-size: 32px; color: var(--indigo);
}

.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--gradient-atmos); padding: var(--space-4);
}
.login-card { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); padding: var(--space-6); width: 100%; max-width: 380px; }
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-card p.sub { color: var(--text-muted); font-size: 13px; margin-bottom: var(--space-5); }

.alert { padding: 12px 14px; border-radius: var(--radius-md); font-size: 13px; margin-bottom: var(--space-4); }
.alert-error { background: var(--red-bg); color: var(--red); }
.alert-success { background: var(--green-bg); color: var(--green); }

.table-wrap { overflow-x: auto; }
table.simple { width: 100%; border-collapse: collapse; font-size: 13px; }
table.simple th, table.simple td { text-align: left; padding: 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.simple th { color: var(--text-muted); font-weight: 600; font-size: 12px; }

.filter-bar { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-bottom: var(--space-4); }
.filter-bar select, .filter-bar input { padding: 8px 10px; border-radius: var(--radius-sm); border: 1px solid var(--border); font-size: 13px; background: var(--surface); color: var(--text); }

.fade-in { animation: fadeIn 180ms ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }

.skeleton { background: linear-gradient(90deg, var(--border) 25%, var(--surface-alt) 50%, var(--border) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: var(--radius-sm); height: 16px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }


/* ---------- Filter panel (transaksi & laporan) ---------- */
.filter-panel {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: var(--space-4); box-shadow: var(--shadow-sm); margin-bottom: var(--space-4);
}
.filter-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.filter-field label {
  font-size: 11px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--text-muted);
}
.filter-field select, .filter-field input {
  width: 100%; min-width: 0; height: 42px; padding: 0 12px;
  border: 1px solid var(--border); border-radius: var(--radius-md);
  font-family: inherit; font-size: 14px; background: var(--surface); color: var(--text);
}
.filter-field select:focus, .filter-field input:focus {
  outline: none; border-color: var(--indigo); box-shadow: 0 0 0 3px var(--indigo-100);
}
.filter-dates { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.filter-actions { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; }
.filter-actions .btn { flex: 1 1 0; min-width: 120px; height: 42px; padding: 0 14px; }
@media (min-width: 720px) {
  .filter-panel { grid-template-columns: repeat(4, 1fr); align-items: end; }
  .filter-dates { grid-column: span 2; }
  .filter-actions { grid-column: span 2; }
}

/* ---------- Laporan: versi layar vs versi cetak ---------- */
.print-only { display: none; }

.report-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: var(--space-4); }
.report-summary .sum { border: 1px solid var(--border); border-radius: var(--radius-md); padding: 12px; background: var(--surface-alt); }
.report-summary .sum small { display: block; font-size: 11px; color: var(--text-muted); font-weight: 600; margin-bottom: 4px; }
.report-summary .sum b { font-size: 16px; }
.report-summary .sum.in b { color: var(--green); }
.report-summary .sum.out b { color: var(--red); }
.report-summary .sum.end { background: var(--indigo-100); }
@media (min-width: 720px) { .report-summary { grid-template-columns: repeat(4, 1fr); } }

/* ---------- Cetak / PDF A4 ---------- */
@media print {
  /* Margin diatur lewat padding sheet, bukan @page, supaya tetap ada margin
     walaupun di dialog print dipilih "Margins: None". */
  @page { size: A4 portrait; margin: 0; }

  html, body, body[data-theme="dark"] {
    background: #fff !important; width: 210mm; margin: 0; padding: 0; overflow: visible;
    color: #0A2540; font-family: 'Inter', 'Noto Sans JP', Arial, sans-serif;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  .bottom-nav, .app-header, .no-print, .fab, .toast, #kkt-toast { display: none !important; }
  main.container { max-width: none; width: 210mm; margin: 0; padding: 0; }
  .print-only { display: block; }

  .rp-frame { width: 210mm; border-collapse: collapse; }
  .rp-frame > thead > tr > td, .rp-frame > tfoot > tr > td { height: 12mm; padding: 0; border: 0; }
  .rp-frame > tbody > tr > td { padding: 0 14mm; border: 0; }

  .rp { font-size: 11px; line-height: 1.45; color: #0A2540; }

  /* Header berwarna */
  .rp-head {
    background: linear-gradient(135deg, #0A2540 0%, #3B36B8 60%, #635BFF 100%);
    color: #fff; border-radius: 12px; padding: 18px 22px; margin-bottom: 14px;
    display: flex; justify-content: space-between; align-items: center; gap: 16px;
  }
  .rp-brand { display: flex; align-items: center; gap: 12px; }
  .rp-logo {
    width: 42px; height: 42px; border-radius: 10px; background: rgba(255,255,255,.16);
    border: 1px solid rgba(255,255,255,.35); display: flex; align-items: center; justify-content: center;
    font-size: 22px; font-weight: 800; color: #fff;
  }
  .rp-brand h1 { margin: 0; font-size: 18px; font-weight: 800; letter-spacing: -.01em; color: #fff; }
  .rp-brand p { margin: 2px 0 0; font-size: 10.5px; color: rgba(255,255,255,.75); letter-spacing: .06em; text-transform: uppercase; }
  .rp-period { text-align: right; }
  .rp-period small { display: block; font-size: 9.5px; letter-spacing: .08em; text-transform: uppercase; color: rgba(255,255,255,.7); }
  .rp-period strong { display: block; margin-top: 3px; font-size: 13px; font-weight: 700; color: #fff; }

  .rp-section { display: flex; align-items: center; gap: 8px; margin: 16px 0 8px; font-size: 12px; font-weight: 800; color: #0A2540; }
  .rp-section::before { content: ''; width: 4px; height: 14px; border-radius: 2px; background: #635BFF; }

  /* Kartu ringkasan */
  .rp-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
  .rp-card { border-radius: 10px; padding: 10px 12px; border: 1px solid #E3E8EF; background: #F6F8FA; break-inside: avoid; }
  .rp-card small { display: block; font-size: 9.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: #5B6B82; }
  .rp-card b { display: block; margin-top: 5px; font-size: 15px; font-weight: 800; color: #0A2540; }
  .rp-card.open { border-left: 4px solid #0A2540; }
  .rp-card.in { background: #E7F7EF; border-color: #BFE6D2; border-left: 4px solid #1F9D66; }
  .rp-card.in b { color: #157347; }
  .rp-card.out { background: #FBEAEA; border-color: #F1C7C7; border-left: 4px solid #D64545; }
  .rp-card.out b { color: #B23A3A; }
  .rp-card.end { background: #EDECFF; border-color: #CFCBFF; border-left: 4px solid #635BFF; }
  .rp-card.end b { color: #3B36B8; }

  .rp-meta { display: flex; gap: 18px; margin-top: 8px; font-size: 10px; color: #5B6B82; }
  .rp-meta b { color: #0A2540; }

  /* Tabel rincian */
  table.rp-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 10.5px; border: 1px solid #DDE3EC; border-radius: 8px; overflow: hidden; }
  .rp-table thead { display: table-header-group; }
  .rp-table th {
    background: #0A2540 !important; color: #fff; text-align: left; padding: 8px 10px;
    font-size: 9.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; white-space: nowrap;
  }
  .rp-table td { padding: 7px 10px; border-bottom: 1px solid #E9EDF3; vertical-align: top; }
  .rp-table tbody tr { break-inside: avoid; page-break-inside: avoid; }
  .rp-table tbody tr:nth-child(even) td { background: #F6F8FC; }
  .rp-table .num { text-align: right; white-space: nowrap; font-weight: 700; font-variant-numeric: tabular-nums; }
  .rp-table .c { text-align: center; color: #5B6B82; width: 26px; }
  .rp-table .in { color: #157347; }
  .rp-table .out { color: #B23A3A; }
  .rp-pill { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 9px; font-weight: 700; }
  .rp-pill.in { background: #E7F7EF; color: #157347; }
  .rp-pill.out { background: #FBEAEA; color: #B23A3A; }
  .rp-table tfoot { display: table-row-group; }
  .rp-table tfoot td { background: #EDECFF !important; font-weight: 800; border-bottom: 0; border-top: 2px solid #635BFF; color: #0A2540; }
  .rp-empty { text-align: center; padding: 24px 0 !important; color: #5B6B82; }

  .rp-foot {
    margin-top: 16px; padding-top: 8px; border-top: 2px solid #635BFF;
    display: flex; justify-content: space-between; font-size: 9.5px; color: #5B6B82; break-inside: avoid;
  }
}
