/* ============================================
   AP Annotator - Mobile Fixes
   Corrections des bugs mobile
   Date : 27 janvier 2026
   ============================================ */

/* ========== FIX: HEADER MOBILE ========== */
@media (max-width: 768px) {
    header {
        position: sticky;
        top: 0;
        z-index: 999;
        backdrop-filter: blur(10px);
    }
    
    header .container {
        flex-direction: column;
        gap: 12px;
    }
    
    header .flex {
        flex-wrap: wrap;
        justify-content: space-between;
        width: 100%;
    }
    
    header button {
        font-size: 14px;
        padding: 8px 12px;
    }
    
    header button span {
        display: none;
    }
    
    header button i {
        margin: 0 !important;
    }
}

/* ========== FIX: MODE BADGE MOBILE ========== */
@media (max-width: 768px) {
    #currentMode {
        font-size: 12px;
        padding: 6px 12px;
        max-width: 120px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

/* ========== FIX: BUTTONS OVERFLOW ========== */
@media (max-width: 768px) {
    .actions {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        justify-content: center;
    }
    
    .actions button {
        flex: 0 0 auto;
        min-width: 44px;
        font-size: 14px;
    }
}

/* ========== FIX: CANVAS TOUCH AREA ========== */
@media (max-width: 768px) {
    #canvasContainer {
        height: calc(100vh - 250px);
        min-height: 300px;
        max-height: calc(100vh - 200px);
        overflow: hidden;
        touch-action: none;
        -webkit-user-select: none;
        user-select: none;
    }
    
    #mainCanvas {
        width: 100%;
        height: 100%;
        touch-action: none;
    }
}

/* ========== FIX: TOOLBAR MOBILE SCROLL ========== */
@media (max-width: 768px) {
    .toolbar {
        display: flex;
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x proximity;
        gap: 8px;
        padding: 12px;
    }
    
    .toolbar::-webkit-scrollbar {
        height: 4px;
    }
    
    .toolbar::-webkit-scrollbar-thumb {
        background: rgba(0, 198, 255, 0.3);
        border-radius: 2px;
    }
    
    .tool-group {
        display: flex;
        gap: 8px;
        flex-shrink: 0;
        scroll-snap-align: start;
    }
}

/* ========== FIX: MODAL MOBILE ========== */
@media (max-width: 768px) {
    .modal {
        padding: 0;
    }
    
    .modal-content {
        width: 100%;
        max-width: 100%;
        height: 100vh;
        max-height: 100vh;
        margin: 0;
        border-radius: 0;
        overflow-y: auto;
    }
    
    .modal-header {
        position: sticky;
        top: 0;
        background: inherit;
        z-index: 10;
        padding-bottom: 16px;
        border-bottom: 1px solid var(--border-color);
    }
    
    .modal-body {
        padding: 16px;
        max-height: calc(100vh - 120px);
        overflow-y: auto;
    }
    
    .modal-footer {
        position: sticky;
        bottom: 0;
        background: inherit;
        padding-top: 16px;
        border-top: 1px solid var(--border-color);
    }
}

/* ========== FIX: FORMS MOBILE ========== */
@media (max-width: 768px) {
    input, 
    textarea, 
    select {
        font-size: 16px !important; /* Prevent iOS zoom */
        padding: 12px;
        border-radius: 8px;
    }
    
    textarea {
        min-height: 100px;
    }
    
    label {
        font-size: 14px;
        font-weight: 500;
        margin-bottom: 8px;
        display: block;
    }
}

/* ========== FIX: LEGEND MOBILE ========== */
@media (max-width: 768px) {
    #legend {
        position: fixed;
        bottom: 80px !important;
        right: 10px !important;
        left: 10px !important;
        max-width: calc(100% - 20px);
        font-size: 12px;
        padding: 8px;
        z-index: 500;
    }
    
    #legend .legend-item {
        font-size: 11px;
        padding: 4px 0;
    }
}

/* ========== FIX: TOAST NOTIFICATIONS MOBILE ========== */
@media (max-width: 768px) {
    .toast {
        bottom: 80px;
        right: 10px;
        left: 10px;
        width: calc(100% - 20px);
        font-size: 14px;
    }
}

/* ========== FIX: DARK MODE TOGGLE MOBILE ========== */
@media (max-width: 768px) {
    .dark-mode-toggle {
        position: fixed;
        top: auto;
        bottom: 90px;
        right: 15px;
        width: 48px;
        height: 48px;
        z-index: 1001;
    }
}

/* ========== FIX: SYNC INDICATOR MOBILE ========== */
@media (max-width: 768px) {
    .sync-indicator {
        top: 10px;
        left: 10px;
        width: 12px;
        height: 12px;
    }
}

/* ========== FIX: UPLOAD SECTION MOBILE ========== */
@media (max-width: 768px) {
    .upload-section {
        padding: 16px;
    }
    
    .upload-options {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }
    
    .upload-btn {
        width: 100%;
        min-height: 48px;
        font-size: 16px;
    }
}

/* ========== FIX: MODE SELECTOR MOBILE ========== */
@media (max-width: 768px) {
    .mode-selector-content {
        width: 95%;
        max-width: 95%;
        padding: 20px;
    }
    
    .mode-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .mode-card {
        padding: 16px;
    }
    
    .mode-card-icon {
        font-size: 28px;
    }
    
    .mode-card-title {
        font-size: 16px;
    }
    
    .mode-card-description {
        font-size: 12px;
    }
}

/* ========== FIX: TABLE MOBILE ========== */
@media (max-width: 768px) {
    table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
    
    thead {
        display: none;
    }
    
    tbody {
        display: block;
    }
    
    tr {
        display: flex;
        flex-direction: column;
        margin-bottom: 12px;
        border: 1px solid var(--border-color);
        border-radius: 8px;
        padding: 12px;
    }
    
    td {
        display: flex;
        justify-content: space-between;
        padding: 8px 0;
        border-bottom: 1px solid var(--border-color);
    }
    
    td:last-child {
        border-bottom: none;
    }
    
    td::before {
        content: attr(data-label);
        font-weight: 600;
        margin-right: 12px;
    }
}

/* ========== FIX: ZOOM CONTROLS MOBILE ========== */
@media (max-width: 768px) {
    .zoom-controls {
        position: fixed;
        bottom: 80px;
        left: 50%;
        transform: translateX(-50%);
        display: flex;
        gap: 8px;
        background: var(--bg-secondary);
        border: 1px solid var(--border-color);
        border-radius: 24px;
        padding: 8px 12px;
        box-shadow: var(--shadow-lg);
        z-index: 900;
    }
    
    .zoom-btn {
        width: 44px;
        height: 44px;
        border-radius: 50%;
        background: var(--bg-tertiary);
        border: 1px solid var(--border-color);
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 18px;
    }
    
    .zoom-value {
        min-width: 60px;
        text-align: center;
        font-size: 14px;
        font-weight: 600;
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* ========== FIX: LANDSCAPE ORIENTATION ========== */
@media (max-width: 768px) and (orientation: landscape) {
    header {
        padding: 8px 16px;
    }
    
    #canvasContainer {
        height: calc(100vh - 150px);
    }
    
    .toolbar {
        padding: 8px;
    }
    
    .dark-mode-toggle {
        bottom: 70px;
        width: 44px;
        height: 44px;
    }
}

/* ========== FIX: PREVENT DOUBLE TAP ZOOM ========== */
@media (max-width: 768px) {
    * {
        touch-action: manipulation;
    }
    
    canvas {
        touch-action: none !important;
    }
}

/* ========== FIX: BUTTON ACTIVE STATES ========== */
@media (max-width: 768px) {
    button:active {
        transform: scale(0.95);
        opacity: 0.8;
        transition: transform 0.1s ease, opacity 0.1s ease;
    }
    
    .tool-btn:active {
        background-color: var(--cyan-cedit);
        color: white;
    }
}

/* ========== FIX: PREVENT TEXT SELECTION ========== */
@media (max-width: 768px) {
    .no-select {
        -webkit-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
    }
}

/* ========== FIX: SAFE AREA INSETS (iOS) ========== */
@supports (padding: max(0px)) {
    @media (max-width: 768px) {
        body {
            padding-top: max(0px, env(safe-area-inset-top));
            padding-bottom: max(0px, env(safe-area-inset-bottom));
            padding-left: max(0px, env(safe-area-inset-left));
            padding-right: max(0px, env(safe-area-inset-right));
        }
        
        .toolbar-mobile,
        .zoom-controls {
            padding-bottom: max(12px, env(safe-area-inset-bottom));
        }
        
        .dark-mode-toggle {
            bottom: max(90px, calc(90px + env(safe-area-inset-bottom)));
        }
    }
}
