/* =======================
   RESET & BASE
======================= */

html, body {
    margin: 0;
    height: 100%;
    background: #fff;
    font-family: Arial, sans-serif;
    color: #000;
}

* {
    box-sizing: border-box;
}


/* =======================
   VUE LISTE DOSSIERS
======================= */

#folders {
    position: absolute;
    inset: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
}

#searchBar {
    display: flex;
    gap: 10px;
    padding: 10px;
    background: #fff;
    border-bottom: 1px solid #ddd;
    position: sticky;
    top: 0;
    z-index: 100;
}

#search {
    flex: 1;
    padding: 10px;
    font-size: 16px;
    border-radius: 10px;
    border: 1px solid #ccc;
}

#addFolder {
    width: 42px;
    height: 42px;
    font-size: 26px;
    border-radius: 50%;
    border: none;
    background: #007AFF;
    color: #fff;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
}

#folderList {
    list-style: none;
    padding: 0;
    margin: 0;
    flex: 1;
    overflow-y: auto;
}

.folderLine {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid #ddd;
    cursor: pointer;
    transition: background 0.2s;
    min-height: 38px;
    padding: 2px 0;
}

.folderLine:hover {
    background: #f5f5f5;
}

.folderLine .left {
    display: flex;
    align-items: center;
    flex: 1;
    overflow: hidden;
}

.folderLine .right {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-right: 3px;
    margin-left: 8px;
    flex-shrink: 0;
}

.dossierLink {
    text-decoration: none;
    padding: 2px 8px;
    display: flex;
    align-items: center;
    width: 100%;
    gap: 8px;
}

.folder-display {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.folder-num {
    font-size: 20px;
    font-weight: bold;
    line-height: 2;
    height: 32px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.folder-info-container {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 1px;
    flex: 1;
    min-height: 32px;
}

.folder-info {
    font-size: 11px;
    color: #666;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.folder-info.truncate-40 {
    max-width: 40ch;
}

.folder-info.truncate-30 {
    max-width: 30ch;
}

/* Couleurs selon le type */
.color-blue {
    color: #007AFF;
}

.color-pink {
    color: #FF2D55;
}

.color-green {
    color: #34C759;
}

.color-default {
    color: #000;
}

.icon {
    font-size: 34px;
}

.edit-icon {
    font-size: 22px;
    background: none;
    border: none;
    padding: 4px;
    cursor: pointer;
    color: #666;
}


/* =======================
   MODAL CRÉATION DOSSIER
======================= */

.overlay {
    position: fixed;
    inset: 0;
    background: rgba(255,255,255,0.98);
    display: none;
    justify-content: center;
    align-items: flex-start;
    z-index: 9999;
}

.modal {
    margin-top: 100px;
    width: 90%;
    max-width: 420px;
    background: #fff;
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
}

.modal h2 {
    margin-top: 0;
}

.modal-fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #fff;
    display: flex;
    flex-direction: column;
    z-index: 10001;
}

.modal-header-fixed {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background: #fff;
    border-bottom: 1px solid #ddd;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    z-index: 10002;
    height: 60px;
    box-sizing: border-box;
}

.modal-header-fixed h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    flex: 1;
}

.modal-header-fixed button {
    background: #007AFF;
    color: white;
    border: none;
    padding: 8px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    font-size: 16px;
    flex-shrink: 0;
}

.modal-body-scroll {
    margin-top: 60px;
    padding: 16px;
    overflow-y: auto;
    flex: 1;
}

.folder-selection-item {
    padding: 12px;
    border-bottom: 1px solid #ddd;
    cursor: pointer;
    transition: background 0.2s;
}

.folder-selection-item:hover {
    background: #f5f5f5;
}

.modal input {
    width: 100%;
    padding: 14px;
    font-size: 18px;
    border: 1px solid #ccc;
    border-radius: 12px;
    margin: 16px 0;
}

.modal .buttons {
    display: flex;
    gap: 10px;
}

.modal button {
    flex: 1;
    padding: 14px;
    font-size: 16px;
    border-radius: 12px;
    border: none;
    background: #007AFF;
    color: #fff;
}


/* =======================
   VUE CAMÉRA
======================= */

#camera {
    display: none;
    position: absolute;
    inset: 0;
}

video {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform-origin: center center;
}

#topBar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 15px;
    background: linear-gradient(to bottom, rgba(0,0,0,.7), transparent);
    color: #fff;
    z-index: 10;
    box-sizing: border-box;
}

#backBtn {
    font-size: 26px;
    padding: 6px;
    cursor: pointer;
}

#folderTag {
    font-size: 20px;
    font-weight: bold;
    letter-spacing: 2px;
}

#controls button {
    background: none;
    border: none;
    color: #fff;
    font-size: 22px;
    margin-left: 10px;
    cursor: pointer;
}

#shutter {
    position: fixed;
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: #fff;
    border: 6px solid #aaa;
    z-index: 9999;
    box-shadow: 0 6px 20px rgba(0,0,0,0.25);
    cursor: pointer;
}

/* Portrait : Horizontal en bas - Galerie (gauche 25%), Shutter (centre 50%), PDF (droite 75%) */
@media (orientation: portrait) {
    #shutter {
        bottom: 30px;
        left: 50%;
        right: auto;
        top: auto;
        transform: translateX(-50%);
        margin: 0;
        padding: 0;
    }
    
    #cameraToGalleryBtn {
        bottom: 40px;
        left: 25%;
        right: auto;
        top: auto;
        transform: translateX(-50%);
        margin: 0;
        padding: 0;
    }
    
    #cameraToGalleryBtn:active {
        transform: translateX(-50%) scale(0.9);
    }
    
    #pdfBtn {
        bottom: 40px;
        left: 75%;
        right: auto;
        top: auto;
        transform: translateX(-50%);
        margin: 0;
        padding: 0;
    }
    
    #pdfBtn:active {
        transform: translateX(-50%) scale(0.9);
    }
}

/* Paysage : Vertical à droite - PDF (haut 25%), Shutter (centre 50%), Galerie (bas 75%) */
@media (orientation: landscape) {
    #shutter {
        right: 30px;
        top: 50%;
        left: auto;
        bottom: auto;
        transform: translateY(-50%);
        margin: 0;
        padding: 0;
    }
    
    #cameraToGalleryBtn {
        right: 40px;
        top: 75%;
        left: auto;
        bottom: auto;
        transform: translateY(-50%);
        margin: 0;
        padding: 0;
    }
    
    #cameraToGalleryBtn:active {
        transform: translateY(-50%) scale(0.9);
    }
    
    #pdfBtn {
        right: 40px;
        top: 25%;
        left: auto;
        bottom: auto;
        transform: translateY(-50%);
        margin: 0;
        padding: 0;
    }
    
    #pdfBtn:active {
        transform: translateY(-50%) scale(0.9);
    }
}

.shutterActive {
    transform: translateX(-50%) scale(.8);
    box-shadow: 0 0 0 10px rgba(255,255,255,.3);
}

#error {
    position: absolute;
    bottom: 120px;
    left: 50%;
    transform: translateX(-50%);
    background: #c00;
    color: #fff;
    padding: 10px 16px;
    border-radius: 8px;
    display: none;
    font-size: 16px;
    z-index: 10000;
}

#cameraToGalleryBtn {
    position: fixed;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: transparent;
    border: 2px solid rgba(255, 255, 255, 0.9);
    font-size: 26px;
    z-index: 9999;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
}

#pdfBtn {
    position: fixed;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(255, 59, 48, 0.9);
    border: none;
    font-size: 26px;
    color: #fff;
    z-index: 9999;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    cursor: pointer;
    display: none; /* Caché car remplacé par la barre de mode */
    align-items: center;
    justify-content: center;
    pointer-events: auto;
}

#pdfBtn.scanning {
    background: rgba(255, 69, 58, 0.9);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

/* Barre de mode Photos/PDF - Style onglets */
#modeBar {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 35px;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
    display: flex;
    justify-content: center;
    align-items: flex-end;
    z-index: 9998;
    padding: 0;
    margin: 0;
}

.mode-btn {
    flex: 1;
    max-width: 200px;
    height: 100%;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-top: 2px solid transparent;
    color: rgba(255, 255, 255, 0.6);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    margin: 0;
    padding: 0;
    border-radius: 0;
    line-height: 35px;
}

.mode-btn.active {
    background: rgba(255, 255, 255, 0.95);
    color: #000;
    border-top-color: #007AFF;
}

.mode-btn:active {
    transform: scale(0.98);
}

/* Modal pour le nom du PDF */
#pdfNameModal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 10001;
    display: flex;
    justify-content: center;
    align-items: center;
}

.pdf-modal-content {
    background: white;
    padding: 30px;
    border-radius: 16px;
    max-width: 400px;
    width: 90%;
}

.pdf-modal-content h3 {
    margin: 0 0 20px 0;
    font-size: 20px;
    color: #333;
}

#pdfNameSelect {
    width: 100%;
    padding: 12px;
    font-size: 16px;
    border: 2px solid #ddd;
    border-radius: 8px;
    margin-bottom: 20px;
}

.pdf-modal-buttons {
    display: flex;
    gap: 10px;
}

.pdf-modal-buttons button {
    flex: 1;
    padding: 12px;
    font-size: 16px;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
}

#pdfCancelBtn {
    background: #f0f0f0;
    color: #333;
}

#pdfConfirmBtn {
    background: #007AFF;
    color: white;
}

#pdfCountdown {
    position: fixed;
    top: 70px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 18px;
    font-weight: 600;
    color: #fff;
    background: rgba(0, 0, 0, 0.7);
    padding: 8px 16px;
    border-radius: 20px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.4);
    z-index: 10000;
    display: none;
    backdrop-filter: blur(10px);
}

#captureFlash {
    position: fixed;
    inset: 0;
    border: 8px solid rgba(200,200,200,.9);
    box-sizing: border-box;
    opacity: 0;
    pointer-events: none;
    z-index: 999;
    transition: opacity .15s ease;
}

.flashOn {
    opacity: 1;
}


/* =======================
   VUE GALERIE
======================= */

#gallery-view {
    display: none;
    position: absolute;
    inset: 0;
}

.topbar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 50px;
    display: flex;
    align-items: center;
    background: #fff;
    border-bottom: 1px solid #ddd;
    z-index: 1000;
    padding: 0;
}

.back-btn {
    width: 50px;
    height: 50px;
    border-radius: 0;
    background: none;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-right: 1px solid #ddd;
    color: #333;
    flex-shrink: 0;
    cursor: pointer;
}

.back-icon {
    width: 22px;
    height: 22px;
}

.gallery-header-content {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 8px;
    min-width: 0;
    overflow: hidden;
}

.gallery-header-num {
    font-weight: bold;
    font-size: 20px;
    flex-shrink: 0;
}

.gallery-header-info-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 2px;
    min-width: 0;
}

.gallery-info-line1 {
    font-size: 12px;
    color: #666;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gallery-info-line2 {
    font-size: 11px;
    color: #666;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.gallery-camera-icon {
    width: 50px;
    height: 50px;
    background: none;
    border: none;
    border-left: 1px solid #ddd;
    font-size: 34px;
    padding: 0;
    margin: 0;
    flex-shrink: 0;
    cursor: pointer;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.folder-name {
    font-size: 20px;
    font-weight: bold;
    line-height: 1.1;
    text-align: center;
    max-width: calc(100% - 100px);
}

.folder-name .folder-info {
    font-size: 13px;
    font-weight: normal;
    color: #666;
    display: block;
    max-width: 30ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin: 0 auto;
}

.camera-btn {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    width: 40px;
    height: 40px;
    border-radius: 4px;
    background: #007AFF;
    border: none;
    font-size: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    cursor: pointer;
}

.camera-btn:active {
    transform: translateY(-50%) scale(0.9);
}

.gallery {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    padding: 55px 5px 5px;
}

.gallery img {
    width: calc(25% - 3px);
    aspect-ratio: 1 / 1;
    object-fit: cover;
    cursor: pointer;
    border-radius: 4px;
    display: block;
}


/* =======================
   LIGHTBOX
======================= */

#lightbox {
    display: none;
    position: fixed;
    inset: 0;
    background: #000;
    z-index: 9999;
}

#lightbox img {
    z-index: 10000;
    pointer-events: auto;
    width: 100vw;
    height: 100vh;
    object-fit: contain;
    transform-origin: center center;
    touch-action: none;
    will-change: transform;
}

#lightbox .close {
    position: absolute;
    top: 20px;
    right: 20px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: rgba(0,0,0,0.6);
    color: #fff;
    font-size: 36px;
    line-height: 56px;
    text-align: center;
    cursor: pointer;
    z-index: 10001;
    pointer-events: auto;
}

#lightbox .close:active {
    transform: scale(0.9);
    background: rgba(0,0,0,0.85);
}

#lightbox .nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    color: #fff;
    font-size: 40px;
    cursor: pointer;
    user-select: none;
    z-index: 10001;
}

#lightbox .nav.left {
    left: 20px;
}

#lightbox .nav.right {
    right: 20px;
}
