/* ============================================
   IPTV Panel - Mobile App-Like Experience
   ============================================ */

/* Desktop: hide action button text labels (icon only) */
.action-label {
    display: none;
}

/* Desktop: hide auto-injected mobile search */
.dt-mobile-search {
    display: none;
}

/* PWA - Full screen feel */
html {
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
}

body {
    -webkit-font-smoothing: antialiased;
    touch-action: manipulation;
}

/* Prevent pull-to-refresh on mobile */
body.mobile-app {
    overscroll-behavior-y: contain;
}

/* ============================================
   MOBILE BOTTOM NAVIGATION
   ============================================ */
.mobile-bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1050;
    background: #fff;
    border-top: 1px solid #eee;
    padding: 4px 0;
    padding-bottom: calc(4px + env(safe-area-inset-bottom));
    box-shadow: 0 -4px 20px rgba(0,0,0,0.08);
}

.mobile-bottom-nav .nav-items {
    display: flex;
    justify-content: space-around;
    align-items: center;
    max-width: 500px;
    margin: 0 auto;
}

.mobile-bottom-nav .nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    color: #a1a5b7;
    font-size: 10px;
    font-weight: 500;
    padding: 4px 8px;
    border-radius: 8px;
    transition: all 0.2s;
    min-width: 56px;
}

.mobile-bottom-nav .nav-item i {
    font-size: 20px;
    margin-bottom: 2px;
}

.mobile-bottom-nav .nav-item.active,
.mobile-bottom-nav .nav-item:active {
    color: #009EF7;
}

.mobile-bottom-nav .nav-item.primary-btn {
    background: linear-gradient(135deg, #009EF7, #0095e8);
    color: #fff;
    border-radius: 14px;
    padding: 8px 16px;
    margin-top: -15px;
    box-shadow: 0 4px 15px rgba(0,158,247,0.4);
}

.mobile-bottom-nav .nav-item.primary-btn i {
    font-size: 22px;
}

.mobile-bottom-nav .nav-item.primary-btn:active {
    color: #fff;
    transform: scale(0.95);
}

/* ============================================
   MOBILE RESPONSIVE OVERRIDES
   ============================================ */
@media (max-width: 991.98px) {

    /* Show bottom nav */
    .mobile-bottom-nav {
        display: block;
    }

    /* Add bottom padding for nav */
    body {
        padding-bottom: 75px !important;
    }

    #pagefooter, #kt_footer {
        padding-bottom: 70px;
    }

    /* Hide desktop sidebar completely on mobile */
    .aside.aside-extended {
        z-index: 1060;
        display: none !important;
    }

    /* When drawer is opened via hamburger menu, show it */
    .aside.aside-extended.drawer-on {
        display: flex !important;
    }

    /* Wrapper takes full width on mobile */
    .wrapper {
        padding-left: 0 !important;
        margin-left: 0 !important;
    }

    .page {
        padding-left: 0 !important;
    }

    body[data-kt-aside-minimize="on"] .wrapper,
    body .wrapper {
        margin-left: 0 !important;
        padding-left: 0 !important;
    }

    /* Compact header on mobile */
    .topbar_base {
        gap: 4px !important;
    }

    .topbar_base .btn-sm {
        padding: 4px 8px !important;
        font-size: 11px !important;
    }

    .topbar_base .d-none.d-md-block,
    .topbar_base .d-none.d-lg-block {
        display: none !important;
    }

    /* Page title compact */
    #kt_header h1.fs-2 {
        font-size: 1.1rem !important;
    }

    .breadcrumb {
        font-size: 11px !important;
    }

    #kt_header {
        padding: 8px 0 !important;
        margin-top: 0 !important;
    }

    .header {
        margin-top: 0 !important;
    }

    /* ============================================
       CARDS - Mobile optimized
       ============================================ */
    .card {
        border-radius: 12px;
        margin-bottom: 12px !important;
    }

    .card-header {
        padding: 12px 16px !important;
        min-height: auto !important;
    }

    .card-body {
        padding: 12px 16px !important;
    }

    .card-title h3 {
        font-size: 15px !important;
    }

    /* Stats cards - 2 per row */
    .row.g-5.g-xl-8 > [class*="col-xl-3"] {
        flex: 0 0 50%;
        max-width: 50%;
        padding: 4px !important;
    }

    .row.g-5.g-xl-8 > [class*="col-xl-3"] .card-body {
        padding: 10px 12px !important;
    }

    .row.g-5.g-xl-8 > [class*="col-xl-3"] .fs-2 {
        font-size: 1.2rem !important;
    }

    .row.g-5.g-xl-8 > [class*="col-xl-3"] .fs-2x {
        font-size: 1.3rem !important;
    }

    /* ============================================
       TABLES - Card layout on mobile (NO horizontal scroll)
       ============================================ */
    .table-responsive,
    .dataTables_scrollBody,
    .dataTables_wrapper {
        overflow-x: hidden !important;
        overflow-y: visible !important;
        margin: 0;
        padding: 0;
    }

    /* Kill any table fixed width and scrollX wrapper */
    table.table,
    table.dataTable {
        width: 100% !important;
        table-layout: auto !important;
    }

    .dataTables_scrollHead,
    .dataTables_scrollBody {
        overflow: visible !important;
    }

    .dataTables_scroll {
        overflow: hidden !important;
    }

    .table-mobile-cards thead {
        display: none;
    }

    .table-mobile-cards,
    .table-mobile-cards tbody,
    .table-mobile-cards tr,
    .table-mobile-cards td {
        display: block;
        width: 100%;
    }

    .table-mobile-cards tr {
        background: #fff;
        border: 1px solid #f1f1f4;
        border-radius: 10px;
        margin-bottom: 10px;
        padding: 14px 18px;
        box-shadow: 0 1px 4px rgba(0,0,0,0.04);
    }

    .table-mobile-cards td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 6px 0 !important;
        border: none !important;
        font-size: 13px;
        text-align: right;
        overflow: hidden;
    }

    .table-mobile-cards td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #a1a5b7;
        font-size: 11px;
        text-transform: uppercase;
        letter-spacing: 0.3px;
        flex-shrink: 0;
        margin-right: 12px;
        text-align: left;
    }

    .table-mobile-cards td[data-label="#"] {
        display: none;
    }

    /* Actions row */
    .table-mobile-cards td[data-label="Actions"],
    .table-mobile-cards td:last-child:not([data-label]) {
        padding-top: 10px !important;
        margin-top: 4px;
        border-top: 1px solid #f1f1f4 !important;
        display: grid !important;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .table-mobile-cards td[data-label="Actions"]::before,
    .table-mobile-cards td:last-child:not([data-label])::before {
        display: none;
    }

    .table-mobile-cards td[data-label="Actions"] .action-btn,
    .table-mobile-cards td[data-label="Actions"] form,
    .table-mobile-cards td:last-child .action-btn,
    .table-mobile-cards td:last-child form {
        width: 100%;
        min-width: 0;
    }

    .table-mobile-cards td[data-label="Actions"] form .btn,
    .table-mobile-cards td:last-child form .btn {
        width: 100%;
    }

    .action-label {
        display: inline !important;
    }

    .action-btn {
        min-height: 40px;
        width: 100% !important;
        height: auto !important;
        font-size: 13px;
        white-space: nowrap;
    }

    /* Text truncation */
    .table-mobile-cards td code,
    .table-mobile-cards td > span:not(.badge),
    .table-mobile-cards td .fw-bolder,
    .table-mobile-cards td .fw-bold,
    .table-mobile-cards td .text-muted {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        max-width: 100%;
        display: inline-block;
    }

    .table-mobile-cards .badge {
        font-size: 11px;
    }

    .table-mobile-cards .btn-sm,
    .table-mobile-cards .btn-icon {
        min-height: 36px;
    }

    .table-mobile-cards td form.d-inline {
        display: inline !important;
    }

    /* DataTables integration */
    .dataTables_wrapper .table-mobile-cards tr.odd,
    .dataTables_wrapper .table-mobile-cards tr.even {
        background: #fff;
    }

    .dataTables_wrapper .dataTables_info {
        font-size: 12px;
        padding: 8px 0;
    }

    .dataTables_wrapper .dataTables_length {
        display: none;
    }

    /* Auto-injected mobile search (from header.php JS) */
    .dt-mobile-search {
        display: block !important;
    }

    /* Export buttons - compact row on mobile */
    .dt-buttons,
    .export-buttons {
        display: flex !important;
        gap: 6px;
        margin-bottom: 10px;
        flex-wrap: wrap;
    }

    .dt-buttons .btn,
    .export-buttons .btn {
        flex: 1;
        min-width: 0;
        font-size: 12px;
        padding: 8px 10px;
        min-height: 36px;
    }

    /* ============================================
       FORMS - Touch friendly
       ============================================ */
    .form-control,
    .form-select {
        min-height: 44px;
        font-size: 16px !important;
    }

    .form-control-lg {
        min-height: 50px;
        font-size: 18px !important;
    }

    .form-control-solid {
        border: 1px solid #e4e6ef;
    }

    .btn {
        min-height: 44px;
        padding-left: 16px;
        padding-right: 16px;
    }

    .btn-lg {
        min-height: 50px;
        font-size: 16px !important;
    }

    .btn-sm {
        min-height: 36px;
    }

    .btn-icon.btn-sm {
        min-height: 36px;
        width: 36px;
        height: 36px;
    }

    /* Form switch larger tap target */
    .form-check.form-switch {
        padding: 12px 0 12px 50px;
    }

    .form-check-input {
        width: 44px !important;
        height: 24px !important;
    }

    /* ============================================
       MODALS - Scrollable on mobile
       ============================================ */
    .modal-dialog {
        margin: 10px;
        max-width: calc(100% - 20px);
        min-height: auto;
        max-height: calc(100vh - 20px);
    }

    .modal-content {
        border: none;
        border-radius: 14px;
        min-height: auto;
        max-height: calc(100vh - 20px);
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    .modal-header {
        position: sticky;
        top: 0;
        background: #fff;
        z-index: 10;
        border-radius: 14px 14px 0 0;
        padding: 14px 16px;
        flex-shrink: 0;
        border-bottom: 1px solid #f1f1f4;
    }

    .modal-body {
        padding: 16px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        flex: 1;
        overscroll-behavior: contain;
    }

    .modal-footer {
        position: sticky;
        bottom: 0;
        background: #fff;
        border-top: 1px solid #f1f1f4;
        flex-shrink: 0;
    }

    /* Large modals - nearly full screen */
    .modal-lg,
    .modal-xl {
        max-width: calc(100% - 20px) !important;
    }

    .modal-dialog-scrollable .modal-body {
        max-height: none;
    }

    .modal-footer {
        padding: 12px 16px;
        gap: 8px;
    }

    .modal-footer .btn {
        flex: 1;
    }

    .modal.show {
        display: flex !important;
        align-items: center;
        justify-content: center;
    }

    .modal.show .modal-dialog {
        animation: modalSlideUp 0.25s ease-out;
        margin: 10px;
    }

    @keyframes modalSlideUp {
        from { transform: translateY(30px); opacity: 0; }
        to { transform: translateY(0); opacity: 1; }
    }

    .modal-lg .modal-dialog,
    .modal-dialog.modal-lg {
        margin: 10px;
        max-width: calc(100% - 20px);
    }

    /* ============================================
       BADGES
       ============================================ */
    .badge {
        font-size: 11px;
        padding: 5px 8px;
    }

    .badge, .session-pill {
        user-select: none;
    }

    /* ============================================
       ALERTS - full width on mobile
       ============================================ */
    .position-fixed.top-0.end-0 {
        left: 10px !important;
        right: 10px !important;
    }

    .position-fixed .alert {
        width: auto !important;
    }

    /* ============================================
       DATATABLES mobile fixes
       ============================================ */
    .dataTables_wrapper .dataTables_paginate .paginate_button {
        min-width: 40px;
        min-height: 40px;
        line-height: 40px;
        padding: 0 !important;
        margin: 0 2px;
    }

    /* ============================================
       SETTINGS tabs - scrollable on mobile
       ============================================ */
    .settings-tabs, .nav-tabs {
        flex-wrap: nowrap !important;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        -ms-overflow-style: none;
    }

    .settings-tabs::-webkit-scrollbar,
    .nav-tabs::-webkit-scrollbar {
        display: none;
    }

    .settings-tabs .nav-link,
    .nav-tabs .nav-link {
        white-space: nowrap;
        font-size: 13px;
        padding: 10px 14px;
    }

    /* Settings form buttons full width */
    .tab-content .btn-primary,
    .tab-content .btn-warning {
        width: 100%;
        margin-top: 10px;
    }

    .tab-content .form-label {
        font-size: 13px;
        margin-bottom: 4px;
    }

    /* ============================================
       PROFILE page
       ============================================ */
    .row.g-5 > .col-xl-6 {
        flex: 0 0 100%;
        max-width: 100%;
    }

    /* ============================================
       CONTAINER - reduce excess padding
       ============================================ */
    .container-fluid,
    #kt_content_container {
        padding-left: 16px !important;
        padding-right: 16px !important;
    }

    /* ============================================
       UTILITY
       ============================================ */
    .d-mobile-none {
        display: none !important;
    }

    .d-mobile-block {
        display: block !important;
    }

    .fs-mobile-7 {
        font-size: 0.85rem !important;
    }
}

/* Small phones */
@media (max-width: 375px) {
    .row.g-5.g-xl-8 > [class*="col-xl-3"] .card-body {
        padding: 8px !important;
    }

    .row.g-5.g-xl-8 > [class*="col-xl-3"] .fs-2 {
        font-size: 1rem !important;
    }

    .modal-body {
        padding: 12px !important;
    }
}

/* ============================================
   PWA STANDALONE MODE
   ============================================ */
@media (display-mode: standalone) {
    body {
        padding-top: env(safe-area-inset-top);
    }

    .powered-by-link {
        display: none;
    }
}
