/* ============================================================
   Sistemberkah — global responsive overrides
   Loaded LAST in all layouts (dashboard, home, auth, error).
   Breakpoints: <=991.98 (tablet), <=767.98 (mobile), <=575.98 (small)
   ============================================================ */

/* ---------- Base ---------- */
body {
    overflow-x: hidden;
}

img {
    max-width: 100%;
}

/* Prevent horizontal scroll from wide rows/cards */
.page-wrapper,
.hp-main-layout {
    overflow-x: clip;
}

/* ---------- Dashboard content spacing ---------- */
@media (max-width: 767.98px) {
    .hp-main-layout-content {
        padding: 16px 12px;
    }

    h1, .h1 { font-size: 1.6rem; }
    h2, .h2 { font-size: 1.35rem; }
    h3, .h3 { font-size: 1.15rem; }
    h4, .h4 { font-size: 1.05rem; }
}

/* ---------- Forms: stop iOS zoom on focus, bigger tap targets ---------- */
/* Form Check & Radio Filters */
.form-check {
    min-height: 1.5rem;
    padding-left: 1.6em;
    margin-bottom: 0;
}

.form-check .form-check-input {
    float: left;
    margin-left: -1.6em;
    margin-top: 0.2em;
    width: 1.15em;
    height: 1.15em;
    cursor: pointer;
}

.form-check-label {
    cursor: pointer;
    -webkit-user-select: none;
       -moz-user-select: none;
        -ms-user-select: none;
            user-select: none;
    font-size: 0.875rem;
}

/* Radio groups wrapped in flex (e.g. Range/Interval Waktu) */
.d-flex:has(> .form-check),
.mb-16.d-flex:has(> .form-check),
div:has(> .form-check.me-8),
div:has(> .form-check.me-16) {
    flex-wrap: wrap;
    gap: 8px 16px;
    align-items: center;
}

@media (max-width: 767.98px) {
    .form-control,
    .form-select,
    input,
    select,
    textarea {
        font-size: 16px;
    }

    .form-control,
    .form-select {
        min-height: 42px;
    }

    .btn {
        min-height: 40px;
    }

    .btn-icon-only {
        min-width: 40px;
    }

    /* Radio / checkbox filter containers on mobile: ensure wrap & no text squash */
    .d-flex:has(> .form-check),
    .mb-16.d-flex,
    .form-group .d-flex {
        flex-wrap: wrap !important;
        gap: 8px 16px !important;
    }

    .form-check {
        display: inline-flex !important;
        align-items: center !important;
        padding-left: 0 !important;
        margin-right: 0 !important;
        margin-bottom: 4px !important;
        white-space: nowrap !important;
        min-width: auto;
    }

    .form-check .form-check-input {
        float: none !important;
        margin: 0 8px 0 0 !important;
        flex-shrink: 0 !important;
    }

    .form-check .form-check-label {
        display: inline-flex !important;
        align-items: center !important;
        white-space: nowrap !important;
        margin-bottom: 0 !important;
    }

    /* Filter action buttons (Tampilkan / Refresh) */
    .col-12.text-right .btn,
    .col-12.text-end .btn,
    .filterby,
    .refresh {
        min-width: 90px;
        margin-bottom: 6px;
    }

    /* select2 renders inline widths; force fluid on mobile */
    .select2-container {
        width: 100% !important;
        max-width: 100%;
    }

    .select2-container--default .select2-selection--single {
        min-height: 42px;
        padding-top: 4px;
    }

    .select2-container--default .select2-selection--multiple {
        min-height: 42px;
        padding: 4px 8px;
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 4px;
    }

    .select2-container--default .select2-selection--multiple .select2-selection__rendered {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 4px;
        padding: 0;
        width: 100%;
    }

    .select2-container--default .select2-selection--multiple .select2-selection__choice {
        margin: 2px 4px 2px 0;
        padding: 2px 8px;
        font-size: 0.8125rem;
        border-radius: 6px;
    }

    /* stack form rows that use inline float/width */
    .form-inline .form-control,
    .form-inline .form-select {
        width: 100%;
    }
}

/* ---------- Table Header Toolbar: Show entries + Search ---------- */
@media (max-width: 767.98px) {
    /* Stack show-entries and search input vertically on mobile */
    form[id*="filter"] .d-flex.justify-content-between,
    .content_container form .d-flex.justify-content-between,
    .card-body > form .d-flex.justify-content-between,
    .card-body > .d-flex.justify-content-between:not(.initpagination) {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 12px !important;
        margin-bottom: 12px !important;
    }

    /* Show [15] data inline row */
    form[id*="filter"] .d-flex.align-items-center,
    .content_container form .d-flex.align-items-center,
    .card-body form .d-flex.align-items-center {
        display: flex !important;
        align-items: center !important;
        flex-wrap: nowrap !important;
        width: 100% !important;
        justify-content: flex-start !important;
    }

    form[id*="filter"] .d-flex.align-items-center span,
    .content_container form .d-flex.align-items-center span,
    .card-body form .d-flex.align-items-center span {
        white-space: nowrap !important;
        flex-shrink: 0 !important;
        display: inline-block !important;
    }

    form[id*="filter"] select[name="limit"],
    .content_container form select[name="limit"],
    .card-body form select[name="limit"],
    select#limit,
    select.searchable_input.form-control.w-auto {
        width: auto !important;
        min-width: 68px !important;
        max-width: 80px !important;
        height: 38px !important;
        min-height: 38px !important;
        padding: 4px 8px !important;
        margin: 0 8px !important;
        flex-shrink: 0 !important;
        display: inline-block !important;
    }

    /* Search input group: full width */
    form[id*="filter"] .input-group,
    .content_container form .input-group,
    .card-body form .input-group,
    .input-group.w-auto {
        width: 100% !important;
        max-width: 100% !important;
        margin-bottom: 0 !important;
        display: flex !important;
    }

    form[id*="filter"] .input-group input.form-control,
    .content_container form .input-group input.form-control,
    .card-body form .input-group input.form-control {
        flex: 1 1 auto !important;
        width: 1% !important;
        min-height: 40px !important;
        font-size: 0.9rem !important;
    }

    form[id*="filter"] .input-group .btn,
    .content_container form .input-group .btn,
    .card-body form .input-group .btn {
        min-width: 44px !important;
        min-height: 40px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
    }
}

/* ---------- Header: notification & profile dropdowns ---------- */
/* hover-only dropdowns are unusable on touch: open on tap via focus */
.hover-dropdown-fade:focus-within .dropdown-fade {
    opacity: 1;
    visibility: visible;
    pointer-events: all;
}

@media (max-width: 767.98px) {
    /* dropdown panels are position-absolute with inline width;
       pin them as a sheet under the header so they never overflow viewport */
    .hp-notification-menu,
    .hp-header-profile-menu {
        position: fixed !important;
        top: 68px !important;
        left: 8px !important;
        right: 8px !important;
        width: auto !important;
        z-index: 1050;
    }

    .hp-notification-menu .row,
    .hp-header-profile-menu .row {
        margin-left: 0;
        margin-right: 0;
    }
}

@media (max-width: 575.98px) {
    /* hide user name beside avatar, keep avatar */
    header .hover-dropdown-fade > span.me-16 {
        display: none;
    }

    header .badge {
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

/* ---------- Mobile offcanvas sidebar ---------- */
@media (max-width: 1199.98px) {
    .hp-mobile-sidebar .hp-sidebar-container {
        overflow-y: auto;
        max-height: calc(100vh - 90px);
        -webkit-overflow-scrolling: touch;
    }

    .hp-mobile-sidebar .hp-sidebar {
        width: 100%;
    }

    /* comfortable tap targets for menu links */
    .hp-mobile-sidebar .hp-sidebar a {
        min-height: 44px;
    }
}

/* ---------- Modals: near-fullscreen on phones ---------- */
@media (max-width: 767.98px) {
    .modal-dialog {
        max-width: calc(100vw - 24px);
        margin: 12px auto;
    }

    .modal-lg,
    .modal-xl {
        max-width: calc(100vw - 24px);
    }

    .modal-body {
        padding: 16px;
    }
}

@media (max-width: 575.98px) {
    .modal-dialog {
        margin: 0;
        max-width: none;
    }

    .modal-content {
        border: 0;
        border-radius: 0;
    }

    .modal-dialog-centered {
        min-height: 100%;
    }
}

/* ---------- Pagination & initpagination ---------- */
.initpagination {
    align-items: center;
}

.pagination {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 4px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.pagination .page-item {
    display: inline-flex;
    align-items: center;
    margin: 0 !important;
    padding: 0 !important;
}

.pagination .page-item.disabled.me-16 {
    margin-right: 0 !important;
    padding: 0 4px;
}

/* Reset theme's margin: 0 16px */
.pagination .page-link {
    margin: 0 !important;
    min-width: 36px;
    height: 36px;
    padding: 4px 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    border-radius: 8px !important;
    font-size: 0.875rem;
    line-height: 1;
    text-decoration: none;
    box-sizing: border-box;
}

@media (max-width: 767.98px) {
    .initpagination,
    .d-flex.justify-content-between.initpagination {
        flex-direction: column !important;
        align-items: center !important;
        text-align: center !important;
        gap: 12px !important;
        margin-top: 16px !important;
        padding-top: 8px !important;
    }

    .initpagination .total_show {
        text-align: center !important;
        width: 100% !important;
        margin-bottom: 2px !important;
        font-size: 0.875rem;
        color: #6c757d;
    }

    .initpagination nav {
        width: 100%;
        display: flex !important;
        justify-content: center !important;
    }

    .pagination {
        display: inline-flex !important;
        flex-wrap: wrap !important;
        justify-content: center !important;
        gap: 4px !important;
    }

    .pagination .page-link {
        min-width: 34px;
        height: 34px;
        padding: 4px 8px;
        font-size: 0.8125rem;
    }
}

/* ---------- Tables → stacked cards on mobile ----------
   JS (responsive-tables.js) copies thead labels into td[data-label]
   and adds .card-table. Opt-out per table with class "no-card". */
@media (max-width: 767.98px) {
    /* defeat inline white-space:nowrap / text-wrap:nowrap on cells */
    .table td,
    .table th {
        white-space: normal !important;
    }

    /* Prevent wrapper from clipping dropdowns / cards */
    .table-responsive:has(table.card-table),
    .table-responsive {
        overflow-x: auto;
    }

    table.card-table {
        display: block;
        width: 100% !important;
        margin-bottom: 0;
        border: 0 !important;
    }

    table.card-table thead {
        display: none !important;
    }

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

    table.card-table tbody tr {
        display: block;
        background: #ffffff;
        border: 1px solid rgba(0, 0, 0, 0.08);
        border-radius: 12px;
        padding: 10px 14px;
        margin-bottom: 14px;
        --bs-table-bg: transparent;
        --bs-table-striped-bg: transparent;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
        transition: box-shadow 0.15s ease;
    }

    table.card-table tbody tr:hover {
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    }

    table.card-table tbody td,
    table.card-table tbody th {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
        padding: 8px 0;
        border: 0 !important;
        border-bottom: 1px solid rgba(0, 0, 0, 0.04) !important;
        text-align: right;
        background: transparent !important;
        font-size: 0.875rem;
        min-height: 36px;
    }

    table.card-table tbody tr > td:last-child,
    table.card-table tbody tr > th:last-child {
        border-bottom: 0 !important;
        padding-bottom: 2px;
    }

    table.card-table tbody td::before,
    table.card-table tbody th::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 0.8125rem;
        text-align: left;
        flex-shrink: 0;
        max-width: 45%;
        color: #6c757d;
        letter-spacing: 0.2px;
    }

    /* First row element (often No. or ID): show as subtle card badge */
    table.card-table tbody tr > td:first-child:not([data-label=""]),
    table.card-table tbody tr > th:first-child:not([data-label=""]) {
        font-weight: 600;
    }

    /* Empty state row (e.g. "Tidak ada data") */
    table.card-table tbody tr.table-empty-row {
        background: transparent;
        border: 1px dashed rgba(0, 0, 0, 0.15);
        box-shadow: none;
        padding: 20px 12px;
    }

    table.card-table tbody tr.table-empty-row td {
        display: block;
        text-align: center;
        padding: 8px;
        border: 0 !important;
        color: #8c8c8c;
        font-size: 0.9rem;
    }

    table.card-table tbody tr.table-empty-row td::before {
        display: none !important;
    }

    table.card-table tbody td:empty,
    table.card-table tbody th:empty {
        display: none;
    }

    /* Nested action buttons, dropdowns, badges */
    table.card-table tbody td .btn-group,
    table.card-table tbody td .d-flex {
        flex-wrap: wrap;
        justify-content: flex-end;
        gap: 6px;
    }

    table.card-table tbody td .btn {
        padding: 4px 10px;
        font-size: 0.8125rem;
    }

    table.card-table tbody td img {
        max-height: 48px;
        -o-object-fit: contain;
           object-fit: contain;
    }
}

/* dark mode variant (theme uses body.dark) */
@media (max-width: 767.98px) {
    body.dark table.card-table tbody tr {
        background: #1e2c3c;
        border-color: rgba(255, 255, 255, 0.08);
        box-shadow: none;
    }

    body.dark table.card-table tbody tr.table-empty-row {
        background: transparent;
        border-color: rgba(255, 255, 255, 0.15);
    }

    body.dark table.card-table tbody td,
    body.dark table.card-table tbody th {
        color: #e6e6e6;
        border-bottom-color: rgba(255, 255, 255, 0.06) !important;
    }

    body.dark table.card-table tbody td::before,
    body.dark table.card-table tbody th::before {
        color: #9cb3c9;
    }
}

/* ---------- Auth pages ---------- */
@media (max-width: 991.98px) {
    .hp-authentication-page .hp-text-item h2 {
        font-size: 1.4rem;
    }
}

@media (max-width: 575.98px) {
    /* hide big illustration so the form is above the fold */
    .hp-authentication-page .hp-bg-item {
        display: none;
    }

    .hp-authentication-page .hp-logo-item img {
        max-width: 60px;
    }

    .hp-authentication-page .col-lg-6.py-sm-64 {
        padding-top: 24px !important;
    }
}

/* ---------- Error pages ---------- */
@media (max-width: 767.98px) {
    .hp-error-content {
        padding: 24px 16px;
    }

    .hp-error-content img {
        max-width: 80%;
        height: auto;
    }
}

/* ---------- Front / landing (Bootsland) ---------- */
@media (max-width: 991.98px) {
    .site-header .navbar-collapse {
        padding: 12px 0;
    }

    .site-header .navbar-nav .nav-link {
        padding: 10px 0;
        min-height: 44px;
        display: flex;
        align-items: center;
    }
}

@media (max-width: 767.98px) {
    .site-header .navbar {
        padding: 8px 0;
    }

    .site-header .navbar-brand img {
        max-width: 120px;
        height: auto;
    }

    /* "Masuk" button inside collapsed menu on mobile */
    .site-header .navbar .btn {
        margin: 8px 0;
    }

    /* hero section: shrink big inline paddings/margins */
    .site-header + section .container[style*="padding"],
    section .container[style*="padding:5rem"] {
        padding: 2.5rem 0 !important;
    }

    .mt-48 {
        margin-top: 24px !important;
    }

    .mb-32 {
        margin-bottom: 24px !important;
    }

    /* hero heading size */
    section h3[style*="font-size:1.8rem"] {
        font-size: 1.35rem !important;
        line-height: 1.4;
    }

    /* step icons shouldn't overflow small cards */
    .step-icon img {
        max-width: 100px;
        height: auto;
    }
}

/* ---------- SweetAlert2 ---------- */
@media (max-width: 575.98px) {
    .swal2-popup {
        width: 92vw;
        padding: 1.25em 1em;
    }
}

/* ---------- Misc utilities ---------- */
@media (max-width: 767.98px) {
    /* long unbroken strings (notas, emails) should wrap */
    .table,
    .card {
        word-break: break-word;
    }

    /* reduce big theme gutters on phones */
    .row.g-16,
    .row.g-24,
    .row.g-32 {
        --bs-gutter-x: 12px;
    }

    .scroll-to-top {
        bottom: 16px;
        right: 16px;
    }
}

/* ---------- Legacy Bootstrap 4 aliases ----------
   Old Paper-theme pages (back/monitoring/_index) use BS4 classes
   removed in BS5. Minimal aliases so they render correctly. */
.btn-block {
    display: block;
    width: 100%;
}

.form-row {
    display: flex;
    flex-wrap: wrap;
    margin-right: -5px;
    margin-left: -5px;
}

.form-row > [class*="col-"] {
    padding-right: 5px;
    padding-left: 5px;
}

/* BS4 .close button (BS5 uses .btn-close) */
.close {
    float: right;
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1;
    color: #000;
    text-shadow: 0 1px 0 #fff;
    opacity: .5;
    background: transparent;
    border: 0;
    padding: 0;
}

.close:hover {
    opacity: .75;
}

/* BS4 badge color classes (BS5 uses .bg-*) */
.badge-primary { background-color: #0d6efd; color: #fff; }
.badge-success { background-color: #198754; color: #fff; }
.badge-warning { background-color: #ffc107; color: #212529; }
.badge-danger  { background-color: #dc3545; color: #fff; }
.badge-info    { background-color: #0dcaf0; color: #212529; }

/* keep legacy modal close button clickable above header text */
.modal-header .close {
    margin: -0.5rem -0.5rem -0.5rem auto;
}
