/**
 * Mobile-First Responsive Design
 * Progressive Web App (PWA) Style
 */

/* ==================== MOBILE BASE (< 768px) ==================== */

@media (max-width: 767px) {
    
    /* ==================== MOBILE APP LAYOUT ==================== */
    
    body {
        padding: 0;
        margin: 0;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
    }
    
    .mobile-app-wrapper {
        display: flex;
        flex-direction: column;
        min-height: 100vh;
        padding-bottom: 70px; /* Space for bottom nav */
    }
    
    /* ==================== MOBILE TOP BAR ==================== */
    
    .mobile-header {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        background: white;
        border-bottom: 1px solid var(--gray-200);
        padding: var(--space-4);
        display: flex;
        align-items: center;
        justify-content: space-between;
        z-index: 1000;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    }
    
    .mobile-header-title {
        font-size: 1.25rem;
        font-weight: 700;
        color: var(--gray-900);
        margin: 0;
    }
    
    .mobile-menu-btn {
        width: 44px;
        height: 44px;
        border: none;
        background: transparent;
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        border-radius: var(--radius);
        transition: var(--transition-fast);
    }
    
    .mobile-menu-btn:active {
        background: var(--gray-100);
        transform: scale(0.95);
    }
    
    .hamburger {
        width: 24px;
        height: 2px;
        background: var(--gray-900);
        position: relative;
        transition: var(--transition);
    }
    
    .hamburger::before,
    .hamburger::after {
        content: '';
        position: absolute;
        width: 24px;
        height: 2px;
        background: var(--gray-900);
        transition: var(--transition);
    }
    
    .hamburger::before {
        top: -8px;
    }
    
    .hamburger::after {
        bottom: -8px;
    }
    
    .hamburger.open {
        background: transparent;
    }
    
    .hamburger.open::before {
        top: 0;
        transform: rotate(45deg);
    }
    
    .hamburger.open::after {
        bottom: 0;
        transform: rotate(-45deg);
    }
    
    /* ==================== MOBILE SIDEBAR (DRAWER) ==================== */
    
    .mobile-sidebar-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1001;
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s, visibility 0.3s;
    }
    
    .mobile-sidebar-overlay.active {
        opacity: 1;
        visibility: visible;
    }
    
    .mobile-sidebar {
        position: fixed;
        top: 0;
        left: -100%;
        width: 85%;
        max-width: 320px;
        height: 100vh;
        background: white;
        z-index: 1002;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        box-shadow: var(--shadow-2xl);
    }
    
    .mobile-sidebar.active {
        left: 0;
    }
    
    .mobile-sidebar-header {
        padding: var(--space-6);
        background: linear-gradient(135deg, var(--primary-600) 0%, var(--primary-700) 100%);
        color: white;
    }
    
    .mobile-user-profile {
        display: flex;
        align-items: center;
        gap: var(--space-4);
    }
    
    .mobile-user-avatar {
        width: 60px;
        height: 60px;
        border-radius: 50%;
        background: rgba(255, 255, 255, 0.2);
        border: 3px solid white;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.5rem;
        font-weight: 700;
    }
    
    .mobile-user-info h3 {
        margin: 0 0 var(--space-1) 0;
        font-size: 1.1rem;
    }
    
    .mobile-user-info p {
        margin: 0;
        opacity: 0.9;
        font-size: 0.875rem;
    }
    
    .mobile-nav {
        padding: var(--space-4) 0;
    }
    
    .mobile-nav-item {
        list-style: none;
    }
    
    .mobile-nav-link {
        display: flex;
        align-items: center;
        gap: var(--space-4);
        padding: var(--space-4) var(--space-6);
        color: var(--gray-700);
        font-weight: 500;
        transition: var(--transition-fast);
        border-left: 4px solid transparent;
    }
    
    .mobile-nav-link:active {
        background: var(--gray-50);
    }
    
    .mobile-nav-link.active {
        background: var(--primary-50);
        color: var(--primary-700);
        border-left-color: var(--primary-600);
    }
    
    .mobile-nav-icon {
        font-size: 1.5rem;
        width: 32px;
        text-align: center;
    }
    
    .mobile-nav-section {
        padding: var(--space-4) var(--space-6);
        font-size: 0.75rem;
        font-weight: 600;
        color: var(--gray-400);
        text-transform: uppercase;
        letter-spacing: 0.1em;
        border-top: 1px solid var(--gray-200);
        margin-top: var(--space-2);
    }
    
    /* ==================== MOBILE BOTTOM NAVIGATION ==================== */
    
    .mobile-bottom-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: white;
        border-top: 1px solid var(--gray-200);
        display: flex;
        justify-content: space-around;
        align-items: center;
        padding: var(--space-2) 0;
        z-index: 999;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
    }
    
    .bottom-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: var(--space-1);
        padding: var(--space-2);
        text-decoration: none;
        color: var(--gray-500);
        transition: var(--transition-fast);
        border-radius: var(--radius);
        position: relative;
    }
    
    .bottom-nav-item:active {
        transform: scale(0.95);
        background: var(--gray-50);
    }
    
    .bottom-nav-item.active {
        color: var(--primary-600);
    }
    
    .bottom-nav-icon {
        font-size: 1.5rem;
        position: relative;
    }
    
    .bottom-nav-icon .badge-count {
        position: absolute;
        top: -8px;
        right: -8px;
        background: var(--error);
        color: white;
        font-size: 0.625rem;
        font-weight: 700;
        padding: 2px 6px;
        border-radius: var(--radius-full);
        min-width: 18px;
        text-align: center;
    }
    
    .bottom-nav-label {
        font-size: 0.75rem;
        font-weight: 500;
    }
    
    .bottom-nav-item.active .bottom-nav-label {
        font-weight: 600;
    }
    
    /* ==================== MOBILE MAIN CONTENT ==================== */
    
    .mobile-main-content {
        flex: 1;
        padding: var(--space-4);
        margin-top: 64px; /* Height of mobile header */
        padding-bottom: 80px; /* Space for bottom nav */
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* ==================== MOBILE CARDS ==================== */
    
    .card {
        border-radius: var(--radius-lg);
        box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
        margin-bottom: var(--space-4);
    }
    
    .card:active {
        transform: scale(0.98);
    }
    
    /* Stats Cards - Mobile Optimized */
    .mobile-stat-grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-3);
        margin-bottom: var(--space-4);
    }
    
    .mobile-stat-card {
        background: white;
        border-radius: var(--radius-lg);
        padding: var(--space-4);
        box-shadow: var(--shadow);
        text-align: center;
        position: relative;
        overflow: hidden;
    }
    
    .mobile-stat-card::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        height: 4px;
        background: linear-gradient(90deg, var(--primary-500), var(--primary-600));
    }
    
    .mobile-stat-number {
        font-size: 1.75rem;
        font-weight: 800;
        color: var(--primary-700);
        margin-bottom: var(--space-1);
    }
    
    .mobile-stat-label {
        font-size: 0.75rem;
        color: var(--gray-600);
        font-weight: 500;
    }
    
    .mobile-stat-icon {
        position: absolute;
        top: var(--space-3);
        right: var(--space-3);
        font-size: 1.5rem;
        opacity: 0.1;
        color: var(--primary-600);
    }
    
    /* ==================== MOBILE BUTTONS ==================== */
    
    .btn {
        width: 100%;
        padding: var(--space-4);
        font-size: 1rem;
        border-radius: var(--radius-lg);
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }
    
    .btn:active {
        transform: scale(0.98);
    }
    
    .btn-group-mobile {
        display: flex;
        gap: var(--space-3);
        margin-bottom: var(--space-4);
    }
    
    .btn-group-mobile .btn {
        flex: 1;
    }
    
    /* Floating Action Button */
    .fab {
        position: fixed;
        bottom: 90px; /* Above bottom nav */
        right: var(--space-4);
        width: 56px;
        height: 56px;
        border-radius: 50%;
        background: linear-gradient(135deg, var(--primary-600) 0%, var(--primary-700) 100%);
        color: white;
        border: none;
        box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.5rem;
        z-index: 998;
        transition: var(--transition);
    }
    
    .fab:active {
        transform: scale(0.95);
    }
    
    .fab-menu {
        position: fixed;
        bottom: 160px;
        right: var(--space-4);
        display: flex;
        flex-direction: column;
        gap: var(--space-3);
        opacity: 0;
        visibility: hidden;
        transform: translateY(20px);
        transition: var(--transition);
        z-index: 997;
    }
    
    .fab-menu.active {
        opacity: 1;
        visibility: visible;
        transform: translateY(0);
    }
    
    .fab-menu-item {
        display: flex;
        align-items: center;
        gap: var(--space-3);
        background: white;
        padding: var(--space-3) var(--space-4);
        border-radius: var(--radius-full);
        box-shadow: var(--shadow-lg);
        text-decoration: none;
        color: var(--gray-700);
        white-space: nowrap;
        transition: var(--transition-fast);
    }
    
    .fab-menu-item:active {
        transform: scale(0.95);
    }
    
    .fab-menu-icon {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        background: var(--primary-100);
        color: var(--primary-700);
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* ==================== MOBILE FORMS ==================== */
    
    .form-input,
    .form-select,
    .form-textarea {
        font-size: 16px; /* Prevents iOS zoom */
        padding: var(--space-4);
        border-radius: var(--radius-lg);
        -webkit-appearance: none;
        appearance: none;
    }
    
    .form-group {
        margin-bottom: var(--space-5);
    }
    
    .form-label {
        font-size: 0.875rem;
        margin-bottom: var(--space-2);
    }
    
    /* Mobile Date Picker */
    input[type="date"],
    input[type="time"] {
        position: relative;
        padding-right: 40px;
    }
    
    /* ==================== MOBILE PROGRESS BARS ==================== */
    
    .mobile-progress-card {
        background: white;
        border-radius: var(--radius-lg);
        padding: var(--space-4);
        margin-bottom: var(--space-3);
        box-shadow: var(--shadow);
    }
    
    .mobile-progress-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: var(--space-3);
    }
    
    .mobile-progress-title {
        font-size: 0.875rem;
        font-weight: 600;
        color: var(--gray-700);
    }
    
    .mobile-progress-score {
        font-size: 1.25rem;
        font-weight: 800;
        color: var(--primary-700);
    }
    
    .progress-bar-wrapper {
        height: 12px;
        border-radius: var(--radius-full);
    }
    
    /* ==================== MOBILE LISTS ==================== */
    
    .mobile-list {
        background: white;
        border-radius: var(--radius-lg);
        overflow: hidden;
        box-shadow: var(--shadow);
        margin-bottom: var(--space-4);
    }
    
    .mobile-list-item {
        padding: var(--space-4);
        border-bottom: 1px solid var(--gray-100);
        display: flex;
        align-items: center;
        gap: var(--space-4);
        transition: var(--transition-fast);
    }
    
    .mobile-list-item:last-child {
        border-bottom: none;
    }
    
    .mobile-list-item:active {
        background: var(--gray-50);
    }
    
    .mobile-list-icon {
        width: 48px;
        height: 48px;
        border-radius: var(--radius);
        background: var(--primary-100);
        color: var(--primary-700);
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.25rem;
        flex-shrink: 0;
    }
    
    .mobile-list-content {
        flex: 1;
        min-width: 0; /* For text truncation */
    }
    
    .mobile-list-title {
        font-size: 0.95rem;
        font-weight: 600;
        color: var(--gray-900);
        margin: 0 0 var(--space-1) 0;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
    
    .mobile-list-subtitle {
        font-size: 0.875rem;
        color: var(--gray-600);
        margin: 0;
    }
    
    .mobile-list-arrow {
        color: var(--gray-400);
        font-size: 1.25rem;
    }
    
    /* ==================== MOBILE TABS ==================== */
    
    .mobile-tabs {
        display: flex;
        background: white;
        border-radius: var(--radius-lg);
        padding: var(--space-1);
        gap: var(--space-1);
        margin-bottom: var(--space-4);
        box-shadow: var(--shadow);
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    
    .mobile-tabs::-webkit-scrollbar {
        display: none;
    }
    
    .mobile-tab {
        flex: 1;
        min-width: 100px;
        padding: var(--space-3);
        text-align: center;
        border-radius: var(--radius);
        background: transparent;
        border: none;
        font-size: 0.875rem;
        font-weight: 500;
        color: var(--gray-600);
        cursor: pointer;
        transition: var(--transition-fast);
        white-space: nowrap;
    }
    
    .mobile-tab.active {
        background: var(--primary-600);
        color: white;
        font-weight: 600;
    }
    
    .mobile-tab:active {
        transform: scale(0.98);
    }
    
    /* ==================== MOBILE SEARCH ==================== */
    
    .mobile-search-bar {
        position: relative;
        margin-bottom: var(--space-4);
    }
    
    .mobile-search-input {
        width: 100%;
        padding: var(--space-3) var(--space-4) var(--space-3) 3rem;
        font-size: 16px;
        border: 2px solid var(--gray-200);
        border-radius: var(--radius-full);
        background: white;
    }
    
    .mobile-search-icon {
        position: absolute;
        left: var(--space-4);
        top: 50%;
        transform: translateY(-50%);
        color: var(--gray-400);
        font-size: 1.25rem;
    }
    
    /* ==================== MOBILE MODALS ==================== */
    
    .mobile-modal {
        position: fixed;
        bottom: -100%;
        left: 0;
        right: 0;
        background: white;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        max-height: 90vh;
        z-index: 1100;
        transition: bottom 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
    }
    
    .mobile-modal.active {
        bottom: 0;
    }
    
    .mobile-modal-handle {
        width: 40px;
        height: 4px;
        background: var(--gray-300);
        border-radius: var(--radius-full);
        margin: var(--space-3) auto;
    }
    
    .mobile-modal-header {
        padding: var(--space-4) var(--space-6);
        border-bottom: 1px solid var(--gray-200);
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    
    .mobile-modal-title {
        font-size: 1.25rem;
        font-weight: 700;
        margin: 0;
    }
    
    .mobile-modal-close {
        width: 40px;
        height: 40px;
        border-radius: 50%;
        background: var(--gray-100);
        border: none;
        color: var(--gray-700);
        font-size: 1.5rem;
        display: flex;
        align-items: center;
        justify-content: center;
        cursor: pointer;
    }
    
    .mobile-modal-close:active {
        background: var(--gray-200);
        transform: scale(0.95);
    }
    
    .mobile-modal-body {
        padding: var(--space-6);
        overflow-y: auto;
        max-height: calc(90vh - 140px);
        -webkit-overflow-scrolling: touch;
    }
    
    /* ==================== MOBILE ALERTS ==================== */
    
    .mobile-toast {
        position: fixed;
        bottom: 90px;
        left: var(--space-4);
        right: var(--space-4);
        background: var(--gray-900);
        color: white;
        padding: var(--space-4);
        border-radius: var(--radius-lg);
        display: flex;
        align-items: center;
        gap: var(--space-3);
        box-shadow: var(--shadow-xl);
        transform: translateY(150%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 1200;
    }
    
    .mobile-toast.show {
        transform: translateY(0);
    }
    
    .mobile-toast-icon {
        font-size: 1.5rem;
    }
    
    .mobile-toast-content {
        flex: 1;
    }
    
    .mobile-toast.success {
        background: var(--success);
    }
    
    .mobile-toast.error {
        background: var(--error);
    }
    
    .mobile-toast.warning {
        background: var(--warning);
        color: var(--gray-900);
    }
    
    /* ==================== MOBILE SWIPE ACTIONS ==================== */
    
    .swipeable-item {
        position: relative;
        background: white;
        overflow: hidden;
    }
    
    .swipe-actions {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        display: flex;
        transform: translateX(100%);
        transition: transform 0.3s;
    }
    
    .swipeable-item.swiped .swipe-actions {
        transform: translateX(0);
    }
    
    .swipe-action {
        padding: var(--space-4);
        min-width: 80px;
        display: flex;
        align-items: center;
        justify-content: center;
        color: white;
        font-size: 1.5rem;
        cursor: pointer;
    }
    
    .swipe-action.delete {
        background: var(--error);
    }
    
    .swipe-action.edit {
        background: var(--primary-600);
    }
    
    /* ==================== MOBILE PULL TO REFRESH ==================== */
    
    .pull-to-refresh {
        position: relative;
        overflow: hidden;
    }
    
    .pull-indicator {
        position: absolute;
        top: -60px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: top 0.3s;
    }
    
    .pull-to-refresh.pulling .pull-indicator {
        top: 20px;
    }
    
    /* ==================== MOBILE LOADING STATES ==================== */
    
    .mobile-skeleton {
        background: linear-gradient(
            90deg,
            var(--gray-200) 25%,
            var(--gray-100) 50%,
            var(--gray-200) 75%
        );
        background-size: 200% 100%;
        animation: shimmer 1.5s infinite;
        border-radius: var(--radius);
    }
    
    @keyframes shimmer {
        0% { background-position: 200% 0; }
        100% { background-position: -200% 0; }
    }
    
    .skeleton-text {
        height: 16px;
        margin-bottom: var(--space-2);
    }
    
    .skeleton-title {
        height: 24px;
        width: 70%;
        margin-bottom: var(--space-3);
    }
    
    .skeleton-avatar {
        width: 48px;
        height: 48px;
        border-radius: 50%;
    }
    
    /* ==================== MOBILE UTILITIES ==================== */
    
    .hide-mobile {
        display: none !important;
    }
    
    .show-mobile {
        display: block !important;
    }
    
    .mobile-only {
        display: block;
    }
    
    /* Prevent text selection on touch */
    .no-select {
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        -webkit-tap-highlight-color: transparent;
    }
    
    /* Safe area insets for notched devices */
    @supports (padding-top: env(safe-area-inset-top)) {
        .mobile-header {
            padding-top: calc(var(--space-4) + env(safe-area-inset-top));
        }
        
        .mobile-bottom-nav {
            padding-bottom: calc(var(--space-2) + env(safe-area-inset-bottom));
        }
    }
    
    /* ==================== MOBILE LANDSCAPE ==================== */
    
    @media (max-height: 500px) and (orientation: landscape) {
        .mobile-bottom-nav {
            display: none;
        }
        
        .fab {
            bottom: var(--space-4);
        }
        
        .mobile-main-content {
            padding-bottom: var(--space-4);
        }
    }
}

/* ==================== TABLET (768px - 1024px) ==================== */

@media (min-width: 768px) and (max-width: 1024px) {
    .mobile-bottom-nav {
        display: none;
    }
    
    .mobile-stat-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .mobile-sidebar {
        max-width: 380px;
    }
    
    .btn-group-mobile .btn {
        max-width: 200px;
    }
}

/* ==================== DESKTOP (> 1024px) ==================== */

@media (min-width: 1025px) {
    .mobile-header,
    .mobile-bottom-nav,
    .mobile-sidebar,
    .mobile-sidebar-overlay,
    .fab,
    .fab-menu {
        display: none !important;
    }
    
    .mobile-main-content {
        margin-top: 0;
        padding-bottom: 0;
    }
    
    .mobile-only {
        display: none !important;
    }
    
    .hide-mobile {
        display: block !important;
    }
}

/* ==================== PWA SPECIFIC ==================== */

/* Standalone mode (when installed as PWA) */
@media (display-mode: standalone) {
    .mobile-header {
        padding-top: calc(var(--space-4) + 20px);
    }
    
    .install-prompt {
        display: none;
    }
}

/* Dark mode support for mobile */
@media (prefers-color-scheme: dark) {
    .mobile-header,
    .mobile-bottom-nav,
    .mobile-sidebar {
        background: #1a1a1a;
        border-color: #333;
    }
    
    .mobile-nav-link,
    .bottom-nav-item {
        color: #e5e5e5;
    }
    
    .mobile-stat-card,
    .card {
        background: #262626;
        color: #e5e5e5;
    }
}

/* ==================== HAPTIC FEEDBACK SIMULATION ==================== */

@keyframes haptic-light {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(0.98); }
}

@keyframes haptic-medium {
    0%, 100% { transform: scale(1); }
    25% { transform: scale(0.96); }
    75% { transform: scale(0.98); }
}

.haptic-light:active {
    animation: haptic-light 0.1s ease-in-out;
}

.haptic-medium:active {
    animation: haptic-medium 0.15s ease-in-out;
}