/* Mobile & Responsive Master Stylesheet for NetBilling */

/* Universal Anti-Overflow Protection (Zero Horizontal Scroll Guarantee) */
html, body {
    overflow-x: hidden !important;
    max-width: 100vw !important;
    width: 100% !important;
    position: relative;
    box-sizing: border-box !important;
}

*, *::before, *::after {
    box-sizing: border-box !important;
    max-width: 100%;
}

img, video, canvas, svg {
    max-width: 100% !important;
    height: auto;
}

pre, code {
    white-space: pre-wrap !important;
    word-break: break-all !important;
}

input, select, textarea, button {
    max-width: 100% !important;
    box-sizing: border-box !important;
}

p, span, td, div, a {
    overflow-wrap: break-word !important;
}

/* Mobile Header / Hamburger Bar (Hidden on Desktop) */
.mobile-topbar {
    display: none;
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    height: 60px;
    background: #ffffff;
    border-bottom: 1px solid #e5e7eb;
    padding: 0 1rem;
    align-items: center;
    justify-content: space-between;
    z-index: 1000;
    box-shadow: 0 2px 4px rgba(0,0,0,0.02);
}

.mobile-topbar-brand {
    font-size: 1.1rem;
    font-weight: 700;
    color: #4f46e5;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.mobile-nav-toggle {
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #1f2937;
}

/* Sidebar Backdrop on Mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.4);
    backdrop-filter: blur(2px);
    z-index: 1040;
}

/* Dual View Utility (Desktop Table vs Mobile Cards) */
.desktop-table-view, .desktop-table-wrap {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.mobile-cards-view, .mobile-item-list {
    display: none;
}

/* Standard Mobile Card Components */
.m-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 0.75rem;
    padding: 1rem;
    margin-bottom: 0.85rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    box-sizing: border-box;
}
.m-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
    border-bottom: 1px dashed #e2e8f0;
    padding-bottom: 0.5rem;
    margin-bottom: 0.25rem;
}
.m-card-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: #0f172a;
}
.m-card-body {
    font-size: 0.83rem;
    line-height: 1.45;
    color: #334155;
}
.m-card-footer {
    display: flex;
    gap: 0.45rem;
    flex-wrap: wrap;
    align-items: center;
    margin-top: 0.35rem;
    padding-top: 0.5rem;
    border-top: 1px dashed #f1f5f9;
}
.m-card-footer .btn, .m-card-footer .btn-sm {
    flex: 1 1 auto;
    justify-content: center;
    text-align: center;
    padding: 0.5rem 0.75rem;
    font-size: 0.8rem;
}

/* Responsive Table Wrapper with Zero Horizontal Overflow on Mobile */
.table-responsive {
    width: 100%;
    max-width: 100%;
    margin-bottom: 0.5rem;
    border-radius: inherit;
    box-sizing: border-box;
}

/* Media Query: Tablet & Mobile (<= 868px) */
@media (max-width: 868px) {
    body {
        display: block !important;
        padding: 0 !important;
        width: 100% !important;
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }

    .mobile-topbar {
        display: flex !important;
    }

    /* Transform Sidebar into Slide-in Drawer */
    .sidebar {
        position: fixed !important;
        top: 0 !important;
        left: -280px !important;
        width: 280px !important;
        height: 100vh !important;
        max-height: 100vh !important;
        padding-bottom: 3.5rem !important;
        z-index: 1050 !important;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
        box-shadow: 4px 0 24px rgba(0,0,0,0.15) !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        overscroll-behavior-y: contain !important;
    }

    .sidebar.open {
        left: 0 !important;
    }

    .sidebar-overlay.active {
        display: block !important;
    }

    /* Main Content adjustment */
    .main-content {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        padding: 0.85rem 0.75rem 2.5rem !important;
        box-sizing: border-box !important;
        overflow-x: hidden !important;
    }

    /* Standalone Container adjustment */
    .container {
        padding: 0.5rem !important;
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
        overflow-x: hidden !important;
    }

    /* Dual View Switching: Hide Wide Desktop Tables, Show Ergonomic Mobile Cards */
    .desktop-table-view, .desktop-table-wrap {
        display: none !important;
    }
    .mobile-cards-view, .mobile-item-list {
        display: block !important;
        width: 100% !important;
    }

    /* Headers */
    .header {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.85rem !important;
        width: 100% !important;
    }

    .header h1 {
        font-size: 1.35rem !important;
        line-height: 1.25 !important;
    }

    .header > div {
        width: 100% !important;
    }

    .header .btn, .header form button {
        width: 100% !important;
        justify-content: center !important;
    }

    /* Filter & Screening Bars, Headers, Toolbars */
    .screening-bar, .toolbar, .filter-card, .table-toolbar,
    .toolbar-bar, .router-selector-bar, .action-header, .card-header-flex,
    .top-bar, .header {
        flex-direction: column !important;
        align-items: stretch !important;
        padding: 0.85rem !important;
        gap: 0.65rem !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .screening-bar form, .toolbar form, .filter-form, .router-selector-left {
        flex-direction: column !important;
        align-items: stretch !important;
        width: 100% !important;
        gap: 0.5rem !important;
    }

    .screening-bar select, .screening-bar input,
    .toolbar select, .toolbar input,
    .filter-form select, .filter-form input,
    .period-selector, .router-select,
    .search-box-wrap, .search-box, .search-box input, .search-box-wrap input,
    #customerSearch, #invoiceSearch, #collectorSearch, #pppoeSearch, #screeningSearch {
        width: 100% !important;
        min-width: 0 !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    /* Multi-column grids to Single Column */
    .grid-2, .grid, .stats-grid, .grid-info, .form-grid,
    .gateway-selector, .collector-cards-grid, .grid-pw {
        grid-template-columns: 1fr !important;
        gap: 0.85rem !important;
        width: 100% !important;
    }

    /* Card adjustments */
    .card, .table-card {
        padding: 1rem !important;
        border-radius: 0.75rem !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    /* Form elements */
    .form-group.full, .form-group.full-width {
        grid-column: span 1 !important;
    }

    /* Buttons inside action groups & headers */
    .btn-action-group {
        display: flex !important;
        flex-direction: column !important;
        gap: 0.35rem !important;
        width: 100% !important;
    }
    .btn-action-group .btn-sm, .btn-action-group .btn,
    .header .btn, .header form button,
    .top-bar .btn, .header-actions, .header-actions .btn-action,
    .btn-action-outline, .btn-action-primary, .btn-action-success,
    .router-select {
        width: 100% !important;
        justify-content: center !important;
        text-align: center !important;
        padding: 0.55rem 0.75rem !important;
        box-sizing: border-box !important;
    }

    /* Action footer in forms & cards */
    .card div[style*="justify-content: flex-end"],
    .card div[style*="justify-content: space-between"],
    .edit-action-footer {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.65rem !important;
        width: 100% !important;
    }
    .card div[style*="justify-content: flex-end"] .btn,
    .card div[style*="justify-content: space-between"] .btn,
    .edit-action-footer .btn {
        width: 100% !important;
        justify-content: center !important;
        text-align: center !important;
    }

    /* Logo Preview Box in Profil */
    .logo-preview-box {
        flex-direction: column !important;
        align-items: center !important;
        text-align: center !important;
        gap: 0.85rem !important;
    }

    /* Router Items in Mikrotik Management */
    .router-item {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.65rem !important;
    }
    .router-item > div:last-child {
        display: flex !important;
        gap: 0.5rem !important;
        width: 100% !important;
    }
    .router-item > div:last-child a,
    .router-item > div:last-child span {
        flex: 1 !important;
        text-align: center !important;
        justify-content: center !important;
    }

    /* Screening Actions in screening_pppoe.php */
    .row-actions {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 0.35rem !important;
        width: 100% !important;
        margin-top: 0.35rem !important;
    }
    .row-actions .btn-mini, .row-actions form, .row-actions form button {
        flex: 1 1 auto !important;
        justify-content: center !important;
        text-align: center !important;
    }

    /* Universal Responsive Card Transformation for Standard Tables */
    .table-responsive {
        overflow-x: hidden !important;
        width: 100% !important;
    }

    .table-responsive:not(.keep-table) > table,
    .table-responsive:not(.keep-table) table {
        display: block !important;
        width: 100% !important;
        min-width: 0 !important;
        border: none !important;
        box-sizing: border-box !important;
    }

    .table-responsive:not(.keep-table) thead {
        display: none !important;
    }

    .table-responsive:not(.keep-table) tbody {
        display: block !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .table-responsive:not(.keep-table) tr {
        display: block !important;
        width: 100% !important;
        background: #ffffff !important;
        border: 1px solid #e5e7eb !important;
        border-radius: 0.75rem !important;
        padding: 0.85rem 1rem !important;
        margin-bottom: 0.85rem !important;
        box-shadow: 0 1px 3px rgba(0,0,0,0.04) !important;
        box-sizing: border-box !important;
    }

    .table-responsive:not(.keep-table) td {
        display: block !important;
        width: 100% !important;
        padding: 0.45rem 0 !important;
        border-bottom: 1px dashed #f1f5f9 !important;
        font-size: 0.85rem !important;
        text-align: left !important;
        word-break: break-word !important;
        overflow-wrap: anywhere !important;
        box-sizing: border-box !important;
    }

    .table-responsive:not(.keep-table) tr td:last-child {
        border-bottom: none !important;
        padding-top: 0.65rem !important;
    }

    /* Modal boxes on mobile */
    .modal-box, .modal-card {
        width: 94% !important;
        max-width: 94% !important;
        padding: 1.15rem !important;
        margin: 1rem auto !important;
        box-sizing: border-box !important;
    }

    /* Navbars on standalone portals */
    .navbar {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.75rem !important;
        padding: 0.85rem 1rem !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    /* Search Boxes */
    .search-box-wrap {
        max-width: 100% !important;
        width: 100% !important;
    }

    /* Tab navigation buttons */
    .filter-tabs-container {
        display: flex !important;
        flex-wrap: wrap !important;
        gap: 0.35rem !important;
    }
    .filter-tab-btn {
        flex: 1 1 calc(50% - 0.35rem) !important;
        justify-content: center !important;
        padding: 0.45rem 0.5rem !important;
        font-size: 0.76rem !important;
        text-align: center !important;
    }
}

/* Sidebar Navigasi Ramping & Rapi (Compact & Scrollable Desktop & Mobile) */
@media (min-width: 869px) {
    .sidebar {
        width: 230px !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        bottom: 0 !important;
        height: 100vh !important;
        max-height: 100vh !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        overscroll-behavior-y: contain !important;
        padding: 1.25rem 0.85rem 3rem 0.85rem !important;
        z-index: 100 !important;
        scrollbar-width: thin !important;
        scrollbar-color: #cbd5e1 transparent !important;
    }

    .main-content {
        margin-left: 230px !important;
        width: calc(100% - 230px) !important;
    }
}

/* Custom Scrollbar yang Halus & Modern untuk Desktop Sidebar */
.sidebar::-webkit-scrollbar {
    width: 5px !important;
}
.sidebar::-webkit-scrollbar-track {
    background: transparent !important;
}
.sidebar::-webkit-scrollbar-thumb {
    background: #cbd5e1 !important;
    border-radius: 4px !important;
}
.sidebar::-webkit-scrollbar-thumb:hover {
    background: #94a3b8 !important;
}

.sidebar h2 {
    margin-bottom: 1.25rem !important;
    font-size: 1.15rem !important;
}
.sidebar a {
    padding: 0.52rem 0.75rem !important;
    margin-bottom: 0.22rem !important;
    font-size: 0.84rem !important;
    font-weight: 500 !important;
    border-radius: 0.45rem !important;
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    line-height: 1.35 !important;
    letter-spacing: -0.01em !important;
}
.sidebar a.logout-link {
    margin-top: 1rem !important;
    margin-bottom: 1.5rem !important;
    padding: 0.52rem 0.75rem !important;
    color: #ef4444 !important;
    background: #fef2f2 !important;
    border: 1px solid #fee2e2 !important;
    display: flex !important;
    align-items: center !important;
    gap: 0.5rem !important;
    font-weight: 600 !important;
}
.sidebar a.logout-link:hover {
    background: #ef4444 !important;
    color: #ffffff !important;
}

