/* ================================================================
   BasaKula — Responsive UI Stylesheet
   Target: Android, iOS, Tablet, Desktop
   Standard: WCAG 2.1 AA | Apple HIG | Material Design 3
   ================================================================ */

/* ================================================================
   1. FONT AWESOME ICON FIX & UNIVERSAL SPACING
   Mencegah ikon bergeser/rusak di Android/iOS & jarak tulisan
   ================================================================ */
.fa, .fas, .far, .fal, .fab, .fa-solid, .fa-regular, .fa-brands {
    display: inline-block !important;
    vertical-align: middle;
    line-height: 1 !important;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-style: normal;
    font-variant: normal;
    text-rendering: auto;
}

/* Ensure icons have proper spacing from adjacent text unless explicitly trailing/alone */
i.fa:not(:last-child):not(.me-0),
i.fas:not(:last-child):not(.me-0),
i.far:not(:last-child):not(.me-0),
i.fa-solid:not(:last-child):not(.me-0),
i.fa-regular:not(:last-child):not(.me-0),
i.fa-brands:not(:last-child):not(.me-0) {
    margin-right: 0.45rem;
}

/* Trailing icons (e.g. "Berikutnya >") */
i.fa:last-child:not(:first-child):not(.ms-0),
i.fa-solid:last-child:not(:first-child):not(.ms-0) {
    margin-left: 0.45rem;
}

/* In elements with flex gap, prevent duplicate spacing */
.gap-1 > i, .gap-2 > i, .gap-3 > i, .gap-4 > i {
    margin-right: 0 !important;
    margin-left: 0 !important;
}

.btn .fa, .btn .fas, .btn .far, .btn .fa-solid, .btn .fa-regular {
    vertical-align: -0.125em;
    line-height: 1 !important;
}

.nav-link .fa, .nav-link .fas, .nav-link .far,
.nav-link .fa-solid, .nav-link .fa-regular {
    flex-shrink: 0;
    width: 1.25em;
    text-align: center;
    margin-right: 0.5rem;
}

/* ─── FRACTIONAL BOOTSTRAP UTILITY POLYFILL ─────────────────── */
/* Padding utilities */
.p-0\.5 { padding: 0.125rem !important; }
.p-1\.5 { padding: 0.375rem !important; }
.p-2\.5 { padding: 0.75rem !important; }
.p-3\.5 { padding: 1.15rem !important; }
.p-4\.5 { padding: 1.75rem !important; }

.px-0\.5 { padding-left: 0.125rem !important; padding-right: 0.125rem !important; }
.px-1\.5 { padding-left: 0.375rem !important; padding-right: 0.375rem !important; }
.px-2\.5 { padding-left: 0.75rem !important; padding-right: 0.75rem !important; }
.px-3\.5 { padding-left: 1.15rem !important; padding-right: 1.15rem !important; }
.px-4\.5 { padding-left: 1.75rem !important; padding-right: 1.75rem !important; }

.py-0\.5 { padding-top: 0.125rem !important; padding-bottom: 0.125rem !important; }
.py-1\.5 { padding-top: 0.375rem !important; padding-bottom: 0.375rem !important; }
.py-2\.5 { padding-top: 0.75rem !important; padding-bottom: 0.75rem !important; }
.py-3\.5 { padding-top: 1.15rem !important; padding-bottom: 1.15rem !important; }
.py-4\.5 { padding-top: 1.75rem !important; padding-bottom: 1.75rem !important; }

.ps-0\.5 { padding-left: 0.125rem !important; }
.ps-1\.5 { padding-left: 0.375rem !important; }
.ps-2\.5 { padding-left: 0.75rem !important; }
.ps-3\.5 { padding-left: 1.15rem !important; }
.ps-4\.5 { padding-left: 1.75rem !important; }

.pe-0\.5 { padding-right: 0.125rem !important; }
.pe-1\.5 { padding-right: 0.375rem !important; }
.pe-2\.5 { padding-right: 0.75rem !important; }
.pe-3\.5 { padding-right: 1.15rem !important; }
.pe-4\.5 { padding-right: 1.75rem !important; }

.pt-0\.5 { padding-top: 0.125rem !important; }
.pt-1\.5 { padding-top: 0.375rem !important; }
.pt-2\.5 { padding-top: 0.75rem !important; }
.pt-3\.5 { padding-top: 1.15rem !important; }
.pt-4\.5 { padding-top: 1.75rem !important; }

.pb-0\.5 { padding-bottom: 0.125rem !important; }
.pb-1\.5 { padding-bottom: 0.375rem !important; }
.pb-2\.5 { padding-bottom: 0.75rem !important; }
.pb-3\.5 { padding-bottom: 1.15rem !important; }
.pb-4\.5 { padding-bottom: 1.75rem !important; }

/* Responsive padding */
@media (min-width: 768px) {
    .p-md-3\.5 { padding: 1.25rem !important; }
    .p-md-4\.5 { padding: 2rem !important; }
}

/* Margin utilities */
.m-0\.5 { margin: 0.125rem !important; }
.m-1\.5 { margin: 0.375rem !important; }
.m-2\.5 { margin: 0.75rem !important; }
.m-3\.5 { margin: 1.15rem !important; }
.m-4\.5 { margin: 1.75rem !important; }

.me-0\.5 { margin-right: 0.125rem !important; }
.me-1\.5 { margin-right: 0.375rem !important; }
.me-2\.5 { margin-right: 0.75rem !important; }
.me-3\.5 { margin-right: 1.15rem !important; }
.me-4\.5 { margin-right: 1.75rem !important; }

.ms-0\.5 { margin-left: 0.125rem !important; }
.ms-1\.5 { margin-left: 0.375rem !important; }
.ms-2\.5 { margin-left: 0.75rem !important; }
.ms-3\.5 { margin-left: 1.15rem !important; }
.ms-4\.5 { margin-left: 1.75rem !important; }

.mt-0\.5 { margin-top: 0.125rem !important; }
.mt-1\.5 { margin-top: 0.375rem !important; }
.mt-2\.5 { margin-top: 0.75rem !important; }
.mt-3\.5 { margin-top: 1.15rem !important; }
.mt-4\.5 { margin-top: 1.75rem !important; }

.mb-0\.5 { margin-bottom: 0.125rem !important; }
.mb-1\.5 { margin-bottom: 0.375rem !important; }
.mb-2\.5 { margin-bottom: 0.75rem !important; }
.mb-3\.5 { margin-bottom: 1.15rem !important; }
.mb-4\.5 { margin-bottom: 1.75rem !important; }

/* Gap utilities */
.gap-0\.5 { gap: 0.125rem !important; }
.gap-1\.5 { gap: 0.375rem !important; }
.gap-2\.5 { gap: 0.75rem !important; }
.gap-3\.5 { gap: 1.15rem !important; }
.gap-4\.5 { gap: 1.75rem !important; }

/* Callout / Border-Left text clearance guarantee */
[style*="border-left"] {
    padding-left: clamp(1.15rem, 3vw, 1.4rem) !important;
}

@media (max-width: 767.98px) {
    p[style*="text-align: justify"],
    .text-justify {
        text-align: left !important;
    }
}

/* ================================================================
   2. FLUID TYPOGRAPHY
   ================================================================ */
h1 { font-size: clamp(1.5rem, 4vw, 2.25rem) !important; }
h2 { font-size: clamp(1.25rem, 3vw, 1.875rem) !important; }
h3 { font-size: clamp(1.1rem, 2.5vw, 1.5rem) !important; }
h4 { font-size: clamp(1rem, 2vw, 1.25rem) !important; }
h5 { font-size: clamp(0.9rem, 1.8vw, 1.1rem) !important; }
h6 { font-size: clamp(0.85rem, 1.5vw, 1rem) !important; }

/* ================================================================
   3. SAFE AREA INSETS (iPhone X+ Notch & Home Indicator)
   ================================================================ */
body {
    padding-left: env(safe-area-inset-left, 0);
    padding-right: env(safe-area-inset-right, 0);
}

/* ================================================================
   4. SIDEBAR MOBILE OVERLAY SYSTEM
   ================================================================ */
#sidebar-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.55);
    z-index: 1049;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

#sidebar-backdrop.active {
    display: block;
    animation: fadeInBackdrop 0.3s ease forwards;
}

@keyframes fadeInBackdrop {
    from { opacity: 0; }
    to { opacity: 1; }
}

.sidebar-close-btn {
    display: none;
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px;
    height: 36px;
    border: none;
    background: rgba(0,0,0,0.08);
    border-radius: 50%;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    color: #666;
    font-size: 1rem;
    transition: background 0.2s;
    z-index: 10;
}

.sidebar-close-btn:hover { background: rgba(0,0,0,0.15); }

/* ================================================================
   5. TOUCH-FRIENDLY UI (min 44x44px)
   ================================================================ */
.btn {
    min-height: 44px;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-sm { min-height: 36px; padding: 0.35rem 0.85rem !important; }
.btn-xs { min-height: 30px; padding: 0.2rem 0.6rem !important; }
.nav-link { min-height: 44px; }

/* ================================================================
   6. TABLE RESPONSIVE — SMOOTH HORIZONTAL SCROLL DI MOBILE
   ================================================================ */
.table-responsive {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
}

.table-responsive table {
    word-break: normal !important;
}

@media (max-width: 767.98px) {
    .table-responsive {
        border-radius: 12px;
    }
}

/* ================================================================
   7. SIDEBAR FULL RESPONSIVENESS
   ================================================================ */
@media (max-width: 991.98px) {
    .wrapper {
        display: block !important;
        width: 100% !important;
        min-height: 100% !important;
    }

    .sidebar {
        position: fixed !important;
        left: 0 !important;
        top: 0 !important;
        bottom: 0 !important;
        height: 100vh !important;
        height: 100dvh !important;
        max-height: 100vh !important;
        max-height: 100dvh !important;
        width: 280px !important;
        min-width: 280px !important;
        max-width: 280px !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: space-between !important;
        overflow: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        margin-left: -280px !important;
        z-index: 1050 !important;
        transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
        box-shadow: 4px 0 24px rgba(0,0,0,0.15) !important;
        padding: 1rem !important;
        padding-bottom: max(1rem, env(safe-area-inset-bottom, 1rem)) !important;
    }

    .sidebar.active {
        margin-left: 0 !important;
    }

    .sidebar-top-section {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch !important;
    }

    .sidebar-user-dropdown, .sidebar .dropdown {
        flex-shrink: 0 !important;
        margin-top: auto !important;
    }

    .sidebar-close-btn {
        display: flex !important;
    }

    #content {
        width: 100% !important;
        min-height: 100vh !important;
        min-height: 100dvh !important;
        padding: 16px 16px 120px 16px !important; /* 120px clearance khusus layar HP tinggi & bottom bar Chrome/Safari */
    }
}

/* Desktop Sidebar Complete Hide when Minimized */
@media (min-width: 992px) {
    .wrapper {
        display: block !important;
        width: 100% !important;
        min-height: 100vh !important;
        position: relative !important;
    }

    .sidebar {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        bottom: 0 !important;
        height: 100vh !important;
        height: 100dvh !important;
        max-height: 100vh !important;
        max-height: 100dvh !important;
        width: 260px !important;
        min-width: 260px !important;
        max-width: 260px !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: space-between !important;
        overflow: hidden !important;
        flex-shrink: 0 !important;
        z-index: 1020 !important;
        background: var(--bg-main) !important;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    }

    .sidebar-top-section {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch !important;
    }

    .sidebar-user-dropdown, .sidebar .dropdown {
        flex-shrink: 0 !important;
        margin-top: auto !important;
        background: var(--bg-main) !important;
    }

    .sidebar.active {
        margin-left: -260px !important;
        transform: translateX(-100%) !important;
        opacity: 0 !important;
        visibility: hidden !important;
    }

    #content {
        margin-left: 260px !important;
        width: calc(100% - 260px) !important;
        min-width: 0 !important;
        min-height: 100vh !important;
        transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1), width 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    }

    .sidebar.active ~ #content {
        margin-left: 0 !important;
        width: 100% !important;
    }
}



/* Mobile Calendar Cell Optimization */
@media (max-width: 575.98px) {
    .calendar-day-cell {
        min-height: 62px !important;
        padding: 4px !important;
    }
}


/* ================================================================
   8. NAVBAR RESPONSIVENESS
   ================================================================ */
.navbar-modern {
    position: relative;
}

@media (max-width: 575.98px) {
    .navbar-modern {
        padding: 0.5rem 0.75rem !important;
        border-radius: 12px !important;
        margin-bottom: 1rem !important;
    }

    .navbar-label-hide-sm { display: none !important; }
}

@media (max-width: 767.98px) {
    .notif-dropdown-container {
        position: static !important;
    }

    .notif-dropdown-menu {
        position: absolute !important;
        top: calc(100% + 8px) !important;
        left: 12px !important;
        right: 12px !important;
        width: auto !important;
        max-width: calc(100vw - 24px) !important;
        transform: none !important;
        margin: 0 !important;
        border-radius: 16px !important;
        box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.2), 0 8px 10px -6px rgba(0, 0, 0, 0.2) !important;
    }
}

/* ================================================================
   9. FORM INPUT IMPROVEMENTS MOBILE
   ================================================================ */
@media (max-width: 767.98px) {
    .form-control, .form-select {
        font-size: 16px !important; /* Prevent iOS Safari auto-zoom */
        min-height: 48px;
        padding: 0.75rem 1rem;
    }

    .form-label { font-size: 0.85rem; }

    .form-control::placeholder,
    input::placeholder {
        font-size: 0.84rem !important;
        opacity: 0.75;
    }

    .input-group > .form-control {
        padding-left: 0.5rem !important;
    }
}

@media (max-width: 400px) {
    .form-control::placeholder,
    input::placeholder {
        font-size: 0.78rem !important;
    }
}

/* ================================================================
   10. CARD & CONTENT IMPROVEMENTS
   ================================================================ */
@media (max-width: 767.98px) {
    .card { border-radius: 16px !important; }
    .card-header { padding: 1rem !important; }
    .card-body { padding: 1rem !important; }
    .rounded-4 { border-radius: 16px !important; }
    .rounded-5 { border-radius: 20px !important; }
}

@media (max-width: 575.98px) {
    #content { padding: 12px !important; }
    nav[aria-label="breadcrumb"] { display: none !important; }
}

/* ================================================================
   11. MODAL BOTTOM SHEET DI MOBILE
   ================================================================ */
@media (max-width: 575.98px) {
    .modal:not(#fileViewerModal) .modal-dialog {
        margin: 0 !important;
        max-width: 100% !important;
        min-height: 100vh !important;
        min-height: 100dvh !important;
        display: flex !important;
        align-items: flex-end !important;
    }

    .modal:not(#fileViewerModal) .modal-content {
        border-radius: 24px 24px 0 0 !important;
        width: 100% !important;
        min-height: 35vh;
        max-height: 90vh !important;
        max-height: 90dvh !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        padding-bottom: max(16px, env(safe-area-inset-bottom, 16px)) !important;
    }

    /* File Viewer Modal di Mobile (< 576px): Fullscreen 100%, Header Melekat Kuat di Atas, Tidak Terpotong */
    #fileViewerModal {
        padding: 0 !important;
        overflow: hidden !important;
    }

    #fileViewerModal .file-viewer-dialog,
    #fileViewerModal .modal-dialog {
        margin: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
        height: 100% !important;
        height: 100dvh !important;
        min-height: 100dvh !important;
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
        justify-content: flex-start !important;
    }

    #fileViewerModal .file-viewer-content,
    #fileViewerModal .modal-content {
        border-radius: 0 !important;
        height: 100% !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        border: 0 !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
    }

    #fileViewerModal .modal-header {
        padding: 8px 12px !important;
        min-height: 52px !important;
        position: sticky !important;
        top: 0 !important;
        z-index: 1060 !important;
        background: #0f172a !important;
        flex-shrink: 0 !important;
    }

    #fileViewerModal .modal-body {
        flex: 1 1 auto !important;
        min-height: 0 !important;
        height: calc(100dvh - 52px) !important;
        overflow: hidden !important;
        position: relative !important;
    }
}

/* File Viewer Modal Default (Desktop & Tablet) */
#fileViewerModal .file-viewer-dialog {
    margin: 1.5rem auto !important;
    max-width: 92vw !important;
    height: calc(100vh - 3rem) !important;
    height: calc(100dvh - 3rem) !important;
    display: flex !important;
    flex-direction: column !important;
}

#fileViewerModal .file-viewer-content {
    border-radius: 20px !important;
    height: 100% !important;
    max-height: 100% !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
}

/* ================================================================
   12. PAGINATION RESPONSIVE
   ================================================================ */
@media (max-width: 575.98px) {
    .pagination {
        flex-wrap: wrap;
        gap: 4px !important;
        justify-content: center;
    }

    .pagination .page-item .page-link {
        height: 36px !important;
        min-width: 36px !important;
        font-size: 0.8rem !important;
    }
}

/* ================================================================
   13. AUTH LAYOUT RESPONSIVENESS
   ================================================================ */
@media (max-width: 767.98px) {
    .glass-left-panel { display: none !important; }

    .auth-form-col {
        flex: 0 0 100% !important;
        max-width: 100% !important;
        width: 100% !important;
    }

    .glass-auth-card {
        border-radius: 20px !important;
    }

    .auth-container {
        padding: 0 4px !important;
        max-width: 100% !important;
    }
}

/* ================================================================
   14. DROPDOWN MENU OVERFLOW FIX
   ================================================================ */
@media (max-width: 575.98px) {
    .dropdown-menu:not(.notif-dropdown-menu) {
        max-width: 94vw !important;
    }
}

/* ================================================================
   15. ADMIN TABLE CARD-VIEW (Tailwind admin panel)
   ================================================================ */
@media (max-width: 767.98px) {
    .admin-table-responsive table { display: block; }
    .admin-table-responsive thead { display: none; }
    .admin-table-responsive tbody { display: block; }

    .admin-table-responsive tr {
        display: block;
        background: white;
        border-radius: 14px;
        margin-bottom: 12px;
        padding: 12px 16px;
        box-shadow: 0 2px 8px rgba(0,0,0,0.06);
        border: 1px solid #e2e8f0;
    }

    .admin-table-responsive td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 6px 0;
        border: none !important;
        font-size: 0.88rem;
        gap: 8px;
        border-bottom: 1px solid #f1f5f9 !important;
    }

    .admin-table-responsive td:last-child {
        border-bottom: none !important;
    }

    .admin-table-responsive td::before {
        content: attr(data-label);
        font-weight: 700;
        font-size: 0.72rem;
        color: #94a3b8;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        min-width: 90px;
    }
}

/* ================================================================
   16. GLOBAL OVERFLOW & SCROLLING FIXES
   ================================================================ */
html {
    overflow-x: hidden !important;
    overflow-y: auto !important;
    max-width: 100%;
}

body {
    overflow-x: hidden !important;
    overflow-y: auto !important;
    max-width: 100%;
    min-height: 100vh;
    -webkit-overflow-scrolling: touch !important;
}

body.sidebar-open {
    overflow: hidden !important;
}

#content {
    overflow-y: visible !important;
    overflow-x: hidden !important;
}

img { max-width: 100%; height: auto; }
.text-break-word { word-break: break-word; overflow-wrap: break-word; }
table:not(.table-responsive table) { word-break: break-word; }
.table-responsive table { word-break: normal !important; }

/* ================================================================
   16.5 PDF & SLIDE READER RESPONSIVENESS
   ================================================================ */
.pdf-scroll-wrapper {
    -webkit-overflow-scrolling: touch;
}

@media (min-width: 768px) {
    .pdf-scroll-wrapper {
        padding: 1.25rem 0.75rem !important;
    }
}

@media (max-width: 767.98px) {
    .slide-reader-deck .next-slide-btn,
    .slide-reader-deck .prev-slide-btn {
        font-size: 0.85rem !important;
        white-space: nowrap !important;
    }

    .slide-reader-deck canvas {
        width: 100% !important;
        height: auto !important;
    }
}

/* ================================================================
   16.6 CALENDAR GRID RESPONSIVENESS
   Mencegah sel kalender menjadi lonjong/kapsul dan teks melebihi border
   ================================================================ */
.calendar-day-cell {
    min-height: 52px;
    padding: 4px 3px !important;
    border-radius: 8px !important;
    transition: all .2s ease;
    cursor: pointer;
    overflow: hidden;
}

@media (min-width: 576px) {
    .calendar-day-cell {
        min-height: 72px;
        padding: 6px 5px !important;
        border-radius: 10px !important;
    }
}

@media (min-width: 768px) {
    .calendar-day-cell {
        min-height: 88px;
        padding: 8px !important;
        border-radius: 12px !important;
    }
}

/* ================================================================
   16.7 FILE ATTACHMENT & SUBMISSION CARD RESPONSIVENESS
   ================================================================ */
.text-truncate-filename {
    min-width: 0 !important;
    max-width: 100% !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    display: inline-block !important;
}

@media (max-width: 575.98px) {
    .card {
        border-radius: 16px !important;
    }
}

/* ================================================================
   17. GLOBAL SCROLLBAR
   ================================================================ */
* {
    scrollbar-width: thin;
    scrollbar-color: rgba(31, 77, 58, 0.25) transparent;
}
*::-webkit-scrollbar { width: 5px; height: 5px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: rgba(31, 77, 58, 0.25); border-radius: 10px; }
*::-webkit-scrollbar-thumb:hover { background: rgba(31, 77, 58, 0.45); }

/* ================================================================
   18. PRINT
   ================================================================ */
@media print {
    .sidebar, .navbar-modern, #sidebarCollapse, .dropdown { display: none !important; }
    #content { padding: 0 !important; }
    body { background: white !important; }
}
