/**
 * NexPay Universal Responsive CSS
 * Fixes all pages for mobile and desktop
 * Include this file in ALL pages
 */

/* ==========================================
   MOBILE TOP BAR WITH LOGO
   ========================================== */

/* Mobile Top Bar (Shows logo on mobile) */
.mobile-top-bar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 70px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    z-index: 9997;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
}

.mobile-top-bar img {
    height: 30px;
}

/* ==========================================
   MOBILE NAVIGATION & SIDEBAR
   ========================================== */

/* Hamburger Menu Button (Mobile Only - RIGHT SIDE) */
.mobile-menu-toggle {
    display: none;

    top: 10px;
    right: 20px;
    z-index: 10000;
    background: linear-gradient(135deg, #4F46E5 0%, #7C3AED 100%);
    border: none;
    border-radius: 8px;
    width: 50px;
    height: 50px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 5px;
}

.mobile-menu-toggle span {
    display: block;
    width: 25px;
    height: 3px;
    background: white;
    border-radius: 2px;
    transition: all 0.3s;
}

/* Mobile Sidebar Overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 9998;
}

@media (max-width: 1024px) {
    /* Show mobile top bar */
    .mobile-top-bar {
        display: flex;
    }

    /* Show hamburger menu on mobile */
    .mobile-menu-toggle {
        display: flex;
    }

    /* Hide sidebar by default on mobile */
    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        height: 100%;
        z-index: 9999;
        transition: left 0.3s ease;
        width: 280px;
        overflow-y: auto;
    }

    /* Admin sidebar */
    .admin-sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        height: 100%;
        z-index: 9999;
        transition: left 0.3s ease;
        width: 280px;
        overflow-y: auto;
    }

    /* Show sidebar when active */
    .sidebar.active {
        left: 0;
    }

    .admin-sidebar.active {
        left: 0;
    }

    /* Show overlay when sidebar active */
    .sidebar-overlay.active {
        display: block;
    }

    /* Adjust main content - REDUCED PADDING */
    .main-content {
        margin-left: 0;
        width: 100%;
        padding-top: 90px;
        padding-left: 15px;
        padding-right: 15px;
        padding-bottom: 20px;
    }

    .admin-content {
        margin-left: 0;
        width: 100%;
        padding-top: 90px;
        padding-left: 15px;
        padding-right: 15px;
        padding-bottom: 20px;
    }

    /* Adjust dashboard body */
    .dashboard-body .main-content {
        padding: 90px 15px 20px;
    }
}

/* ==========================================
   TOP BAR RESPONSIVE
   ========================================== */

@media (max-width: 768px) {
    .top-bar {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
        padding: 20px 15px;
    }

    .top-bar h2 {
        font-size: 1.5rem;
    }

    .user-info {
        width: 100%;
        justify-content: flex-start;
    }

    .admin-top-bar {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }
}

/* ==========================================
   DASHBOARD CARDS RESPONSIVE
   ========================================== */

@media (max-width: 1200px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }

    .stat-card {
        padding: 20px;
    }

    .stat-value {
        font-size: 1.8rem;
    }
}

/* ==========================================
   PORTFOLIO RESPONSIVE
   ========================================== */

@media (max-width: 1024px) {
    .portfolio-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .portfolio-grid {
        grid-template-columns: 1fr;
    }

    .portfolio-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }

    .portfolio-actions {
        width: 100%;
        flex-direction: column;
    }

    .portfolio-actions .btn-primary,
    .portfolio-actions .btn-secondary {
        width: 100%;
    }
}

/* ==========================================
   TRADE PAGE RESPONSIVE
   ========================================== */

@media (max-width: 1024px) {
    .trade-grid {
        grid-template-columns: 1fr;
    }

    .crypto-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .crypto-grid {
        grid-template-columns: 1fr;
    }

    .trade-modal-content {
        width: 95%;
        margin: 5%;
        padding: 20px;
    }
}

/* ==========================================
   TABLES RESPONSIVE
   ========================================== */

@media (max-width: 1024px) {
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        min-width: 800px;
    }

    .admin-table {
        font-size: 0.9rem;
    }

    .admin-table th,
    .admin-table td {
        padding: 10px;
    }
}

@media (max-width: 768px) {
    table {
        font-size: 0.85rem;
    }

    .portfolio-table th,
    .portfolio-table td {
        padding: 10px;
    }

    /* Stack table for very small screens */
    .action-buttons {
        flex-direction: column;
        gap: 5px;
    }

    .action-buttons .btn-action {
        width: 100%;
        text-align: center;
    }
}

/* ==========================================
   FORMS RESPONSIVE
   ========================================== */

@media (max-width: 768px) {
    .form-row {
        grid-template-columns: 1fr !important;
    }

    .form-group {
        margin-bottom: 15px;
    }

    input,
    textarea,
    select {
        font-size: 16px; /* Prevents iOS zoom */
    }

    .btn-primary,
    .btn-secondary {
        width: 100%;
        padding: 14px;
        font-size: 1rem;
    }
}

/* ==========================================
   DEPOSIT/WITHDRAW RESPONSIVE
   ========================================== */

@media (max-width: 1024px) {
    .wallet-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .crypto-selection-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .wallet-grid {
        grid-template-columns: 1fr;
    }

    .crypto-selection-grid {
        grid-template-columns: 1fr;
    }

    .instruction-steps {
        gap: 15px;
    }

    .step {
        flex-direction: column;
        text-align: center;
    }

    .step-number {
        margin-bottom: 10px;
    }
}

/* ==========================================
   MODALS RESPONSIVE
   ========================================== */

@media (max-width: 768px) {
    .modal-content {
        width: 95%;
        margin: 5%;
        padding: 20px;
        max-height: 90vh;
        overflow-y: auto;
    }

    .modal-header h3 {
        font-size: 1.3rem;
    }

    .modal-footer {
        flex-direction: column;
        gap: 10px;
    }

    .modal-footer button {
        width: 100%;
    }

    /* Cropper modal */
    .cropper-modal-content {
        width: 95%;
        max-height: 95vh;
    }

    .cropper-container-wrapper {
        max-height: 300px;
    }

    .cropper-controls {
        padding: 15px;
    }

    .control-group {
        flex-direction: column;
    }

    .btn-control {
        width: 100%;
        margin-right: 0;
        margin-bottom: 8px;
    }
}

/* ==========================================
   PROFILE PAGE RESPONSIVE
   ========================================== */

@media (max-width: 1024px) {
    .profile-grid {
        grid-template-columns: 1fr;
    }

    .profile-header-card {
        flex-direction: column;
        text-align: center;
    }

    .edit-user-container {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .profile-avatar {
        width: 120px;
        height: 120px;
    }

    .profile-avatar-placeholder {
        width: 120px;
        height: 120px;
        font-size: 3rem;
    }

    .camera-icon-btn {
        width: 35px;
        height: 35px;
    }

    .camera-icon-btn svg {
        width: 16px;
        height: 16px;
    }

    .info-grid {
        grid-template-columns: 1fr;
    }
}

/* ==========================================
   AUTH PAGES RESPONSIVE (Login/Register)
   ========================================== */

@media (max-width: 1024px) {
    .auth-container {
        flex-direction: column;
    }

    .auth-left {
        display: none; /* Hide brand section on mobile */
    }

    .auth-right {
        width: 100%;
        padding: 40px 20px;
    }
}

@media (max-width: 768px) {
    .auth-form-wrapper {
        padding: 30px 20px;
    }

    .auth-header h2 {
        font-size: 1.5rem;
    }

    .brand-logo {
        font-size: 2rem;
    }
}

/* ==========================================
   ADMIN PANEL RESPONSIVE
   ========================================== */

@media (max-width: 1024px) {
    .admin-stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .admin-cards-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .admin-stats-grid {
        grid-template-columns: 1fr;
    }

    .admin-card {
        padding: 20px;
    }

    .user-stats {
        flex-direction: column;
        gap: 15px;
    }

    .user-stat {
        width: 100%;
    }
}

/* ==========================================
   TRANSACTIONS PAGE RESPONSIVE
   ========================================== */

@media (max-width: 768px) {
    .transaction-filters {
        flex-wrap: wrap;
        gap: 10px;
    }

    .filter-tab {
        flex: 1 1 calc(50% - 5px);
        min-width: auto;
        font-size: 0.85rem;
        padding: 10px;
    }

    .transaction-summary {
        grid-template-columns: 1fr;
        gap: 15px;
    }
}

/* ==========================================
   BADGES & STATUS RESPONSIVE
   ========================================== */

@media (max-width: 768px) {
    .badge {
        font-size: 0.75rem;
        padding: 4px 10px;
    }

    .status-badge {
        font-size: 0.75rem;
        padding: 5px 12px;
    }
}

/* ==========================================
   BUTTONS RESPONSIVE
   ========================================== */

@media (max-width: 768px) {
    .btn-action {
        padding: 8px 12px;
        font-size: 0.85rem;
    }

    .danger-actions {
        flex-direction: column;
    }

    .danger-actions .btn-danger {
        width: 100%;
    }
}

/* ==========================================
   BALANCE MANAGEMENT RESPONSIVE
   ========================================== */

@media (max-width: 768px) {
    .balance-actions {
        grid-template-columns: 1fr;
    }

    .current-balance-value {
        font-size: 1.5rem;
    }
}

/* ==========================================
   GENERAL MOBILE FIXES
   ========================================== */

@media (max-width: 768px) {
    /* Reduce padding globally */
    .profile-section,
    .form-section {
        padding: 20px;
    }

    /* Fix font sizes */
    h2 {
        font-size: 1.5rem;
    }

    h3 {
        font-size: 1.3rem;
    }

    h4 {
        font-size: 1.1rem;
    }

    /* Fix spacing */
    .profile-container,
    .dashboard-container {
        gap: 20px;
    }

    /* Fix full-width elements */
    .full-width {
        grid-column: 1;
    }

    /* Touch-friendly spacing */
    .nav-link {
        padding: 15px 20px;
        font-size: 1rem;
    }

    /* Fix alert boxes */
    .alert {
        padding: 15px;
        font-size: 0.9rem;
    }
}

/* ==========================================
   LANDSCAPE MODE (PHONES)
   ========================================== */

@media (max-width: 768px) and (orientation: landscape) {
    .cropper-container-wrapper {
        max-height: 250px;
    }

    .modal-content {
        max-height: 85vh;
    }
}

/* ==========================================
   LARGE TABLETS (iPad, etc.)
   ========================================== */

@media (min-width: 769px) and (max-width: 1024px) {
    .sidebar {
        width: 250px;
    }

    .main-content {
        margin-left: 250px;
    }

    .admin-sidebar {
        width: 250px;
    }

    .admin-content {
        margin-left: 250px;
    }
}

/* ==========================================
   PREVENT TEXT SELECTION ISSUES
   ========================================== */

@media (max-width: 768px) {
    /* Prevent double-tap zoom on buttons */
    button {
        touch-action: manipulation;
    }

    /* Improve tap targets */
    a, button, input, select, textarea {
        min-height: 44px;
    }
}

/* ==========================================
   PRINT STYLES (BONUS)
   ========================================== */

@media print {
    .sidebar,
    .admin-sidebar,
    .top-bar,
    .mobile-menu-toggle,
    .mobile-top-bar,
    .sidebar-overlay,
    .btn-primary,
    .btn-secondary {
        display: none;
    }

    .main-content,
    .admin-content {
        margin-left: 0;
        width: 100%;
    }
}

/* ==========================================
   CRITICAL MOBILE FIXES - FORCE SINGLE COLUMN
   ========================================== */

@media (max-width: 1024px) {
    /* Force everything to use full width */
    * {
        box-sizing: border-box;
    }
    
    body {
        overflow-x: hidden !important;
        max-width: 100vw !important;
    }
    
    /* REMOVED AGGRESSIVE PADDING - Let pages control their own spacing */
    
    /* Force mobile top bar to fit */
    .mobile-top-bar {
        width: 100% !important;
        max-width: 100vw !important;
        left: 0 !important;
        right: 0 !important;
    }
    
   /* Force all grids to single column */
.stats-grid,
.admin-stats-grid,
.crypto-holdings-grid,
.wallet-grid,
.crypto-selection-grid,
.portfolio-grid,
.info-grid {
    grid-template-columns: 1fr !important;
    width: 100% !important;
}

/* Force withdraw/deposit sections to stack */
.info-section,
.withdraw-section,
.deposit-section {
    width: 100% !important;
    max-width: 100% !important;
    margin-bottom: 20px !important;
}
    
    /* Force all cards to full width */
    .admin-stat-card,
    .stat-card,
    .crypto-holding-card,
    .wallet-card,
    .info-card {
        width: 100% !important;
        max-width: 100% !important;
    }
    
    /* Fix forms */
    .form-row {
        grid-template-columns: 1fr !important;
        width: 100% !important;
    }
    
    .form-group {
        width: 100% !important;
    }
    
    /* Fix tables */
    .table-responsive {
        width: 100% !important;
        overflow-x: auto !important;
    }
    
    table {
        min-width: 100% !important;
    }
}

@media (max-width: 768px) {
    /* Extra mobile fixes */
    .admin-stat-card .stat-icon {
        width: 50px !important;
        height: 50px !important;
        font-size: 1.8rem !important;
    }
    
    .admin-stat-card .stat-value {
        font-size: 1.5rem !important;
    }
    
    .stat-value {
        font-size: 1.5rem !important;
    }
    
    /* Fix buttons */
    .btn-primary,
    .btn-secondary,
    .btn-action {
        width: 100% !important;
        max-width: 100% !important;
    }
    
    /* Fix any containers with padding */
    .profile-section,
    .form-section,
    .admin-table-section {
        padding: 15px !important;
    }
}

/* ==========================================
   FIX MODAL ON MOBILE - CRITICAL
   ========================================== */

/* Ensure modal is hidden by default */
.modal {
    display: none !important;
    position: fixed !important;
    z-index: 10000 !important;
    left: 0 !important;
    top: 0 !important;
    width: 100% !important;
    height: 100% !important;
    overflow: auto !important;
    background-color: rgba(0, 0, 0, 0.7) !important;
    align-items: center;
    justify-content: center;
}

/* Show modal when display is set to block via JavaScript */
.modal[style*="display: block"],
.modal[style*="display:block"] {
    display: flex !important;
}

@media (max-width: 1024px) {
    /* Force modal content to be centered and full width */
    .modal .modal-content {
        width: 95% !important;
        max-width: 500px !important;
        margin: auto !important;
        position: relative !important;
    }
    
    /* Ensure withdraw/deposit sections stack properly */
    .info-section,
    .withdraw-section {
        display: block !important;
        width: 100% !important;
        float: none !important;
        clear: both !important;
    }
}

/* ==========================================
   ADMIN MOBILE MENU FIX
   ========================================== */

@media (max-width: 1024px) {
    /* Ensure admin pages get mobile menu */
    .admin-body .mobile-top-bar {
        display: flex !important;
    }
    
    .admin-body .mobile-menu-toggle {
        display: flex !important;
    }
    
    /* Ensure admin sidebar hides properly */
    .admin-body .admin-sidebar {
        position: fixed !important;
        left: -280px !important;
        top: 0 !important;
        height: 100% !important;
        z-index: 9999 !important;
        transition: left 0.3s ease !important;
    }
    
    .admin-body .admin-sidebar.active {
        left: 0 !important;
    }
    
    /* Adjust admin content for mobile */
    .admin-body .admin-content {
        margin-left: 0 !important;
        width: 100% !important;
        padding-top: 90px !important;
        padding-left: 15px !important;
        padding-right: 15px !important;
    }
}