/* Mobile-specific optimizations for EU Grants Parser */

/* Global mobile improvements */
* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

body {
    overflow-x: hidden;
    width: 100%;
    max-width: 100vw;
}

/* Touch-friendly improvements */
@media (max-width: 768px) {
    /* Ensure all containers respect viewport width */
    .container, .main-content, .grants-grid, .grant-card {
        max-width: 100vw;
        overflow-x: hidden;
    }
    
    /* Fix potential overflow issues */
    .ai-search-form, .search-container {
        max-width: 100%;
        overflow-x: hidden;
    }
    
    /* Better touch targets */
    .grant-card {
        cursor: pointer;
        -webkit-tap-highlight-color: rgba(59, 130, 246, 0.1);
        width: 100%;
        max-width: 100%;
        overflow-x: hidden;
    }
    
    /* Fix text overflow */
    .grant-title, .grant-programme, .block-content {
        word-wrap: break-word;
        overflow-wrap: break-word;
        hyphens: auto;
        max-width: 100%;
    }
    
    /* Ensure inputs don't overflow */
    .ai-search-input, .search-input {
        max-width: 100%;
        overflow-x: hidden;
    }
    
    /* Improved button feedback */
    .grant-btn:active,
    .search-btn:active,
    .nav-link:active {
        transform: scale(0.98);
        transition: transform 0.1s ease;
    }
    
    /* Better form inputs */
    .search-input:focus {
        outline: none;
        border-color: var(--accent-blue);
        box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
    }
    
    /* Improved card interactions */
    .grant-card:hover {
        transform: translateY(-2px);
        box-shadow: var(--shadow-lg);
    }
    
    /* Better spacing for touch */
    .grant-actions {
        margin-top: 20px;
    }
    
    /* Improved readability */
    .grant-title {
        word-wrap: break-word;
        hyphens: auto;
    }
    
    /* Better mobile navigation */
    .mobile-menu {
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
    }
    
    /* Improved loading states */
    .loading {
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 200px;
    }
    
    /* Better error states */
    .error-message {
        padding: 20px;
        text-align: center;
        color: var(--text-secondary);
        background: var(--bg-card);
        border-radius: 12px;
        margin: 20px 0;
    }
}

/* Very small screens */
@media (max-width: 480px) {
    /* Even more compact spacing */
    .grant-card {
        margin-bottom: 12px;
    }
    
    /* Better text sizing */
    .grant-title {
        font-size: 1rem;
        line-height: 1.3;
    }
    
    /* Improved button sizing */
    .grant-btn {
        font-size: 14px;
        padding: 12px 16px;
    }
    
    /* Better form layout */
    .search-container {
        gap: 10px;
    }
    
    /* Improved stats display */
    .stats {
        gap: 8px;
    }
    
    .stat-card {
        padding: 12px 8px;
    }
}

/* Landscape orientation on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .header {
        padding: 20px 0 30px;
    }
    
    .header h1 {
        font-size: 1.5rem;
        margin: 10px 0;
    }
    
    .header p {
        font-size: 13px;
        margin-bottom: 20px;
    }
    
    .search-container {
        margin-bottom: 20px;
    }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .grant-card {
        border-width: 0.5px;
    }
    
    .nav-link {
        border-width: 0.5px;
    }
}

/* Dark mode optimizations */
@media (prefers-color-scheme: dark) {
    .grant-card {
        border-color: rgba(255, 255, 255, 0.1);
    }
    
    .search-input {
        background: rgba(255, 255, 255, 0.05);
        border-color: rgba(255, 255, 255, 0.1);
    }
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .grant-card:hover {
        transform: none;
    }
}

/* Print styles */
@media print {
    .navbar,
    .mobile-menu,
    .search-container,
    .grant-actions {
        display: none !important;
    }
    
    .grant-card {
        break-inside: avoid;
        box-shadow: none;
        border: 1px solid #ccc;
    }
    
    body {
        background: white !important;
        color: black !important;
    }
}
