/* Jasiri Mobile Optimizations - PWA Ready */

/* === MOBILE-FIRST RESPONSIVE DESIGN === */

/* Safe Area Support for Devices with Notches */
:root {
    --safe-area-inset-top: env(safe-area-inset-top, 0px);
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
    --safe-area-inset-left: env(safe-area-inset-left, 0px);
    --safe-area-inset-right: env(safe-area-inset-right, 0px);
}

/* PWA Standalone Mode Adjustments */
@media (display-mode: standalone) {
    body {
        padding-top: var(--safe-area-inset-top);
        padding-bottom: var(--safe-area-inset-bottom);
    }
    
    .navbar {
        padding-top: calc(1rem + var(--safe-area-inset-top));
    }
}

/* === MOBILE NAVIGATION OPTIMIZATIONS === */
@media (max-width: 768px) {
    /* Navigation Bar */
    .navbar {
        padding: 0.75rem 1rem;
        min-height: 60px;
    }
    
    .navbar .logo {
        font-size: 1.25rem;
    }
    
    /* Mobile Menu Button */
    .mobile-menu-btn {
        padding: 0.5rem;
        border-radius: 8px;
        transition: all 0.2s ease;
        -webkit-tap-highlight-color: transparent;
    }
    
    .mobile-menu-btn:active {
        transform: scale(0.95);
        background-color: rgba(84, 230, 182, 0.1);
    }
}

/* === DASHBOARD MOBILE OPTIMIZATIONS === */
@media (max-width: 768px) {
    .dashboard-container {
        padding: 0.5rem;
        min-height: calc(100vh - 60px);
    }
    
    /* Hero Section Mobile */
    .hero-section {
        padding: 1.5rem 1rem;
        margin-bottom: 1rem;
        border-radius: 16px;
    }
    
    .hero-section h1 {
        font-size: 1.75rem !important;
        line-height: 1.3;
        margin-bottom: 0.5rem;
    }
    
    .hero-section p {
        font-size: 0.95rem;
        line-height: 1.5;
    }
    
    /* Stats Cards Mobile */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
        margin-bottom: 1.5rem;
    }
    
    .stat-card {
        padding: 1rem;
        border-radius: 12px;
    }
    
    .stat-card .stat-number {
        font-size: 1.5rem;
    }
    
    .stat-card .stat-label {
        font-size: 0.8rem;
    }
    
    /* Upload Zone Mobile */
    .upload-zone {
        padding: 2rem 1rem;
        border-radius: 16px;
        margin-bottom: 1.5rem;
    }
    
    .upload-zone h3 {
        font-size: 1.25rem;
        margin-bottom: 0.5rem;
    }
    
    .upload-zone p {
        font-size: 0.9rem;
        margin-bottom: 1rem;
    }
    
    /* Device Icons Mobile */
    .device-icons {
        flex-wrap: wrap;
        gap: 0.5rem;
        justify-content: center;
    }
    
    .device-icon {
        width: 40px;
        height: 40px;
        font-size: 1.25rem;
    }
}

/* === ASSET CARDS MOBILE OPTIMIZATIONS === */
@media (max-width: 768px) {
    .assets-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .asset-card {
        padding: 1rem;
        border-radius: 12px;
    }
    
    .asset-card .asset-image {
        height: 150px;
        border-radius: 8px;
    }
    
    .asset-card .asset-title {
        font-size: 1rem;
        margin: 0.75rem 0 0.5rem;
    }
    
    .asset-card .asset-details {
        font-size: 0.85rem;
        margin-bottom: 1rem;
    }
    
    .asset-card .asset-actions {
        flex-direction: column;
        gap: 0.5rem;
    }
    
    .asset-card .btn {
        width: 100%;
        padding: 0.75rem;
        font-size: 0.9rem;
        border-radius: 8px;
    }
}

/* === FORM OPTIMIZATIONS === */
@media (max-width: 768px) {
    .form-input {
        padding: 0.875rem;
        font-size: 16px; /* Prevents zoom on iOS */
        border-radius: 8px;
    }
    
    .form-textarea {
        padding: 0.875rem;
        font-size: 16px;
        min-height: 100px;
        border-radius: 8px;
    }
    
    .form-select {
        padding: 0.875rem;
        font-size: 16px;
        border-radius: 8px;
    }
    
    /* File Upload Mobile */
    .file-upload-zone {
        padding: 2rem 1rem;
        border-radius: 12px;
        border: 2px dashed #d1d5db;
        text-align: center;
        transition: all 0.3s ease;
    }
    
    .file-upload-zone.dragover {
        border-color: #54e6b6;
        background-color: rgba(84, 230, 182, 0.05);
    }
    
    .file-upload-zone input[type="file"] {
        position: absolute;
        opacity: 0;
        width: 100%;
        height: 100%;
        cursor: pointer;
    }
}

/* === BUTTON OPTIMIZATIONS === */
@media (max-width: 768px) {
    .btn-primary,
    .btn-secondary,
    .btn-jasiri {
        min-height: 44px; /* Apple's recommended touch target */
        padding: 0.75rem 1.5rem;
        font-size: 0.95rem;
        border-radius: 8px;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
    }
    
    .btn-primary:active,
    .btn-secondary:active,
    .btn-jasiri:active {
        transform: scale(0.98);
    }
    
    /* Floating Action Button */
    .fab {
        position: fixed;
        bottom: calc(1rem + var(--safe-area-inset-bottom));
        right: 1rem;
        width: 56px;
        height: 56px;
        border-radius: 50%;
        background: #54e6b6;
        color: #000;
        border: none;
        box-shadow: 0 4px 12px rgba(84, 230, 182, 0.4);
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 1.5rem;
        z-index: 1000;
        transition: all 0.3s ease;
        -webkit-tap-highlight-color: transparent;
    }
    
    .fab:active {
        transform: scale(0.95);
    }
}

/* === MODAL OPTIMIZATIONS === */
@media (max-width: 768px) {
    .modal {
        padding: 0;
        align-items: flex-end;
    }
    
    .modal-content {
        width: 100%;
        max-width: none;
        border-radius: 24px 24px 0 0;
        max-height: 92vh;
        overflow-y: auto;
        margin: 0;
        animation: slideUp 0.3s ease-out;
    }
    
    @keyframes slideUp {
        from {
            transform: translateY(100%);
        }
        to {
            transform: translateY(0);
        }
    }
    
    .modal-header {
        padding: 1.25rem 1.5rem;
        padding-top: 1.75rem;
        border-bottom: 1px solid #e5e7eb;
        position: sticky;
        top: 0;
        background: white;
        z-index: 10;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
    
    .modal-header::before {
        content: '';
        position: absolute;
        top: 0.75rem;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 4px;
        background: #d1d5db;
        border-radius: 2px;
    }
    
    .modal-body {
        padding: 1.5rem;
        padding-bottom: calc(1.5rem + env(safe-area-inset-bottom));
    }
    
    .modal-footer {
        padding: 1.25rem 1.5rem;
        padding-bottom: calc(1.25rem + env(safe-area-inset-bottom));
        border-top: 1px solid #e5e7eb;
        position: sticky;
        bottom: 0;
        background: white;
        display: flex;
        gap: 0.75rem;
    }
    
    .modal-footer .btn {
        flex: 1;
    }
}

/* === TOUCH OPTIMIZATIONS === */
@media (hover: none) and (pointer: coarse) {
    /* Remove hover effects on touch devices */
    .hover\\:scale-105:hover {
        transform: none;
    }
    
    .hover\\:shadow-lg:hover {
        box-shadow: none;
    }
    
    /* Add active states for touch feedback */
    .touch-feedback:active,
    .touch-manipulation:active {
        transform: scale(0.97);
        opacity: 0.85;
    }
    
    /* Improve tap targets */
    a, button, [role="button"], input[type="submit"], input[type="button"] {
        min-height: 48px;
        min-width: 48px;
    }
    
    /* Better link spacing */
    a {
        padding: 0.25rem 0;
    }
    
    /* Card touch feedback */
    .asset-card:active,
    .stat-card:active {
        transform: scale(0.98);
    }
}

/* === LOADING STATES === */
@media (max-width: 768px) {
    .loading-skeleton {
        background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
        background-size: 200% 100%;
        animation: loading 1.5s infinite;
        border-radius: 8px;
    }
    
    @keyframes loading {
        0% { background-position: 200% 0; }
        100% { background-position: -200% 0; }
    }
    
    .loading-overlay {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(255, 255, 255, 0.9);
        display: flex;
        align-items: center;
        justify-content: center;
        z-index: 9999;
    }
    
    .loading-spinner {
        width: 40px;
        height: 40px;
        border: 3px solid #f3f3f3;
        border-top: 3px solid #54e6b6;
        border-radius: 50%;
        animation: spin 1s linear infinite;
    }
    
    @keyframes spin {
        0% { transform: rotate(0deg); }
        100% { transform: rotate(360deg); }
    }
}

/* === ACCESSIBILITY IMPROVEMENTS === */
@media (max-width: 768px) {
    /* Focus indicators */
    .focus\\:ring-2:focus {
        outline: none;
        box-shadow: 0 0 0 3px rgba(84, 230, 182, 0.5);
    }
    
    /* High contrast mode support */
    @media (prefers-contrast: high) {
        .btn-primary {
            border: 2px solid #000;
        }
        
        .asset-card {
            border: 2px solid #000;
        }
    }
    
    /* Reduced motion support */
    @media (prefers-reduced-motion: reduce) {
        * {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
        }
    }
}

/* === OFFLINE STYLES === */
.offline {
    filter: grayscale(0.5);
}

.offline::before {
    content: "You're offline";
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: #ef4444;
    color: white;
    text-align: center;
    padding: 0.5rem;
    font-size: 0.875rem;
    z-index: 10000;
}

/* === PULL-TO-REFRESH === */
@media (max-width: 768px) {
    .pull-to-refresh {
        position: relative;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .pull-to-refresh-indicator {
        position: absolute;
        top: -60px;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: center;
        background: #54e6b6;
        border-radius: 50%;
        color: #000;
        transition: all 0.3s ease;
        opacity: 0;
    }
    
    .pull-to-refresh.pulling .pull-to-refresh-indicator {
        opacity: 1;
        top: 10px;
    }
}

/* === BOTTOM NAVIGATION (for PWA) === */
@media (max-width: 768px) and (display-mode: standalone) {
    .bottom-nav {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: white;
        border-top: 1px solid #e5e7eb;
        padding: calc(0.5rem + var(--safe-area-inset-bottom)) 0 var(--safe-area-inset-bottom);
        z-index: 1000;
    }
    
    .bottom-nav-items {
        display: flex;
        justify-content: space-around;
        align-items: center;
    }
    
    .bottom-nav-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        padding: 0.5rem;
        color: #6b7280;
        text-decoration: none;
        font-size: 0.75rem;
        transition: color 0.2s ease;
        -webkit-tap-highlight-color: transparent;
    }
    
    .bottom-nav-item.active {
        color: #54e6b6;
    }
    
    .bottom-nav-item svg {
        width: 24px;
        height: 24px;
        margin-bottom: 0.25rem;
    }
    
    /* Adjust main content for bottom nav */
    .main-content {
        padding-bottom: calc(80px + var(--safe-area-inset-bottom));
    }
}

/* === SWIPE GESTURES === */
@media (max-width: 768px) {
    .swipeable {
        touch-action: pan-x;
        position: relative;
        overflow: hidden;
    }
    
    .swipe-actions {
        position: absolute;
        top: 0;
        right: 0;
        height: 100%;
        display: flex;
        align-items: center;
        background: #ef4444;
        color: white;
        padding: 0 1rem;
        transform: translateX(100%);
        transition: transform 0.3s ease;
    }
    
    .swipeable.swiped .swipe-actions {
        transform: translateX(0);
    }
}

/* === PERFORMANCE OPTIMIZATIONS === */
@media (max-width: 768px) {
    /* GPU acceleration for smooth animations */
    .gpu-accelerated {
        transform: translateZ(0);
        will-change: transform;
    }
    
    /* Optimize images for mobile */
    img {
        max-width: 100%;
        height: auto;
        object-fit: cover;
    }
    
    /* Lazy loading support */
    img[loading="lazy"] {
        opacity: 0;
        transition: opacity 0.3s ease;
    }
    
    img[loading="lazy"].loaded {
        opacity: 1;
    }
}
