/* ===== ROOT VARIABLES ===== */
:root {
    --primary-green: #2E7D32;
    --primary-green-light: #4CAF50;
    --primary-green-dark: #1B5E20;
    --primary-blue: #1976D2;
    --primary-blue-light: #42A5F5;
    --primary-blue-dark: #0D47A1;
    --accent-yellow: #FF9800;
    --accent-purple: #7C4DFF;
    --bg-light: #F5F7FA;
    --bg-white: #FFFFFF;
    --text-dark: #1A1A2E;
    --text-muted: #6B7280;
    --sidebar-width: 260px;
    --navbar-height: 60px;
    --bottom-nav-height: 62px;
    --border-radius: 12px;
    --shadow-sm: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 16px rgba(0,0,0,0.12);
    --shadow-lg: 0 8px 32px rgba(0,0,0,0.16);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== GLOBAL — PREVENT HORIZONTAL SCROLL ===== */
*, *::before, *::after { box-sizing: border-box; }
html {
    /* 'clip' (tidak seperti 'hidden') tidak menciptakan scroll container baru di Safari.
       Ini fix utama untuk WebKit horizontal overflow bug. */
    overflow-x: clip;
    max-width: 100%;
    scroll-behavior: smooth;
}
body {
    font-family: 'Inter', sans-serif;
    background: var(--bg-light);
    color: var(--text-dark);
    /* Jangan set overflow-x: hidden di KEDUANYA html & body — Safari bug.
       Cukup html saja (overflow-x: clip) + width constraint di body. */
    width: 100%;
    min-width: 0;
    position: relative;
}
img, video, canvas, iframe {
    max-width: 100%;
    height: auto;
}

/* ===== SIDEBAR & BACKDROP ===== */
.sidebar-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    z-index: 998;
    opacity: 0; visibility: hidden;
    transition: var(--transition);
}
.sidebar-overlay.show {
    opacity: 1; visibility: visible;
}
.sidebar {
    position: fixed; top: 0; left: 0;
    width: var(--sidebar-width); height: 100%;
    background: linear-gradient(180deg, var(--primary-green-dark) 0%, var(--primary-green) 55%, var(--primary-blue-dark) 100%);
    color: white; z-index: 999;
    transition: transform 0.3s ease;
    overflow-y: auto;
    overflow-x: hidden;
    box-shadow: 4px 0 24px rgba(0,0,0,0.18);
}
.sidebar.collapsed { transform: translateX(-100%); }
.sidebar-header {
    padding: 18px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.15);
    min-height: 70px;
}
.sidebar-header .logo-icon { font-size: 28px; line-height: 1; }
.sidebar-header h4 { font-weight: 700; letter-spacing: 1px; margin: 0; font-size: 17px; }
.sidebar-header small { opacity: 0.8; font-size: 11px; }
.sidebar-nav { padding: 12px 10px; }
.sidebar-nav .nav-link {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 14px; margin-bottom: 3px;
    color: rgba(255,255,255,0.85); text-decoration: none;
    border-radius: 10px; transition: var(--transition);
    font-size: 14px; font-weight: 500;
    white-space: nowrap;
}
.sidebar-nav .nav-link:hover {
    background: rgba(255,255,255,0.15);
    color: white;
    /* Hapus translateX — bisa memicu subpixel reflow di Safari
       dan berkontribusi ke horizontal overflow pada fixed parent */
}
.sidebar-nav .nav-link.active {
    background: rgba(255,255,255,0.22);
    color: white; font-weight: 600;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.sidebar-nav .nav-link i,
.sidebar-nav .nav-link svg { width: 20px; height: 20px; flex-shrink: 0; }

/* ===== MAIN CONTENT ===== */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    transition: margin 0.3s ease;
    overflow-x: hidden;
    width: calc(100% - var(--sidebar-width));
}
.main-content.expanded {
    margin-left: 0;
    width: 100%;
}

/* Ensure Bootstrap Modals sit cleanly on top of all fixed elements */
.modal-backdrop {
    z-index: 1060 !important;
}
.modal {
    z-index: 1065 !important;
}

/* ===== TOP NAVBAR ===== */
.top-navbar {
    height: var(--navbar-height);
    background: var(--bg-white);
    border-bottom: 1px solid #E5E7EB;
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 20px;
    position: sticky; top: 0; z-index: 997;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    max-width: 100%;
}
.page-title {
    color: var(--text-dark);
    font-weight: 600;
    font-size: 16px;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}
.sidebar-toggle {
    color: var(--text-dark); text-decoration: none; border: none;
    padding: 6px; background: none; flex-shrink: 0;
}
.sidebar-toggle svg { width: 22px; height: 22px; }

/* ===== PAGE CONTENT ===== */
.page-content {
    padding: 20px;
    overflow-x: hidden;
    max-width: 100%;
}

/* ===== STAT CARDS ===== */
.stat-card {
    background: var(--bg-white);
    border-radius: var(--border-radius);
    padding: 18px 16px;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    border-left: 4px solid transparent;
    position: relative; overflow: hidden;
}
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); }
.stat-card .stat-icon {
    width: 48px; height: 48px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center; font-size: 22px;
}
.stat-card .stat-value { font-size: 24px; font-weight: 700; margin: 0; }
.stat-card .stat-label { font-size: 13px; color: var(--text-muted); margin: 0; }
.stat-card.green { border-left-color: var(--primary-green); }
.stat-card.green .stat-icon { background: rgba(46,125,50,0.1); color: var(--primary-green); }
.stat-card.blue { border-left-color: var(--primary-blue); }
.stat-card.blue .stat-icon { background: rgba(25,118,210,0.1); color: var(--primary-blue); }
.stat-card.yellow { border-left-color: var(--accent-yellow); }
.stat-card.yellow .stat-icon { background: rgba(255,152,0,0.1); color: var(--accent-yellow); }
.stat-card.purple { border-left-color: var(--accent-purple); }
.stat-card.purple .stat-icon { background: rgba(124,77,255,0.1); color: var(--accent-purple); }

/* ===== CARDS ===== */
.card {
    border: none; border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm); transition: var(--transition);
    overflow: hidden;
}
.card:hover { box-shadow: var(--shadow-md); }
.card-header {
    background: transparent; border-bottom: 1px solid #E5E7EB;
    font-weight: 600; padding: 14px 18px;
}
.card-body { padding: 18px; }

/* ===== BUTTONS ===== */
.btn { border-radius: 8px; font-weight: 500; transition: var(--transition); }
.btn-primary {
    background: linear-gradient(135deg, var(--primary-green), var(--primary-blue));
    border: none; padding: 10px 20px;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(46,125,50,0.35); filter: brightness(1.08); }
.btn-success { background: var(--primary-green); border: none; }
.btn-success:hover { background: var(--primary-green-light); transform: translateY(-2px); }
.btn-info { background: var(--primary-blue); border: none; color: white; }
.btn-info:hover { background: var(--primary-blue-light); color: white; transform: translateY(-2px); }

/* ===== TABLES ===== */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.table { border-collapse: separate; border-spacing: 0; min-width: 100%; }
.table thead th {
    background: linear-gradient(135deg, var(--primary-green), var(--primary-blue));
    color: white; font-weight: 600; font-size: 13px;
    padding: 12px 14px; border: none;
    text-transform: uppercase; letter-spacing: 0.4px;
    white-space: nowrap;
}
.table thead th:first-child { border-radius: 10px 0 0 0; }
.table thead th:last-child { border-radius: 0 10px 0 0; }
.table tbody tr { transition: background 0.15s; }
.table tbody tr:hover { background: rgba(46,125,50,0.04); }
.table tbody td {
    padding: 11px 14px; vertical-align: middle;
    border-bottom: 1px solid #F0F0F0; font-size: 14px;
}

/* ===== FORMS ===== */
.form-control, .form-select {
    border-radius: 8px; border: 2px solid #E5E7EB;
    padding: 10px 12px; transition: var(--transition);
    max-width: 100%;
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary-green);
    box-shadow: 0 0 0 3px rgba(46,125,50,0.15);
}
.form-label { font-weight: 500; font-size: 14px; color: var(--text-dark); }

/* ===== PROGRESS BARS ===== */
.progress { height: 10px; border-radius: 6px; background: #E8F5E9; overflow: hidden; }
.progress-bar {
    background: linear-gradient(90deg, var(--primary-green), var(--primary-green-light));
    border-radius: 6px; transition: width 1s ease-in-out;
}
.progress-bar.blue {
    background: linear-gradient(90deg, var(--primary-blue), var(--primary-blue-light));
}

/* ===== BADGES ===== */
.badge { border-radius: 6px; padding: 4px 9px; font-weight: 500; }

/* ===== LOGIN PAGE ===== */
.login-page {
    min-height: 100vh;
    background: linear-gradient(135deg, var(--primary-green-dark) 0%, var(--primary-green) 35%, var(--primary-blue) 70%, var(--primary-blue-dark) 100%);
    display: flex; align-items: center; justify-content: center;
    padding: 16px; position: relative; overflow: hidden;
}
.login-page::before {
    content: '';
    position: absolute;
    /* Ganti inset: -50% (= lebar 300%) dengan ukuran pixel aman */
    top: -100%; left: -100%;
    width: 300%; height: 300%;
    background: radial-gradient(circle, rgba(255,255,255,0.05) 0%, transparent 70%);
    animation: pulse 8s ease-in-out infinite;
    will-change: transform;   /* Isolasi ke GPU layer, cegah reflow */
    pointer-events: none;
}
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.1); } }
.login-card {
    background: rgba(255,255,255,0.96);
    backdrop-filter: blur(20px);
    border-radius: 20px;
    padding: 40px 36px;
    width: 100%; max-width: 420px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    position: relative; z-index: 1; text-align: center;
}
.login-card .logo-icon { font-size: 56px; margin-bottom: 8px; }
.login-card .app-name {
    font-size: 34px; font-weight: 800;
    background: linear-gradient(135deg, var(--primary-green), var(--primary-blue));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    background-clip: text; margin-bottom: 4px;
}
.login-card .app-subtitle { color: var(--text-muted); font-size: 13px; margin-bottom: 6px; }
.login-card .slogan {
    font-style: italic; color: var(--primary-green);
    font-size: 12px; margin-bottom: 28px;
    padding: 10px 12px; background: rgba(46,125,50,0.08);
    border-radius: 10px; line-height: 1.5;
}
.login-card .input-group { margin-bottom: 14px; }
.login-card .input-group-text {
    background: transparent; border: 2px solid #E5E7EB; border-right: none;
    border-radius: 10px 0 0 10px; color: var(--primary-green);
}
.login-card .form-control {
    border: 2px solid #E5E7EB; border-left: none;
    border-radius: 0 10px 10px 0; padding: 12px 12px;
}
.login-card .btn-login {
    width: 100%;
    background: linear-gradient(135deg, var(--primary-green), var(--primary-blue));
    border: none; border-radius: 10px;
    padding: 14px; font-weight: 600;
    color: white; font-size: 16px; transition: var(--transition); margin-top: 6px;
}
.login-card .btn-login:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(46,125,50,0.4); }

/* ===== APP BOTTOM NAVIGATION (MOBILE) ===== */
.bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0;
    height: calc(var(--bottom-nav-height) + env(safe-area-inset-bottom, 0px));
    background: rgba(255,255,255,0.97);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid #E5E7EB;
    display: flex; align-items: stretch; justify-content: space-around;
    z-index: 1050;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.08);
    /* Safe Area Insets — WAJIB untuk iPhone notch & home indicator */
    padding-bottom: env(safe-area-inset-bottom, 0px);
    padding-left: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
}
.bottom-nav-item {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; color: #9CA3AF; text-decoration: none;
    font-size: 10px; font-weight: 500; flex: 1;
    padding: 8px 4px;
    transition: color 0.2s ease;
    position: relative;
}
.bottom-nav-item i, .bottom-nav-item svg {
    width: 22px; height: 22px; transition: transform 0.2s ease;
}
.bottom-nav-item.active {
    color: var(--primary-green);
    font-weight: 600;
}
.bottom-nav-item.active::before {
    content: '';
    position: absolute; top: 0; left: 20%; right: 20%;
    height: 3px; border-radius: 0 0 4px 4px;
    background: var(--primary-green);
}
.bottom-nav-item.active i,
.bottom-nav-item.active svg {
    transform: scale(1.15) translateY(-1px);
    color: var(--primary-green);
}
.bottom-nav-item:active { transform: scale(0.94); }

/* ===== READING CORNER ===== */
.checklist-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 14px; background: var(--bg-light);
    border-radius: 8px; margin-bottom: 8px; transition: var(--transition);
}
.checklist-item:hover { background: #E8F5E9; }
.checklist-item.completed { background: #E8F5E9; }
.checklist-item .check-icon {
    width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center; font-size: 13px;
}
.checklist-item.completed .check-icon { background: var(--primary-green); color: white; }
.checklist-item:not(.completed) .check-icon { background: #E0E0E0; color: #9E9E9E; }

/* ===== GALLERY ===== */
.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 12px;
}
.gallery-item {
    border-radius: 10px; overflow: hidden; position: relative;
    aspect-ratio: 1; box-shadow: var(--shadow-sm); transition: var(--transition);
}
.gallery-item:hover { transform: scale(1.02); box-shadow: var(--shadow-md); }
.gallery-item img { width: 100%; height: 100%; object-fit: cover; }
.gallery-item .gallery-delete {
    position: absolute; top: 6px; right: 6px;
    background: rgba(244,67,54,0.9); color: white; border: none;
    border-radius: 50%; width: 30px; height: 30px;
    display: flex; align-items: center; justify-content: center;
    opacity: 0; transition: var(--transition); cursor: pointer;
}
.gallery-item:hover .gallery-delete { opacity: 1; }

/* ===== MOBILE DATA CARDS (pengganti tabel di HP) ===== */
.mobile-data-card {
    background: var(--bg-white);
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 10px;
    box-shadow: var(--shadow-sm);
    border-left: 4px solid var(--primary-green);
    display: none; /* Disembunyikan di desktop */
}
.mobile-data-card .mdc-top {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 8px;
}
.mobile-data-card .mdc-name {
    font-weight: 600; font-size: 15px; color: var(--text-dark);
}
.mobile-data-card .mdc-badge {
    font-size: 12px; font-weight: 500;
    padding: 3px 10px; border-radius: 20px;
    background: rgba(46,125,50,0.1); color: var(--primary-green);
}
.mobile-data-card .mdc-detail {
    display: flex; flex-wrap: wrap; gap: 6px 16px;
    font-size: 13px; color: var(--text-muted); margin-bottom: 10px;
}
.mobile-data-card .mdc-detail span { display: flex; align-items: center; gap: 4px; }
.mobile-data-card .mdc-actions { display: flex; gap: 8px; }
.mobile-data-card .mdc-actions .btn { flex: 1; padding: 8px 6px; font-size: 13px; }

/* ===== PRINT STYLES ===== */
@media print {
    .sidebar, .top-navbar, .bottom-nav, .sidebar-overlay,
    .btn, .no-print, .d-print-none { display: none !important; }
    .main-content { margin-left: 0 !important; max-width: 100% !important; }
    .page-content { padding: 0 !important; }
    .card { box-shadow: none !important; border: 1px solid #ddd !important; }
    .mobile-data-card { display: none !important; }
    .desktop-table { display: table !important; }
}

/* ===== DESKTOP (> 992px) ===== */
@media (min-width: 993px) {
    .mobile-data-card { display: none !important; }
    .desktop-table-wrapper { display: block !important; }
}

/* ===== RESPONSIVE TABLET (≤ 992px) ===== */
@media (max-width: 992px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar:not(.collapsed) { transform: translateX(0); }
    .main-content {
        margin-left: 0;
        max-width: 100%;
    }
    .stat-card .stat-value { font-size: 20px; }
}

/* ===== RESPONSIVE MOBILE (≤ 768px) ===== */
@media (max-width: 768px) {
    html, body {
        overflow-x: hidden !important;
    }
    .main-content {
        overflow-x: hidden;
        /* Fix: ganti 100vw dengan 100% — di Safari, 100vw termasuk
           lebar scrollbar sehingga 15-17px lebih lebar dari viewport */
        max-width: 100%;
        width: 100%;
    }
    .page-content {
        padding: 12px 12px calc(var(--bottom-nav-height) + 16px) 12px;
        overflow-x: hidden;
    }
    .top-navbar {
        padding: 0 12px;
        height: 56px;
    }
    .page-title {
        font-size: 14px;
        max-width: 150px;
    }

    /* Sembunyikan tabel DataTables di mobile, tampilkan mobile cards */
    .mobile-only-cards .desktop-table-wrapper {
        display: none !important;
    }
    .mobile-only-cards .mobile-data-card {
        display: block !important;
    }
    /* Jika tidak ada mobile-only-cards, tabel tetap scroll horizontal tapi tidak meluber */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
        border-radius: 8px;
    }
    /* Ukuran DataTables controls */
    .dataTables_wrapper {
        overflow-x: hidden;
    }
    .dataTables_wrapper .dataTables_length,
    .dataTables_wrapper .dataTables_filter {
        float: none !important;
        text-align: left !important;
        margin-bottom: 8px;
    }
    .dataTables_wrapper .dataTables_filter input {
        width: 100% !important;
        margin-left: 0 !important;
        display: block;
        margin-top: 4px;
    }
    .dataTables_wrapper .dataTables_paginate {
        float: none !important;
        text-align: center !important;
        margin-top: 12px;
    }
    .dataTables_wrapper .dataTables_info {
        float: none !important;
        text-align: center !important;
    }
    /* Cards */
    .card-body { padding: 14px 12px; }
    .card-header { padding: 12px 14px; }
    /* Stat cards — 2 per row */
    .stat-card {
        padding: 12px 14px;
    }
    .stat-card .stat-icon { width: 38px; height: 38px; font-size: 16px; }
    .stat-card .stat-value { font-size: 18px; }
    .stat-card .stat-label { font-size: 11px; }
    /* Forms */
    .form-control, .form-select {
        font-size: 16px !important; /* prevents iOS zoom */
        padding: 10px 12px;
    }
    /* Page headers */
    .page-header-flex {
        flex-wrap: wrap;
        gap: 10px;
    }
    .page-header-flex h2 {
        font-size: 17px;
    }
    /* Columns full width */
    .col-md-6, .col-md-8, .col-md-4, .col-md-3 {
        max-width: 100% !important;
        flex: 0 0 100% !important;
    }
    /* Table button text hidden on mobile */
    .btn-label {
        display: none;
    }
    /* Breadcrumb */
    .breadcrumb { font-size: 12px; }
    /* Row gaps */
    .row { --bs-gutter-x: 10px; --bs-gutter-y: 10px; }
    /* Summary tabs / filter bar */
    .filter-row .col-md-2,
    .filter-row .col-md-4 {
        max-width: 100% !important;
        flex: 0 0 100% !important;
    }
}

/* ===== RESPONSIVE SMALL MOBILE (≤ 480px) ===== */
@media (max-width: 480px) {
    .page-content { padding: 10px 10px calc(var(--bottom-nav-height) + 12px) 10px; }
    .login-card { padding: 28px 18px; border-radius: 16px; }
    .login-card .app-name { font-size: 26px; }
    .login-card .logo-icon { font-size: 44px; }
    .bottom-nav-item { font-size: 9px; }
    .bottom-nav-item i, .bottom-nav-item svg { width: 20px; height: 20px; }
    .stat-card .stat-value { font-size: 16px; }
}

/* ===== ANIMATIONS ===== */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(14px); }
    to { opacity: 1; transform: translateY(0); }
}
.animate-fade-in { animation: fadeInUp 0.4s ease-out both; }
.animate-delay-1 { animation-delay: 0.08s; }
.animate-delay-2 { animation-delay: 0.16s; }
.animate-delay-3 { animation-delay: 0.24s; }
.animate-delay-4 { animation-delay: 0.32s; }
.animate-delay-5 { animation-delay: 0.40s; }
