/* ============================================================
   E-SPMB - MOBILE & RESPONSIVE STYLESHEET (HP & TABLET)
   SD Muhammadiyah Serut
   Dioptimalkan: Ultra-ringkas, hemat tempat, font proporsional di HP
   ============================================================ */

/* ===== TABLET BREAKPOINT (<= 1024px) ===== */
@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
        width: min(var(--sidebar-width), 84vw);
        box-shadow: none;
        z-index: 9999;
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    }

    #sidebarOverlay {
        z-index: 9998;
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
    }

    .main-wrapper {
        margin-left: 0;
    }

    .mobile-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 34px;
        height: 34px;
    }
}

/* ===== HANDPHONE BREAKPOINT (<= 768px) ===== */
@media (max-width: 768px) {
    /* 0. Base Font Scaling: Mengurangi skala teks agar tidak makan tempat */
    html {
        font-size: 13.5px !important;
    }

    /* 1. Global Container & Spacing (Hemat Ruang) */
    .content-area {
        padding: 6px 6px 12px;
    }

    .container {
        padding: 0;
        max-width: 100%;
    }

    /* 2. Header Ringkas */
    .header {
        padding: 0 8px;
        height: 44px;
        gap: 6px;
    }

    .header-divider,
    .datetime-container,
    .live-badge {
        display: none !important;
    }

    .header-right {
        gap: 4px;
    }

    .logo-badge {
        width: 26px;
        height: 26px;
        border-radius: 6px;
    }

    .logo-badge i {
        font-size: 15px;
    }

    .logo-text h1 {
        font-size: 0.75rem !important;
        line-height: 1.15;
    }

    .logo-text p {
        font-size: 0.55rem !important;
    }

    .refresh-btn {
        width: 28px;
        height: 28px;
        min-width: 28px;
        border-radius: 6px;
    }

    .refresh-btn i {
        font-size: 14px;
    }

    .mobile-toggle {
        width: 28px;
        height: 28px;
        padding: 2px;
    }

    .mobile-toggle i {
        font-size: 18px;
    }

    /* 3. Hero Section Kompak (Hemat Tempat) */
    .hero-bar {
        flex-direction: column;
        align-items: stretch;
        padding: 8px 10px !important;
        gap: 8px !important;
        border-radius: 12px;
        margin-bottom: 8px;
        box-shadow: 0 4px 14px rgba(5, 150, 105, 0.22);
    }

    .hero-bar::before {
        display: none;
    }

    .hero-left {
        width: 100%;
    }

    .hero-info h2 {
        font-size: 0.6rem !important;
        letter-spacing: 0.6px;
        margin-bottom: 1px !important;
    }

    .hero-total {
        font-size: 1.25rem !important;
        letter-spacing: -0.5px;
        line-height: 1.1;
    }

    .hero-total span {
        font-size: 0.72rem;
        font-weight: 600;
        margin-left: 2px;
    }

    .hero-sub {
        font-size: 0.6rem !important;
        margin: 1px 0 6px;
    }

    #egressStatusBadge {
        margin-top: 3px !important;
        padding: 2px 6px !important;
        font-size: 0.55rem !important;
        gap: 3px !important;
    }

    #egressStatusBadge i {
        font-size: 11px !important;
    }

    .hero-chips {
        width: 100%;
        gap: 4px;
    }

    .hero-chip {
        padding: 2px 7px !important;
        font-size: 0.62rem !important;
        gap: 4px;
        border-radius: 6px;
    }

    .hero-chip .num {
        font-size: 0.8rem !important;
    }

    .hero-right {
        padding: 6px 10px !important;
        min-width: auto !important;
        width: 100%;
        text-align: left !important;
        border-radius: 8px;
        background: rgba(255, 255, 255, 0.15);
    }

    .hero-right p:first-child {
        font-size: 0.58rem !important;
        margin-bottom: 2px !important;
        letter-spacing: 0.4px !important;
    }

    #heroQuotaDisplay {
        font-size: 1.15rem !important;
        letter-spacing: -0.4px;
        line-height: 1;
    }

    #heroQuotaDisplay span {
        font-size: 0.72rem !important;
        margin-left: 3px !important;
    }

    #heroQuotaBar {
        height: 3px !important;
    }

    #heroQuotaYear {
        font-size: 0.58rem !important;
        margin-top: 2px !important;
    }

    /* 4. Stats Grid (2x2 Kompak & Rapi) */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 6px;
        margin-bottom: 8px;
    }

    .stat-card {
        padding: 6px 8px;
        gap: 6px;
        border-radius: 8px;
    }

    .stat-icon {
        width: 26px;
        height: 26px;
        border-radius: 6px;
    }

    .stat-icon i {
        font-size: 14px;
    }

    .stat-info h3 {
        font-size: 0.92rem;
        letter-spacing: -0.2px;
        line-height: 1;
    }

    .stat-info p {
        font-size: 0.56rem;
        letter-spacing: 0.2px;
        margin-top: 1px;
    }

    /* 5. Main Table Card & Toolbar */
    .main-card {
        padding: 8px 6px;
        border-radius: 10px;
    }

    .toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
        margin-bottom: 8px;
    }

    .toolbar-left {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 5px;
    }

    .table-controls {
        width: 100%;
        display: flex;
        flex-direction: column;
        gap: 5px;
    }

    .search-box {
        max-width: 100% !important;
        min-width: 100% !important;
        width: 100%;
    }

    .search-box input {
        height: 30px;
        font-size: 0.72rem;
        padding: 4px 8px 4px 28px;
        border-radius: 6px;
    }

    .search-box i {
        left: 8px;
        font-size: 14px;
    }

    .filter-row {
        width: 100%;
        display: flex;
        gap: 4px;
    }

    .filter-group {
        flex: 1;
        min-width: 0;
        height: 30px;
        padding: 2px 6px !important;
        border-radius: 6px !important;
    }

    .filter-group i {
        font-size: 13px !important;
        margin-right: 3px !important;
    }

    .filter-group select {
        width: 100%;
        font-size: 0.68rem !important;
    }

    /* Toolbar Right: Baris Horizontal Swipe Touch-Friendly */
    .toolbar-right {
        width: 100%;
        display: flex;
        gap: 4px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 2px;
        scrollbar-width: none;
        flex-wrap: nowrap;
    }

    .toolbar-right::-webkit-scrollbar {
        display: none;
    }

    .toolbar-right .action-btn {
        flex-shrink: 0;
        white-space: nowrap;
        height: 28px;
        padding: 3px 8px !important;
        font-size: 0.66rem !important;
        border-radius: 6px;
        gap: 3px;
    }

    .toolbar-right .action-btn i {
        font-size: 13px !important;
    }

    #syncBadge {
        flex-shrink: 0;
        white-space: nowrap;
        padding: 2px 6px !important;
        font-size: 0.6rem !important;
        gap: 3px !important;
        border-radius: 5px;
    }

    #syncBadge i {
        font-size: 12px !important;
    }

    /* Bulk Actions Bar */
    #bulkActions {
        padding: 6px 8px !important;
        flex-direction: column;
        gap: 6px;
        align-items: stretch !important;
        border-radius: 6px !important;
    }

    #bulkButtons {
        width: 100%;
        justify-content: flex-start;
        overflow-x: auto;
        flex-wrap: nowrap;
        padding-bottom: 2px;
        -webkit-overflow-scrolling: touch;
        gap: 4px;
    }

    #bulkButtons .action-btn {
        flex-shrink: 0;
        white-space: nowrap;
        height: 26px;
        padding: 3px 8px !important;
        font-size: 0.65rem !important;
    }

    /* 6. Tabel Data di Layar HP (Teks Pas, Hemat Tempat) */
    .table-wrap {
        border-radius: 6px;
        -webkit-overflow-scrolling: touch;
    }

    table {
        min-width: 620px;
    }

    table th {
        padding: 5px 4px !important;
        font-size: 0.62rem !important;
        letter-spacing: 0.2px;
    }

    table td {
        padding: 5px 4px !important;
        font-size: 0.66rem !important;
        line-height: 1.2;
    }

    .name-cell {
        min-width: 95px;
        font-size: 0.68rem !important;
    }

    .name-cell small {
        font-size: 0.56rem !important;
    }

    .time-cell {
        display: inline-flex;
        flex-direction: column;
        align-items: flex-start;
        gap: 0px;
        line-height: 1.15;
    }

    .time-cell .time-date {
        font-size: 0.62rem !important;
        font-weight: 600;
        white-space: nowrap;
    }

    .time-cell .time-hour {
        font-size: 0.55rem !important;
        color: var(--text-muted);
        font-family: 'DM Mono', monospace;
        white-space: nowrap;
    }


    .no-col {
        width: 28px !important;
    }

    .no-badge {
        width: 20px !important;
        height: 20px !important;
        font-size: 0.58rem !important;
        border-radius: 4px;
    }

    .gender-badge {
        width: 20px !important;
        height: 20px !important;
        font-size: 0.58rem !important;
        border-radius: 4px;
    }

    .row-checkbox {
        width: 16px !important;
        height: 16px !important;
        min-width: 16px;
    }

    .btn-icon {
        width: 24px !important;
        height: 24px !important;
        min-width: 24px !important;
        border-radius: 5px !important;
    }

    .btn-icon i {
        font-size: 13px !important;
    }

    .name-main { font-size: 0.68rem; }
    .name-meta { font-size: 0.56rem; gap: 4px; }
    .tag { font-size: 0.5rem; padding: 0 4px; }
    .multi-year-chip { font-size: 0.55rem; padding: 1px 5px; }
    .school-cell { min-width: 90px; max-width: 130px; font-size: 0.62rem; }
    .status-note { font-size: 0.56rem; max-width: 120px; }
    .status-note i { font-size: 10px; }
    .action-cell { gap: 3px; }

    .badge {
        font-size: 0.55rem !important;
        padding: 1px 4px !important;
        border-radius: 4px;
    }

    .status-pill {
        font-size: 0.55rem !important;
        padding: 1px 5px !important;
        border-radius: 4px;
    }

    .btn-detail {
        height: 24px !important;
        padding: 2px 6px !important;
        font-size: 0.62rem !important;
        gap: 2px;
        border-radius: 5px;
    }

    .btn-detail i {
        font-size: 12px !important;
    }

    /* Table Footer & Pagination */
    .table-footer {
        flex-direction: column;
        gap: 6px;
        align-items: center;
        text-align: center;
        font-size: 0.65rem;
        padding-top: 8px;
        margin-top: 8px;
    }

    .pagination {
        display: flex;
        gap: 2px;
        flex-wrap: wrap;
        justify-content: center;
    }

    .page-btn {
        min-width: 24px;
        height: 24px;
        font-size: 0.65rem;
        padding: 0 4px;
        border-radius: 5px;
    }

    /* 7. Modal Formulir & Detail (Ultra Kompak & Nyaman di HP) */
    .modal {
        padding: 4px;
        align-items: flex-end;
    }

    .modal-content,
    .map-content {
        padding: 12px 10px !important;
        border-radius: 14px 14px 0 0 !important;
        max-height: 94vh;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0;
    }

    .modal-header {
        margin-bottom: 8px;
        padding-bottom: 6px;
        position: sticky;
        top: -12px;
        background: white;
        z-index: 15;
        margin-top: -12px;
        padding-top: 12px;
    }

    .modal-header h2 {
        font-size: 0.82rem;
    }

    .modal-header p {
        font-size: 0.6rem;
    }

    .btn-close {
        width: 26px;
        height: 26px;
        border-radius: 5px;
    }

    .btn-close i {
        font-size: 15px;
    }

    .detail-section-title {
        font-size: 0.6rem;
        margin: 8px 0 4px;
        padding-bottom: 3px;
        letter-spacing: 0.4px;
        font-weight: 800;
    }

    /* Grid 2 Kolom Kompak: Menghemat tinggi scroll hingga 50% di HP */
    .detail-grid {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 4px 6px !important;
    }

    .detail-item.col-span-2 {
        grid-column: span 2 !important;
    }

    .detail-item {
        margin-bottom: 2px !important;
    }

    .detail-item label {
        font-size: 0.56rem !important;
        margin-bottom: 2px !important;
        font-weight: 700;
        line-height: 1.1;
    }

    .detail-item p {
        font-size: 0.72rem !important;
        line-height: 1.25;
    }

    /* Input & Select di Modal HP: Kompak & Presisi */
    .detail-item input,
    .detail-item select,
    .detail-item textarea,
    .modal-content input,
    .modal-content select {
        font-size: 0.72rem !important;
        min-height: 28px !important;
        height: 28px !important;
        padding: 3px 6px !important;
        border-radius: 6px !important;
        border-width: 1px !important;
    }

    .modal-footer {
        margin-top: 8px;
        padding-top: 6px;
        flex-direction: column-reverse;
        gap: 4px;
        position: sticky;
        bottom: -12px;
        background: white;
        z-index: 15;
        margin-bottom: -12px;
        padding-bottom: 12px;
    }

    .modal-footer button {
        width: 100%;
        justify-content: center;
        min-height: 32px;
        height: 32px;
        font-size: 0.72rem;
        border-radius: 6px;
    }

    /* 8. Toast Mobile */
    .toast-container {
        left: 8px;
        right: 8px;
        bottom: 10px;
        align-items: center;
    }

    .toast {
        max-width: 100%;
        width: 100%;
        font-size: 0.7rem;
        padding: 6px 10px;
        border-radius: 6px;
    }
}

/* ===== EXTRA COMPACT PHONES (<= 480px) ===== */
@media (max-width: 480px) {
    html {
        font-size: 12.5px !important;
    }

    .header {
        padding: 0 4px;
        height: 40px;
    }

    .logo-text p {
        display: none;
    }

    .hero-bar {
        padding: 6px 8px !important;
    }

    .hero-total {
        font-size: 1.15rem !important;
    }

    .stat-card {
        padding: 5px 6px;
    }

    .stat-info h3 {
        font-size: 0.85rem;
    }

    .main-card {
        padding: 6px 4px;
    }
}

/* ===== SCOPED PRINT TEMPLATE RESET ===== */
#printTemplate,
#printTemplate * {
    box-sizing: border-box !important;
}

#printTemplate table {
    width: 100% !important;
    border-collapse: collapse !important;
    border: none !important;
    margin: 0 !important;
    padding: 0 !important;
    table-layout: fixed !important;
}

#printTemplate tr {
    border: none !important;
    background: none !important;
    padding: 0 !important;
    margin: 0 !important;
}

#printTemplate td {
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    font-size: 8.5pt !important;
    font-family: 'Times New Roman', serif !important;
    color: black !important;
    line-height: 1.1 !important;
    vertical-align: top !important;
}
