:root {
    --pd: #0b3d6e; --pm: #1565c0;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bot: env(safe-area-inset-bottom, 0px);
    --appbar-h: 56px; --bnav-h: 62px;
}
body { background: #f2f5f9; font-size: 14px; -webkit-tap-highlight-color: transparent; }
.bg-primary-dark { background: var(--pd); }

/* ================= Sidebar (desktop) / drawer (HP) ================= */
.sidebar { background: linear-gradient(180deg, var(--pd), #082b4e); color: #fff; }
@media (min-width: 992px) {
    .sidebar { position: fixed; top: 0; left: 0; bottom: 0; width: 240px; overflow-y: auto; }
    .main { margin-left: 240px; }
}
.sidebar .offcanvas-header { background: var(--pd); padding-top: calc(16px + var(--safe-top)); }
.sidebar-inner { padding: 15px 10px; }
.brand { gap: 10px; align-items: center; padding: 5px 10px 15px; border-bottom: 1px solid rgba(255,255,255,.15); }
.brand small, .user-box small { display: block; font-size: 11px; opacity: .75; }
.user-box { display: flex; gap: 10px; align-items: center; padding: 15px 10px; }
.user-box i { font-size: 30px; }
.sidebar .nav-link { color: #dbe7f5; border-radius: 8px; padding: 9px 12px; margin-bottom: 2px; }
.sidebar .nav-link i { width: 22px; display: inline-block; }
.sidebar .nav-link:hover { background: rgba(255,255,255,.1); color: #fff; }
.sidebar .nav-link.active { background: #fff; color: var(--pd); font-weight: 600; }
.nav-title { font-size: 11px; opacity: .6; padding: 14px 12px 4px; letter-spacing: 1px; }
.sidebar ul { list-style: none; padding: 0; }

.main { padding: 20px; min-height: 100vh; }

.card { border: 0; border-radius: 12px; box-shadow: 0 2px 8px rgba(0,0,0,.06); }
.card-header { background: #fff; border-bottom: 1px solid #eef1f5; font-weight: 600; border-radius: 12px 12px 0 0 !important; }
.page-title { font-weight: 700; color: var(--pd); margin-bottom: 15px; }

.stat-card { padding: 18px; border-radius: 14px; color: #fff; position: relative; overflow: hidden; min-height: 92px; }
.stat-card h3 { font-weight: 700; margin: 0; font-size: 28px; }
.stat-card i { position: absolute; right: 12px; top: 10px; font-size: 48px; opacity: .25; }
.bg-g1 { background: linear-gradient(135deg, #1565c0, #42a5f5); }
.bg-g2 { background: linear-gradient(135deg, #2e7d32, #66bb6a); }
.bg-g3 { background: linear-gradient(135deg, #ef6c00, #ffa726); }
.bg-g4 { background: linear-gradient(135deg, #6a1b9a, #ab47bc); }

.table thead th { background: #eef3fa; font-size: 13px; white-space: nowrap; }
.table td { vertical-align: middle; }

/* Scanner */
#reader { width: 100%; max-width: 480px; margin: auto; border-radius: 10px; overflow: hidden; }
#reader video { border-radius: 10px; }

/* Signature pad */
.sig-wrap { border: 2px dashed #90a4ae; border-radius: 10px; background: #fff; position: relative; touch-action: none; }
#sigCanvas { width: 100%; height: 260px; display: block; touch-action: none; cursor: crosshair; }
.sig-hint { position: absolute; bottom: 8px; left: 0; right: 0; text-align: center; color: #b0bec5; font-size: 12px; pointer-events: none; }
.sig-line { position: absolute; left: 10%; right: 10%; bottom: 30px; border-bottom: 1px solid #cfd8dc; pointer-events: none; }

.pilih-bukti .btn { padding: 18px 4px; font-size: 13px; border-radius: 14px; }
.pilih-bukti .btn i { font-size: 34px; display: block; }
#previewFoto { max-width: 100%; max-height: 320px; border-radius: 8px; }
.bukti-img { max-width: 100%; max-height: 400px; border: 1px solid #ddd; border-radius: 8px; background: #fff; }

/* ================= Kelola (iframe di modal) ================= */
body.embed { background: #f2f5f9; }
body.embed .main { margin-left: 0 !important; padding: 12px !important; min-height: 0; }
.kelola-body { padding: 0 !important; height: 78vh; }
.kelola-frame { display: block; width: 100%; height: 100%; border: 0; }
.ac-hint { font-size: 12px; }

/* ================= Login ================= */
.login-bg { min-height: 100vh; min-height: 100dvh; background: linear-gradient(160deg, #0b3d6e, #1565c0 60%, #42a5f5); display: flex; align-items: center; justify-content: center; padding: calc(20px + var(--safe-top)) 16px calc(20px + var(--safe-bot)); }
.login-card { max-width: 390px; width: 100%; border-radius: 22px; }
.login-logo { width: 84px; height: 84px; border-radius: 22px; box-shadow: 0 8px 22px rgba(11,61,110,.35); }
.login-card .form-control, .login-card .input-group-text, .login-card .btn { border-radius: 12px; }
.login-card .input-group > :not(:first-child) { border-top-left-radius: 0; border-bottom-left-radius: 0; }
.login-card .input-group > :not(:last-child) { border-top-right-radius: 0; border-bottom-right-radius: 0; }

/* ================= Popup install ================= */
.install-card { border-radius: 22px; border: 0; }
.install-icon { width: 84px; height: 84px; border-radius: 20px; box-shadow: 0 6px 18px rgba(0,0,0,.2); }
.install-step { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px dashed #e3e8ef; font-size: 14px; }
.install-step span { flex: 0 0 26px; height: 26px; border-radius: 50%; background: var(--pm); color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; font-size: 13px; }
.ios-arrow { text-align: center; font-size: 28px; color: var(--pm); animation: bounce 1s infinite; }
@keyframes bounce { 50% { transform: translateY(8px); } }

/* ================= Banner koneksi ================= */
.net-banner { display: none; position: fixed; left: 50%; transform: translateX(-50%); top: calc(var(--appbar-h) + var(--safe-top) + 8px); z-index: 1090; padding: 8px 16px; border-radius: 30px; font-size: 13px; color: #fff; box-shadow: 0 4px 14px rgba(0,0,0,.2); white-space: nowrap; max-width: 94vw; overflow: hidden; text-overflow: ellipsis; }
.net-banner.off { background: #c62828; }
.net-banner.on { background: #2e7d32; }
@media (min-width: 992px) { .net-banner { top: 12px; } }

/* =====================================================
   TAMPILAN HP (seperti aplikasi)
   ===================================================== */
.appbar, .bottom-nav { display: none; }
@media (max-width: 991.98px) {
    body.has-appbar { padding-top: calc(var(--appbar-h) + var(--safe-top)); padding-bottom: calc(var(--bnav-h) + var(--safe-bot)); }
    .main { padding: 12px 12px 16px; min-height: 0; }

    .appbar { display: flex; position: fixed; top: 0; left: 0; right: 0; z-index: 1030; align-items: center; gap: 4px;
        height: calc(var(--appbar-h) + var(--safe-top)); padding: var(--safe-top) 6px 0; background: var(--pd); color: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.18); }
    .appbar-title { flex: 1; font-weight: 600; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center; }
    .appbar-btn { width: 44px; height: 44px; border: 0; background: transparent; color: #fff; font-size: 24px; border-radius: 50%; display: flex; align-items: center; justify-content: center; text-decoration: none; }
    .appbar-btn:active { background: rgba(255,255,255,.15); }

    .bottom-nav { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 1030; background: #fff;
        height: calc(var(--bnav-h) + var(--safe-bot)); padding-bottom: var(--safe-bot); box-shadow: 0 -2px 12px rgba(0,0,0,.08); border-top: 1px solid #e8edf3; }
    .bottom-nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; color: #7a8899; text-decoration: none; font-size: 11px; position: relative; }
    .bottom-nav a i { font-size: 21px; line-height: 1; }
    .bottom-nav a.active { color: var(--pm); font-weight: 600; }
    .bottom-nav a.active::before { content: ''; position: absolute; top: 0; width: 28px; height: 3px; border-radius: 0 0 3px 3px; background: var(--pm); }
    .bottom-nav a.bn-fab i { width: 52px; height: 52px; margin-top: -26px; border-radius: 50%; background: linear-gradient(135deg, #1565c0, #42a5f5); color: #fff;
        display: flex; align-items: center; justify-content: center; font-size: 26px; box-shadow: 0 6px 16px rgba(21,101,192,.45); border: 4px solid #fff; }
    .bottom-nav a.bn-fab.active::before { display: none; }

    /* judul halaman sudah ada di app bar */
    .page-title { font-size: 1.15rem; }
    h4.page-title.mb-0 { display: none; }
    .flash-wrap, .alert { border-radius: 12px; }

    /* sentuhan lebih besar & cegah zoom iOS saat fokus input */
    .form-control, .form-select, .input-group-text { font-size: 16px !important; min-height: 44px; }
    .form-control-sm, .form-select-sm { min-height: 38px; }
    .btn { min-height: 40px; }
    .btn-sm { min-height: 34px; }
    .card { border-radius: 14px; }
    .stat-card { padding: 14px; }
    .stat-card h3 { font-size: 24px; }
    .stat-card i { font-size: 38px; }

    .offcanvas-lg.sidebar { width: 82vw !important; max-width: 320px; }
    .modal-dialog-scrollable .modal-content { max-height: 100%; }
    .kelola-body { height: auto; flex: 1; }
    .modal-fullscreen-md-down .modal-content { padding-top: var(--safe-top); }
    .modal-fullscreen-sm-down .modal-content { padding-top: var(--safe-top); }

    /* tombol aksi atas halaman: rata & bisa wrap */
    .page-actions { width: 100%; }
    .page-actions .btn { flex: 1 1 auto; }
}

/* ===== Tabel -> kartu di HP (class .tbl-card) ===== */
@media screen and (max-width: 767.98px) {
    .card-list { background: transparent; box-shadow: none; }
    .card-list > .card-footer { background: transparent !important; border: 0; }
    .card-list .table-responsive { overflow: visible; }
    table.tbl-card { border-collapse: separate; border-spacing: 0; background: transparent !important; }
    table.tbl-card thead { display: none; }
    table.tbl-card, table.tbl-card tbody { display: block; width: 100%; }
    table.tbl-card tbody tr { display: block; background: #fff; border-radius: 14px; margin: 0 0 10px; padding: 10px 14px;
        box-shadow: 0 2px 8px rgba(0,0,0,.06); border: 1px solid #edf1f6; }
    table.tbl-card.table-hover tbody tr:hover > * { --bs-table-accent-bg: transparent; }
    table.tbl-card tbody td { display: flex; justify-content: flex-end; flex-wrap: wrap; align-items: center; column-gap: 6px; row-gap: 0; border: 0 !important;
        padding: 4px 0 !important; text-align: right; background: transparent !important; box-shadow: none !important; min-height: 26px; }
    table.tbl-card tbody td > br { display: none; }
    table.tbl-card tbody td::before { content: attr(data-label); flex: 0 0 38%; margin-right: auto; text-align: left; color: #7a8899; font-size: 12px; font-weight: 600; }
    table.tbl-card tbody td[data-label=""]::before, table.tbl-card td.no-label::before { display: none; }
    table.tbl-card td.td-title { font-size: 15px; font-weight: 700; color: var(--pd); justify-content: flex-start; text-align: left; padding-bottom: 6px !important; border-bottom: 1px solid #f0f3f7 !important; margin-bottom: 4px; }
    table.tbl-card td.td-title::before { display: none; }
    table.tbl-card td.td-no { display: none; }
    table.tbl-card td.td-aksi { justify-content: flex-end; flex-wrap: wrap; gap: 6px; border-top: 1px dashed #e3e8ef !important; margin-top: 6px; padding-top: 10px !important; }
    table.tbl-card td.td-aksi::before { display: none; }
    table.tbl-card td.td-aksi .btn { min-width: 42px; }
    table.tbl-card td.td-aksi .btn-success { flex: 1; }
    table.tbl-card td[colspan] { justify-content: center; text-align: center; }
    table.tbl-card td.td-check { position: absolute; }
    table.tbl-card tbody tr { position: relative; }
    table.tbl-card td.td-check { top: 10px; right: 12px; padding: 0 !important; min-height: 0; }
    table.tbl-card td.td-check::before { display: none; }
}

/* ================= Cetak ================= */
.print-only { display: none !important; }
@media print {
    .no-print, .sidebar, .navbar, .appbar, .bottom-nav, .net-banner, footer, .btn { display: none !important; }
    body.has-appbar { padding: 0 !important; }
    .main { margin: 0 !important; padding: 0 !important; }
    body { background: #fff; }
    .card { box-shadow: none; }
    div.print-only, p.print-only { display: block !important; }
    th.print-only, td.print-only { display: table-cell !important; }
    .print-hide { display: none !important; }
    .table { font-size: 11px; }
    .table-responsive { overflow: visible !important; }
    @page { size: A4 landscape; margin: 10mm; }
}
