/**
 * Admin panel responsive overrides.
 * Layout shell fixes live in style.css (shared with member portal).
 */

/* ------------------------------------------------------------------ */
/* Tablet (768px – 1140px)                                            */
/* ------------------------------------------------------------------ */
@media screen and (min-width: 768px) and (max-width: 1140px) {
    .admin-page .card h4.header-title {
        font-size: 20px;
        line-height: 36px;
    }

    .admin-page .top-tab-area {
        margin: 0 0.5rem;
    }

    .admin-page .profile-section-tab .table-view-12 {
        width: 100%;
        max-width: 100%;
        flex: 0 0 100%;
    }

    .dashboard-page .custom-box-1,
    .dashboard-page .custom-box-2 {
        width: 100%;
        max-width: 100%;
        flex: 0 0 100%;
    }

    .admin-area .topbar {
        flex-wrap: wrap;
        gap: 0.5rem;
        padding-top: 0.25rem;
        padding-bottom: 0.25rem;
    }

    .admin-area .topbar .app-search {
        order: 3;
        flex: 1 1 100%;
        max-width: 100%;
        margin: 0 !important;
    }

    .admin-area .topbar .app-search form {
        max-width: 100%;
    }
}

/* ------------------------------------------------------------------ */
/* Mobile (≤ 767px)                                                   */
/* ------------------------------------------------------------------ */
@media screen and (max-width: 767.98px) {
    /* Content shell */
    .content-page {
        padding-left: 0.5rem;
        padding-right: 0.5rem;
    }

    .content-page .content.admin-page {
        overflow-x: hidden;
    }

    .admin-page .page-top-gap,
    .page-top-gap {
        margin-top: 10px;
    }

    .admin-page .top-tab-area {
        margin: 0;
    }

    /* ---- Mobile topbar: single row [menu | search | profile] ---- */
    .navbar-custom.admin-area {
        position: sticky !important;
        top: 0 !important;
        z-index: 1070 !important;
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        min-height: auto !important;
        padding: 0 0.5rem !important;
        background: var(--ct-topbar-bg, #fff) !important;
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    }

    .navbar-custom.admin-area .topbar {
        display: flex !important;
        flex-wrap: nowrap !important;
        align-items: center !important;
        gap: 0.5rem !important;
        min-height: 56px !important;
        padding: 0.35rem 0 !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    .navbar-custom.admin-area .navbar-toggle {
        display: none !important;
    }

    .admin-area .topbar > .d-flex {
        flex: 0 0 auto !important;
    }

    .navbar-custom .button-toggle-menu {
        flex-shrink: 0;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        min-width: 44px;
        min-height: 44px;
        width: 44px;
        padding: 0;
        cursor: pointer;
    }

    .navbar-custom .button-toggle-menu i {
        pointer-events: none;
    }

    .admin-area .topbar .app-search {
        flex: 1 1 auto !important;
        order: 0 !important;
        min-width: 0 !important;
        width: auto !important;
        max-width: none !important;
        margin: 0 !important;
        overflow: hidden;
    }

    .admin-area .topbar .app-search form {
        height: auto !important;
        max-width: 100% !important;
        width: 100% !important;
        margin: 0 !important;
    }

    .admin-area .topbar .app-search .input-group {
        width: 100%;
    }

    .admin-area .topbar .app-search input[type=search] {
        font-size: 14px;
        min-width: 0;
    }

    .navbar-custom.admin-area .topbar-menu {
        flex: 0 0 auto !important;
        margin-left: 0 !important;
        position: relative !important;
        padding-left: 0 !important;
    }

    .navbar-custom.admin-area .nav-user {
        min-height: auto !important;
        height: auto !important;
        padding: 0.25rem !important;
        border: 0 !important;
        gap: 0 !important;
    }

    .navbar-custom.admin-area .dropdown {
        position: relative !important;
    }

    .navbar-custom.admin-area .dropdown .dropdown-menu {
        position: absolute !important;
        right: 0 !important;
        left: auto !important;
        top: calc(100% + 4px) !important;
        min-width: 10rem !important;
        max-width: calc(100vw - 1.5rem) !important;
        margin: 0 !important;
    }

    html.sidebar-enable .navbar-custom.admin-area .app-search {
        visibility: hidden;
        pointer-events: none;
    }

    /* ---- Mobile sidebar drawer (iOS: use left, not transform) ---- */
    html[data-sidenav-size=full]:not([data-layout=topnav]) .leftside-menu,
    html[data-sidenav-size=fullscreen]:not([data-layout=topnav]) .leftside-menu,
    html:not([data-layout=topnav]) .leftside-menu {
        position: fixed !important;
        top: var(--admin-mobile-topbar-height, 56px) !important;
        left: -100% !important;
        right: auto !important;
        bottom: 0 !important;
        width: 280px !important;
        max-width: 85vw !important;
        min-width: 0 !important;
        height: auto !important;
        max-height: none !important;
        margin-left: 0 !important;
        opacity: 1 !important;
        visibility: visible !important;
        transform: none !important;
        -webkit-transform: none !important;
        transition: left 0.25s ease-in-out !important;
        -webkit-transition: left 0.25s ease-in-out !important;
        pointer-events: none !important;
        z-index: 1080 !important;
        box-shadow: none !important;
        overflow-y: auto !important;
        overflow-x: hidden !important;
        -webkit-overflow-scrolling: touch;
        background: #fff !important;
        -webkit-backface-visibility: hidden;
        backface-visibility: hidden;
    }

    html.sidebar-enable:not([data-layout=topnav]) .leftside-menu,
    html:not([data-layout=topnav]) .leftside-menu.admin-mobile-sidebar-open {
        left: 0 !important;
        margin-left: 0 !important;
        opacity: 1 !important;
        visibility: visible !important;
        pointer-events: auto !important;
        box-shadow: 4px 0 20px rgba(0, 0, 0, 0.2) !important;
        z-index: 1080 !important;
    }

    html.sidebar-enable:not([data-layout=topnav]) .button-close-fullsidebar {
        display: block !important;
        z-index: 2;
    }

    #admin-sidebar-backdrop,
    #custom-backdrop {
        position: fixed !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        top: var(--admin-mobile-topbar-height, 56px) !important;
        z-index: 1075 !important;
        background-color: rgba(0, 0, 0, 0.5) !important;
        opacity: 1 !important;
    }

    html:not([data-layout=topnav]) .content-page {
        margin-left: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    .wrapper,
    body {
        overflow-x: hidden;
    }

    body.admin-sidebar-open {
        overflow: hidden !important;
        touch-action: none;
    }

    /* Bootstrap modals must stay clickable above admin chrome on mobile */
    body.modal-open {
        touch-action: auto !important;
    }

    body.modal-open .modal.show {
        pointer-events: auto !important;
    }

    body.modal-open .modal.show .modal-dialog,
    body.modal-open .modal.show .modal-content,
    body.modal-open .modal.show button,
    body.modal-open .modal.show a,
    body.modal-open .modal.show input,
    body.modal-open .modal.show select,
    body.modal-open .modal.show textarea,
    body.modal-open .modal.show label {
        pointer-events: auto !important;
        touch-action: manipulation;
    }

    /* Docs image zoom overlay */
    .custom-image-modal {
        z-index: 1100 !important;
        align-items: center;
        justify-content: center;
        touch-action: manipulation;
    }

    .custom-image-modal .close {
        z-index: 1101;
        top: calc(var(--admin-mobile-topbar-height, 56px) + 12px);
        right: 16px;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        line-height: 1;
        pointer-events: auto !important;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }

    .custom-image-modal .modal-content {
        pointer-events: auto;
        touch-action: manipulation;
    }

    /* Override theme hidden state on iOS */
    html[data-sidenav-size=full]:not([data-layout=topnav]):not(.sidebar-enable) .leftside-menu {
        margin-left: 0 !important;
        opacity: 1 !important;
        visibility: visible !important;
    }

    /* Typography */
    .admin-page .card h4.header-title {
        font-size: 18px;
        line-height: 32px;
    }

    .admin-common-title {
        font-size: 16px;
    }

    /* Dashboard */
    .dashboard-page .custom-box-1,
    .dashboard-page .custom-box-2 {
        width: 100%;
        max-width: 100%;
        flex: 0 0 100%;
    }

    .dashboard-card {
        min-height: auto;
        padding: 1rem;
    }

    .dashboard-card h3 {
        font-size: 24px;
        line-height: 32px;
    }

    .dashboard-card h5 {
        font-size: 14px;
        line-height: 22px;
    }

    .dashboard-graph-card .count {
        font-size: 20px;
    }

    .dashboard-graph-card .title {
        font-size: 14px;
    }

    .col-lg-5.dashboard-graph-card {
        padding-right: 0.469rem !important;
    }

    .admin-page .dashboard-graph-card .common-card .card-body {
        min-height: auto;
        padding: 15px;
    }

    /* Profile / user details */
    .admin-page .profile-section-tab .table-view-12 {
        width: 100%;
        max-width: 100%;
        flex: 0 0 100%;
        padding-left: 0.469rem;
        padding-right: 0.469rem;
    }

    .admin-page .silva-profile-main img {
        float: none !important;
        display: block;
        margin: 0 auto 10px;
    }

    .admin-page .profile-area {
        flex-direction: column;
        text-align: center;
    }

    .admin-page .profile-text p,
    .admin-page .profile-text h4 {
        text-align: center;
    }

    .admin-page .user-details-table .button-area {
        text-align: center;
        padding: 10px 0;
    }

    /* Tables */
    .admin-page .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
    }

    .admin-page .custom-table-2 {
        min-width: 600px;
    }

    .admin-page .custom-table-2 tbody tr td {
        padding: 12px 10px;
        font-size: 13px;
        white-space: nowrap;
    }

    .admin-page .custom-table-2 .table-area th {
        font-size: 12px;
        padding: 10px 8px;
        white-space: nowrap;
    }

    /* DataTables controls */
    .admin-page .dataTables_wrapper .row {
        margin-left: 0;
        margin-right: 0;
    }

    .admin-page .dataTables_wrapper .row > div {
        padding-left: 0;
        padding-right: 0;
    }

    .admin-page .dataTables_length,
    .admin-page .dataTables_filter,
    .admin-page .dataTables_info,
    .admin-page .dataTables_paginate {
        width: 100%;
        text-align: left !important;
        margin-bottom: 0.5rem;
        float: none !important;
    }

    .admin-page .dataTables_filter input {
        width: 100% !important;
        margin-left: 0 !important;
    }

    .admin-page .dataTables_paginate .pagination {
        flex-wrap: wrap;
        justify-content: center;
    }

    /* Forms & filters */
    .admin-page .select-range-picker {
        flex-direction: column !important;
        width: 100%;
    }

    .admin-page .select-range-picker input {
        min-width: 0;
        width: 100%;
    }

    .admin-page .select-range-picker .common-btn {
        width: 100%;
        margin-top: 0.5rem;
    }

    .deposit-tab-content .filter-btn,
    .deposit-tab-content .export-btn {
        width: 100%;
    }

    .admin-page .data-search-area .row > [class*="col-"] {
        margin-bottom: 0.75rem;
    }

    /* Inline-width filter controls (deposits, withdrawals, reports) */
    .admin-page form .form-select[style*="width: auto"],
    .admin-page form .form-control[style*="width: auto"],
    .admin-page .data-search-area .form-select,
    .admin-page .data-search-area .form-control {
        width: 100% !important;
        min-width: 0;
    }

    .admin-page .data-search-area .d-flex,
    .admin-page .data-search-area form.d-flex {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 0.5rem;
    }

    .admin-page .data-search-area .d-flex > * {
        width: 100%;
    }

    /* Action button groups */
    .admin-page .card-header .d-flex,
    .admin-page .dashbox-title {
        gap: 0.5rem;
    }

    .deposit-details-title-area .last-row,
    .withdraw-details-title-area .last-row {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 0.5rem;
    }

    .deposit-details-title-area img,
    .withdraw-details-title-area img {
        max-width: 48px;
        height: auto;
    }

    .deposit-details-table .equal-width td,
    .withdraw-details-table .equal-width td {
        display: block;
        width: 100% !important;
    }

    .deposit-details-table .deposit-action-buttons,
    .withdraw-details-table .withdraw-action-buttons {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
        justify-content: flex-start;
    }

    /* Keep confirmation modals hidden until Bootstrap opens them */
    .modal.approve-deposit:not(.show),
    .modal.approve-withdraw:not(.show),
    .modal.reject-deposit:not(.show),
    .modal.reject-withdraw:not(.show) {
        display: none !important;
    }

    /* Modals */
    .admin-page .modal-dialog,
    body > .modal .modal-dialog {
        margin: 0.5rem auto;
        max-width: calc(100% - 1rem);
    }

    .admin-page .modal-dialog.modal-lg,
    .admin-page .modal-dialog.modal-xl,
    body > .modal .modal-dialog.modal-lg,
    body > .modal .modal-dialog.modal-xl {
        max-width: calc(100% - 1rem);
    }

    .admin-page .custom-modal .common-select,
    .admin-page .custom-modal input[type=text],
    .admin-page .custom-modal select.select-box,
    body > .modal.custom-modal .common-select,
    body > .modal.custom-modal input[type=text],
    body > .modal.custom-modal select.select-box {
        width: 100%;
    }

    /* MT account settings popups (relocated to body on mobile) */
    .modal[id^="mt4Setting"] .modal-dialog,
    .modal[id^="mt5Setting"] .modal-dialog,
    .modal[id^="mt_group_change"] .modal-dialog,
    .modal.mt-trading-accounts-modal .modal-dialog {
        margin: 0.75rem auto;
        max-width: calc(100% - 1.5rem);
        width: 100%;
        max-height: calc(100dvh - 1.5rem - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
        display: flex;
        flex-direction: column;
    }

    .modal[id^="mt4Setting"] .modal-content,
    .modal[id^="mt5Setting"] .modal-content,
    .modal[id^="mt_group_change"] .modal-content,
    .modal.mt-trading-accounts-modal .modal-content {
        background-color: #fff;
        border-radius: 0.5rem;
        box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.15);
        max-height: calc(100dvh - 1.5rem - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
        display: flex;
        flex-direction: column;
        overflow: hidden;
        border: none;
    }

    .modal[id^="mt4Setting"] .modal-body,
    .modal[id^="mt5Setting"] .modal-body,
    .modal[id^="mt_group_change"] .modal-body,
    .modal.mt-trading-accounts-modal .modal-body {
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        flex: 1 1 auto;
    }

    .modal[id^="mt4Setting"] .modal-dialog[style*="box-shadow"],
    .modal[id^="mt5Setting"] .modal-dialog[style*="box-shadow"],
    .modal[id^="mt_group_change"] .modal-dialog[style*="box-shadow"],
    .modal.mt-trading-accounts-modal .modal-dialog[style*="box-shadow"] {
        box-shadow: none !important;
    }

    .mt-trading-accounts .col-6 {
        flex: 0 0 100%;
        max-width: 100%;
    }

    .mt-trading-accounts button {
        width: 100%;
        min-width: 0;
    }

    .mt-trading-accounts .col-12.text-center .btn-danger,
    .mt-trading-accounts .col-12.text-center .btn-success {
        width: 100%;
        max-width: 100%;
    }

    /* KYC / back office */
    .kyc-office-content .table-view-12 {
        width: 100%;
    }

    .kyc-office-content .item-card {
        min-height: auto;
    }

    /* Admin profile */
    .admin-profile .box-area-first,
    .admin-profile .box-area-second,
    .admin-profile .full-area {
        width: 100%;
    }

    /* Gateway / forms */
    .create-manual-gateway .row > [class*="col-"],
    .create-manual-gateway.new-withdraw .row > [class*="col-"] {
        margin-bottom: 0.75rem;
    }

    /* Pagination */
    .pagination-rounded .page-link {
        padding: 8px 12px;
        font-size: 13px;
    }

    /* Child/nested tables */
    .admin-page .child-table-area {
        overflow-x: auto;
    }

    .admin-page .child-table-area .child-table {
        min-width: 500px;
    }

    /* Support ticket & misc cards */
    .admin-page .common-card .card-body {
        padding: 15px;
    }

    #clear-session-alert {
        margin: 0.5rem 0;
        font-size: 14px;
    }

    /* Admin login page */
    .authentication-bg .account-pages {
        padding-top: 1rem !important;
    }

    .authentication-bg .common-card.login {
        margin-top: 1rem !important;
    }

    .authentication-bg .account-pages h4 {
        font-size: 18px;
        line-height: 28px;
    }

    /* Collapsible search/filter panel */
    .admin-mobile-filter__toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.35rem;
        min-height: 44px;
        font-weight: 500;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }

    .admin-mobile-filter__toggle.is-active::after {
        content: "";
        width: 8px;
        height: 8px;
        border-radius: 50%;
        background-color: #1d4f79;
        margin-left: 0.15rem;
    }

    .admin-mobile-filter__panel {
        display: grid;
        grid-template-rows: 0fr;
        opacity: 0;
        pointer-events: none;
        transition: grid-template-rows 0.3s ease, opacity 0.25s ease;
    }

    .admin-mobile-filter.is-open .admin-mobile-filter__panel {
        grid-template-rows: 1fr;
        opacity: 1;
        pointer-events: auto;
    }

    .admin-mobile-filter__inner {
        overflow: hidden;
        min-height: 0;
    }
}

/* ------------------------------------------------------------------ */
/* Small mobile (≤ 480px)                                             */
/* ------------------------------------------------------------------ */
@media screen and (max-width: 480px) {
    .admin-page .card h4.header-title {
        font-size: 16px;
        line-height: 28px;
    }

    .admin-page .nav-tabs.nav-bordered li a,
    .admin-page .nav-tabs .nav-link.active {
        font-size: 12px;
        padding: 8px 10px;
    }

    .dashboard-graph-card .count {
        font-size: 18px;
    }

    .btn.common-view-all-dropdown,
    .btn.common-view-all-btn {
        width: auto;
        min-width: 80px;
        font-size: 12px;
    }

    .admin-page .custom-table-2 tbody tr td {
        font-size: 12px;
        padding: 10px 8px;
    }
}

/* Desktop: keep filter panels always expanded */
@media screen and (min-width: 768px) {
    .admin-mobile-filter__toggle {
        display: none !important;
    }

    .admin-mobile-filter__panel {
        display: block;
        grid-template-rows: none;
        opacity: 1;
        pointer-events: auto;
    }

    .admin-mobile-filter__inner {
        overflow: visible;
    }
}
