:root {
  /* Merah utama diredupkan (maroon lembut) supaya tidak terlalu mencolok,
     tetap selaras dengan warna logo, dipakai untuk aksen & tombol utama. */
  --merah: #A6323D;
  --merah-gelap: #832531;
  --merah-lembut: #F6E9EA;
  --hitam: #23211F;
  --abu: #F7F5F2;
  --abu-tua: #EFEBE6;
  --border: #E4DFD8;
  --teks: #33302C;
  --teks-lembut: #74706A;
  --sukses: #3D7A5C;
  --sukses-lembut: #E7F1EB;
  --bahaya: #A6323D;
  --bahaya-lembut: #F6E9EA;
  --warning: #9C7A2E;
  --warning-lembut: #F5EFDE;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', Tahoma, sans-serif;
  background: var(--abu);
  color: var(--teks);
  overflow-x: hidden;
}

a { text-decoration: none; color: inherit; }

/* ---------- LAYOUT ---------- */
.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  background: var(--hitam);
  color: #fff;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px;
  border-bottom: 1px solid #38352F;
}
.sidebar .brand img { width: 42px; height: 42px; border-radius: 50%; }
.sidebar .brand div { font-weight: 700; line-height: 1.2; font-size: 15px; }
.sidebar .brand span { font-weight: 400; font-size: 11px; color: #A39C93; }

.sidebar nav { flex: 1; padding: 10px 0; }
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  color: #D8D2C9;
  font-size: 14.5px;
  border-left: 3px solid transparent;
}
.sidebar nav a:hover { background: #302C27; }
.sidebar nav a.active {
  background: #302C27;
  border-left: 3px solid var(--merah);
  color: #fff;
  font-weight: 600;
}
.sidebar .logout {
  padding: 14px 20px;
  border-top: 1px solid #38352F;
  color: #D9AEB2;
  font-size: 14px;
}

.main {
  flex: 1;
  min-width: 0;
}

.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.topbar .topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}
.topbar h1 { font-size: 19px; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; flex: 1; }
.topbar .user-chip {
  background: var(--abu);
  padding: 5px 14px 5px 5px;
  border-radius: 30px;
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.topbar .user-chip:hover { background: var(--abu-tua); }
.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--hitam);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12.5px;
  font-weight: 800;
  flex-shrink: 0;
}

.content { padding: 24px; min-width: 0; }

/* ---------- HAMBURGER (mobile only) ---------- */
.hamburger-btn {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
  flex-shrink: 0;
}
.hamburger-btn span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--hitam);
  margin: 5px 0;
  border-radius: 2px;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 998;
}
.sidebar-overlay.show { display: block; }

/* ---------- RESPONSIVE (mobile) ---------- */
@media (max-width: 768px) {
  .hamburger-btn { display: block; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 260px;
    max-width: 82vw;
    z-index: 999;
    transform: translateX(-100%);
    transition: transform .25s ease;
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); }

  .topbar { padding: 12px 16px; }
  .topbar h1 { font-size: 16.5px; }
  .content { padding: 14px; }

  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr 1fr; }

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

  .page-header { flex-wrap: wrap; gap: 10px; }

  .login-box { width: 100%; max-width: 340px; padding: 24px 20px 20px; }

  .modal-box { padding: 18px; }

  .kop-surat { flex-direction: column; text-align: center; }
  .kop-teks { text-align: center; }

  .ttd-blok { flex-direction: column; align-items: center; }
  .ttd-kolom { width: 100%; }
}

@media (max-width: 480px) {
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
}

/* ---------- TABLE RESPONSIVE ---------- */
.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table-responsive table { min-width: 560px; }

/* ---------- CARDS ---------- */
.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  margin-bottom: 20px;
}

.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
@media (max-width: 900px) {
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr 1fr; }
}

.grid-dok {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
}
@media (max-width: 600px) {
  .grid-dok { grid-template-columns: repeat(3, 1fr); gap: 8px; }
}

.stat-card { text-align: left; }
.stat-card .label { font-size: 12.5px; color: var(--teks-lembut); text-transform: uppercase; letter-spacing: .04em; }
.stat-card .value { font-size: 24px; font-weight: 800; margin-top: 6px; }
.stat-card.merah .value { color: var(--merah); }
.stat-card.sukses .value { color: var(--sukses); }
.stat-card.bahaya .value { color: var(--bahaya); }

/* ---------- TABLE ---------- */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; }
th { background: var(--abu); font-weight: 700; font-size: 12.5px; text-transform: uppercase; color: var(--teks-lembut); }
tr:hover td { background: var(--abu); }

/* ---------- BADGE ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 700; }
.badge.hijau { background: var(--sukses-lembut); color: var(--sukses); }
.badge.merah { background: var(--bahaya-lembut); color: var(--bahaya); }
.badge.kuning { background: var(--warning-lembut); color: var(--warning); }
.badge.abu { background: var(--abu-tua); color: var(--teks-lembut); }

/* ---------- BADGE NOTIFIKASI (angka kecil di menu sidebar/bottom-nav) ---------- */
.nav-badge {
  margin-left: auto;
  background: var(--merah);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.bn-dot {
  position: absolute;
  top: 2px;
  right: 6px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--merah);
  border: 1.5px solid #fff;
}
.bn-icon { position: relative; display: inline-flex; }

/* ---------- ICONS ---------- */
.ic { flex-shrink: 0; vertical-align: -3px; }

/* ---------- BUTTONS ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 7px;
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
}
.btn-merah { background: var(--merah); color: #fff; }
.btn-merah:hover { background: var(--merah-gelap); }
.btn-hitam { background: var(--hitam); color: #fff; }
.btn-outline { background: #fff; border: 1px solid var(--border); color: var(--teks); }
.btn-hijau { background: var(--sukses); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 6px; }
.btn-wa { background: #25D366; color: #fff; }

/* ---------- FORM ---------- */
.form-group { margin-bottom: 14px; }
.form-group label { display: block; margin-bottom: 5px; font-size: 13.5px; font-weight: 600; color: var(--teks); }
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 14px;
  font-family: inherit;
}
.form-row { display: flex; gap: 14px; }
.form-row .form-group { flex: 1; }

.password-wrap { position: relative; }
.password-wrap input { padding-right: 42px; }
.toggle-pass {
  position: absolute;
  right: 2px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px 10px;
  color: var(--teks-lembut);
  line-height: 1;
  display: flex;
  align-items: center;
}
.toggle-pass:hover { color: var(--teks); }

/* ---------- CHART ---------- */
.chart-wrap { position: relative; height: 280px; }
@media (max-width: 600px) {
  .chart-wrap { height: 220px; }
}

/* ---------- LOGIN PAGE ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--hitam), var(--merah-gelap));
}
.login-box {
  background: #fff;
  width: min(380px, 92vw);
  border-radius: 14px;
  padding: 30px 30px 24px;
  box-shadow: 0 20px 50px rgba(35,33,31,.28);
}
.login-box img { width: 70px; height: 70px; display: block; margin: 0 auto 8px; border-radius: 50%; }
.login-box h2 { text-align: center; margin: 0 0 2px; font-size: 19px; }
.login-box p.sub { text-align: center; color: var(--teks-lembut); font-size: 13px; margin-bottom: 20px; }
.tab-switch { display: flex; background: var(--abu); border-radius: 8px; padding: 4px; margin-bottom: 20px; }
.tab-switch button {
  flex: 1; padding: 8px; border: none; background: transparent; border-radius: 6px;
  cursor: pointer; font-weight: 600; font-size: 13.5px; color: var(--teks-lembut);
}
.tab-switch button.active { background: #fff; color: var(--merah); box-shadow: 0 1px 3px rgba(0,0,0,.15); }

/* ---------- MODAL / POPUP ---------- */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  align-items: center; justify-content: center;
  z-index: 999;
}
.modal-overlay.show { display: flex; }
.modal-box {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  width: min(380px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
}
.modal-box h3 { margin-top: 0; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }

.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.alert-sukses { background: var(--sukses-lembut); color: var(--sukses); border: 1px solid #cfe3d8; }
.alert-bahaya { background: var(--bahaya-lembut); color: var(--bahaya); border: 1px solid #e6c7ca; }
.alert-warning { background: var(--warning-lembut); color: var(--warning); border: 1px solid #e6d7ac; }

.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.page-header h2 { margin: 0; font-size: 20px; }

.filter-bar { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; margin-bottom: 16px; }

/* Print */
@media print {
  .sidebar, .topbar, .bottom-nav, .sidebar-overlay, .no-print { display: none !important; }
  .app, .main, .content { display: block !important; padding: 0 !important; margin: 0 !important; }
  .content { padding: 0; }
  body { background: #fff; }
  #area-cetak { border: none !important; box-shadow: none !important; border-radius: 0 !important; padding: 0 !important; }
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }
}

/* ---------- DOKUMENTASI ---------- */
.doc-card { padding: 8px; margin-bottom: 0; }
.doc-thumb { width: 100%; height: 90px; object-fit: cover; border-radius: 6px; cursor: pointer; display: block; }
.doc-card .doc-caption { font-size: 12px; margin: 6px 0 2px; }
.doc-card .doc-meta { font-size: 10.5px; }
.doc-caption { font-size: 13.5px; font-weight: 600; margin: 10px 0 2px; line-height: 1.35; }
.doc-meta { font-size: 11.5px; color: var(--teks-lembut); margin: 0; }

/* ---------- KOP SURAT (laporan cetak) ---------- */
.kop-surat {
  display: flex;
  align-items: center;
  gap: 16px;
  padding-bottom: 10px;
}
.kop-logo { width: 70px; height: 70px; object-fit: contain; flex-shrink: 0; }
.kop-teks { flex: 1; text-align: center; }
.kop-teks h1 { margin: 0; font-size: 21px; letter-spacing: .04em; text-transform: uppercase; font-weight: 800; }
.kop-teks p { margin: 4px 0 0; font-size: 12.5px; color: var(--teks); }
.kop-garis-tebal { height: 3px; background: var(--hitam); margin-top: 4px; }
.kop-garis-tipis { height: 1px; background: var(--hitam); margin-top: 3px; margin-bottom: 18px; }
@media print {
  .kop-garis-tebal, .kop-garis-tipis { background: #000; }
}

/* ---------- SURAT LAPORAN (meta, paragraf, tanda tangan) ---------- */
.surat-meta { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 16px; flex-wrap: wrap; gap: 10px; }
.meta-table { border: none; width: auto; }
.meta-table td { border: none; padding: 1px 4px; font-size: 13.5px; vertical-align: top; }
.meta-table td:first-child { padding-left: 0; white-space: nowrap; }
.surat-tanggal { font-size: 13.5px; }
.surat-paragraf { font-size: 13.5px; line-height: 1.6; text-align: justify; margin: 0 0 18px; }

.ttd-blok { display: flex; justify-content: space-between; margin-top: 30px; gap: 20px; }
.ttd-kolom { text-align: center; font-size: 13.5px; width: 240px; }
.ttd-spasi { height: 60px; }
.ttd-nama { font-weight: 700; text-decoration: underline; }


/* ---------- FORM HINT ---------- */
.form-hint {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--teks-lembut);
  line-height: 1.4;
}

/* ---------- MOBILE POLISH ---------- */
@media (max-width: 768px) {
  .card { padding: 14px; margin-bottom: 14px; border-radius: 8px; }

  .form-group input,
  .form-group select,
  .form-group textarea {
    font-size: 16px; /* hindari zoom otomatis di iOS */
    padding: 11px 12px;
  }

  .btn-block-mobile {
    display: block;
    width: 100%;
    text-align: center;
    padding: 12px 16px;
  }

  .page-header h2 { font-size: 17px; }

  .table-responsive table { min-width: 0; width: 100%; }

  /* Tabel jadi kartu di layar kecil */
  .table-responsive table thead { display: none; }
  .table-responsive table,
  .table-responsive table tbody,
  .table-responsive table tr,
  .table-responsive table td {
    display: block;
    width: 100%;
  }
  .table-responsive table tr {
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-bottom: 10px;
    padding: 10px 12px;
    background: #fff;
  }
  .table-responsive table td {
    border: none;
    padding: 4px 0;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
    font-size: 13.5px;
  }
  .table-responsive table td::before {
    content: attr(data-label);
    font-weight: 700;
    color: var(--teks-lembut);
    font-size: 12px;
    text-transform: uppercase;
    flex-shrink: 0;
    min-width: 90px;
  }
  .table-responsive table td[colspan] {
    display: block;
    text-align: center;
  }
  .table-responsive table td[colspan]::before { content: none; }

  .modal-box { width: 92vw; max-width: 400px; margin: 12px; }
  .modal-actions { flex-direction: column; }
  .modal-actions .btn { width: 100%; text-align: center; }
}

@media (max-width: 480px) {
  .content { padding: 12px; }
  .user-chip { font-size: 12px; padding: 3px 10px 3px 3px; }
  .topbar h1 { font-size: 15px; }
}

/* ======================================================
   TAMPILAN APP MOBILE (bottom nav, top bar, kartu bulat)
   Hanya aktif di layar kecil - tampilan desktop tidak berubah
   ====================================================== */
.bottom-nav { display: none; }

@media (max-width: 768px) {
  /* ---------- Top bar ala aplikasi ---------- */
  .topbar {
    position: sticky;
    top: 0;
    z-index: 500;
    border-radius: 0 0 22px 22px;
    box-shadow: 0 4px 16px rgba(17, 17, 17, .06);
  }
  .user-text { display: none; }
  .user-chip {
    padding: 3px;
    background: transparent;
  }
  .user-avatar { width: 36px; height: 36px; font-size: 14px; }

  /* ---------- Kartu ala aplikasi: bulat, tanpa garis tepi, bayangan lembut ---------- */
  .card {
    border: none;
    border-radius: 18px;
    box-shadow: 0 2px 14px rgba(17, 17, 17, .06);
  }

  .stat-card { border-radius: 18px; padding: 16px; }
  .stat-card .label { color: var(--teks-lembut); }
  .stat-card.sukses { background: var(--sukses-lembut); }
  .stat-card.bahaya { background: var(--bahaya-lembut); }
  .stat-card.merah { background: var(--merah-lembut); }

  .modal-box { border-radius: 20px; }

  /* ---------- Tombol & badge lebih membulat ---------- */
  .btn { border-radius: 12px; }
  .btn-sm { border-radius: 8px; }
  .badge { border-radius: 30px; }

  /* ---------- Tombol aksi utama di bawah judul halaman, full width ---------- */
  .page-header {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .page-header .btn {
    width: 100%;
    text-align: center;
    padding: 12px;
  }

  /* ---------- Filter bar jadi kartu ---------- */
  .filter-bar {
    background: #fff;
    padding: 12px;
    border-radius: 16px;
    box-shadow: 0 2px 14px rgba(17, 17, 17, .06);
    margin-bottom: 16px;
  }
  .filter-bar .form-group { flex: 1 1 120px; }

  /* ---------- Ruang bawah supaya konten tidak tertutup bottom nav ---------- */
  .content { padding-bottom: 88px; }

  /* ---------- Bottom navigation bar ---------- */
  .bottom-nav {
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 950;
    background: #fff;
    border-top: 1px solid var(--border);
    box-shadow: 0 -6px 20px rgba(17, 17, 17, .07);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
    justify-content: space-around;
    align-items: stretch;
  }
  .bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 6px 2px;
    margin: 0 2px;
    border-radius: 12px;
    color: #A39C93;
    font-size: 10.5px;
    font-weight: 600;
    text-align: center;
  }
  .bottom-nav a .bn-icon { font-size: 19px; line-height: 1; }
  .bottom-nav a.active { color: var(--merah); background: var(--merah-lembut); }
}

@media (max-width: 480px) {
  .content { padding-bottom: 84px; }
  .bottom-nav a { font-size: 10px; }
}
