/* ============================================
   AP Annotator - Mobile Styles
   Optimisation pour smartphones et tablettes
   Date : 27 janvier 2026
   ============================================ */

/* ========== TOUCH EVENTS PREVENTION ========== */
* {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* Allow text selection in inputs */
input, textarea {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* ========== MOBILE BREAKPOINTS ========== */

/* Tablet and below (< 1024px) */
@media (max-width: 1024px) {
    .sidebar {
        width: 100%;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border-color);
    }
}

/* Mobile (< 768px) */
@media (max-width: 768px) {
    /* ========== BODY & LAYOUT ========== */
    body {
        overflow-x: hidden;
    }
    
    .container {
        padding: 0 var(--spacing-sm);
    }
    
    /* ========== HEADER ========== */
    header {
        padding: var(--spacing-sm) var(--spacing-md);
    }
    
    header h1 {
        font-size: var(--font-size-h4);
    }
    
    header p {
        font-size: var(--font-size-tiny);
    }
    
    /* ========== SIDEBAR - HIDDEN ON MOBILE ========== */
    .sidebar {
        display: none;
    }
    
    /* ========== TOOLBAR - HORIZONTAL SCROLL ========== */
    .toolbar {
        flex-wrap: nowrap;
        overflow-x: auto;
        overflow-y: hidden;
        -webkit-overflow-scrolling: touch;
        gap: var(--spacing-xs);
        padding: var(--spacing-sm);
        scrollbar-width: none; /* Firefox */
        -ms-overflow-style: none; /* IE/Edge */
    }
    
    .toolbar::-webkit-scrollbar {
        display: none; /* Chrome/Safari */
    }
    
    /* ========== TOOL GROUPS ========== */
    .tool-group {
        flex-shrink: 0;
        gap: var(--spacing-xs);
    }
    
    /* ========== BUTTONS - TOUCH FRIENDLY ========== */
    .tool-btn {
        min-width: 44px !important;
        min-height: 44px !important;
        width: 44px;
        height: 44px;
        font-size: 20px;
        flex-shrink: 0;
    }
    
    .btn {
        min-height: 44px;
        padding: var(--spacing-sm) var(--spacing-md);
        font-size: var(--font-size-base);
    }
    
    /* ========== ACTIONS BUTTONS ========== */
    .actions button {
        padding: var(--spacing-sm) var(--spacing-md);
        font-size: var(--font-size-small);
        white-space: nowrap;
    }
    
    .actions button span {
        display: none; /* Hide text on mobile, keep icons */
    }
    
    .actions button.important span {
        display: inline; /* Show text for important buttons */
    }
    
    /* ========== CANVAS CONTAINER ========== */
    .canvas-container {
        height: calc(100vh - 200px);
        min-height: 400px;
    }
    
    canvas {
        max-width: 100%;
        height: auto;
        touch-action: none; /* Disable default touch behaviors */
    }
    
    /* ========== CONTROLS ========== */
    .control-group {
        margin-bottom: var(--spacing-md);
    }
    
    .control-label {
        font-size: var(--font-size-small);
    }
    
    /* Sliders touch-friendly */
    input[type="range"] {
        height: 8px;
        cursor: pointer;
    }
    
    input[type="range"]::-webkit-slider-thumb {
        width: 24px;
        height: 24px;
    }
    
    input[type="range"]::-moz-range-thumb {
        width: 24px;
        height: 24px;
    }
    
    /* ========== MODALS ========== */
    .modal-content {
        width: 95%;
        max-width: 95%;
        max-height: 90vh;
        padding: var(--spacing-md);
    }
    
    .modal-header {
        margin-bottom: var(--spacing-md);
    }
    
    .modal-title {
        font-size: var(--font-size-h5);
    }
    
    /* ========== ZOOM CONTROLS ========== */
    .zoom-controls {
        flex-wrap: wrap;
        gap: var(--spacing-sm);
    }
    
    .zoom-btn {
        min-width: 44px;
        min-height: 44px;
    }
    
    /* ========== ANNOTATIONS LIST ========== */
    .annotations-list {
        max-height: 300px;
    }
    
    .annotation-item {
        padding: var(--spacing-md);
    }
    
    /* ========== UPLOAD ZONE ========== */
    .upload-zone {
        padding: var(--spacing-lg);
        min-height: 200px;
    }
    
    .upload-icon {
        font-size: 36px;
    }
    
    /* ========== FORMS ========== */
    input, textarea, select {
        font-size: 16px; /* Prevent zoom on iOS */
        min-height: 44px;
    }
    
    label {
        font-size: var(--font-size-small);
    }
    
    /* ========== BADGES ========== */
    .badge {
        font-size: 10px;
        padding: 4px 8px;
    }
}

/* ========== SMALL MOBILE (< 480px) ========== */
@media (max-width: 480px) {
    header h1 {
        font-size: var(--font-size-h5);
    }
    
    .toolbar {
        padding: var(--spacing-xs);
    }
    
    .tool-btn {
        font-size: 18px;
    }
    
    .modal-content {
        width: 98%;
        padding: var(--spacing-sm);
    }
    
    .actions button span.important {
        font-size: var(--font-size-tiny);
    }
}

/* ========== LANDSCAPE MODE ========== */
@media (max-width: 768px) and (orientation: landscape) {
    .canvas-container {
        height: calc(100vh - 120px);
    }
    
    header {
        padding: var(--spacing-xs) var(--spacing-md);
    }
    
    .toolbar {
        padding: var(--spacing-xs);
    }
}

/* ========== MOBILE FLOATING TOOLBAR ========== */
@media (max-width: 768px) {
    .toolbar-mobile {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--background-card);
        border-top: 1px solid var(--border-color);
        padding: var(--spacing-sm);
        display: flex;
        justify-content: space-around;
        align-items: center;
        z-index: var(--z-fixed);
        box-shadow: 0 -4px 12px rgba(0, 0, 0, 0.3);
    }
    
    .toolbar-mobile .tool-btn {
        background: transparent;
        border: none;
        color: var(--text-secondary);
        font-size: 24px;
        padding: var(--spacing-sm);
        min-width: 44px;
        min-height: 44px;
        transition: all var(--transition-fast);
    }
    
    .toolbar-mobile .tool-btn.active {
        color: var(--primary-color);
        transform: scale(1.2);
    }
    
    .toolbar-mobile .tool-btn:active {
        transform: scale(0.95);
    }
}

/* ========== HAMBURGER MENU ========== */
.hamburger {
    display: none;
    width: 44px;
    height: 44px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 24px;
    cursor: pointer;
    padding: var(--spacing-sm);
}

@media (max-width: 768px) {
    .hamburger {
        display: flex;
        align-items: center;
        justify-content: center;
    }
}

/* ========== MOBILE MENU PANEL ========== */
.mobile-menu-panel {
    display: none;
    position: fixed;
    top: 0;
    right: -100%;
    width: 80%;
    max-width: 320px;
    height: 100vh;
    background: var(--background-card);
    box-shadow: -4px 0 12px rgba(0, 0, 0, 0.3);
    z-index: var(--z-modal);
    transition: right var(--transition-normal);
    overflow-y: auto;
    padding: var(--spacing-lg);
}

.mobile-menu-panel.open {
    display: block;
    right: 0;
}

.mobile-menu-backdrop {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: calc(var(--z-modal) - 1);
}

.mobile-menu-backdrop.open {
    display: block;
}

/* ========== TOUCH FEEDBACK ========== */
@media (max-width: 768px) {
    button:active,
    .tool-btn:active {
        transform: scale(0.95);
        opacity: 0.8;
    }
    
    .card:active {
        transform: scale(0.98);
    }
}

/* ========== PREVENT OVERSCROLL ========== */
body {
    overscroll-behavior: none;
}

/* ========== SAFE AREAS (iOS notch) ========== */
@supports (padding: max(0px)) {
    body {
        padding-left: max(0px, env(safe-area-inset-left));
        padding-right: max(0px, env(safe-area-inset-right));
    }
    
    .toolbar-mobile {
        padding-bottom: max(var(--spacing-sm), env(safe-area-inset-bottom));
    }
}
