/* ==================== MOBILE RESPONSIVE STYLES ==================== */

/* Mobile Sidebar Enhancements */
@media (max-width: 1024px) {


    /* --- Full Screen Sticky Header --- */
    .top-header {
        position: sticky;
        top: 0;
        z-index: 10002;
        /* Above Sidebar */
        background: rgba(15, 23, 42, 0.95);
        /* More solid for contrast */
        backdrop-filter: blur(15px);
        -webkit-backdrop-filter: blur(15px);
        border-bottom: 1px solid var(--glass-border);
        margin-bottom: 1.5rem;
        padding: 0.75rem 1rem;
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
    }

    .header-left {
        gap: 0.75rem;
    }

    /* --- Content Layout --- */
    .main-content {
        margin-left: 0 !important;
        margin-right: 0 !important;
        padding: 0 1rem 1rem 1rem;
        /* Remove top padding as header is sticky */
        width: 100%;
    }

    .page-title {
        font-size: 1.1rem;
        font-weight: 600;
        color: #fff;
    }

    /* --- Full Screen Vertical Wipe Sidebar --- */
    .sidebar {
        width: 100% !important;
        height: calc(100vh - 70px) !important;
        /* EXACT height available below header */
        position: fixed;
        top: 70px;
        /* Starts exactly at header bottom */
        left: 0;
        bottom: 0;
        background: rgba(10, 15, 30, 0.98);
        /* Deep sleek dark */
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);

        /* Vertical Wipe Animation */
        clip-path: inset(0 0 100% 0);
        /* Hidden (Clipped from bottom to top) */
        transition: clip-path 0.5s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;

        z-index: 10001;
        display: flex;
        flex-direction: column;
        border-right: none;
        overflow-y: auto;
        opacity: 0;
        visibility: visible;
        /* Always "there" for layout, hidden by clip-path/opacity */
        transform: none !important;
        /* Disable slide transform */
    }

    .sidebar.active {
        clip-path: inset(0 0 0 0);
        /* Fully Visible (Wipe Down) */
        opacity: 1;
    }

    /* Hide Sidebar Header (Logo) inside the menu */
    .sidebar-header {
        display: none;
    }

    /* Centered Navigation with Flexbox */
    .nav-menu {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        height: 100%;
        width: 100%;
        padding: 2rem 0;
        gap: 1rem;
    }

    .nav-item {
        width: 100%;
        display: flex;
        justify-content: center;
        margin-bottom: 1rem;
        opacity: 0;
        transform: translateY(-20px);
        /* Start slightly above */
        transition: opacity 0.3s ease, transform 0.3s ease;
    }

    /* Staggered Drop Animation for Items */
    .sidebar.active .nav-item {
        opacity: 1;
        transform: translateY(0);
    }

    .sidebar.active .nav-item:nth-child(1) {
        transition-delay: 0.1s;
    }

    .sidebar.active .nav-item:nth-child(2) {
        transition-delay: 0.15s;
    }

    .sidebar.active .nav-item:nth-child(3) {
        transition-delay: 0.2s;
    }

    .sidebar.active .nav-item:nth-child(4) {
        transition-delay: 0.25s;
    }

    .sidebar.active .nav-item:nth-child(5) {
        transition-delay: 0.3s;
    }

    .sidebar.active .nav-item:nth-child(6) {
        transition-delay: 0.35s;
    }

    .nav-link {
        font-size: 1.5rem;
        /* Touch friendly */
        font-weight: 500;
        color: var(--text-secondary);
        padding: 0.8rem 2.5rem;
        border-radius: 50px;
        width: auto;
        min-width: 200px;
        /* Consistent width */
        justify-content: flex-start;
        /* Icon on left, but centered group */
        text-align: left;
        gap: 20px;
        background: transparent;
        transition: all 0.2s ease;
    }

    .nav-link i {
        font-size: 1.6rem;
        width: 30px;
        text-align: center;
    }

    .nav-link:hover,
    .nav-item.active .nav-link {
        color: #fff;
        background: rgba(255, 255, 255, 0.08);
        /* Subtle highlight */
        transform: translateX(5px);
    }

    .sidebar-footer {
        border-top: none;
        padding: 2rem;
        display: flex;
        justify-content: center;
        flex-direction: column;
        align-items: center;
        gap: 1.5rem;
        width: 100%;
    }

    /* Compact Language Switcher */
    .language-selector {
        width: auto;
        display: flex;
        justify-content: center;
    }

    .language-buttons {
        display: flex;
        background: rgba(0, 0, 0, 0.3);
        /* Darker backdrop */
        padding: 4px;
        border-radius: 12px;
        border: 1px solid rgba(255, 255, 255, 0.1);
        gap: 4px;
    }

    .lang-btn {
        background: transparent;
        border: none;
        color: var(--text-secondary);
        padding: 8px 14px;
        font-size: 0.9rem;
        font-weight: 600;
        cursor: pointer;
        border-radius: 8px;
        transition: all 0.2s ease;
        text-transform: uppercase;
        letter-spacing: 0.5px;
    }

    .lang-btn:hover {
        color: #fff;
        background: rgba(255, 255, 255, 0.05);
    }

    .lang-btn.active {
        background: var(--primary);
        color: #fff;
        box-shadow: 0 2px 8px rgba(99, 102, 241, 0.4);
    }

    /* User Profile in Menu */
    .user-profile {
        background: rgba(255, 255, 255, 0.03);
        padding: 1rem 2rem;
        border-radius: 50px;
        width: auto;
        border: 1px solid rgba(255, 255, 255, 0.05);
    }

    .user-info {
        display: block;
        text-align: left;
    }


    /* Menu Toggle Button Styling (Matched to HTML class .menu-toggle) */
    .menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 45px;
        height: 45px;
        border-radius: 12px;
        background: rgba(255, 255, 255, 0.05);
        border: 1px solid rgba(255, 255, 255, 0.1);
        color: #fff;
        font-size: 1.4rem;
        transition: all 0.3s ease;
        z-index: 10003;
        cursor: pointer;
        /* Ensure pointer */
    }

    .menu-toggle:hover,
    .menu-toggle:active {
        background: var(--primary);
        color: #fff;
        transform: scale(1.05);
    }

    /* Overlay not needed */
    .sidebar-overlay {
        display: none !important;
    }

    /* --- RTL Handling --- */
    html[dir='rtl'] .sidebar {
        right: 0;
        left: auto;
        transform: translateX(100%) !important;
        border-right: none;
        border-left: 1px solid var(--glass-border);
    }

    html[dir='rtl'] .sidebar.active {
        transform: translateX(0) !important;
    }

    html[dir='rtl'] .menu-toggle {
        margin: 0;
        /* Reset margins for flex layout */
    }
}

/* Dashboard Stats Grid */
@media (max-width: 1024px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

@media (max-width: 640px) {
    .stats-grid {
        grid-template-columns: 1fr !important;
        /* Stack vertically on phones */
    }

    .stat-card {
        display: flex;
        flex-direction: row;
        /* Horizontal layout for stats on phone to save space */
        align-items: center;
        gap: 1rem;
        padding: 1rem;
        text-align: left;
    }

    .stat-card .stat-icon {
        margin: 0;
        width: 3rem;
        height: 3rem;
        flex-shrink: 0;
    }

    .stat-card .stat-info {
        flex: 1;
    }

    .stat-card .stat-value {
        font-size: 1.5rem;
        margin-bottom: 0;
    }
}

/* Responsive Tables (Card View) */
@media (max-width: 768px) {
    .table-responsive {
        border: 0;
        overflow-x: hidden;
        /* Prevent horizontal scroll, use cards instead */
    }

    .report-table thead {
        display: none;
        /* Hide table headers */
    }

    .report-table,
    .report-table tbody,
    .report-table tr,
    .report-table td {
        display: block;
        width: 100%;
    }

    .report-table tr {
        margin-bottom: 1rem;
        background: rgba(255, 255, 255, 0.03);
        /* Glass dark */
        border: 1px solid var(--glass-border);
        border-radius: var(--radius-lg);
        padding: 1rem;
        transition: transform 0.2s ease;
    }

    .report-table tr:active {
        transform: scale(0.98);
        background: rgba(255, 255, 255, 0.05);
    }

    .report-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.75rem 0;
        border-bottom: 1px solid rgba(255, 255, 255, 0.05);
        color: var(--text-secondary);
        text-align: right;
    }

    /* Make essential columns visible on mobile if hidden */
    .report-table td.mobile-hide:nth-child(2) {
        display: flex !important;
        /* Force show Name column */
    }

    .report-table td:last-child {
        border-bottom: 0;
    }

    .report-table td::before {
        content: attr(data-label);
        /* Requires data-label attr in HTML */
        font-weight: 600;
        color: var(--gray-600);
        text-align: left;
        margin-right: 1rem;
    }

    /* Fallback if data-label is missing (can be specific per table type) */
    /* Members Table */
    #membersReportTable td:nth-of-type(1)::before {
        content: "Name";
    }

    #membersReportTable td:nth-of-type(2)::before {
        content: "Phone";
    }

    #membersReportTable td:nth-of-type(3)::before {
        content: "Subscription";
    }

    #membersReportTable td:nth-of-type(4)::before {
        content: "Join Date";
    }

    #membersReportTable td:nth-of-type(5)::before {
        content: "Expiry";
    }

    #membersReportTable td:nth-of-type(6)::before {
        content: "Status";
    }

    #membersReportTable td:nth-of-type(7)::before {
        content: "Paid";
    }

    /* Revenue Table */
    #revenueReportTable td:nth-of-type(1)::before {
        content: "Date";
    }

    #revenueReportTable td:nth-of-type(2)::before {
        content: "Member";
    }

    #revenueReportTable td:nth-of-type(3)::before {
        content: "Type";
    }

    #revenueReportTable td:nth-of-type(4)::before {
        content: "Amount";
    }

    /* General Mobile Padding Adjustments */
    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .section-actions {
        width: 100%;
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
    }

    .btn {
        width: 100%;
        /* Full width buttons on mobile */
    }

    /* Forms */
    .form-row {
        grid-template-columns: 1fr !important;
        /* Stack form fields */
    }

    .filters,
    .tab-filters .filter-row {
        flex-direction: column;
    }

    .filter-group {
        width: 100%;
    }

    /* --- Mobile Reports Improvements --- */
    .chart-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.75rem !important;
    }

    .chart-title {
        margin-bottom: 0.25rem;
        width: 100%;
        font-size: 1.1rem;
    }

    /* Make dropdowns full width for touch */
    .chart-actions,
    .chart-header select,
    .chart-header .form-select {
        width: 100% !important;
        max-width: 100% !important;
        height: 45px;
        /* Better touch target */
    }

    /* Increase container height for Doughnut chart legend */
    .chart-container {
        height: auto !important;
        min-height: 420px !important;
        /* Extra room for legends */
        padding: 1.25rem !important;
        display: flex;
        flex-direction: column;
    }

    .chart-container canvas {
        flex: 1;
        max-height: 300px;
        /* Keep chart reasonable */
        margin-bottom: 1rem;
    }
}

/* ==================== RESPONSIVE LOGO ==================== */
@media (max-width: 640px) {
    .logo {
        transform: scale(0.85);
        /* Slightly bigger than 0.8 */
        transform-origin: left center;
    }

    html[dir='rtl'] .logo {
        transform-origin: right center;
    }

    .header-left h1 {
        font-size: 1.1rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 140px;
    }
}