/* ============================================================
   E-INVENTARIS - MOBILE & RESPONSIVE STYLESHEET
   SD Muhammadiyah Serut
   Fix: No zoom, No horizontal scroll, Layout rapi di HP
   ============================================================ */

/* ── GLOBAL: PAKSA TIDAK BISA GESER KANAN-KIRI & NO DOUBLE-TAP ZOOM ── */
html, body {
    overflow-x: hidden !important;
    max-width: 100vw !important;
    overscroll-behavior-x: none;
    touch-action: pan-y; /* hanya scroll vertikal */
}

/* Cegah double-tap zoom di tombol, link, dan form */
button, input, select, textarea, a, .nav-item, .mobile-nav-btn {
    touch-action: manipulation;
}

/* Pastikan semua wrapper utama tidak meluap ke samping */
.main-wrapper,
.content-area,
.tab-content,
.panel,
.top-header,
.stats-grid {
    max-width: 100% !important;
    box-sizing: border-box !important;
}

/* Pengecualian: Tabel tetap bebas melebar di dalam container tabelnya sendiri */
.table-responsive .data-table,
.table-responsive table {
    max-width: none !important;
}

/* OVERLAY FOR SIDEBAR */
#sidebarOverlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(2px);
    z-index: 999;
    display: none;
    opacity: 0;
    transition: opacity 0.25s ease;
}
#sidebarOverlay.active {
    display: block;
    opacity: 1;
}

/* BOTTOM NAVIGATION (MOBILE) */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: #0f172a;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 950;
    align-items: center;
    justify-content: space-around;
    padding: 0 4px;
    box-shadow: 0 -4px 16px rgba(0,0,0,0.15);
    /* Safe area iPhone */
    padding-bottom: env(safe-area-inset-bottom, 0px);
}

.mobile-nav-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 10px;
    font-weight: 500;
    cursor: pointer;
    padding: 6px 2px;
    border-radius: 8px;
    transition: color 0.15s ease;
    min-width: 0;
}
.mobile-nav-btn i {
    font-size: 22px;
}
.mobile-nav-btn.active {
    color: #fbbf24;
    font-weight: 700;
}
.mobile-nav-btn span {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 52px;
}

/* ══════════════════════════════════════════════════════════════
   TABLET (≤ 992px)
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 992px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.active {
        transform: translateX(0);
    }
    .main-wrapper {
        margin-left: 0 !important;
        padding-bottom: 70px;
        width: 100% !important;
        min-width: 0 !important;
    }
    .btn-menu-mobile {
        display: block !important;
    }
    .mobile-bottom-nav {
        display: flex !important;
    }
    .content-area {
        padding: 16px;
        overflow-x: hidden;
    }
    .top-header {
        padding: 0 14px;
    }
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
    .scanner-grid {
        grid-template-columns: 1fr !important;
    }
    /* Tabel selalu scrollable horizontal di dalam container, bukan page */
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
    }
    /* Dashboard grid */
    [style*="grid-template-columns: repeat(auto-fit"] {
        grid-template-columns: 1fr !important;
    }
}

/* ══════════════════════════════════════════════════════════════
   MOBILE KECIL (≤ 640px) — PERBAIKAN MENYELURUH
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 640px) {

    /* LAYOUT DASAR */
    .content-area {
        padding: 12px !important;
        overflow-x: hidden !important;
    }

    /* HEADER */
    .top-header {
        padding: 0 12px !important;
        height: 54px !important;
    }
    .header-title h2 {
        font-size: 14px !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 160px;
    }
    .header-title p {
        display: none;
    }
    /* Sembunyikan teks "Scan Barcode" di header, cukup ikon */
    .top-header .header-right .btn span {
        display: none;
    }
    .user-badge {
        display: none; /* sembunyikan badge user di mobile kecil */
    }

    /* STATS GRID */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px;
    }
    .stat-card {
        padding: 12px 10px;
    }
    .stat-value {
        font-size: 18px !important;
    }
    .stat-label {
        font-size: 10.5px;
    }
    .stat-sub {
        display: none;
    }
    .stat-icon {
        width: 36px !important;
        height: 36px !important;
    }
    .stat-icon i {
        font-size: 18px !important;
    }

    /* PANEL */
    .panel-header {
        padding: 12px 14px !important;
        flex-wrap: wrap;
        gap: 8px;
    }
    .panel-title {
        font-size: 13px !important;
    }
    .panel-body {
        padding: 12px !important;
        overflow-x: hidden;
    }

    /* TOOLBAR FILTER */
    .toolbar {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 8px !important;
    }
    .search-box {
        max-width: 100% !important;
        min-width: 0 !important;
        width: 100%;
    }
    .filter-group {
        width: 100%;
        flex-wrap: wrap;
        gap: 6px;
    }
    .filter-select {
        flex: 1;
        min-width: 120px;
        font-size: 12px !important;
        padding: 7px 8px;
    }

    /* TABEL DATA */
    .table-responsive {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
        border-radius: 10px;
        /* Tabel boleh scroll horizontal di dalam box-nya, bukan page */
        max-width: calc(100vw - 24px);
    }
    .data-table {
        font-size: 12px !important;
        min-width: 520px; /* paksa tabel tetap bisa scroll di dalam box */
    }
    .data-table th, .data-table td {
        padding: 9px 10px !important;
    }

    /* MODAL */
    .modal-overlay {
        padding: 12px 8px 0 !important;
        align-items: flex-end !important; /* muncul dari bawah di mobile */
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
    .modal-card {
        max-height: 88vh !important;
        max-height: 88dvh !important;
        border-radius: 16px 16px 0 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
        margin: 0 !important;
    }
    .modal-card.modal-lg,
    .modal-card.modal-xl {
        max-width: 100% !important;
    }
    .modal-card > form,
    .modal-card form {
        display: flex !important;
        flex-direction: column !important;
        flex: 1 !important;
        min-height: 0 !important;
        overflow: hidden !important;
    }
    .modal-header {
        padding: 14px 16px !important;
        flex-shrink: 0 !important;
    }
    .modal-header h3 {
        font-size: 14px !important;
    }
    .modal-body {
        padding: 14px 16px 20px !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        flex: 1 1 auto !important;
        min-height: 0 !important;
        overscroll-behavior-y: contain !important;
    }
    .modal-footer {
        padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px)) !important;
        flex-direction: column-reverse !important;
        gap: 8px !important;
        flex-shrink: 0 !important;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.05) !important;
    }
    .modal-footer .btn {
        width: 100%;
        justify-content: center;
    }

    /* FORM */
    .form-grid {
        grid-template-columns: 1fr !important;
    }
    .form-group {
        margin-bottom: 14px;
    }
    .form-label {
        font-size: 12px !important;
    }
    .form-control,
    select.form-control,
    input,
    select,
    textarea {
        font-size: 16px !important; /* WAJIB: min 16px cegah iOS Safari auto-zoom saat fokus */
        padding: 10px 12px !important;
    }

    /* TOMBOL */
    .btn {
        font-size: 12.5px !important;
        padding: 8px 14px !important;
    }
    .btn-sm {
        font-size: 11.5px !important;
        padding: 5px 10px !important;
    }

    /* BADGE */
    .badge {
        font-size: 10px !important;
        padding: 2px 7px !important;
    }

    /* PAGINATION */
    .pagination {
        gap: 4px !important;
        flex-wrap: wrap;
    }
    .pagination button {
        min-width: 32px;
        height: 32px;
        font-size: 12px !important;
    }

    /* SCANNER: 1 KOLOM, FULL WIDTH */
    .scanner-grid {
        grid-template-columns: 1fr !important;
        gap: 14px !important;
    }
    .scanner-viewport-wrapper {
        min-height: 260px;
        border-radius: 12px;
    }
    .scanner-card-header {
        padding: 10px 12px;
        flex-wrap: wrap;
        gap: 6px;
    }
    .scanner-code-display {
        font-size: 11px;
        max-width: 54%;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    .scanner-product-title {
        font-size: 15px !important;
    }
    .scanner-card-body {
        padding: 14px;
    }
    .scanner-actions {
        flex-direction: column;
        gap: 8px;
    }
    .scanner-actions .btn,
    .scanner-actions a.btn {
        width: 100%;
        justify-content: center;
    }
    .pill-meta {
        font-size: 11px;
        padding: 3px 8px;
    }

    /* HTML5-QRCODE: cegah overflow */
    #pageScannerView,
    #modalScannerView {
        overflow: hidden !important;
        max-width: 100% !important;
    }
    #pageScannerView > *,
    #modalScannerView > * {
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    /* DASHBOARD AUTO-FIT GRID jadi 1 kolom */
    .panel + .panel {
        margin-top: 12px;
    }

    /* Print: sembunyikan */
    .header-right .btn:not(:last-child) {
        display: none;
    }
}

/* ══════════════════════════════════════════════════════════════
   VERY SMALL (≤ 380px) — HP LAYAR KECIL
   ══════════════════════════════════════════════════════════════ */
@media (max-width: 380px) {
    .stats-grid {
        grid-template-columns: 1fr !important; /* 1 kolom di HP sangat kecil */
    }
    .hide-xs {
        display: none !important;
    }
    .mobile-nav-btn span {
        display: none; /* hanya ikon di HP sangat kecil */
    }
    .mobile-bottom-nav {
        height: 54px;
    }
    .content-area {
        padding: 10px !important;
    }
}

/* ══════════════════════════════════════════════════════════════
   FIX iOS SAFARI: input font-size ≥ 16px agar tidak auto-zoom
   ══════════════════════════════════════════════════════════════ */
@media screen and (-webkit-min-device-pixel-ratio: 0) and (max-width: 640px) {
    input[type="text"],
    input[type="number"],
    input[type="date"],
    input[type="email"],
    input[type="password"],
    input[type="search"],
    input[type="tel"],
    input[type="url"],
    select,
    textarea {
        font-size: 16px !important;
    }
}

/* ══════════════════════════════════════════════════════════════
   PRINT: sembunyikan elemen navigasi saat cetak
   ══════════════════════════════════════════════════════════════ */
@media print {
    .sidebar,
    .top-header,
    .mobile-bottom-nav,
    #sidebarOverlay,
    .btn,
    .toolbar,
    .pagination {
        display: none !important;
    }
    .main-wrapper {
        margin-left: 0 !important;
    }
    .content-area {
        padding: 0 !important;
    }
}
