* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: #f5f7f5;
    color: #18231c;
    overflow-x: hidden;
}

body.no-scroll {
    overflow: hidden;
}

.app {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

img {
    max-width: 100%;
}

/* SIDEBAR */

.sidebar {
    width: 255px;
    min-height: 100vh;
    background: #123524;
    color: white;
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 210;
    overflow-y: auto;
    transition: transform .25s ease;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(10, 20, 14, .5);
    z-index: 200;
    opacity: 0;
    transition: opacity .2s ease;
}

.sidebar-overlay.sidebar-overlay-show {
    display: block;
    opacity: 1;
}

/* Hamburger toggle: hidden by default (desktop) */
.menu-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 38px;
    height: 38px;
    min-width: 38px;
    border: 1px solid #d7ded9;
    border-radius: 8px;
    background: #fff;
    cursor: pointer;
    padding: 0;
}

.menu-toggle span {
    display: block;
    width: 18px;
    height: 2px;
    background: #123524;
    margin: 0 auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 4px 10px 30px;
}

.brand-icon {
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.brand-icon img {
    width: 42px;
    height: 42px;
    object-fit: contain;
    display: block;
}

.brand strong {
    display: block;
    font-size: 15px;
    letter-spacing: .5px;
}

.brand span {
    display: block;
    font-size: 11px;
    color: #b9cbbf;
    margin-top: 3px;
}

nav {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

nav a {
    color: #cbd8cf;
    text-decoration: none;
    padding: 13px 14px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 14px;
}

nav a:hover,
nav a.active {
    background: #1d5136;
    color: white;
}

nav a.active {
    box-shadow: inset 3px 0 #facc15;
}

nav a span {
    width: 20px;
    text-align: center;
}

.sidebar-bottom {
    margin-top: auto;
    padding: 15px 10px 5px;
    color: #b9cbbf;
}

.system-status {
    font-size: 12px;
    margin-bottom: 10px;
}

.dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: #4ade80;
    border-radius: 50%;
    margin-right: 6px;
}

.sidebar-bottom small {
    font-size: 10px;
}

/* MAIN */

.main {
    margin-left: 255px;
    width: calc(100% - 255px);
    min-width: 0;
}

.topbar {
    min-height: 78px;
    background: white;
    border-bottom: 1px solid #e6ebe7;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 14px clamp(16px, 3vw, 34px);
    flex-wrap: wrap;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.topbar-titles {
    min-width: 0;
}

.breadcrumb {
    font-size: 11px;
    color: #849188;
    margin-bottom: 4px;
    overflow-wrap: break-word;
}

h1 {
    font-size: clamp(18px, 4vw, 23px);
    overflow-wrap: break-word;
}

.user-box {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.avatar {
    width: 38px;
    height: 38px;
    min-width: 38px;
    border-radius: 50%;
    background: #dcfce7;
    color: #166534;
    display: grid;
    place-items: center;
    font-weight: 700;
}

.user-box strong,
.user-box small {
    display: block;
}

.user-box strong {
    font-size: 13px;
}

.user-box small {
    color: #87928a;
    font-size: 11px;
    margin-top: 2px;
}

.btn-logout {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    padding: 8px 12px;
    border-radius: 8px;
    background: #fee2e2;
    color: #b91c1c;
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.15s ease;
}

.btn-logout:hover,
.btn-logout:focus {
    background: #fecaca;
    color: #991b1b;
}

.btn-logout span:first-child {
    font-size: 14px;
    line-height: 1;
}

.content {
    padding: clamp(16px, 3vw, 30px) clamp(14px, 3vw, 34px);
    min-width: 0;
    overflow-x: hidden;
}

/* WELCOME */

.welcome {
    background: #eaf7ed;
    border: 1px solid #d4ead9;
    border-radius: 16px;
    padding: clamp(18px, 3vw, 25px) clamp(18px, 3vw, 28px);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 22px;
    flex-wrap: wrap;
}

.eyebrow {
    color: #278344;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1px;
}

.welcome h2 {
    font-size: clamp(17px, 4vw, 23px);
    margin: 8px 0;
    max-width: 650px;
    overflow-wrap: break-word;
}

.welcome p {
    color: #647169;
    font-size: 13px;
    max-width: 700px;
    line-height: 1.6;
}

.welcome-icon {
    font-size: clamp(36px, 8vw, 58px);
    padding-right: 0;
}

/* STAT */

.stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    margin-bottom: 30px;
}

.stat-card {
    background: white;
    border: 1px solid #e7ebe8;
    border-radius: 14px;
    padding: 18px;
    display: flex;
    align-items: center;
    gap: 13px;
}

.stat-icon {
    width: 45px;
    height: 45px;
    border-radius: 11px;
    display: grid;
    place-items: center;
    font-size: 19px;
}

.yellow { background: #fef3c7; }
.green { background: #dcfce7; }
.blue { background: #dbeafe; }
.purple { background: #ede9fe; }
.orange { background: #ffedd5; }

.stat-card span,
.stat-card small {
    display: block;
}

.stat-card span {
    color: #77827b;
    font-size: 11px;
}

.stat-card strong {
    display: block;
    font-size: 25px;
    margin: 2px 0;
}

.stat-card small {
    color: #9aa39d;
    font-size: 10px;
}

/* TABLE */

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 13px;
}

.section-head h3 {
    font-size: 17px;
}

.section-head p {
    color: #849087;
    font-size: 11px;
    margin-top: 3px;
}

.btn-primary {
    text-decoration: none;
    background: #16803c;
    color: white;
    padding: 10px 15px;
    border-radius: 9px;
    font-size: 12px;
    font-weight: 600;
}

.btn-primary:hover {
    background: #126c32;
}

.table-card {
    background: white;
    border: 1px solid #e7ebe8;
    border-radius: 14px;
    overflow: hidden;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 900px;
}

th {
    background: #f8faf8;
    color: #6f7972;
    text-align: left;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .4px;
    padding: 13px 14px;
}

td {
    padding: 14px;
    border-top: 1px solid #eef1ef;
    font-size: 12px;
    color: #505b53;
}

td strong {
    color: #1b3323;
}

.badge {
    display: inline-block;
    padding: 5px 8px;
    border-radius: 6px;
    background: #ecfdf3;
    color: #18753a;
    font-size: 10px;
}

.badge-off {
    background: #f1f2f0;
    color: #7a827c;
}

.muted {
    color: #98a19b;
}

.empty {
    text-align: center;
    padding: 30px;
    color: #999;
}

footer {
    padding: 0 34px 25px;
    color: #98a19b;
    font-size: 10px;
}

@media (max-width: 1050px) {
    .stats {
        grid-template-columns: repeat(2, 1fr);
    }
}

/* Below this width, the sidebar becomes an off-canvas drawer opened
   by the hamburger button, so content always has full width and
   nothing is squeezed or hidden — this covers phones and a folded
   Z Fold's outer screen (~280-420px) as well as an unfolded Z Fold's
   inner screen in portrait (~600-720px). */
@media (max-width: 900px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.sidebar-open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0, 0, 0, .25);
    }

    .menu-toggle {
        display: flex;
    }

    .main {
        margin-left: 0;
        width: 100%;
    }

    .stats {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 560px) {
    .stats {
        grid-template-columns: 1fr;
    }

    .welcome {
        justify-content: flex-start;
    }

    .welcome-icon {
        order: -1;
    }

    .user-box-text {
        display: none;
    }

    .btn-logout-text {
        display: none;
    }

    .btn-logout {
        padding: 8px;
    }
}

@media (max-width: 360px) {
    .topbar {
        padding: 12px 12px;
    }

    .content {
        padding: 14px 10px;
    }
}

/* =========================================================
   TAMBAHAN: Form, Alert, Search Bar, Pagination, Aksi Tabel
   (Fitur Tambah/Edit/Hapus Data Blok)
   ========================================================= */

.btn-secondary {
    background: #123524;
    color: #fff;
    border: none;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.btn-ghost {
    background: transparent;
    color: #123524;
    border: 1px solid #d7ded9;
    padding: 10px 18px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    display: inline-block;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 30px;
    height: 30px;
    border-radius: 6px;
    background: #eef3ee;
    color: #123524;
    text-decoration: none;
    margin-right: 4px;
    font-size: 14px;
}

.btn-icon.danger {
    background: #fdeceb;
    color: #c0392b;
}

.actions {
    white-space: nowrap;
}

/* ALERT / FLASH MESSAGE */

.alert {
    padding: 14px 18px;
    border-radius: 10px;
    margin-bottom: 18px;
    font-size: 14px;
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.alert-success {
    background: #e8f6ee;
    color: #17794a;
    border: 1px solid #b9e6cc;
}

.alert-error {
    background: #fdeceb;
    color: #c0392b;
    border: 1px solid #f5c6c2;
}

.alert ul {
    margin: 6px 0 0 18px;
}

/* SEARCH BAR */

.search-bar {
    display: flex;
    gap: 10px;
    padding: 16px 20px 0;
}

.search-bar input[type="text"] {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid #d7ded9;
    border-radius: 8px;
    font-size: 13px;
}

/* TABLE FOOTER / LINK MORE */

.table-footer {
    padding: 14px 20px;
    border-top: 1px solid #eef1ee;
}

.link-more {
    color: #17794a;
    font-weight: 600;
    font-size: 13px;
    text-decoration: none;
}

/* PAGINATION */

.pagination {
    padding: 16px 20px;
    display: flex;
    justify-content: flex-end;
}

.pagination ul.pagination,
ul.pagination {
    display: flex;
    list-style: none;
    gap: 6px;
    flex-wrap: wrap;
}

.pagination li a {
    display: inline-block;
    padding: 6px 12px;
    border-radius: 6px;
    border: 1px solid #d7ded9;
    color: #123524;
    text-decoration: none;
    font-size: 13px;
}

.pagination li.active a {
    background: #123524;
    color: #fff;
    border-color: #123524;
}

/* FORM CARD */

.form-card {
    background: #fff;
    border-radius: 14px;
    padding: 26px 28px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.form-card fieldset {
    border: none;
    border-top: 1px solid #eef1ee;
    padding: 20px 0 4px;
    margin-bottom: 6px;
}

.form-card fieldset:first-of-type {
    border-top: none;
    padding-top: 0;
}

.form-card legend {
    font-size: 14px;
    font-weight: 700;
    color: #123524;
    padding: 0 0 12px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px 20px;
}

.form-span-2 {
    grid-column: span 2;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 12.5px;
    font-weight: 600;
    color: #3c463f;
}

.form-group .req {
    color: #c0392b;
}

.form-group input,
.form-group select {
    padding: 10px 12px;
    border: 1px solid #d7ded9;
    border-radius: 8px;
    font-size: 13.5px;
    font-family: inherit;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #17794a;
    box-shadow: 0 0 0 3px rgba(23,121,74,0.12);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding-top: 18px;
    border-top: 1px solid #eef1ee;
    margin-top: 6px;
}

@media (max-width: 900px) {
    .form-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 600px) {
    .form-grid {
        grid-template-columns: 1fr;
    }
    .form-span-2 {
        grid-column: span 1;
    }
    .search-bar {
        flex-direction: column;
    }
}


/* =========================================================
   UTILITAS RESPONSIVE: TABEL JADI KARTU DI HP  (.table-stack)
   Pakai: <table class="table-stack"> dan beri atribut
   data-label="Nama Kolom" pada tiap <td> (label tampil di HP).
   <td> tanpa data-label = tanpa label (mis. baris "kosong").
   Modifier .table-stack-form = label di atas, isi (input/select)
   selebar kartu. Di layar > 720px tabel tampil normal seperti biasa.
   ========================================================= */
@media (max-width: 720px) {
    .table-stack {
        min-width: 0 !important;
    }

    .table-stack,
    .table-stack tbody {
        display: block;
        width: 100%;
    }

    /* Header tabel disembunyikan secara visual (tetap terbaca screen reader) */
    .table-stack thead {
        position: absolute;
        width: 1px;
        height: 1px;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
    }

    .table-stack tr {
        display: block;
        padding: 10px 14px;
        border-top: 1px solid #eef1ef;
    }

    .table-stack tbody tr:first-child {
        border-top: 0;
    }

    .table-stack td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 14px;
        padding: 6px 0;
        border: 0;
        font-size: 13px;
        text-align: right;
        overflow-wrap: anywhere;
    }

    .table-stack td::before {
        content: attr(data-label);
        flex: 0 0 38%;
        max-width: 38%;
        text-align: left;
        font-size: 10.5px;
        font-weight: 700;
        letter-spacing: .3px;
        text-transform: uppercase;
        color: #6f7972;
    }

    .table-stack td:not([data-label])::before {
        content: none;
    }

    .table-stack td.empty {
        display: block;
        text-align: center;
    }

    .table-stack td.actions {
        white-space: normal;
    }

    .table-stack .btn-icon {
        width: 40px;
        height: 40px;
        margin-right: 0;
    }

    /* Varian form: label di atas, input/select selebar kartu */
    .table-stack-form td {
        flex-direction: column;
        align-items: stretch;
        gap: 4px;
        text-align: left;
    }

    .table-stack-form td::before {
        flex: none;
        max-width: none;
    }
}


/* =========================================================
   PEMILIH WILAYAH BERTINGKAT (form Blok: Provinsi -> Desa)
   Dropdown buatan sendiri — dipasang oleh wilayah-indonesia.js
   ========================================================= */
.wil-combo {
    position: relative;
}

.wil-combo input {
    width: 100%;
    box-sizing: border-box;
    padding-right: 34px;
    text-overflow: ellipsis;
}

/* panah kecil di kanan kolom (hiasan; klik kolom = buka daftar) */
.wil-combo::after {
    content: "";
    position: absolute;
    right: 13px;
    top: 50%;
    width: 7px;
    height: 7px;
    margin-top: -6px;
    border-right: 2px solid #7a877f;
    border-bottom: 2px solid #7a877f;
    transform: rotate(45deg);
    pointer-events: none;
    transition: transform 0.15s ease, margin-top 0.15s ease;
}

.wil-combo.is-open::after {
    margin-top: -2px;
    transform: rotate(225deg);
}

.wil-list {
    position: absolute;
    z-index: 40;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    max-height: 260px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    background: #fff;
    border: 1px solid #cfd8d2;
    border-radius: 8px;
    box-shadow: 0 10px 24px rgba(18, 53, 36, 0.16);
    padding: 4px;
}

.wil-list[hidden] {
    display: none;
}

.wil-item {
    padding: 9px 10px;
    border-radius: 6px;
    font-size: 13.5px;
    color: #1f2a23;
    cursor: pointer;
    line-height: 1.3;
}

.wil-item:hover,
.wil-item.is-active {
    background: #e8f4ee;
}

.wil-item.is-selected {
    background: #d6ecdf;
    color: #0f5c37;
    font-weight: 600;
}

.wil-msg {
    padding: 10px;
    font-size: 12.5px;
    color: #66736b;
    line-height: 1.4;
}

.wil-retry {
    display: block;
    width: 100%;
    text-align: left;
    padding: 10px;
    border: 0;
    border-radius: 6px;
    background: #fdf2e9;
    color: #a04a0c;
    font: inherit;
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
}

.wil-retry:hover {
    background: #fbe6d3;
}

@media (max-width: 600px) {
    .wil-list {
        max-height: 55vh;
    }
    .wil-item {
        padding: 12px 10px;
        font-size: 14.5px;
    }
}
