/**
 * Team Portal Mobile Core
 * Consolidated stylesheet for mobile-first layout, touch interactions, and PWA features.
 * Replaces: mobile.css, pwa.css
 *
 * @package TeamPortal
 * @version 2.0.0
 */

/* ==========================================================================
   PART 1: MOBILE BASE & RESET
   ========================================================================== */
@media (max-width: 768px) {
    /* Improve touch targets */
    button, .button, a.button, input[type="submit"], input[type="button"], .wp-core-ui .button {
        min-height: 48px; min-width: 48px; padding: 12px 24px; font-size: 16px;
    }
    
    /* Remove tap highlight */
    * { -webkit-tap-highlight-color: rgba(102, 126, 234, 0.2); }
    
    /* Improve form inputs */
    input[type="text"], input[type="email"], input[type="password"],
    input[type="number"], input[type="tel"], input[type="url"],
    textarea, select {
        min-height: 48px; font-size: 16px; padding: 12px 16px;
    }
    
    body { font-size: 16px; line-height: 1.6; }
}

/* ==========================================================================
   PART 2: MOBILE LAYOUT (App Shell)
   ========================================================================== */

/* Mobile Header */
.mobile-header {
    position: sticky; top: 0; background: white;
    border-bottom: 1px solid #e5e7eb; padding: 12px 16px;
    display: none; align-items: center; justify-content: space-between;
    z-index: 99998; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}
@media (max-width: 768px) { .mobile-header { display: flex; } }

.mobile-header-left, .mobile-header-right { display: flex; align-items: center; gap: 8px; }
.mobile-header-title { font-size: 18px; font-weight: 700; color: #1f2937; margin: 0; }

.mobile-menu-button, .mobile-search-button, .mobile-notifications-button {
    width: 40px; height: 40px; border: none; background: #f3f4f6;
    border-radius: 10px; display: flex; align-items: center; justify-content: center;
    cursor: pointer; font-size: 20px; transition: all 0.3s ease;
}
.mobile-menu-button:active { background: #e5e7eb; transform: scale(0.95); }

/* Bottom Navigation Bar */
.mobile-bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0;
    background: white; border-top: 1px solid #e5e7eb;
    display: none; z-index: 99999;
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.1);
}
@media (max-width: 768px) { .mobile-bottom-nav { display: flex; } }

.mobile-bottom-nav-items {
    display: flex; width: 100%; justify-content: space-around;
    align-items: center; padding: 8px 0;
}

.mobile-bottom-nav-item {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 8px 12px; text-decoration: none; color: #6b7280;
    transition: all 0.3s ease; min-width: 60px; position: relative;
}

.mobile-bottom-nav-item.active { color: #667eea; }
.mobile-bottom-nav-item.active::before {
    content: ""; position: absolute; top: 0; left: 50%;
    transform: translateX(-50%); width: 30px; height: 3px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 0 0 3px 3px;
}

.mobile-bottom-nav-icon { font-size: 24px; margin-bottom: 4px; }
.mobile-bottom-nav-label { font-size: 11px; font-weight: 500; }
.mobile-bottom-nav-badge {
    position: absolute; top: 4px; right: 8px; background: #ef4444; color: white;
    font-size: 10px; font-weight: 700; padding: 2px 6px; border-radius: 10px;
    min-width: 18px; text-align: center;
}

/* Mobile Sidebar (Off-canvas) */
.mobile-sidebar {
    position: fixed; top: 0; right: -100%; width: 80%; max-width: 320px;
    height: 100vh; background: white; z-index: 999999;
    transition: right 0.3s ease; overflow-y: auto;
    padding-bottom: env(safe-area-inset-bottom);
}
.mobile-sidebar.active { right: 0; }

.mobile-sidebar-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.5); z-index: 999998;
    opacity: 0; visibility: hidden; transition: all 0.3s ease;
}
.mobile-sidebar-overlay.active { opacity: 1; visibility: visible; }

.mobile-sidebar-header {
    padding: 20px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white; position: relative;
}
.mobile-sidebar-close {
    position: absolute; top: 16px; left: 16px; width: 36px; height: 36px;
    border: none; background: rgba(255, 255, 255, 0.2); color: white;
    border-radius: 8px; font-size: 24px; cursor: pointer;
}
.mobile-sidebar-user { display: flex; align-items: center; gap: 12px; margin-top: 10px; }
.mobile-sidebar-avatar {
    width: 50px; height: 50px; border-radius: 50%; background: white;
    display: flex; align-items: center; justify-content: center; font-size: 24px;
}
.mobile-sidebar-user-info h3 { margin: 0; font-size: 16px; font-weight: 600; color: white; }
.mobile-sidebar-user-info p { margin: 4px 0 0; font-size: 13px; opacity: 0.9; color: rgba(255,255,255,0.9); }

.mobile-sidebar-menu { padding: 0; margin: 0; list-style: none; }
.mobile-sidebar-menu-item { border-bottom: 1px solid #f3f4f6; }
.mobile-sidebar-menu-item a {
    display: flex; align-items: center; padding: 16px 20px; color: #374151;
    text-decoration: none; transition: all 0.3s ease;
}
.mobile-sidebar-menu-item.active a { background: #f0f4f8; color: #667eea; font-weight: 600; }
.mobile-sidebar-menu-icon { font-size: 24px; margin-left: 12px; width: 24px; text-align: center; }

/* ==========================================================================
   PART 3: MOBILE COMPONENT OVERRIDES
   ========================================================================== */

/* Pull to Refresh */
.pull-to-refresh {
    position: absolute; top: -60px; left: 0; right: 0; height: 60px;
    display: flex; align-items: center; justify-content: center;
    transition: transform 0.3s ease;
}
.pull-to-refresh.pulling { transform: translateY(60px); }
.pull-to-refresh-icon { font-size: 24px; animation: rotate 1s linear infinite; }
@keyframes rotate { to { transform: rotate(360deg); } }

/* Swipe Indicators */
.swipe-indicator {
    position: fixed; top: 50%; transform: translateY(-50%); width: 50px; height: 50px;
    background: rgba(102, 126, 234, 0.9); border-radius: 50%;
    display: flex; align-items: center; justify-content: center; color: white;
    font-size: 24px; opacity: 0; pointer-events: none; transition: opacity 0.3s ease; z-index: 99997;
}
.swipe-indicator.left { left: 20px; }
.swipe-indicator.right { right: 20px; }
.swipe-indicator.active { opacity: 1; animation: swipePulse 0.6s ease infinite; }
@keyframes swipePulse { 0%, 100% { transform: translateY(-50%) scale(1); } 50% { transform: translateY(-50%) scale(1.1); } }

/* Touch Friendly Tables (Generic) */
@media (max-width: 768px) {
    .wp-list-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .wp-list-table thead { display: none; }
    .wp-list-table tbody, .wp-list-table tr { display: block; }
    .wp-list-table tr {
        margin-bottom: 16px; background: white; border-radius: 12px;
        padding: 16px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    }
    .wp-list-table td {
        display: flex; justify-content: space-between; padding: 12px 0 !important;
        border: none !important; border-bottom: 1px solid #f3f4f6 !important;
    }
    .wp-list-table td:last-child { border-bottom: none !important; }
    .wp-list-table td::before {
        content: attr(data-label); font-weight: 600; color: #6b7280; margin-left: 8px;
    }
}

/* Mobile Modals */
@media (max-width: 768px) {
    .mobile-modal {
        position: fixed; bottom: -100%; left: 0; right: 0; background: white;
        border-radius: 24px 24px 0 0; z-index: 999999; transition: bottom 0.3s ease;
        max-height: 90vh; overflow-y: auto; padding-bottom: env(safe-area-inset-bottom);
    }
    .mobile-modal.active { bottom: 0; }
    .mobile-modal-header { padding: 16px 20px; border-bottom: 1px solid #e5e7eb; }
    .mobile-modal-title { font-size: 18px; font-weight: 700; color: #1f2937; margin: 0; }
    .mobile-modal-content { padding: 20px; }
}

/* Mobile Tabs */
.mobile-tabs {
    display: flex; overflow-x: auto; -webkit-overflow-scrolling: touch;
    border-bottom: 2px solid #e5e7eb; margin-bottom: 20px; gap: 8px;
}
.mobile-tabs::-webkit-scrollbar { display: none; }
.mobile-tab {
    padding: 12px 20px; border: none; background: transparent; color: #6b7280;
    font-size: 15px; font-weight: 500; white-space: nowrap; cursor: pointer;
    position: relative; transition: all 0.3s ease;
}
.mobile-tab.active { color: #667eea; font-weight: 700; }

/* ==========================================================================
   PART 4: PWA STYLES
   ========================================================================== */

/* Install Prompt */
.pwa-install-prompt {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.7); backdrop-filter: blur(5px);
    display: flex; align-items: center; justify-content: center;
    z-index: 999999; opacity: 0; visibility: hidden; transition: all 0.3s ease;
}
.pwa-install-prompt.show { opacity: 1; visibility: visible; }
.pwa-install-dialog {
    background: white; border-radius: 20px; padding: 40px; max-width: 400px;
    width: 90%; text-align: center; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    transform: scale(0.9); transition: transform 0.3s ease;
}
.pwa-install-prompt.show .pwa-install-dialog { transform: scale(1); }

/* PWA Actions */
.pwa-install-actions { display: flex; gap: 12px; }
.pwa-install-accept, .pwa-install-cancel {
    flex: 1; padding: 14px 24px; border: none; border-radius: 12px;
    font-size: 16px; font-weight: 600; cursor: pointer; transition: all 0.3s ease;
}
.pwa-install-accept {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white;
}
.pwa-install-cancel { background: #f3f4f6; color: #6b7280; }

/* Update Notification */
.pwa-update-notification {
    position: fixed; top: 20px; right: 20px; background: white; border-radius: 12px;
    padding: 20px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15); max-width: 400px;
    z-index: 999998; transform: translateX(calc(100% + 40px)); transition: transform 0.3s ease;
}
.pwa-update-notification.show { transform: translateX(0); }

/* Status Notification */
.pwa-status-notification {
    position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(100px);
    background: white; padding: 16px 24px; border-radius: 50px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15); display: flex; align-items: center; gap: 12px;
    z-index: 999997; transition: transform 0.3s ease;
}
.pwa-status-notification.show { transform: translateX(-50%) translateY(0); }
.pwa-status-notification.offline { background: #fef3c7; border: 2px solid #fbbf24; }
.pwa-status-notification.online { background: #d1fae5; border: 2px solid #10b981; }

/* Standalone Mode */
.pwa-installed {
    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);
}
.pwa-installed #wpadminbar { top: env(safe-area-inset-top); }
.pwa-loading-screen {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    z-index: 9999999; opacity: 1; transition: opacity 0.5s ease;
}
.pwa-loading-screen.hidden { opacity: 0; pointer-events: none; }
