/* ============================================
   Mobile-Responsive Chore Modal Styles
   Integrates with existing style.css, clean-ui.css
   ============================================ */

/* IMPORTANT: This file should be loaded AFTER style.css and clean-ui.css
   to properly override desktop styles for mobile */

/* Mobile-specific modal behavior - only affects mobile viewports */
@media (max-width: 768px) {
    /* Override desktop modal positioning for mobile slide-up effect */
    .modal {
        padding: 0 !important;
        align-items: flex-end !important; /* Align to bottom for slide-up */
    }
    
    /* Full-screen mobile modals for add/edit chore */
    #add-chore-modal .modal-content,
    #edit-chore-modal .modal-content {
        max-width: 100% !important;
        width: 100% !important;
        max-height: 95vh !important;
        margin: 0 !important;
        border-radius: 20px 20px 0 0 !important; /* Rounded top corners only */
        animation: slideUpMobile 0.3s ease-out;
        display: flex;
        flex-direction: column;
    }
    
    @keyframes slideUpMobile {
        from {
            transform: translateY(100%);
            opacity: 0;
        }
        to {
            transform: translateY(0);
            opacity: 1;
        }
    }
    
    /* Modal header - make sticky on mobile */
    #add-chore-modal .modal-header,
    #edit-chore-modal .modal-header {
        position: sticky !important;
        top: 0 !important;
        background: var(--surface-color, #fff) !important;
        z-index: 10 !important;
        padding: 1rem 1.25rem !important;
        border-bottom: 1px solid var(--border-color, #e5e7eb) !important;
        border-radius: 20px 20px 0 0 !important;
        flex-shrink: 0;
        min-height: 60px;
    }
    
    #add-chore-modal .modal-header h2,
    #edit-chore-modal .modal-header h2 {
        font-size: 1.125rem !important;
        margin: 0 !important;
    }
    
    /* Close button - larger touch target */
    #add-chore-modal .modal-close,
    #edit-chore-modal .modal-close {
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
        min-height: 36px !important;
        border-radius: 50% !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        background: var(--gray-100, #f3f4f6) !important;
        border: none !important;
        font-size: 1.5rem !important;
    }
    
    /* Modal body - scrollable area */
    #add-chore-modal .modal-body-flex,
    #edit-chore-modal .modal-body-flex {
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        padding: 0.85rem 0.85rem calc(0.85rem + env(safe-area-inset-bottom)) !important;
        flex: 1;
        max-height: calc(95vh - 132px) !important; /* Account for header and footer */
    }
    
    /* Form styling - use existing .modal-form but enhance for mobile */
    #add-chore-modal .modal-form,
    #edit-chore-modal .modal-form {
        display: flex !important;
        flex-direction: column !important;
        gap: 1.25rem !important;
    }
    
    /* Chore entry cards - enhance existing .chore-entry for mobile */
    #add-chore-modal .chore-entry,
    #edit-chore-modal .chore-entry {
        background: var(--gray-50, #f9fafb) !important;
        border-radius: 16px !important;
        padding: 1.25rem !important;
        margin-bottom: 0 !important; /* Remove margin, use gap instead */
    }
    
    /* Chore entry header */
    #add-chore-modal .chore-entry-header,
    #edit-chore-modal .chore-entry-header {
        margin-bottom: 1rem !important;
    }
    
    .chore-entry-title {
        display: flex;
        align-items: center;
        gap: 0.75rem;
    }
    
    .chore-number {
        width: 32px;
        height: 32px;
        background: var(--primary-color, #667eea);
        color: white;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        font-weight: 600;
        font-size: 0.875rem;
        flex-shrink: 0;
    }
    
    .chore-entry-title h3 {
        font-size: 1rem !important;
        margin: 0 !important;
    }
    
    /* Form groups - enhance existing styles */
    #add-chore-modal .form-group,
    #edit-chore-modal .form-group {
        display: flex;
        flex-direction: column;
        gap: 0.5rem;
        margin-bottom: 0 !important; /* Use gap from parent instead */
    }
    
    #add-chore-modal .form-group label,
    #edit-chore-modal .form-group label {
        font-size: 0.875rem !important;
        margin-bottom: 0 !important;
    }
    
    /* Input fields - touch optimized */
    #add-chore-modal .form-group input[type="text"],
    #add-chore-modal .form-group input[type="number"],
    #add-chore-modal .form-group select,
    #add-chore-modal .form-group textarea,
    #edit-chore-modal .form-group input[type="text"],
    #edit-chore-modal .form-group input[type="number"],
    #edit-chore-modal .form-group select,
    #edit-chore-modal .form-group textarea {
        font-size: 16px !important; /* Prevent iOS zoom */
        padding: 0.875rem 1rem !important;
        border-radius: 12px !important;
        min-height: 48px !important;
    }
    
    /* Select dropdowns */
    #add-chore-modal .form-group select,
    #edit-chore-modal .form-group select {
        padding-right: 3rem !important;
        background-position: right 1rem center !important;
    }
    
    /* Color picker row */
    .color-picker-row {
        display: flex !important;
        align-items: center !important;
        gap: 0.75rem !important;
        padding: 0.75rem !important;
        background: white !important;
        border-radius: 12px !important;
        border: 1px solid var(--border-color, #e5e7eb) !important;
    }
    
    #add-chore-modal input[type="color"],
    #edit-chore-modal input[type="color"] {
        width: 48px !important;
        height: 48px !important;
        min-width: 48px !important;
        min-height: 48px !important;
        border: none !important;
        border-radius: 8px !important;
        cursor: pointer !important;
        padding: 0 !important;
    }
    
    .color-presets {
        display: flex !important;
        gap: 0.5rem !important;
        flex-wrap: wrap !important;
    }
    
    .color-preset {
        width: 40px !important;
        height: 40px !important;
        min-width: 40px !important;
        min-height: 40px !important;
        border-radius: 50% !important;
        border: 3px solid white !important;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
        cursor: pointer !important;
        transition: transform 0.2s !important;
        -webkit-tap-highlight-color: transparent !important;
        padding: 0 !important;
    }
    
    .color-preset:active {
        transform: scale(0.9) !important;
    }
    
    /* Helper text */
    #add-chore-modal .helper-text,
    #edit-chore-modal .helper-text,
    #add-chore-modal .form-group small,
    #edit-chore-modal .form-group small {
        font-size: 0.75rem !important;
        color: var(--gray-500, #6b7280) !important;
        margin-top: 0.25rem !important;
    }
    
    /* Form actions - sticky footer on mobile */
    #add-chore-modal .form-actions,
    #edit-chore-modal .form-actions {
        position: sticky !important;
        bottom: 0 !important;
        background: var(--surface-color, #fff) !important;
        padding: 0.9rem 0.85rem !important;
        margin: 0 -0.85rem -0.85rem !important;
        border-top: 1px solid var(--border-color, #e5e7eb) !important;
        display: flex !important;
        gap: 0.7rem !important;
        z-index: 10 !important;
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.05) !important;
        flex-shrink: 0;
        justify-content: stretch !important;
    }
    
    /* Buttons in form actions - override existing styles for mobile */
    #add-chore-modal .form-actions .btn,
    #edit-chore-modal .form-actions .btn {
        flex: 1 !important;
        padding: 0.875rem 1.5rem !important;
        border-radius: 12px !important;
        font-size: 1rem !important;
        font-weight: 600 !important;
        min-height: 48px !important;
        transition: all 0.2s !important;
        -webkit-tap-highlight-color: transparent !important;
        justify-content: center !important;
    }
    
    /* Override .btn-outline for mobile modals */
    #add-chore-modal .form-actions .btn-outline,
    #edit-chore-modal .form-actions .btn-outline {
        background: white !important;
        border: 2px solid var(--border-color, #e5e7eb) !important;
        color: var(--gray-700, #374151) !important;
    }
    
    /* Override .btn-primary for mobile modals */
    #add-chore-modal .form-actions .btn-primary,
    #edit-chore-modal .form-actions .btn-primary {
        box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3) !important;
    }
    
    #add-chore-modal .form-actions .btn:active,
    #edit-chore-modal .form-actions .btn:active {
        transform: scale(0.98) !important;
    }
    
    /* Secondary button (Add Another Chore) */
    #add-chore-modal .form-actions .btn-secondary,
    #edit-chore-modal .form-actions .btn-secondary {
        width: 100% !important;
        background: var(--gray-100, #f3f4f6) !important;
        color: var(--gray-700, #374151) !important;
        border: 1px solid var(--border-color, #e5e7eb) !important;
        justify-content: center !important;
        display: flex !important;
        align-items: center !important;
        gap: 0.5rem !important;
        margin-bottom: 0.5rem !important;
    }
    
    /* Remove chore button */
    #add-chore-modal .remove-chore,
    #edit-chore-modal .remove-chore {
        padding: 0.5rem 1rem !important;
        font-size: 0.875rem !important;
        border-radius: 8px !important;
        background: var(--red-50, #fef2f2) !important;
        color: var(--red-600, #dc2626) !important;
        border: 1px solid var(--red-200, #fecaca) !important;
        min-height: 36px !important;
    }
    
    /* Premium upgrade prompt */
    .premium-upgrade-prompt {
        margin-top: 1rem;
    }
    
    .upgrade-banner {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        padding: 1rem;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        border-radius: 12px;
        color: white;
        font-size: 0.875rem;
    }
    
    .upgrade-banner .btn {
        margin-left: auto !important;
        background: white !important;
        color: var(--primary-color, #667eea) !important;
        padding: 0.5rem 1rem !important;
        border-radius: 8px !important;
        border: none !important;
        white-space: nowrap;
        min-height: auto !important;
    }
}

/* Extra small devices - additional adjustments */
@media (max-width: 480px) {
    #add-chore-modal .modal-header,
    #edit-chore-modal .modal-header {
        padding: 0.875rem 1rem !important;
    }
    
    #add-chore-modal .modal-header h2,
    #edit-chore-modal .modal-header h2 {
        font-size: 1rem !important;
    }
    
    #add-chore-modal .modal-body-flex,
    #edit-chore-modal .modal-body-flex {
        padding: 0.75rem 0.75rem calc(0.75rem + env(safe-area-inset-bottom)) !important;
    }
    
    #add-chore-modal .chore-entry,
    #edit-chore-modal .chore-entry {
        padding: 1rem !important;
    }
    
    /* Stack buttons vertically on very small screens */
    #add-chore-modal .form-actions,
    #edit-chore-modal .form-actions {
        flex-direction: column !important;
        padding: 0.75rem 0.75rem !important;
        margin: 0 -0.75rem -0.75rem !important;
    }
    
    #add-chore-modal .form-actions .btn,
    #edit-chore-modal .form-actions .btn {
        width: 100% !important;
    }
    
    /* Smaller color presets on tiny screens */
    .color-preset {
        width: 36px !important;
        height: 36px !important;
        min-width: 36px !important;
        min-height: 36px !important;
    }
}

/* Dark mode support for mobile modals */
[data-theme="dark"] #add-chore-modal .modal-header,
[data-theme="dark"] #edit-chore-modal .modal-header,
[data-theme="dark"] #add-chore-modal .modal-body-flex,
[data-theme="dark"] #edit-chore-modal .modal-body-flex,
[data-theme="dark"] #add-chore-modal .form-actions,
[data-theme="dark"] #edit-chore-modal .form-actions {
    background: var(--gray-900, #111827) !important;
    border-color: var(--gray-700, #374151) !important;
}

[data-theme="dark"] #add-chore-modal .chore-entry,
[data-theme="dark"] #edit-chore-modal .chore-entry {
    background: var(--gray-800, #1f2937) !important;
    border-color: var(--gray-700, #374151) !important;
}

[data-theme="dark"] #add-chore-modal .form-group input,
[data-theme="dark"] #add-chore-modal .form-group select,
[data-theme="dark"] #add-chore-modal .form-group textarea,
[data-theme="dark"] #edit-chore-modal .form-group input,
[data-theme="dark"] #edit-chore-modal .form-group select,
[data-theme="dark"] #edit-chore-modal .form-group textarea {
    background: var(--gray-800, #1f2937) !important;
    border-color: var(--gray-700, #374151) !important;
    color: var(--gray-100, #f3f4f6) !important;
}

[data-theme="dark"] .color-picker-row {
    background: var(--gray-800, #1f2937) !important;
    border-color: var(--gray-700, #374151) !important;
}

[data-theme="dark"] #add-chore-modal .form-actions .btn-outline,
[data-theme="dark"] #edit-chore-modal .form-actions .btn-outline {
    background: var(--gray-800, #1f2937) !important;
    border-color: var(--gray-700, #374151) !important;
    color: var(--gray-100, #f3f4f6) !important;
}

[data-theme="dark"] #add-chore-modal .form-actions .btn-secondary,
[data-theme="dark"] #edit-chore-modal .form-actions .btn-secondary {
    background: var(--gray-800, #1f2937) !important;
    color: var(--gray-100, #f3f4f6) !important;
}

/* Dark mode with prefers-color-scheme fallback */
@media (prefers-color-scheme: dark) {
    @media (max-width: 768px) {
        #add-chore-modal .modal-header,
        #edit-chore-modal .modal-header,
        #add-chore-modal .modal-body-flex,
        #edit-chore-modal .modal-body-flex,
        #add-chore-modal .form-actions,
        #edit-chore-modal .form-actions {
            background: var(--gray-900, #111827);
            border-color: var(--gray-700, #374151);
        }
        
        #add-chore-modal .chore-entry,
        #edit-chore-modal .chore-entry {
            background: var(--gray-800, #1f2937);
            border-color: var(--gray-700, #374151);
        }
    }
}

/* Landscape mode adjustments */
@media (max-width: 768px) and (orientation: landscape) {
    #add-chore-modal .modal-content,
    #edit-chore-modal .modal-content {
        max-height: 90vh !important;
    }
    
    #add-chore-modal .modal-body-flex,
    #edit-chore-modal .modal-body-flex {
        max-height: calc(90vh - 120px) !important;
    }
}

/* Touch-specific improvements */
@media (hover: none) and (pointer: coarse) {
    /* Ensure minimum touch targets */
    #add-chore-modal .modal-close,
    #edit-chore-modal .modal-close {
        min-width: 44px !important;
        min-height: 44px !important;
    }
    
    #add-chore-modal .form-actions .btn,
    #edit-chore-modal .form-actions .btn {
        min-height: 48px !important;
    }
    
    .color-preset {
        min-width: 44px !important;
        min-height: 44px !important;
    }
    
    /* Remove hover effects on touch devices */
    #add-chore-modal .form-actions .btn:hover,
    #edit-chore-modal .form-actions .btn:hover {
        transform: none !important;
    }
    
    /* Add active state feedback */
    #add-chore-modal .form-actions .btn:active,
    #edit-chore-modal .form-actions .btn:active {
        opacity: 0.8 !important;
    }
}
