/* ============================================
   MOBILE OPTIMIZATION - ARCHIE TECH NEXUS
   ============================================ */

/* CRITICAL: Force page to fit viewport */
html, body {
    max-width: 100vw !important;
    overflow-x: hidden !important;
}

html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    /* Remove 300ms click delay */
    touch-action: manipulation;
}

body {
    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;
}

/* Fix container overflow */
.container, .landing-hero, section, .modal, .login-container {
    max-width: 100vw;
    overflow-x: hidden;
    box-sizing: border-box;
}

/* ===========================================
   CRITICAL FIX: Mobile Touch/Click Support
   =========================================== */

/* Enable touch action on all interactive elements */
a, button, .btn, input, select, textarea,
.payment-choice-btn, .modal-close, .feature-item, .nav-item {
    touch-action: manipulation;
    -webkit-tap-highlight-color: rgba(0, 255, 136, 0.3);
}

/* Remove ALL touch blocking - let everything be clickable */
@media (max-width: 768px) {
    /* Make all clickable elements work on touch */
    a, button, .btn, 
    input[type="submit"], input[type="button"],
    .payment-choice-btn, .modal-close, .feature-item, .nav-item,
    .mobile-nav-item, .mobile-menu-btn {
        cursor: pointer !important;
        -webkit-tap-highlight-color: rgba(0, 255, 136, 0.3) !important;
    }
    
    /* CRITICAL: Add minimum touch target size */
    button, .btn, a.btn, .payment-choice-btn {
        min-height: 44px !important;
        min-width: 44px !important;
    }
    
    /* CRITICAL: Disable transforms on hover/active - they break mobile touch */
    .btn:hover,
    .btn:active,
    .btn-primary:hover,
    .btn-primary:active,
    .btn-secondary:hover,
    .btn-secondary:active,
    .card:hover,
    .payment-choice-btn:hover,
    .payment-choice-btn:active {
        transform: none !important;
    }
    
    /* Ensure button active state works on touch */
    .btn:active,
    .btn-primary:active {
        opacity: 0.8;
        background: linear-gradient(135deg, #00cc6a, #00994d) !important;
    }
}

/* Input fields - allow text selection and typing */
input, textarea, select {
    font-size: 16px !important; /* Prevents iOS zoom */
    -webkit-user-select: text !important;
    user-select: text !important;
}

/* Ensure modals don't block underlying page when closed */
.modal-overlay {
    pointer-events: none;
}

.modal-overlay.active {
    pointer-events: auto;
}

.modal-overlay.active .modal {
    pointer-events: auto;
}

/* Install prompt should not block page when hidden */
.install-prompt:not(.show) {
    pointer-events: none;
}

/* Safe area for notched phones */
.app-layout {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* Mobile Header */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    z-index: 1000;
    padding: 0 16px;
    align-items: center;
    justify-content: space-between;
}

.mobile-header-logo {
    font-size: 18px;
    font-weight: 800;
    color: var(--accent-primary);
    display: flex;
    align-items: center;
    gap: 8px;
}

.mobile-header-logo img {
    width: 28px;
    height: 28px;
}

.mobile-menu-btn {
    width: 40px;
    height: 40px;
    background: var(--bg-tertiary);
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Mobile Bottom Navigation */
.mobile-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    z-index: 1000;
    padding-bottom: env(safe-area-inset-bottom);
}

.mobile-nav-items {
    display: flex;
    height: 100%;
    justify-content: space-around;
    align-items: center;
}

.mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 12px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 10px;
    font-weight: 500;
    transition: color 0.2s ease;
    min-width: 60px;
}

.mobile-nav-item span:first-child {
    font-size: 20px;
}

.mobile-nav-item.active,
.mobile-nav-item:hover {
    color: var(--accent-primary);
}

/* Mobile Overlay */
.mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 998;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-overlay.active {
    display: block;
    opacity: 1;
}

/* Install App Banner */
.install-banner {
    display: none;
    position: fixed;
    bottom: 80px;
    left: 16px;
    right: 16px;
    background: linear-gradient(135deg, var(--bg-card), var(--bg-tertiary));
    border: 1px solid var(--accent-primary);
    border-radius: var(--radius-lg);
    padding: 16px;
    z-index: 999;
    box-shadow: 0 10px 40px rgba(0, 255, 136, 0.2);
    animation: slideUp 0.3s ease;
}

.install-banner.show {
    display: block;
}

@keyframes slideUp {
    from { transform: translateY(100px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}

.install-banner-content {
    display: flex;
    align-items: center;
    gap: 12px;
}

.install-banner-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    background: var(--bg-secondary);
}

.install-banner-text {
    flex: 1;
}

.install-banner-title {
    font-weight: 700;
    font-size: 14px;
    margin-bottom: 2px;
}

.install-banner-desc {
    font-size: 12px;
    color: var(--text-muted);
}

.install-banner-actions {
    display: flex;
    gap: 8px;
}

.install-banner .btn {
    padding: 10px 16px;
    font-size: 12px;
}

.install-banner .btn-close {
    background: transparent;
    color: var(--text-muted);
    padding: 8px;
}

/* ============================================
   TABLET & MOBILE RESPONSIVE STYLES
   ============================================ */

@media (max-width: 1024px) {
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .grid-3 { grid-template-columns: repeat(2, 1fr); }
    
    .sidebar {
        width: 220px;
    }
    
    .main-content {
        margin-left: 220px;
    }
}

@media (max-width: 768px) {
    /* Show mobile elements */
    .mobile-header {
        display: flex;
    }
    
    .mobile-nav {
        display: block;
    }
    
    /* Hide desktop sidebar */
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 280px;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        z-index: 1001;
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    /* Adjust main content */
    .main-content {
        margin-left: 0;
        padding: 72px 16px 80px 16px;
    }
    
    /* Header adjustments */
    .header {
        display: none;
    }
    
    /* Grid adjustments */
    .grid-4, .grid-3, .grid-2 {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    /* Card adjustments */
    .card {
        padding: 16px;
    }
    
    .stat-card {
        padding: 16px;
    }
    
    .stat-card h3 {
        font-size: 24px;
    }
    
    /* Typography */
    h1 { font-size: 1.75rem; }
    h2 { font-size: 1.5rem; }
    h3 { font-size: 1.25rem; }
    
    /* Buttons */
    .btn {
        padding: 14px 20px;
        font-size: 14px;
        width: 100%;
    }
    
    .btn-sm {
        padding: 10px 16px;
        width: auto;
    }
    
    /* Forms */
    .input-group input,
    .input-group select,
    .input-group textarea {
        font-size: 16px !important; /* Prevents iOS zoom */
        padding: 14px 16px;
    }
    
    /* Tables */
    .members-table {
        display: block;
        overflow-x: auto;
    }
    
    .members-table th,
    .members-table td {
        padding: 12px 8px;
        font-size: 13px;
    }
    
    /* Chat */
    .chat-layout {
        flex-direction: column;
    }
    
    .chat-sidebar {
        display: none;
        position: fixed;
        top: 56px;
        left: 0;
        right: 0;
        bottom: 64px;
        z-index: 100;
    }
    
    .chat-sidebar.open {
        display: flex;
    }
    
    .chat-main {
        height: calc(100vh - 120px);
    }
    
    .chat-input-area {
        padding: 12px;
    }
    
    .chat-input-area input {
        font-size: 16px;
    }
    
    /* Messages */
    .message {
        max-width: 85%;
    }
    
    /* Modal - properly sized for mobile */
    .modal {
        max-width: 100%;
        width: 100%;
        margin: 0;
        border-radius: 20px 20px 0 0;
        max-height: 90vh;
        overflow-y: auto;
        box-sizing: border-box;
    }
    
    .modal-overlay {
        pointer-events: none;
    }
    
    .modal-overlay.active {
        align-items: flex-end;
        pointer-events: auto;
    }
    
    .modal-overlay.active .modal {
        pointer-events: auto;
    }
    
    /* CRITICAL: Modal inputs must be typeable */
    .modal input, .modal select, .modal textarea {
        font-size: 16px !important;
        padding: 14px 16px;
        width: 100%;
        box-sizing: border-box;
        -webkit-appearance: none;
        appearance: none;
        border-radius: 8px;
        pointer-events: auto !important;
        -webkit-user-select: text !important;
        user-select: text !important;
    }
    
    .modal .btn {
        pointer-events: auto !important;
        cursor: pointer !important;
        padding: 16px 24px;
        font-size: 15px;
    }
    
    /* Landing page - FORCE PROPER WIDTH */
    .landing-hero {
        padding: 20px 12px 80px 12px;
        min-height: auto;
        width: 100%;
        max-width: 100vw;
        box-sizing: border-box;
    }
    
    .landing-hero .container {
        width: 100%;
        max-width: 100%;
        padding: 0;
        box-sizing: border-box;
    }
    
    .landing-logo {
        font-size: 18px;
        word-break: break-word;
    }
    
    .landing-tagline {
        font-size: 12px;
        padding: 0 8px;
        word-break: break-word;
    }
    
    .landing-price {
        font-size: 38px;
    }
    
    .landing-price-label {
        font-size: 12px;
    }
    
    #exchangeRates {
        font-size: 10px !important;
        flex-wrap: wrap;
        padding: 0 8px;
    }
    
    .landing-features {
        gap: 6px;
        flex-wrap: wrap;
        justify-content: center;
        padding: 0 4px;
    }
    
    .feature-item {
        padding: 6px 8px;
        font-size: 10px;
    }
    
    .benefits-grid {
        grid-template-columns: 1fr;
        padding: 0 8px;
        margin: 20px auto 16px;
        gap: 10px;
        max-width: 100%;
        box-sizing: border-box;
    }
    
    .benefit-card {
        padding: 14px;
        box-sizing: border-box;
    }
    
    .benefit-icon {
        font-size: 24px;
    }
    
    .benefit-title {
        font-size: 13px;
    }
    
    .benefit-desc {
        font-size: 11px;
    }
    
    .founder-section {
        margin-top: 20px;
        padding: 0 8px;
    }
    
    .founder-avatar {
        width: 50px;
        height: 50px;
        font-size: 20px;
    }
    
    .founder-name {
        font-size: 15px;
    }
    
    .founder-title {
        font-size: 10px;
    }
    
    .founder-desc {
        font-size: 11px;
        padding: 0 8px;
    }
    
    /* CRITICAL: Landing page button must be clickable */
    .landing-hero .btn {
        display: block;
        width: 90%;
        max-width: 280px;
        margin: 16px auto;
        padding: 16px 24px;
        font-size: 15px;
        min-height: 52px;
        position: relative;
        z-index: 100;
        pointer-events: auto !important;
        cursor: pointer !important;
        -webkit-appearance: none;
    }
    
    /* Install prompt on landing */
    .install-prompt {
        bottom: 16px;
        left: 12px;
        right: 12px;
        z-index: 100;
    }
    
    /* Profile */
    .profile-header {
        flex-direction: column;
        text-align: center;
    }
    
    .profile-avatar {
        margin: 0 auto;
    }
    
    /* Referral link */
    .referral-link {
        flex-direction: column;
    }
    
    .referral-link input {
        width: 100%;
    }
    
    /* Code vault */
    .snippet-card pre {
        font-size: 12px;
        max-height: 200px;
    }
    
    /* Leaderboard */
    .leaderboard-item {
        padding: 12px;
    }
    
    .leaderboard-rank {
        width: 30px;
        height: 30px;
        font-size: 14px;
    }
    
    /* Admin */
    .admin-nav {
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }
    
    .content-tabs {
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 8px;
    }
    
    .content-tab {
        flex-shrink: 0;
    }
    
    /* Toast */
    .toast-container {
        left: 16px;
        right: 16px;
        bottom: 80px;
    }
    
    .toast {
        width: 100%;
    }
}

@media (max-width: 480px) {
    /* Extra small screens */
    .main-content {
        padding: 64px 12px 80px 12px;
    }
    
    .card {
        padding: 12px;
    }
    
    .stat-card {
        padding: 12px;
    }
    
    .stat-card h3 {
        font-size: 20px;
    }
    
    .stat-card p {
        font-size: 11px;
    }
    
    h1 { font-size: 1.5rem; }
    h2 { font-size: 1.25rem; }
    h3 { font-size: 1.1rem; }
    
    .landing-price {
        font-size: 40px;
    }
    
    .payment-choice {
        flex-direction: column;
    }
    
    .payment-choice-btn {
        padding: 16px;
    }
    
    /* Hide less important columns on very small screens */
    .hide-mobile {
        display: none !important;
    }
}

/* Landscape mode adjustments */
@media (max-height: 500px) and (orientation: landscape) {
    .mobile-nav {
        height: 48px;
    }
    
    .mobile-nav-item {
        flex-direction: row;
        gap: 6px;
    }
    
    .mobile-nav-item span:first-child {
        font-size: 16px;
    }
    
    .main-content {
        padding-bottom: 60px;
    }
    
    .modal {
        max-height: 95vh;
    }
}

/* Dark mode scrollbar for mobile */
@media (max-width: 768px) {
    ::-webkit-scrollbar {
        width: 4px;
        height: 4px;
    }
    
    ::-webkit-scrollbar-thumb {
        background: var(--text-muted);
    }
}

/* Print styles */
@media print {
    .sidebar,
    .mobile-header,
    .mobile-nav,
    .install-banner {
        display: none !important;
    }
    
    .main-content {
        margin: 0;
        padding: 0;
    }
}
