/**
 * Mobile-First Responsive Styles for Photo Analysis
 *
 * Touch-optimized, performance-focused styles for mobile devices.
 * Includes bottom sheet patterns, gesture hints, and touch targets.
 *
 * @package ENNU\PhotoAnalysis
 * @since 2.0.0
 */

/* ========================================
   Mobile-First Base Styles
   ======================================== */

/* Container adjustments */
.ennu-photo-analysis-container {
    width: 100%;
    padding: 12px;
    box-sizing: border-box;
}

/* ========================================
   Face Chart Thumbnail Fixes for Mobile
   ======================================== */

/* Ensure photo thumbnails display correctly */
.photo-thumbnails-strip {
    display: flex !important;
    flex-direction: column;
    gap: 6px;
    z-index: 100;
}

.photo-row {
    display: flex !important;
    align-items: center;
    gap: 4px;
}

/* Fix thumbnail images on mobile */
.thumb-photo {
    display: flex !important;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #1a1a22;
}

.thumb-photo img {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover !important;
    display: block !important;
}

/* Ensure silhouette thumbnails show */
.thumb-silhouette {
    display: flex !important;
    align-items: center;
    justify-content: center;
}

.thumb-silhouette svg {
    display: block !important;
}

/* Mobile-specific thumbnail sizing */
@media (max-width: 768px) {
    .photo-thumbnails-strip {
        top: 8px !important;
        left: 8px !important;
        max-width: 120px;
    }

    .thumb-photo,
    .thumb-silhouette {
        width: 48px !important;
        height: 48px !important;
        min-width: 48px !important;
        min-height: 48px !important;
        border-radius: 6px;
    }

    .thumb-photo img {
        border-radius: 6px;
    }

    /* Prevent image distortion */
    .thumb-photo img[src=""],
    .thumb-photo img:not([src]) {
        display: none !important;
    }

    /* Loading placeholder */
    .thumb-photo:not(:has(img[src])) {
        background: linear-gradient(135deg, #2a2a35 0%, #1a1a22 100%);
    }

    .thumb-photo:not(:has(img[src]))::after {
        content: '';
        width: 20px;
        height: 20px;
        border: 2px solid rgba(255,255,255,0.2);
        border-top-color: rgba(255,255,255,0.6);
        border-radius: 50%;
        animation: spin 1s linear infinite;
    }
}

/* Very small screens */
@media (max-width: 480px) {
    .photo-thumbnails-strip {
        top: 4px !important;
        left: 4px !important;
        padding: 4px !important;
        max-width: 100px;
    }

    .thumb-photo,
    .thumb-silhouette {
        width: 40px !important;
        height: 40px !important;
        min-width: 40px !important;
        min-height: 40px !important;
    }

    .thumb-delete {
        width: 20px !important;
        height: 20px !important;
    }
}

/* ========================================
   Image Loading Error States
   ======================================== */

/* Broken image fallback */
.thumb-photo img {
    background: linear-gradient(135deg, #2a2a35 0%, #1a1a22 100%);
}

/* When image fails to load */
.thumb-photo img:not([src]),
.thumb-photo img[src=""],
.thumb-photo img[src="undefined"],
.thumb-photo img[src="null"] {
    visibility: hidden;
}

.thumb-photo:has(img:not([src])),
.thumb-photo:has(img[src=""]),
.thumb-photo:has(img[src="undefined"]) {
    background: linear-gradient(135deg, #3a3a45 0%, #2a2a32 100%) !important;
}

.thumb-photo:has(img:not([src]))::before,
.thumb-photo:has(img[src=""])::before {
    content: '📷';
    font-size: 16px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* Cross-browser broken image fallback (for browsers that don't support :has) */
.thumb-photo {
    position: relative;
}

.thumb-photo img.error,
.thumb-photo img[data-error="true"] {
    opacity: 0 !important;
}

.thumb-photo:has(img.error)::after,
.thumb-photo:has(img[data-error])::after {
    content: '!';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #ef4444;
    font-weight: bold;
    font-size: 18px;
}

/* Touch-friendly buttons */
.ennu-ai-btn,
.ennu-fc-btn,
button[class*="ennu-"] {
    min-height: 44px;
    min-width: 44px;
    padding: 12px 16px;
    font-size: 16px; /* Prevents iOS zoom on focus */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

/* Form inputs */
input[type="text"],
input[type="email"],
input[type="number"],
select,
textarea {
    font-size: 16px; /* Prevents iOS zoom */
    padding: 12px;
    border-radius: 8px;
}

/* ========================================
   Bottom Sheet Pattern
   ======================================== */

.ennu-bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-height: 90vh;
    background: var(--ennu-ai-bg-primary, #0f172a);
    border-radius: 24px 24px 0 0;
    box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.3);
    transform: translateY(calc(100% - 80px));
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
    overflow: hidden;
    touch-action: pan-y;
}

.ennu-bottom-sheet.expanded {
    transform: translateY(0);
}

.ennu-bottom-sheet.minimized {
    transform: translateY(calc(100% - 60px));
}

.ennu-bottom-sheet.hidden {
    transform: translateY(100%);
}

/* Drag handle */
.ennu-bottom-sheet-handle {
    display: flex;
    justify-content: center;
    padding: 12px;
    cursor: grab;
    touch-action: none;
}

.ennu-bottom-sheet-handle::before {
    content: '';
    width: 40px;
    height: 4px;
    background: rgba(255, 255, 255, 0.3);
    border-radius: 2px;
}

.ennu-bottom-sheet-handle:active::before {
    background: rgba(255, 255, 255, 0.5);
}

/* Sheet header */
.ennu-bottom-sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

/* Sheet content */
.ennu-bottom-sheet-content {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    max-height: calc(90vh - 100px);
    padding: 16px;
}

/* ========================================
   Mobile Photo Upload
   ======================================== */

.ennu-photo-upload-mobile {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 20px;
}

.ennu-upload-zone-mobile {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    border: 2px dashed rgba(255, 255, 255, 0.2);
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.05);
    transition: all 0.2s ease;
}

.ennu-upload-zone-mobile.active {
    border-color: var(--ennu-ai-accent, #3b82f6);
    background: rgba(59, 130, 246, 0.1);
}

.ennu-upload-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.ennu-upload-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 20px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    color: var(--ennu-ai-text-secondary, #94a3b8);
    cursor: pointer;
    transition: all 0.2s ease;
}

.ennu-upload-option:active {
    transform: scale(0.98);
    background: rgba(255, 255, 255, 0.1);
}

.ennu-upload-option .icon {
    font-size: 32px;
}

/* ========================================
   Mobile Analysis Results
   ======================================== */

.ennu-results-mobile {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Score summary card */
.ennu-score-summary-mobile {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.2), rgba(139, 92, 246, 0.1));
    border-radius: 16px;
}

.ennu-score-circle-mobile {
    width: 80px;
    height: 80px;
    flex-shrink: 0;
}

.ennu-score-details-mobile {
    flex: 1;
}

.ennu-score-value-large {
    font-size: 36px;
    font-weight: 700;
    line-height: 1;
    color: var(--ennu-ai-text-primary, #f1f5f9);
}

.ennu-score-label-mobile {
    font-size: 14px;
    color: var(--ennu-ai-text-secondary, #94a3b8);
    margin-top: 4px;
}

/* Horizontal scrolling scores */
.ennu-scores-scroll {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding: 4px 0 16px;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.ennu-scores-scroll::-webkit-scrollbar {
    display: none;
}

.ennu-score-card-mobile {
    flex: 0 0 auto;
    width: 120px;
    padding: 16px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    text-align: center;
    scroll-snap-align: start;
}

.ennu-score-card-value {
    font-size: 24px;
    font-weight: 600;
    color: var(--ennu-ai-text-primary, #f1f5f9);
}

.ennu-score-card-label {
    font-size: 12px;
    color: var(--ennu-ai-text-muted, #64748b);
    margin-top: 4px;
}

/* ========================================
   Mobile Conditions List
   ======================================== */

.ennu-conditions-mobile {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ennu-condition-mobile {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    border-left: 3px solid var(--severity-color, #94a3b8);
}

.ennu-condition-mobile.mild {
    --severity-color: #22c55e;
}

.ennu-condition-mobile.moderate {
    --severity-color: #eab308;
}

.ennu-condition-mobile.severe {
    --severity-color: #ef4444;
}

.ennu-condition-icon-mobile {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(var(--severity-rgb, 148, 163, 184), 0.2);
    border-radius: 10px;
    flex-shrink: 0;
}

.ennu-condition-content-mobile {
    flex: 1;
    min-width: 0;
}

.ennu-condition-name-mobile {
    font-size: 15px;
    font-weight: 600;
    color: var(--ennu-ai-text-primary, #f1f5f9);
}

.ennu-condition-details-mobile {
    font-size: 13px;
    color: var(--ennu-ai-text-secondary, #94a3b8);
    margin-top: 4px;
}

/* Swipe actions */
.ennu-condition-actions-mobile {
    display: flex;
    gap: 8px;
}

.ennu-action-btn-mobile {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: transform 0.1s ease;
}

.ennu-action-btn-mobile:active {
    transform: scale(0.95);
}

.ennu-action-btn-mobile.approve {
    background: rgba(34, 197, 94, 0.2);
    color: #22c55e;
}

.ennu-action-btn-mobile.reject {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

/* ========================================
   Mobile Recommendations
   ======================================== */

.ennu-recommendations-mobile {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ennu-recommendation-mobile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.ennu-recommendation-priority {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.ennu-recommendation-priority.high {
    background: #ef4444;
}

.ennu-recommendation-priority.medium {
    background: #eab308;
}

.ennu-recommendation-priority.low {
    background: #22c55e;
}

.ennu-recommendation-info {
    flex: 1;
    min-width: 0;
}

.ennu-recommendation-name-mobile {
    font-size: 15px;
    font-weight: 500;
    color: var(--ennu-ai-text-primary, #f1f5f9);
}

.ennu-recommendation-category-mobile {
    font-size: 12px;
    color: var(--ennu-ai-text-muted, #64748b);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ennu-add-treatment-mobile {
    padding: 8px 16px;
    background: var(--ennu-ai-accent, #3b82f6);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
}

/* ========================================
   Mobile Photo Comparison
   ======================================== */

.ennu-comparison-mobile {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.ennu-comparison-slider {
    position: relative;
    height: 300px;
    border-radius: 16px;
    overflow: hidden;
    touch-action: pan-x;
}

.ennu-comparison-before,
.ennu-comparison-after {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ennu-comparison-before {
    clip-path: inset(0 50% 0 0);
}

.ennu-comparison-handle {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 4px;
    background: white;
    transform: translateX(-50%);
    cursor: ew-resize;
    touch-action: pan-x;
}

.ennu-comparison-handle::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 36px;
    height: 36px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

.ennu-comparison-labels {
    display: flex;
    justify-content: space-between;
}

.ennu-comparison-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--ennu-ai-text-muted, #64748b);
}

/* ========================================
   Floating Action Button
   ======================================== */

.ennu-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--ennu-ai-accent, #3b82f6);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(59, 130, 246, 0.4);
    border: none;
    cursor: pointer;
    z-index: 999;
    transition: all 0.2s ease;
}

.ennu-fab:active {
    transform: scale(0.95);
}

.ennu-fab.expanded {
    width: auto;
    border-radius: 28px;
    padding: 0 24px;
    gap: 8px;
}

/* ========================================
   Pull to Refresh
   ======================================== */

.ennu-pull-refresh {
    position: absolute;
    top: -60px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
}

.ennu-pull-refresh.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(70px);
}

.ennu-pull-refresh-spinner {
    width: 24px;
    height: 24px;
    border: 2px solid rgba(255, 255, 255, 0.2);
    border-top-color: var(--ennu-ai-accent, #3b82f6);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* ========================================
   Gesture Hints
   ======================================== */

.ennu-gesture-hint {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.7);
    border-radius: 20px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.8);
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1001;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.ennu-gesture-hint.visible {
    opacity: 1;
}

/* ========================================
   Safe Area Insets (iPhone X+)
   ======================================== */

@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .ennu-bottom-sheet {
        padding-bottom: env(safe-area-inset-bottom);
    }

    .ennu-fab {
        bottom: calc(24px + env(safe-area-inset-bottom));
    }
}

/* ========================================
   Landscape Orientation
   ======================================== */

@media (orientation: landscape) and (max-height: 500px) {
    .ennu-bottom-sheet {
        max-height: 80vh;
    }

    .ennu-bottom-sheet-content {
        max-height: calc(80vh - 80px);
    }

    .ennu-comparison-slider {
        height: 200px;
    }
}

/* ========================================
   Tablet Styles (768px+)
   ======================================== */

@media (min-width: 768px) {
    .ennu-bottom-sheet {
        left: 50%;
        width: 500px;
        transform: translateX(-50%) translateY(calc(100% - 80px));
        border-radius: 24px;
        bottom: 20px;
    }

    .ennu-bottom-sheet.expanded {
        transform: translateX(-50%) translateY(0);
    }

    .ennu-upload-options {
        grid-template-columns: repeat(4, 1fr);
    }

    .ennu-scores-scroll {
        flex-wrap: wrap;
        overflow: visible;
    }

    .ennu-score-card-mobile {
        flex: 1 1 calc(25% - 12px);
    }
}

/* ========================================
   Desktop Override (992px+)
   ======================================== */

@media (min-width: 992px) {
    .ennu-bottom-sheet {
        position: relative;
        bottom: auto;
        left: auto;
        transform: none;
        max-height: none;
        border-radius: 16px;
    }

    .ennu-bottom-sheet-handle {
        display: none;
    }

    .ennu-fab {
        display: none;
    }
}

/* ========================================
   Reduced Motion
   ======================================== */

@media (prefers-reduced-motion: reduce) {
    .ennu-bottom-sheet,
    .ennu-fab,
    .ennu-action-btn-mobile,
    * {
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
    }
}

/* ========================================
   High Contrast Mode
   ======================================== */

@media (prefers-contrast: high) {
    .ennu-condition-mobile,
    .ennu-recommendation-mobile,
    .ennu-score-card-mobile {
        border: 2px solid currentColor;
    }

    .ennu-ai-btn,
    .ennu-add-treatment-mobile {
        border: 2px solid white;
    }
}

/* ========================================
   Dark Mode Enhancements
   ======================================== */

@media (prefers-color-scheme: dark) {
    .ennu-bottom-sheet {
        background: #0f172a;
    }

    .ennu-upload-zone-mobile {
        background: rgba(255, 255, 255, 0.03);
    }
}

/* ========================================
   Animations
   ======================================== */

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

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

.ennu-animate-slide-up {
    animation: slideUp 0.3s ease forwards;
}

/* ========================================
   ANNOTATION SIZE ENHANCEMENTS
   Make Face Chart annotations bigger and more visible
   ======================================== */

/* Override canvas-drawn annotation badge sizes via CSS variables */
:root {
    --fc-badge-size: 32px;
    --fc-badge-font-size: 14px;
    --fc-label-font-size: 14px;
}

/* Annotation point markers should be larger */
.face-chart-annotation,
.annotation-marker,
[data-annotation-id] {
    min-width: 32px !important;
    min-height: 32px !important;
}

/* Increase annotation label boxes */
.annotation-label-box,
.face-chart-annotation-label,
.fc-label-box {
    font-size: 14px !important;
    padding: 8px 12px !important;
    min-width: 100px !important;
    border-radius: 8px !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2) !important;
}

/* Touch-friendly annotation hit areas */
@media (pointer: coarse) {
    :root {
        --fc-badge-size: 44px;
        --fc-badge-font-size: 16px;
        --fc-label-font-size: 15px;
    }
    
    .face-chart-annotation,
    .annotation-marker,
    [data-annotation-id] {
        min-width: 44px !important;
        min-height: 44px !important;
    }
    
    .annotation-label-box,
    .face-chart-annotation-label {
        font-size: 15px !important;
        padding: 10px 14px !important;
    }
}

/* Tablet screens */
@media (max-width: 1024px) {
    :root {
        --fc-badge-size: 36px;
        --fc-badge-font-size: 15px;
    }
}

/* Mobile screens */
@media (max-width: 768px) {
    :root {
        --fc-badge-size: 40px;
        --fc-badge-font-size: 16px;
        --fc-label-font-size: 14px;
    }
    
    .annotation-label-box,
    .face-chart-annotation-label {
        max-width: 200px !important;
    }
}

