/* ============================================================
   Kontrakanku — custom CSS (mobile-first, Bootstrap 5 sebagai basis)
   Urutan: base -> komponen mobile -> media query >= 576px -> >= 992px
   ============================================================ */

:root {
    --kk-primary: #0e7c6b;
    --kk-primary-dark: #0a5c50;
    --kk-ink: #1c2420;
    --kk-muted: #6b7672;
    --kk-bg: #f4f6f5;
    --kk-card: #ffffff;
    --kk-line: #e4e9e7;
    --kk-danger: #c2410c;
    --kk-danger-bg: #fef3ec;
    --kk-warn: #92400e;
    --kk-warn-bg: #fef6e7;
    --kk-ok: #0e7c6b;
    --kk-ok-bg: #e6f4f1;
    --kk-info-bg: #eef2f1;
    --kk-radius: 16px;
    --kk-touch: 44px;
}

* { -webkit-tap-highlight-color: transparent; }

html { scroll-behavior: smooth; }

body {
    background: var(--kk-bg);
    color: var(--kk-ink);
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    overflow-x: clip;
}

img, svg, video { max-width: 100%; }

/* ---------- Shell / sidebar (desktop) ---------- */

.kk-shell { min-height: 100vh; min-height: 100dvh; }

.kk-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 248px;
    flex-direction: column;
    background: #0d2b26;
    color: #e8efed;
    padding: 20px 14px;
    z-index: 1030;
}

.kk-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
    text-decoration: none;
    color: inherit;
    font-weight: 800;
    font-size: 1.15rem;
    padding: 4px 8px 16px;
}

.kk-brand-mark {
    width: 36px;
    height: 36px;
    flex: 0 0 auto;
    border-radius: 11px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--kk-primary);
    color: #fff;
    font-size: 1.1rem;
}

.kk-brand-text {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.kk-nav { display: flex; flex-direction: column; gap: 4px; }

.kk-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: var(--kk-touch);
    padding: 8px 12px;
    border-radius: 12px;
    color: #c6d2ce;
    text-decoration: none;
    font-weight: 600;
    font-size: .95rem;
}

.kk-nav a i { font-size: 1.1rem; }
.kk-nav a:hover { background: rgba(255,255,255,.08); color: #fff; }
.kk-nav a.active { background: var(--kk-primary); color: #fff; }

.kk-sidebar-foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid rgba(255,255,255,.12); }
.kk-user { font-weight: 700; margin-bottom: 6px; overflow-wrap: break-word; }
.kk-logout {
    background: none; border: 0; color: #c6d2ce; font-weight: 600;
    padding: 10px 0; cursor: pointer; min-height: var(--kk-touch);
}
.kk-logout:hover { color: #fff; }

/* ---------- Main + mobile header ---------- */

.kk-main { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; min-width: 0; }

.kk-topbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 56px;
    padding: 8px 12px;
    padding-top: max(8px, env(safe-area-inset-top));
    background: rgba(244,246,245,.94);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--kk-line);
}

.kk-topbar .kk-brand { color: var(--kk-ink); padding: 0; font-size: 1.05rem; flex: 1 1 auto; }
.kk-topbar-title { font-weight: 800; font-size: 1.1rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kk-topbar-user {
    margin-left: auto;
    font-size: .82rem;
    color: var(--kk-muted);
    font-weight: 600;
    min-width: 0;
    max-width: 38vw;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.kk-admin { margin-left: auto; min-width: 0; }

.mobile-profile-trigger,
.kk-profile-btn {
    appearance: none;
    -webkit-appearance: none;
    margin: 0;
    font: inherit;
    text-transform: none;
    text-decoration: none;
    box-shadow: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: var(--kk-touch);
    height: var(--kk-touch);
    background: var(--kk-info-bg);
    border: 1px solid var(--kk-line);
    border-radius: 999px;
    color: var(--kk-ink);
    font-size: 1.45rem;
    line-height: 1;
    padding: 0 10px 0 8px;
    touch-action: manipulation;
    user-select: none;
    -webkit-user-select: none;
}

.mobile-profile-trigger .kk-profile-caret,
.kk-profile-btn .kk-profile-caret {
    font-size: .7rem;
    color: var(--kk-muted);
    line-height: 1;
}

.mobile-profile-trigger > i,
.kk-profile-btn > i { pointer-events: none; }

@media (hover: hover) and (pointer: fine) {
    .mobile-profile-trigger,
    .kk-profile-btn { cursor: pointer; }
    .mobile-profile-trigger:hover,
    .kk-profile-btn:hover {
        background: var(--kk-ok-bg);
        border-color: var(--kk-primary);
        color: var(--kk-primary-dark);
    }
    .mobile-profile-trigger:hover .kk-profile-caret,
    .kk-profile-btn:hover .kk-profile-caret { color: var(--kk-primary-dark); }
}

.mobile-profile-trigger:focus-visible,
.kk-profile-btn:focus-visible {
    outline: 2px solid var(--kk-primary);
    outline-offset: 2px;
    background: var(--kk-ok-bg);
}

.mobile-profile-trigger:active,
.mobile-profile-trigger.show,
.kk-profile-btn:active, .kk-profile-btn.show {
    background: var(--kk-ok-bg);
    border-color: var(--kk-primary);
    color: var(--kk-primary-dark);
}

.kk-admin { position: relative; }

.kk-profile-menu {
    display: none;
    margin: 0;
    max-width: calc(100vw - 24px);
    overflow-wrap: break-word;
}

.kk-profile-menu.show {
    display: block;
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    left: auto;
}

.kk-profile-ident {
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding: 10px 12px 8px;
    min-width: 0;
}

.kk-profile-name { font-weight: 800; font-size: .95rem; overflow-wrap: break-word; }
.kk-profile-email { font-size: .78rem; color: var(--kk-muted); overflow-wrap: break-word; }

.kk-admin .dropdown-menu {
    background: #fff;
    border-radius: 14px;
    border: 1px solid var(--kk-line);
    box-shadow: 0 8px 24px rgba(16,24,20,.12);
    min-width: min(200px, calc(100vw - 24px));
    max-height: calc(100dvh - 70px);
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 6px;
    z-index: 1040;
}

.kk-admin .dropdown-item {
    border-radius: 10px;
    font-weight: 600;
    font-size: .92rem;
    padding: 10px 12px;
    min-height: var(--kk-touch);
    display: flex;
    align-items: center;
}

.kk-admin form { margin: 0; }

.kk-admin button.dropdown-item {
    width: 100%;
    text-align: left;
    background: transparent;
    border: 0;
}

.kk-admin .dropdown-item.active { background: var(--kk-primary); }

.kk-content { padding: 16px 12px 110px; max-width: 1080px; width: 100%; margin: 0 auto; min-width: 0; }

.kk-alert { border-radius: 14px; border: 0; box-shadow: 0 1px 2px rgba(0,0,0,.06); overflow-wrap: break-word; }

/* ---------- Page head ---------- */

.kk-page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px 12px;
    margin-bottom: 14px;
}

.kk-page-head > div:first-child { min-width: 0; flex: 1 1 200px; }
.kk-page-head h1 {
    font-size: clamp(1.2rem, 4.5vw, 1.45rem);
    font-weight: 800;
    margin: 0;
    letter-spacing: -.01em;
    overflow-wrap: break-word;
}
.kk-page-head p { margin: 2px 0 0; color: var(--kk-muted); font-size: .88rem; }
.kk-page-head .btn { min-height: var(--kk-touch); display: inline-flex; align-items: center; }

/* ---------- Card generik ---------- */

.kk-card {
    background: var(--kk-card);
    border: 1px solid var(--kk-line);
    border-radius: var(--kk-radius);
    box-shadow: 0 1px 2px rgba(16,24,20,.05);
    min-width: 0;
}

.kk-section-title {
    font-weight: 800;
    font-size: 1rem;
    margin: 24px 0 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.kk-section-title .count {
    font-size: .75rem; background: var(--kk-ink); color: #fff;
    border-radius: 999px; padding: 1px 9px; font-weight: 700;
}

/* ---------- Statistik dashboard ---------- */

.kk-stat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }

.kk-stat { padding: 12px; min-width: 0; }
.kk-stat .label {
    font-size: .7rem; color: var(--kk-muted); font-weight: 700;
    text-transform: uppercase; letter-spacing: .04em;
    overflow-wrap: break-word;
}
.kk-stat .value {
    font-size: clamp(1rem, 5vw, 1.3rem);
    font-weight: 800;
    letter-spacing: -.01em;
    margin-top: 2px;
    font-variant-numeric: tabular-nums;
    overflow-wrap: break-word;
}
.kk-stat .sub { font-size: .78rem; color: var(--kk-muted); font-weight: 600; }
.kk-stat.danger .value { color: var(--kk-danger); }

/* ---------- Kartu tagihan ---------- */

.kk-bill { padding: 14px; margin-bottom: 10px; }
.kk-bill-top { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.kk-bill-top > div { min-width: 0; }
.kk-bill-name { font-weight: 800; font-size: 1rem; overflow-wrap: break-word; }
.kk-bill-unit { color: var(--kk-muted); font-size: .85rem; font-weight: 600; overflow-wrap: break-word; }
.kk-bill-amount {
    font-weight: 800;
    font-size: clamp(.95rem, 4.2vw, 1.1rem);
    font-variant-numeric: tabular-nums;
    text-align: right;
    flex: 0 0 auto;
    max-width: 44%;
    overflow-wrap: break-word;
}
.kk-bill-meta { font-size: .83rem; color: var(--kk-muted); margin-top: 6px; overflow-wrap: break-word; }

/* Mobile: tombol aksi full-width bertumpuk agar mudah dijangkau ibu jari */
.kk-bill-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.kk-bill-actions .btn {
    width: 100%;
    min-height: var(--kk-touch);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border-radius: 12px;
    font-weight: 700;
    padding: 10px 12px;
}

/* ---------- Badge ---------- */

.kk-badge {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: .74rem; font-weight: 800;
    padding: 4px 10px; border-radius: 999px;
    max-width: 100%;
    overflow-wrap: break-word;
}
.kk-badge.overdue { background: var(--kk-danger-bg); color: var(--kk-danger); }
.kk-badge.due { background: var(--kk-warn-bg); color: var(--kk-warn); }
.kk-badge.unpaid { background: var(--kk-info-bg); color: #3f4a46; }
.kk-badge.paid, .kk-badge.ok { background: var(--kk-ok-bg); color: var(--kk-ok); }
.kk-badge.void { background: #f1f1f1; color: #6b7672; }

/* ---------- Tombol ---------- */

.btn-kk { background: var(--kk-primary); border-color: var(--kk-primary); color: #fff; font-weight: 700; border-radius: 12px; }
.btn-kk:hover, .btn-kk:active, .btn-kk:focus { background: var(--kk-primary-dark); border-color: var(--kk-primary-dark); color: #fff; }
.btn-wa { background: #1fa855; border-color: #1fa855; color: #fff; font-weight: 700; border-radius: 12px; }
.btn-wa:hover, .btn-wa:active, .btn-wa:focus { background: #178245; border-color: #178245; color: #fff; }

/* ---------- Form ---------- */

.kk-form .form-label { font-weight: 700; font-size: .88rem; }
.kk-form .form-control, .kk-form .form-select,
.modal .form-control, .modal .form-select {
    border-radius: 12px;
    border-color: var(--kk-line);
    font-size: 1rem;
    min-height: var(--kk-touch);
    padding: 10px 12px;
    max-width: 100%;
}

.kk-form .form-control:focus, .kk-form .form-select:focus,
.modal .form-control:focus, .modal .form-select:focus {
    border-color: var(--kk-primary);
    box-shadow: 0 0 0 .2rem rgba(14,124,107,.15);
}

.kk-form textarea.form-control { min-height: 88px; }
.invalid-feedback { overflow-wrap: break-word; }

/* ---------- Tabel ---------- */

.kk-table-wrap { overflow-x: auto; border-radius: var(--kk-radius); -webkit-overflow-scrolling: touch; }
.kk-table-wrap table { margin-bottom: 0; }
.kk-empty { text-align: center; padding: 36px 20px; color: var(--kk-muted); }
.kk-empty i { font-size: 2.2rem; display: block; margin-bottom: 8px; }

.pagination { flex-wrap: wrap; row-gap: 6px; }

/* ---------- Bottom nav (mobile) ---------- */

.kk-bottomnav {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 1020;
    display: flex;
    background: #fff;
    border-top: 1px solid var(--kk-line);
    padding: 4px 2px calc(6px + env(safe-area-inset-bottom));
}

.kk-bottomnav a {
    flex: 1 1 0;
    min-width: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
    text-decoration: none; color: var(--kk-muted);
    font-size: .66rem; font-weight: 700;
    min-height: 56px;
    padding: 6px 2px;
}

.kk-bottomnav a i { font-size: 1.25rem; line-height: 1; }
.kk-bottomnav a span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.kk-bottomnav a.active { color: var(--kk-primary); }

/* ---------- Login ---------- */

.kk-login-wrap {
    min-height: 100vh; min-height: 100dvh;
    display: flex; align-items: center; justify-content: center;
    padding: 20px 16px;
    padding-top: max(20px, env(safe-area-inset-top));
    padding-bottom: max(20px, env(safe-area-inset-bottom));
    background: linear-gradient(160deg, #0d2b26 0%, #0e7c6b 100%);
}
.kk-login-card { width: 100%; max-width: 400px; background: #fff; border-radius: 22px; padding: 28px 22px; }
.kk-login-brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.3rem; margin-bottom: 4px; }
.kk-login-card .form-control { font-size: 1rem; min-height: var(--kk-touch); border-radius: 12px; }
.kk-login-card .btn { min-height: 48px; }

/* ---------- Pilih periode pembayaran ---------- */

.kk-check-row {
    display: flex; align-items: center; gap: 10px;
    min-height: 56px;
    padding: 10px 12px;
    border: 1px solid var(--kk-line);
    border-radius: 12px;
    margin-bottom: 8px;
    cursor: pointer;
    font-size: .92rem;
}
.kk-check-row.checked { border-color: var(--kk-primary); background: #f0faf8; }
.kk-check-row input { width: 22px; height: 22px; flex: 0 0 auto; accent-color: var(--kk-primary); }
.kk-check-row > span:first-of-type { min-width: 0; overflow-wrap: break-word; }
.kk-check-row .amt {
    margin-left: auto; flex: 0 0 auto;
    font-weight: 800; font-variant-numeric: tabular-nums;
    font-size: .9rem;
}

.kk-pay-total {
    position: sticky;
    bottom: 0;
    background: var(--kk-ink);
    color: #fff;
    border-radius: 12px;
    padding: 12px 14px;
}

/* ---------- Key-value ---------- */

.kk-kv { display: grid; grid-template-columns: 118px minmax(0, 1fr); gap: 6px 10px; font-size: .92rem; }
.kk-kv dt { color: var(--kk-muted); font-weight: 600; min-width: 0; }
.kk-kv dd { margin: 0; font-weight: 600; min-width: 0; overflow-wrap: break-word; }

/* ---------- Danger zone ---------- */

.kk-danger-zone {
    border-top: 1px solid var(--kk-line);
    padding: 18px 4px 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.kk-danger-zone h2 {
    margin: 0 0 4px;
    font-size: 1rem;
    font-weight: 800;
    color: var(--kk-danger);
}

.kk-danger-zone p {
    margin: 0;
    color: var(--kk-muted);
    font-size: .9rem;
}

.kk-danger-zone .btn {
    min-height: var(--kk-touch);
    align-self: flex-start;
    font-weight: 700;
    border-radius: 12px;
}

.kk-danger-note {
    display: inline-flex;
    align-items: flex-start;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 12px;
    background: var(--kk-danger-bg);
    color: var(--kk-danger);
    font-weight: 700;
    font-size: .88rem;
    overflow-wrap: anywhere;
}

/* ---------- Filter pills ---------- */

.kk-filter-pills {
    display: flex; gap: 8px;
    overflow-x: auto;
    padding-bottom: 6px;
    margin-inline: -12px;
    padding-inline: 12px;
    scrollbar-width: thin;
}
.kk-filter-pills .btn {
    border-radius: 999px; white-space: nowrap; font-weight: 700; font-size: .85rem;
    min-height: 40px;
    display: inline-flex; align-items: center;
}


/* ---------- Modal ---------- */

.modal-content { border-radius: 18px; border: 0; }
.modal-header, .modal-footer { flex-wrap: wrap; gap: 8px; }
.modal-footer .btn { min-height: var(--kk-touch); border-radius: 12px; font-weight: 700; }
.modal-title { font-weight: 800; font-size: 1.05rem; }

/* ============================================================
   >= 576px (HP besar / phablet): aksi kartu boleh horizontal
   ============================================================ */
@media (min-width: 576px) {
    .kk-content { padding-inline: 16px; }
    .kk-bill-actions { flex-direction: row; }
    .kk-bill-actions .btn { width: auto; }
    .kk-bill-actions .btn-wa, .kk-bill-actions .btn-kk { flex: 1 1 0; }
    .kk-bill-actions .btn-detail { flex: 0 0 auto; padding-inline: 16px; }
    .kk-filter-pills { margin-inline: 0; padding-inline: 0; }
}

/* ============================================================
   >= 768px (tablet): statistik 4 kolom
   ============================================================ */
@media (min-width: 768px) {
    .kk-stat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .kk-stat { padding: 14px 15px; }
}

/* ============================================================
   >= 992px (desktop): sidebar permanen, tanpa bottom nav
   ============================================================ */
@media (min-width: 992px) {
    .kk-main { margin-left: 248px; }
    .kk-content { padding: 28px 32px 48px; }
    .kk-kv { grid-template-columns: 150px minmax(0, 1fr); }
}

/* Layar sangat sempit (<= 350px): statistik 1 kolom agar terbaca */
@media (max-width: 350px) {
    .kk-stat-grid { grid-template-columns: minmax(0, 1fr); }
    .kk-kv { grid-template-columns: minmax(0, 1fr); }
    .kk-kv dt { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; }
}

@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
    * { transition: none; }
}
