/* IBO Panel — modern UI layer on top of Metronic */

:root {
    --ibo-accent: #6366f1;
    --ibo-accent-hover: #4f46e5;
    --ibo-accent-soft: rgba(99, 102, 241, 0.12);
    --ibo-sidebar-from: #0f172a;
    --ibo-sidebar-to: #1e293b;
    --ibo-radius: 0.75rem;
    --ibo-shadow: 0 4px 24px rgba(15, 23, 42, 0.08);
}

[data-bs-theme="dark"] {
    --ibo-shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
}

[data-bs-theme="light"] .theme-dark-show,
[data-bs-theme="dark"] .theme-light-show {
    display: none !important;
}

[data-bs-theme="light"] .theme-light-show,
[data-bs-theme="dark"] .theme-dark-show {
    display: flex !important;
}

.panel-sidebar-shell {
    display: flex !important;
    flex-direction: column !important;
    height: 100%;
    min-height: 0;
    overflow: hidden;
}

.panel-sidebar-menu {
    flex: 1 1 auto;
    min-height: 0;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
}

.panel-sidebar-footer {
    flex-shrink: 0;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(0, 0, 0, 0.18);
    display: flex;
}

.panel-sidebar-flags {
    align-items: center;
}

.panel-sidebar-flag {
    display: inline-flex;
    padding: 3px;
    border-radius: 6px;
    border: 2px solid transparent;
    opacity: 0.72;
    transition: opacity 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
    line-height: 0;
}

.panel-sidebar-flag:hover,
.panel-sidebar-flag.is-active {
    opacity: 1;
    border-color: var(--ibo-accent);
    transform: translateY(-1px);
}

.panel-sidebar-flag img {
    display: block;
    border-radius: 3px;
    object-fit: cover;
}

.panel-lang-flag {
    display: inline-block;
    border-radius: 3px;
    object-fit: cover;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.panel-lang-btn {
    min-height: 36px;
    padding-left: 0.55rem;
    padding-right: 0.65rem;
}

.panel-lang-option.active {
    background: var(--ibo-accent-soft);
}

.panel-lang-switcher .menu-link {
    display: flex;
    align-items: center;
}

.panel-sidebar-mobile-head {
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

[data-kt-app-sidebar-fixed="true"] .panel-sidebar-shell {
    height: 100dvh !important;
    max-height: 100dvh !important;
}

@media (min-width: 992px) {
    #kt_app_sidebar.app-sidebar.panel-sidebar-shell {
        display: flex !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        bottom: 0 !important;
        height: 100vh !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        margin: 0 !important;
        z-index: 105;
    }

    #panel_mobile_drawer.panel-mobile-drawer {
        display: none !important;
    }

    [data-kt-app-sidebar-fixed="true"] .panel-sidebar-shell {
        height: 100dvh !important;
        max-height: 100dvh !important;
    }
}

/* Sidebar */
.app-sidebar {
    background: linear-gradient(180deg, var(--ibo-sidebar-from) 0%, var(--ibo-sidebar-to) 100%) !important;
    border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.app-sidebar .menu-heading {
    color: rgba(255, 255, 255, 0.45) !important;
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    font-weight: 600;
}

.app-sidebar .menu-link {
    border-radius: 0.5rem;
    margin: 0.15rem 0;
    transition: background 0.2s ease, color 0.2s ease;
}

.app-sidebar .menu-link.active,
.app-sidebar .menu-link:hover {
    background: var(--ibo-accent-soft) !important;
    color: #fff !important;
}

.app-sidebar .menu-link.active .menu-title,
.app-sidebar .menu-link:hover .menu-title {
    color: #fff !important;
}

.app-sidebar .menu-link.active {
    box-shadow: inset 3px 0 0 var(--ibo-accent);
}

/* Header */
.app-header {
    backdrop-filter: blur(12px);
    background: rgba(var(--bs-body-bg-rgb), 0.85) !important;
    border-bottom: 1px solid var(--bs-border-color);
    position: relative;
    z-index: 1300;
}

#kt_app_header,
#kt_app_header_container,
#kt_app_header_wrapper,
#kt_header_user_menu_toggle {
    overflow: visible !important;
}

#kt_header_user_menu_toggle .menu-sub-dropdown,
#kt_header_user_menu_toggle .menu-sub.menu-sub-dropdown {
    z-index: 1400 !important;
    overflow: visible !important;
}

/* Cards */
.card {
    border: 1px solid var(--bs-border-color);
    border-radius: var(--ibo-radius);
    box-shadow: var(--ibo-shadow);
}

.card-header {
    border-bottom-color: var(--bs-border-color);
}

/* Stat tiles (VPN dashboard) */
.ibo-stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.ibo-stat-card {
    background: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: var(--ibo-radius);
    padding: 1.25rem 1.5rem;
    box-shadow: var(--ibo-shadow);
}

.ibo-stat-card .ibo-stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--ibo-accent);
}

.ibo-stat-card .ibo-stat-label {
    font-size: 0.8rem;
    color: var(--bs-secondary-color);
    margin-top: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

/* Tables */
.table > :not(caption) > * > * {
    padding: 0.85rem 1rem;
}

.table tbody tr {
    transition: background 0.15s ease;
}

.table-hover tbody tr:hover {
    background: var(--ibo-accent-soft);
}

/* Action badges */
.badge-action-connect { background: rgba(34, 197, 94, 0.15); color: #16a34a; }
.badge-action-disconnect { background: rgba(148, 163, 184, 0.2); color: #64748b; }
.badge-action-error { background: rgba(239, 68, 68, 0.15); color: #dc2626; }

[data-bs-theme="dark"] .badge-action-connect { color: #4ade80; }
[data-bs-theme="dark"] .badge-action-disconnect { color: #94a3b8; }
[data-bs-theme="dark"] .badge-action-error { color: #f87171; }

/* Buttons */
.btn-primary {
    background: var(--ibo-accent);
    border-color: var(--ibo-accent);
}

.btn-primary:hover,
.btn-primary:focus {
    background: var(--ibo-accent-hover);
    border-color: var(--ibo-accent-hover);
}

/* Login page */
body.app-blank {
    background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 50%, #312e81 100%);
    overflow-x: hidden;
}

.panel-login-page {
    min-height: 100dvh;
    min-height: 100svh;
    width: 100%;
    display: flex;
    flex-direction: column;
}

.panel-login-page > .d-flex {
    width: 100%;
    max-width: 100%;
    flex: 1 1 auto;
}

.panel-login-inner {
    width: 100%;
    max-width: min(420px, 100%);
    margin: 0 auto;
}

.panel-login-hero {
    margin-bottom: 1.25rem !important;
    padding: 0 0.25rem;
}

.panel-login-logo {
    display: block;
    margin-left: auto;
    margin-right: auto;
    width: auto;
    max-width: min(160px, 48vw);
    max-height: 64px;
    height: auto;
    margin-bottom: 0.75rem !important;
}

.panel-login-title {
    font-size: clamp(1.25rem, 5.5vw, 2rem);
    line-height: 1.15;
    margin-bottom: 0.35rem !important;
}

.panel-login-subtitle {
    font-size: clamp(0.8rem, 3.2vw, 1rem);
    opacity: 0.88;
    line-height: 1.35;
}

.panel-login-form-wrap {
    width: 100%;
    max-width: min(420px, 100%);
    margin: 0 auto;
}

.panel-login-form-box {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 1rem;
    border: 1px solid rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(8px);
    padding: clamp(1.1rem, 4vw, 2rem) !important;
}

.panel-login-form-box .fv-row {
    margin-bottom: 0.75rem !important;
}

.panel-login-form-box .fv-row:last-of-type {
    margin-bottom: 0.5rem !important;
}

.panel-login-form-box .form-control {
    border-radius: 0.5rem;
    padding: 0.65rem 0.9rem !important;
    font-size: 16px;
    min-height: 44px;
}

.panel-login-form-box .btn-primary {
    border-radius: 0.5rem;
    padding: 0.7rem 1rem;
    font-weight: 600;
    min-height: 44px;
}

.panel-login-theme {
    margin-top: 1.25rem !important;
    font-size: 0.95rem;
}

body.app-blank .form-control {
    border-radius: 0.5rem;
    padding: 0.85rem 1rem;
}

body.app-blank .btn-primary {
    border-radius: 0.5rem;
    padding: 0.85rem;
    font-weight: 600;
}

body.app-blank .w-lg-500px {
    background: rgba(255, 255, 255, 0.03);
    border-radius: 1rem;
    border: 1px solid rgba(255, 255, 255, 0.08);
    backdrop-filter: blur(8px);
}

@media (max-width: 575.98px) {
    .panel-login-page > .d-flex {
        padding: max(0.75rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom)) !important;
        justify-content: center;
    }

    .panel-login-hero {
        margin-bottom: 0.75rem !important;
    }

    .panel-login-logo {
        max-width: 110px;
        max-height: 48px;
    }

    .panel-login-title {
        font-size: 1.35rem !important;
    }

    .panel-login-form-box {
        padding: 1rem !important;
    }

    .panel-login-theme {
        margin-top: 0.85rem !important;
        font-size: 0.85rem;
    }

    body.app-blank .text-center.py-6 {
        padding-top: 0.75rem !important;
        padding-bottom: max(0.75rem, env(safe-area-inset-bottom)) !important;
    }
}

/* Code snippets in panel */
code {
    background: var(--ibo-accent-soft);
    color: var(--ibo-accent);
    padding: 0.15rem 0.4rem;
    border-radius: 0.35rem;
    font-size: 0.85em;
}

/* Footer */
.app-footer {
    border-top: 1px solid var(--bs-border-color);
}

/* Featured sidebar item (Contact Requests) */
.app-sidebar .menu-link.menu-featured {
    background: rgba(99, 102, 241, 0.18) !important;
    border: 1px solid rgba(99, 102, 241, 0.35);
    font-weight: 600;
}

.app-sidebar .menu-link.menu-featured.active,
.app-sidebar .menu-link.menu-featured:hover {
    background: rgba(99, 102, 241, 0.28) !important;
    box-shadow: inset 3px 0 0 #a5b4fc, 0 0 0 1px rgba(165, 180, 252, 0.25);
}

.app-sidebar .menu-link.menu-featured .badge {
    font-size: 0.65rem;
    min-width: 1.25rem;
}

/* Responsive tables */
.ibo-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.ibo-table-wrap .table {
    min-width: 640px;
}

/* Responsive layout */
@media (max-width: 991.98px) {
    html, body, #kt_app_body, #kt_app_root, .app-root {
        overflow-x: hidden;
        max-width: 100%;
        width: 100%;
    }

    #kt_app_body,
    [data-kt-app-sidebar-fixed="true"] {
        --bs-app-sidebar-width: 0px !important;
        --bs-app-sidebar-gap-start: 0px !important;
        --bs-app-sidebar-gap-end: 0px !important;
    }

    #kt_app_header {
        position: sticky;
        top: 0;
        z-index: 1210 !important;
        pointer-events: auto;
    }

    #kt_app_header_container {
        position: relative;
        z-index: 1211;
        pointer-events: auto;
    }

    #kt_app_sidebar_toggle,
    .panel-sidebar-toggle-btn {
        min-width: 44px !important;
        min-height: 44px !important;
        flex-shrink: 0;
        position: relative;
        z-index: 1212 !important;
        pointer-events: auto !important;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        cursor: pointer;
    }

    #kt_app_sidebar_toggle i,
    .panel-sidebar-toggle-btn i {
        pointer-events: none;
    }

    #kt_app_header_container {
        flex-wrap: nowrap;
        min-height: 52px;
        padding-top: 0.35rem;
        padding-bottom: 0.35rem;
    }

    #kt_app_header .d-flex.d-lg-none {
        position: relative;
        z-index: 1212;
        pointer-events: auto;
    }

    #kt_app_header_wrapper {
        flex: 1 1 auto;
        min-width: 0;
        justify-content: flex-end;
    }

    #kt_app_header_wrapper .app-page-title {
        display: none !important;
    }

    .app-page,
    .app-wrapper,
    .app-main,
    #kt_app_content,
    #kt_app_content_container {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 0 !important;
    }

    .app-wrapper {
        margin-left: 0 !important;
        padding-left: 0 !important;
    }

    .app-main {
        margin-left: 0 !important;
        padding-left: 0 !important;
        width: 100% !important;
    }

    .app-container.container-fluid {
        padding-left: 0.75rem;
        padding-right: 0.75rem;
        max-width: 100%;
    }

    .app-content {
        padding-top: 0.75rem !important;
    }

    /* Metronic hides .app-sidebar on mobile — use #panel_mobile_drawer instead */
    #kt_app_sidebar.app-sidebar.panel-sidebar-shell {
        display: none !important;
    }

    #panel_mobile_drawer.panel-mobile-drawer {
        display: flex !important;
        flex-direction: column !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        bottom: 0 !important;
        visibility: visible !important;
        opacity: 1 !important;
        width: min(300px, 88vw) !important;
        max-width: 300px !important;
        height: 100dvh !important;
        max-height: 100dvh !important;
        margin: 0 !important;
        z-index: 1250 !important;
        transform: translate3d(-105%, 0, 0);
        transition: transform 0.28s ease;
        box-shadow: 0 0 40px rgba(0, 0, 0, 0.45);
        pointer-events: auto;
        will-change: transform;
        background: linear-gradient(180deg, var(--ibo-sidebar-from) 0%, var(--ibo-sidebar-to) 100%);
        border-right: 1px solid rgba(255, 255, 255, 0.06);
        overflow: hidden;
    }

    #panel_mobile_drawer.panel-mobile-drawer.is-open {
        transform: translate3d(0, 0, 0) !important;
    }

    #panel_mobile_drawer .panel-sidebar-menu {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    #panel_mobile_drawer[hidden] {
        display: none !important;
    }

    body.panel-mobile-nav-open #panel_mobile_drawer[hidden] {
        display: flex !important;
    }

    /* Legacy drawer rules (unused on mobile) */
    #kt_app_sidebar.app-sidebar.panel-sidebar-shell.panel-sidebar-open {
        transform: translate3d(0, 0, 0) !important;
    }

    .panel-sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(15, 23, 42, 0.55);
        z-index: 1240;
        pointer-events: auto;
        touch-action: manipulation;
    }

    .panel-sidebar-overlay.show {
        display: block;
    }

    body.panel-sidebar-active {
        overflow: hidden;
    }

    body.panel-sidebar-active .panel-sidebar-menu {
        touch-action: pan-y;
        -webkit-overflow-scrolling: touch;
    }

    .drawer-overlay {
        z-index: 1105 !important;
    }

    .panel-lang-switcher {
        display: none !important;
    }

    .card-body {
        padding: 1rem;
    }

    .card-header {
        flex-direction: column;
        align-items: stretch !important;
        padding: 1rem;
        gap: 0.75rem;
    }

    .card-header .card-title,
    .card-header .card-toolbar {
        width: 100%;
    }

    .card-header .card-title .form-control,
    .card-header .card-title .w-250px {
        width: 100% !important;
        max-width: 100% !important;
    }

    .card-header .card-toolbar .d-flex {
        width: 100%;
        flex-direction: column;
    }

    .card-header .card-toolbar .btn {
        width: 100%;
    }

    .card-body .row > [class*="col-md-"],
    .card-body .row > [class*="col-lg-"],
    .card-body .row > [class*="col-xl-"] {
        flex: 0 0 100%;
        max-width: 100%;
    }

    .form-control,
    .form-select {
        font-size: 16px;
        min-height: 44px;
    }

    .card-body > .btn-primary,
    .card-body > .btn-light-primary {
        width: 100%;
        min-height: 44px;
    }

    .backdrop-preview-toolbar {
        flex-direction: column;
        align-items: stretch !important;
    }

    .backdrop-preview-toolbar .btn {
        width: 100%;
    }

    .ibo-stat-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .table,
    .table-responsive,
    .ibo-table-wrap {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .table {
        min-width: 560px;
    }

    .modal-dialog {
        margin: 0.5rem auto;
        max-width: calc(100% - 1rem);
    }
}

@media (min-width: 992px) {
    .panel-sidebar-overlay {
        display: none !important;
    }
}

@media (max-width: 575.98px) {
    .ibo-stat-grid {
        grid-template-columns: 1fr;
    }

    .modal-dialog.modal-lg {
        max-width: calc(100% - 1rem);
        margin: 0.5rem auto;
    }

    .app-sidebar .menu-link {
        padding-top: 0.65rem;
        padding-bottom: 0.65rem;
    }
}

/* TMDB / Sport backdrop previews */
.backdrop-layout-card {
    border: 2px solid var(--bs-border-color);
    border-radius: 0.75rem;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.02);
    cursor: pointer;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.backdrop-layout-card:hover,
.backdrop-layout-card.border-primary {
    border-color: var(--ibo-accent, #6366f1);
}

.backdrop-layout-card__head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.35rem;
}

.backdrop-preview-frame {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background: #0f172a;
    border-radius: 0.5rem;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.backdrop-preview-frame--wide {
    max-width: 100%;
}

.backdrop-preview-frame--compact {
    width: 100%;
    max-width: 100%;
    aspect-ratio: 16 / 9;
    margin: 0;
}

#tmdb_preview_section .backdrop-preview-frame,
#images_preview_wrap.backdrop-preview-frame {
    max-width: 100%;
}

.backdrop-preview-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.5rem;
}

.backdrop-preview-toolbar .form-text {
    margin: 0;
}

.backdrop-preview-frame iframe {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    background: #000;
}

.backdrop-preview-loading {
    position: absolute;
    inset: 0;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.82);
    pointer-events: none;
}

.backdrop-preview-frame.is-loading iframe {
    opacity: 0.35;
}

/* VPN country flags */
.vpn-country-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 220px;
    overflow-y: auto;
    border: 1px solid var(--bs-border-color);
    border-radius: 0.5rem;
    padding: 6px;
    background: var(--bs-body-bg);
}

.vpn-country-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    border: 1px solid transparent;
    border-radius: 0.45rem;
    background: transparent;
    color: inherit;
    padding: 8px 10px;
    text-align: left;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

.vpn-country-item:hover,
.vpn-country-item.is-active {
    background: var(--ibo-accent-soft);
    border-color: rgba(99, 102, 241, 0.35);
}

.vpn-country-item__flag {
    flex-shrink: 0;
    border-radius: 3px;
    object-fit: cover;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.vpn-country-item__name {
    flex: 1 1 auto;
    font-weight: 600;
    font-size: 0.9rem;
}

.vpn-country-item__code {
    flex-shrink: 0;
    font-size: 0.75rem;
    color: var(--bs-secondary-color);
    font-weight: 600;
}

.vpn-country-selected {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 0.5rem;
    background: var(--ibo-accent-soft);
    border: 1px solid rgba(99, 102, 241, 0.25);
}

.vpn-country-selected__flag {
    height: 28px;
    width: auto;
    border-radius: 3px;
    object-fit: cover;
}

.vpn-country-selected__label {
    font-weight: 600;
}

.vpn-table-country {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.vpn-table-country__flag {
    border-radius: 3px;
    object-fit: cover;
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
}

@media (max-width: 575.98px) {
    .vpn-country-list {
        max-height: 180px;
    }
}
