:root {
  --brand-red: #8b1e1e;
  --brand-navy: #0b2a4a;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body {
  background: #f4f5f7;
  padding-bottom: calc(72px + var(--safe-bottom)); /* ruang untuk bottom nav di HP */
  font-size: 15px;
}
@media (min-width: 768px) {
  body { padding-bottom: 24px; font-size: 15px; }
}

/* ===== Header atas ===== */
.app-topbar {
  background: #fff;
  border-bottom: 1px solid #e3e5e8;
  position: sticky;
  top: 0;
  z-index: 20;
}
.app-logo { height: 40px; width: auto; }
.app-title { font-weight: 700; font-size: 0.95rem; color: var(--brand-navy); line-height: 1.1; }
.app-subtitle { font-size: 0.72rem; color: #6c757d; }
@media (min-width: 768px) {
  .app-logo { height: 52px; }
  .app-title { font-size: 1.15rem; }
}

.app-content { padding: 12px; max-width: 1100px; margin: 0 auto; }

/* ===== Bottom nav (mobile) ===== */
.app-bottomnav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: #fff;
  border-top: 1px solid #e3e5e8;
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 6px 4px calc(6px + var(--safe-bottom));
  z-index: 30;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.05);
}
.bn-item {
  display: flex; flex-direction: column; align-items: center;
  font-size: 0.65rem; color: #6c757d; text-decoration: none;
  gap: 2px; min-width: 52px; padding: 4px 0;
}
.bn-item i { font-size: 1.25rem; }
.bn-item.active { color: var(--brand-red); font-weight: 600; }
.bn-fab {
  background: var(--brand-red);
  color: #fff !important;
  width: 50px; height: 50px;
  border-radius: 50%;
  margin-top: -22px;
  box-shadow: 0 3px 10px rgba(139,30,30,0.4);
  justify-content: center;
}
.bn-fab i { font-size: 1.5rem; }

/* ===== Kartu entri ala mobile (dipakai di form input) ===== */
.entry-card {
  background: #fff;
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.entry-card .form-label { font-size: 0.78rem; color: #6c757d; margin-bottom: 2px; }
.entry-card .form-control, .entry-card .form-select {
  font-size: 1rem;
  padding: 10px 12px;
}
/* Target sentuh besar - nyaman untuk jempol di HP kecil */
.btn-touch { min-height: 46px; font-size: 1rem; }

.stok-akhir-preview {
  background: #eef6ee;
  border: 1px dashed #7cb87c;
  border-radius: 8px;
  padding: 8px 12px;
  font-weight: 700;
  color: #1e6b1e;
}

/* ===== Preview foto barang (upload penerimaan) ===== */
.photo-preview {
  display: flex; align-items: center; gap: 10px;
  background: #f8f9fa; border: 1px solid #e3e5e8; border-radius: 8px; padding: 8px;
}
.photo-preview img {
  width: 64px; height: 64px; object-fit: cover; border-radius: 6px; border: 1px solid #ddd;
}
.photo-remove-chk { font-size: 0.78rem; color: #dc3545; display: flex; align-items: center; gap: 4px; }
.photo-btn-row { display: flex; gap: 8px; }
.photo-btn-row .btn { font-size: 0.88rem; }

/* ===== Tabel rekap (desktop nyaman, mobile bisa discroll) ===== */
.table-recap-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-recap { background: #fff; font-size: 0.85rem; }
.table-recap th { white-space: nowrap; background: #f1f3f5; position: sticky; top: 0; }

/* ===== Kartu ringkas untuk list di mobile ===== */
.list-card {
  background: #fff; border-radius: 10px; padding: 12px 14px;
  margin-bottom: 8px; box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  display: flex; justify-content: space-between; align-items: center;
  text-decoration: none; color: inherit;
}
.list-card .lc-title { font-weight: 600; color: var(--brand-navy); }
.list-card .lc-sub { font-size: 0.78rem; color: #6c757d; }

/* ===== Fitur riwayat/kartu-stok/dashboard tambahan ===== */
#chartTren, #chartKartuStok { max-width: 100%; }
#chartTren canvas, #chartKartuStok canvas { max-height: 260px; }
.table-recap td, .table-recap th { vertical-align: middle; }

/* =========================================================
   AREA CETAK / PDF -- mengikuti layout dokumen asli
   Sembunyi di layar, hanya tampil & aktif saat print/save-as-pdf
   ========================================================= */
.print-only { display: none; }

/* ---------------------------------------------------------
   KOP SURAT -- meniru persis kop dokumen asli SPPG
   Berlaku di layar (pratinjau) maupun saat cetak/PDF
   --------------------------------------------------------- */
.print-doc {
  font-family: 'Times New Roman', Times, serif;
  color: #000;
  background: #fff;
}

.kop-surat {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 6px 4px 10px;
}
.kop-logo { height: 90px; width: 90px; object-fit: contain; flex: 0 0 auto; }
.kop-text { text-align: center; flex: 1 1 auto; }
.kop-nama { font-size: 17pt; font-weight: 700; letter-spacing: .3px; text-transform: uppercase; line-height: 1.25; }
.kop-yayasan { font-size: 12pt; line-height: 1.3; }
.kop-alamat { font-size: 11pt; line-height: 1.3; }
.kop-email { font-size: 11pt; line-height: 1.3; }
.kop-email a { color: #1155cc; text-decoration: underline; }

.kop-garis { height: 4px; background: #808080; margin: 0 0 8px; }

.kop-judul-dok {
  text-align: center;
  font-weight: 700;
  font-size: 13pt;
  text-transform: uppercase;
  margin-bottom: 4px;
  letter-spacing: .3px;
}

.print-header { text-align: center; margin-bottom: 8px; }
.print-header .ph-sub { font-size: 10pt; }

table.sortable th.th-sortable {
  cursor: pointer;
  user-select: none;
  position: relative;
  padding-right: 20px !important;
}
table.sortable th.th-sortable:hover { background: #f1f3f5; }
table.sortable th.th-sortable::after {
  content: '\2195';
  position: absolute;
  right: 6px;
  opacity: .35;
  font-size: .85em;
}
table.sortable th.th-sort-asc::after { content: '\2191'; opacity: 1; color: #8b1e1e; }
table.sortable th.th-sort-desc::after { content: '\2193'; opacity: 1; color: #8b1e1e; }

@media print {
  body { background: #fff; padding-bottom: 0; }
  .app-topbar, .app-bottomnav, .no-print { display: none !important; }
  .app-content { padding: 0; max-width: 100%; }
  .print-only { display: block; }
  .print-doc { width: 100%; }

  .kop-logo { height: 75px; width: 75px; }
  .kop-nama { font-size: 15pt; }
  .kop-yayasan, .kop-alamat, .kop-email { font-size: 10pt; }

  table.print-table {
    width: 100%; border-collapse: collapse; font-size: 9pt;
  }
  table.print-table th, table.print-table td {
    border: 1px solid #000; padding: 3px 5px; vertical-align: middle;
  }
  table.print-table th { text-align: center; font-weight: 700; background: #eee !important; -webkit-print-color-adjust: exact; }
  table.print-table td.num { text-align: right; }
  table.print-table td.center { text-align: center; }
  table.print-table img.print-photo {
    width: 55px; height: 55px; object-fit: cover; border: 1px solid #000;
  }

  .print-doc + .print-doc { page-break-before: always; }

  @page { size: A4 landscape; margin: 10mm 8mm; }
}
