/**
 * Parents Corner Mobile Optimizations
 * Mobile-specific styles for touch interactions and responsive design
 */

/* ========================================
   TOUCH TARGET OPTIMIZATION
   ======================================== */

/* Ensure minimum 44x44px touch targets on mobile */
@media (max-width: 768px) {
    button,
    .kids-btn,
    a.kids-btn,
    .profile-option,
    .avatar-option,
    .color-option,
    .period-filter-btn,
    .kids-nav-link,
    .recommendation-card button {
        min-width: 44px;
        min-height: 44px;
        padding: 12px 16px;
    }

    /* Increase spacing between touch targets */
    .dashboard-controls {
        gap: 16px;
    }

    .period-filters {
        gap: 12px;
    }

    .kids-audio-controls {
        gap: 12px;
    }

    /* Larger tap targets for profile selector */
    #profile-selector {
        min-height: 48px;
        font-size: 16px;
        padding: 12px 16px;
    }

    /* Larger tap targets for chart legend items */
    .chart-legend-item {
        min-height: 44px;
        padding: 8px 12px;
    }
}

/* ========================================
   SWIPE GESTURE FEEDBACK
   ======================================== */

.swipe-feedback {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(30, 64, 175, 0.95);
    color: white;
    padding: 12px 20px;
    border-radius: 12px;
    font-size: 14px;
    font-weight: 600;
    z-index: 10000;
    pointer-events: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.swipe-feedback-right {
    left: 20px;
    animation: swipeFeedbackSlideRight 0.3s ease-out;
}

.swipe-feedback-left {
    right: 20px;
    animation: swipeFeedbackSlideLeft 0.3s ease-out;
}

@keyframes swipeFeedbackSlideRight {
    0% {
        opacity: 0;
        transform: translateY(-50%) translateX(-20px);
    }
    100% {
        opacity: 1;
        transform: translateY(-50%) translateX(0);
    }
}

@keyframes swipeFeedbackSlideLeft {
    0% {
        opacity: 0;
        transform: translateY(-50%) translateX(20px);
    }
    100% {
        opacity: 1;
        transform: translateY(-50%) translateX(0);
    }
}

/* ========================================
   TOUCH INTERACTION FEEDBACK
   ======================================== */

.touch-active {
    opacity: 0.7;
    transform: scale(0.98);
    transition: all 0.1s ease;
}

/* Prevent text selection during touch interactions */
@media (max-width: 768px) {
    .dashboard-controls,
    .period-filters,
    .profile-selector-container,
    .chart-container {
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        -webkit-tap-highlight-color: transparent;
    }
}

/* ========================================
   CHART TOUCH OPTIMIZATION
   ======================================== */

@media (max-width: 768px) {
    .chart-container {
        /* Allow vertical scrolling but prevent horizontal pan */
        touch-action: pan-y;
        overflow-x: hidden;
    }

    .chart-container canvas {
        /* Prevent default touch behaviors */
        touch-action: pan-y;
        max-width: 100%;
    }

    /* Increase chart legend touch targets */
    .chart-legend {
        padding: 12px;
    }

    .chart-legend-item {
        padding: 10px 12px;
        margin: 4px 0;
        border-radius: 8px;
        cursor: pointer;
    }

    .chart-legend-item:active {
        background: rgba(30, 64, 175, 0.1);
    }
}

/* ========================================
   MOBILE LAYOUT OPTIMIZATIONS
   ======================================== */

@media (max-width: 768px) {
    /* Stack dashboard controls vertically */
    .dashboard-controls {
        flex-direction: column;
        align-items: stretch;
    }

    .profile-selector-container,
    .period-filters {
        width: 100%;
    }

    /* Full-width period filter buttons */
    .period-filters {
        display: flex;
        justify-content: space-between;
    }

    .period-filter-btn {
        flex: 1;
        text-align: center;
    }

    /* Optimize summary stats for mobile */
    .summary-stats-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .stat-card {
        padding: 20px;
    }

    /* Single column charts on mobile */
    .charts-grid {
        grid-template-columns: 1fr;
        gap: 24px;
    }

    /* Optimize recommendation cards for mobile */
    .recommendations-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }

    .recommendation-card {
        padding: 20px;
    }

    /* Optimize profile management modal for mobile */
    .profile-modal-content {
        width: 95%;
        max-width: 95%;
        margin: 20px auto;
        max-height: 90vh;
        overflow-y: auto;
    }

    .profile-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    /* Optimize avatar and color selectors for mobile */
    .avatar-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 12px;
    }

    .avatar-option {
        font-size: 32px;
        padding: 12px;
    }

    .color-grid {
        grid-template-columns: repeat(5, 1fr);
        gap: 12px;
    }

    .color-option {
        width: 48px;
        height: 48px;
    }
}

/* ========================================
   SMALL MOBILE OPTIMIZATIONS (< 480px)
   ======================================== */

@media (max-width: 480px) {
    /* Reduce padding on small screens */
    .kids-card,
    .stat-card,
    .recommendation-card {
        padding: 16px;
    }

    /* Smaller font sizes for small screens */
    .stat-value {
        font-size: 28px;
    }

    .stat-label {
        font-size: 13px;
    }

    /* Compact chart containers */
    .chart-container {
        padding: 12px;
    }

    .chart-title {
        font-size: 16px;
    }

    /* Smaller avatar options */
    .avatar-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }

    .avatar-option {
        font-size: 28px;
        padding: 10px;
    }

    /* Smaller color options */
    .color-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 8px;
    }

    .color-option {
        width: 40px;
        height: 40px;
    }

    /* Compact period filters */
    .period-filter-btn {
        padding: 10px 12px;
        font-size: 14px;
    }

    /* Smaller buttons */
    .kids-btn {
        padding: 10px 14px;
        font-size: 14px;
    }
}

/* ========================================
   LANDSCAPE MOBILE OPTIMIZATIONS
   ======================================== */

@media (max-width: 768px) and (orientation: landscape) {
    /* Optimize for landscape mode */
    .summary-stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .charts-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .profile-modal-content {
        max-height: 85vh;
    }
}

/* ========================================
   REDUCED MOTION SUPPORT
   ======================================== */

@media (prefers-reduced-motion: reduce) {
    .reduce-motion *,
    .reduce-motion *::before,
    .reduce-motion *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .swipe-feedback {
        animation: none;
    }

    .touch-active {
        transition: none;
    }
}

/* ========================================
   ACCESSIBILITY ENHANCEMENTS FOR MOBILE
   ======================================== */

@media (max-width: 768px) {
    /* Larger focus indicators on mobile */
    button:focus,
    .kids-btn:focus,
    a:focus,
    input:focus,
    select:focus {
        outline: 3px solid var(--kids-accent-1, #10B981);
        outline-offset: 3px;
    }

    /* Ensure sufficient color contrast */
    .period-filter-btn {
        border: 2px solid rgba(30, 64, 175, 0.3);
    }

    .period-filter-btn.active {
        border-color: var(--kids-primary, #1E40AF);
        background: var(--kids-primary, #1E40AF);
        color: white;
    }

    /* Improve readability on small screens */
    body {
        font-size: 16px; /* Prevent zoom on input focus in iOS */
    }

    input,
    select,
    textarea {
        font-size: 16px; /* Prevent zoom on input focus in iOS */
    }
}

/* ========================================
   SWIPE HINT INDICATOR
   ======================================== */

@media (max-width: 768px) {
    .swipe-hint {
        position: fixed;
        bottom: 20px;
        left: 50%;
        transform: translateX(-50%);
        background: rgba(30, 64, 175, 0.9);
        color: white;
        padding: 8px 16px;
        border-radius: 20px;
        font-size: 12px;
        font-weight: 600;
        z-index: 9999;
        pointer-events: none;
        animation: swipeHintFade 3s ease-in-out;
        opacity: 0;
    }

    @keyframes swipeHintFade {
        0%, 100% {
            opacity: 0;
        }
        10%, 90% {
            opacity: 1;
        }
    }

    /* Show swipe hint on first visit */
    .show-swipe-hint .swipe-hint {
        animation: swipeHintFade 4s ease-in-out;
    }
}

/* ========================================
   PERFORMANCE OPTIMIZATIONS
   ======================================== */

@media (max-width: 768px) {
    /* Use GPU acceleration for animations */
    .touch-active,
    .swipe-feedback,
    .kids-btn,
    .recommendation-card {
        will-change: transform, opacity;
        transform: translateZ(0);
        backface-visibility: hidden;
    }

    /* Reduce shadow complexity on mobile */
    .kids-card,
    .stat-card,
    .recommendation-card {
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    }

    .kids-card:hover,
    .stat-card:hover {
        box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    }
}

/* ========================================
   SAFE AREA INSETS (for notched devices)
   ======================================== */

@supports (padding: max(0px)) {
    @media (max-width: 768px) {
        .dashboard-controls,
        .summary-stats-grid,
        .charts-grid,
        .recommendations-grid {
            padding-left: max(16px, env(safe-area-inset-left));
            padding-right: max(16px, env(safe-area-inset-right));
        }

        .profile-modal-content {
            padding-bottom: max(20px, env(safe-area-inset-bottom));
        }
    }
}
