/**
 * Mobile-First Responsive CSS for Africa Surveys
 * Progressive Web App (PWA) optimizations
 */

/* Base mobile-first styles */
* {
    box-sizing: border-box;
}

/* Mobile-first container */
.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 15px;
}

/* Responsive grid system */
.row {
    display: flex;
    flex-wrap: wrap;
    margin: 0 -15px;
}

.col {
    flex: 1;
    padding: 0 15px;
}

.col-12 { flex: 0 0 100%; max-width: 100%; }
.col-6 { flex: 0 0 50%; max-width: 50%; }
.col-4 { flex: 0 0 33.333333%; max-width: 33.333333%; }
.col-3 { flex: 0 0 25%; max-width: 25%; }

/* Mobile navigation */
.mobile-nav {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 9999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.mobile-nav.active {
    opacity: 1;
    visibility: visible;
}

.mobile-nav-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
}

.mobile-nav a {
    display: block;
    color: white;
    font-size: 24px;
    margin: 20px 0;
    text-decoration: none;
    transition: color 0.3s ease;
}

.mobile-nav a:hover {
    color: #4a6fdc;
}

.mobile-menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    color: #333;
    cursor: pointer;
    padding: 10px;
}

/* Touch-friendly buttons */
.btn {
    min-height: 44px;
    padding: 12px 24px;
    font-size: 16px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.btn:hover, .btn:focus {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.btn:active {
    transform: translateY(0);
}

.btn-primary {
    background: linear-gradient(135deg, #4a6fdc, #5a7fe8);
    color: white;
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-outline {
    background: transparent;
    border: 2px solid #4a6fdc;
    color: #4a6fdc;
}

/* Form optimizations for mobile */
.form-group {
    margin-bottom: 20px;
}

.form-control {
    width: 100%;
    padding: 12px 16px;
    font-size: 16px; /* Prevents zoom on iOS */
    border: 2px solid #e0e6ed;
    border-radius: 8px;
    background-color: #fff;
    transition: all 0.3s ease;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.form-control:focus {
    outline: none;
    border-color: #4a6fdc;
    box-shadow: 0 0 0 3px rgba(74, 111, 220, 0.1);
}

/* Select dropdown improvements */
.form-select {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23343a40' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 16px 12px;
    padding-right: 40px;
}

/* Checkbox and radio improvements */
.form-check {
    display: flex;
    align-items: center;
    margin-bottom: 12px;
    min-height: 24px;
}

.form-check-input {
    width: 20px;
    height: 20px;
    margin-right: 12px;
    flex-shrink: 0;
}

.form-check-label {
    font-size: 16px;
    line-height: 1.4;
    cursor: pointer;
}

/* Card components */
.card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    overflow: hidden;
    margin-bottom: 20px;
}

.card-header {
    padding: 20px;
    border-bottom: 1px solid #e0e6ed;
    background-color: #f8f9fa;
}

.card-body {
    padding: 20px;
}

.card-footer {
    padding: 15px 20px;
    border-top: 1px solid #e0e6ed;
    background-color: #f8f9fa;
}

/* Loading states */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Error and success states */
.alert {
    padding: 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 16px;
}

.alert-success {
    background-color: #d4edda;
    border: 1px solid #c3e6cb;
    color: #155724;
}

.alert-error {
    background-color: #f8d7da;
    border: 1px solid #f5c6cb;
    color: #721c24;
}

.alert-warning {
    background-color: #fff3cd;
    border: 1px solid #ffeaa7;
    color: #856404;
}

/* PWA specific styles */
.pwa-install-prompt {
    position: fixed;
    bottom: 20px;
    left: 20px;
    right: 20px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    padding: 20px;
    display: none;
    z-index: 1000;
}

.pwa-install-prompt.show {
    display: block;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.pwa-install-content {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
}

.pwa-install-icon {
    width: 48px;
    height: 48px;
    border-radius: 8px;
    margin-right: 15px;
    background: #4a6fdc;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 24px;
}

.pwa-install-text h4 {
    margin: 0 0 4px 0;
    font-size: 18px;
    color: #333;
}

.pwa-install-text p {
    margin: 0;
    font-size: 14px;
    color: #666;
}

.pwa-install-actions {
    display: flex;
    gap: 10px;
}

.pwa-install-actions .btn {
    flex: 1;
    font-size: 14px;
    padding: 10px 16px;
}

/* Responsive breakpoints */
@media (max-width: 768px) {
    .mobile-menu-toggle {
        display: block;
    }
    
    .desktop-nav {
        display: none;
    }
    
    .col-md-6 { flex: 0 0 100%; max-width: 100%; }
    .col-md-4 { flex: 0 0 100%; max-width: 100%; }
    .col-md-3 { flex: 0 0 100%; max-width: 100%; }
    
    .container {
        padding: 0 10px;
    }
    
    .card-body {
        padding: 15px;
    }
    
    .btn {
        width: 100%;
        margin-bottom: 10px;
    }
    
    .btn + .btn {
        margin-left: 0;
    }
    
    /* Stack form elements vertically on mobile */
    .form-row {
        flex-direction: column;
    }
    
    .form-row .form-group {
        width: 100%;
        margin-right: 0;
    }
    
    /* Larger touch targets for mobile */
    .form-check-input {
        width: 24px;
        height: 24px;
    }
    
    /* Optimize header for mobile */
    .header {
        padding: 10px 0;
    }
    
    .logo {
        height: 40px;
    }
    
    /* Footer adjustments */
    .footer-content {
        flex-direction: column;
        text-align: center;
    }
    
    .footer-section {
        margin-bottom: 30px;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 0 8px;
    }
    
    .card {
        margin: 0 -8px 20px -8px;
        border-radius: 0;
    }
    
    .pwa-install-prompt {
        left: 10px;
        right: 10px;
        bottom: 10px;
    }
    
    .pwa-install-content {
        flex-direction: column;
        text-align: center;
    }
    
    .pwa-install-icon {
        margin: 0 auto 15px auto;
    }
    
    .pwa-install-actions {
        flex-direction: column;
    }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .logo,
    .icon {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .card {
        background: #2d3748;
        color: #e2e8f0;
    }
    
    .form-control {
        background: #4a5568;
        border-color: #718096;
        color: #e2e8f0;
    }
    
    .form-control:focus {
        border-color: #4a6fdc;
        background: #2d3748;
    }
    
    .alert {
        color: #e2e8f0;
    }
    
    .alert-success {
        background: #2f855a;
        border-color: #38a169;
    }
    
    .alert-error {
        background: #c53030;
        border-color: #e53e3e;
    }
    
    .alert-warning {
        background: #d69e2e;
        border-color: #ecc94b;
    }
}

/* Reduced motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Print styles */
@media print {
    .mobile-menu-toggle,
    .pwa-install-prompt,
    .btn,
    .footer {
        display: none !important;
    }
    
    .card {
        box-shadow: none;
        border: 1px solid #ccc;
    }
    
    .container {
        width: 100% !important;
        max-width: none !important;
    }
}

/* Safari specific fixes */
@supports (-webkit-touch-callout: none) {
    .form-control {
        font-size: 16px; /* Prevents zoom on focus */
    }
    
    .btn {
        -webkit-appearance: none;
    }
}

/* iOS specific fixes */
@supports (-webkit-overflow-scrolling: touch) {
    .mobile-nav {
        -webkit-overflow-scrolling: touch;
    }
    
    .card {
        -webkit-overflow-scrolling: touch;
    }
}