/* ============================================================
   RVKXSE CLOUD — Dashboard fichiers (index.html)
   Styles spécifiques à cette page. Les tokens (--bg, --accent,
   --panel, --border, --ink, --muted, --red, --green, etc.) et les
   composants génériques (.btn-*, .card, inputs, .badge…) viennent
   de design-system.css, qui doit être chargé AVANT ce fichier.
   ============================================================ */

        /* box-sizing, reset, fond et police de base viennent de design-system.css */
        html { touch-action: manipulation; }
        body { height: 100vh; overflow: hidden; }

        /* Dashboard */
        #dashboard-screen { display: none; height: 100vh; display: flex; }
        .sidebar {
            width: 280px;
            background: var(--sidebar);
            border-right: 1px solid var(--border);
            display: flex;
            flex-direction: column;
            padding: 20px 0;
            flex-shrink: 0;
            overflow-y: auto;
        }
        .brand {
            padding: 8px 20px 24px;
            font-size: 24px;
            font-weight: 700;
            color: var(--accent);
            display: flex;
            align-items: center;
            gap: 14px;
        }
        .brand img { height: 40px; width: auto; }
        .nav-item {
            padding: 10px 20px;
            display: flex;
            align-items: center;
            gap: 12px;
            color: var(--muted);
            cursor: pointer;
            transition: 0.2s;
        }
        .nav-item:hover, .nav-item.active {
            background-color: #1c2231;
            color: var(--ink);
            font-weight: 500;
        }
        .nav-item.danger { color: var(--red); }
        .nav-item.danger:hover { background-color: rgba(240,102,95,0.13); }

        .filter-chip {
            display: inline-flex;
            align-items: center;
            flex-shrink: 0;
            white-space: nowrap;
            cursor: pointer;
        }

        #hamburger-btn {
            display: none;
            appearance: none;
            -webkit-appearance: none;
            background: none;
            border: none;
            margin: 0;
            padding: 8px;
            cursor: pointer;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            gap: 4px;
            -webkit-tap-highlight-color: transparent;
        }
        #hamburger-btn span {
            display: block;
            width: 20px;
            height: 2px;
            background: var(--ink);
            border-radius: 2px;
        }
        #sidebar-overlay {
            display: none;
            position: fixed;
            inset: 0;
            background: rgba(0,0,0,0.4);
            z-index: 1000;
        }
        #sidebar-overlay.visible { display: block; }
        
        .main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
        .header {
            background: var(--panel);
            padding: 15px 30px;
            border-bottom: 1px solid var(--border);
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        .search-bar {
            display: flex;
            align-items: center;
            background: #1c2231;
            border-radius: 8px;
            padding: 8px 15px;
            width: 400px;
        }
        .search-bar input {
            border: none;
            background: transparent;
            margin-left: 10px;
            width: 100%;
            outline: none;
        }
        .upload-btn {
            background: var(--accent);
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 6px;
            font-weight: 600;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            min-width: 170px;
        }
        .newfolder-btn {
            background: transparent;
            color: var(--ink);
            border: 1px solid #5a6379;
            padding: 10px 20px;
            border-radius: 6px;
            font-weight: 600;
            cursor: pointer;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            min-width: 170px;
        }
        .content-area {
            flex: 1;
            padding: 30px;
            overflow-y: auto;
        }
        .file-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
            gap: 20px;
        }
        .file-card {
            background: var(--panel);
            border: 1px solid var(--border);
            border-radius: 8px;
            padding: 15px;
            display: flex;
            flex-direction: column;
            align-items: center;
            position: relative;
        }
        .file-icon { font-size: 48px; color: var(--muted); margin-bottom: 15px; }
        .file-icon.has-thumb { width: 100%; height: 90px; display: flex; align-items: center; justify-content: center; overflow: hidden; border-radius: 6px; background: #1c2231; cursor: pointer; }
        .file-icon.has-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
        .file-icon.has-thumb.thumb-pending { font-size: 28px; opacity: 0.5; }
        .file-name {
            font-size: 14px;
            font-weight: 500;
            text-align: center;
            word-break: break-word;
            margin-bottom: 5px;
        }
        .status-badge {
            font-size: 10px;
            padding: 2px 6px;
            border-radius: 12px;
            font-weight: bold;
        }
        .status-private { background: #1c2231; color: #868faa; }
        .status-public { background: rgba(67,201,141,0.14); color: #43c98d; }
        .file-meta {
            font-size: 11px;
            color: var(--muted);
            margin-top: auto;
            padding-top: 10px;
            width: 100%;
            display: flex;
            justify-content: space-between;
        }
        .action-btn {
            background: var(--panel);
            border: 1px solid var(--border);
            border-radius: 4px;
            width: 24px;
            height: 24px;
            display: flex;
            align-items: center;
            justify-content: center;
            cursor: pointer;
            color: var(--muted);
            position: absolute;
            top: 10px;
            right: 10px;
            opacity: 0;
            transition: 0.2s;
        }
        .file-card:hover .action-btn { opacity: 1; }
        .action-btn:hover { color: var(--red); border-color: var(--red); }
        .action-btn.restore-btn:hover { color: #43c98d; border-color: #43c98d; }
        .action-btn.second { right: 40px; }

        .file-select {
            position: absolute;
            top: 10px;
            left: 10px;
            width: 18px;
            height: 18px;
            cursor: pointer;
            z-index: 2;
        }
        .file-card.selected {
            border-color: var(--accent);
            box-shadow: 0 0 0 2px var(--accent);
        }
        .file-card.folder-card { align-self: start; }

        .bulk-bar {
            display: none;
            align-items: center;
            gap: 12px;
            background: #1c2231;
            color: white;
            padding: 10px 16px;
            border-radius: 8px;
            margin-bottom: 16px;
            font-size: 13px;
        }
        .bulk-bar.visible { display: flex; }
        .bulk-bar button.bulk-select-all { background: transparent; color: #fff; border: 1px solid #363f57; }
        .bulk-bar span.count { font-weight: 600; margin-right: auto; }
        .bulk-bar button {
            border: none;
            border-radius: 4px;
            padding: 6px 12px;
            font-size: 12px;
            cursor: pointer;
        }
        .bulk-bar button.bulk-primary { background: #7c5cff; color: white; }
        .bulk-bar button.bulk-danger { background: #f0665f; color: white; }
        .bulk-bar button.bulk-success { background: #43c98d; color: white; }
        .bulk-bar button.bulk-cancel { background: transparent; color: #c3c8db; border: 1px solid #363f57; }

        /* Modal */
        .modal {
            display: none;
            position: fixed;
            top: 0; left: 0; width: 100%; height: 100%;
            background: rgba(0,0,0,0.5);
            justify-content: center;
            align-items: center;
            z-index: 1000;
        }
        .modal-content {
            background: var(--panel);
            padding: 30px;
            border-radius: 12px;
            width: 500px;
            max-width: 90%;
        }
        .drop-zone {
            border: 2px dashed var(--border);
            border-radius: 8px;
            padding: 40px;
            text-align: center;
            margin: 20px 0;
            cursor: pointer;
        }
        .drop-zone.dragover { border-color: var(--accent); background: rgba(124,92,255,0.10); }
        .form-group { margin-bottom: 15px; }
        .form-group label { display: block; margin-bottom: 5px; font-weight: 500; }
        .form-group input, .form-group select {
            width: 100%;
            padding: 10px;
            border: 1px solid var(--border);
            border-radius: 6px;
            font-size: 16px; /* >=16px empêche le zoom auto au focus sur iOS Safari */
        }
        .btn-primary {
            background: var(--accent);
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 6px;
            font-weight: 600;
            cursor: pointer;
            width: 100%;
        }
        .btn-danger {
            background: var(--red);
            color: white;
            border: none;
            padding: 10px 20px;
            border-radius: 6px;
            font-weight: 600;
            cursor: pointer;
            width: 100%;
            margin-top: 10px;
        }
        .empty-state { text-align: center; padding: 60px 20px; color: var(--muted); }
        .empty-state i { font-size: 64px; margin-bottom: 20px; opacity: 0.5; }

        /* Sélecteur de dossier (catégorie d'upload / déplacement de fichier) : fenêtre centrée
           en mode navigation (drill-down) plutôt qu'un menu déroulant ou un arbre indenté à plat. */
        .folder-picker { position: relative; }
        .folder-picker-trigger {
            width: 100%;
            min-height: 44px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            gap: 8px;
            padding: 10px 12px;
            border: 1px solid var(--border);
            border-radius: 6px;
            background: var(--panel);
            font-size: 14px;
            color: var(--ink);
            cursor: pointer;
            text-align: left;
        }
        .folder-picker-trigger:hover { border-color: #5a6379; }
        .folder-picker-trigger span.fp-label { display: flex; align-items: center; gap: 8px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

        /* Modale centrée de sélection de dossier (drill-down) */
        .fp-modal-content { width: 420px; padding: 0; overflow: hidden; display: flex; flex-direction: column; max-height: 80vh; }
        .fp-modal-header {
            display: flex;
            align-items: center;
            gap: 10px;
            padding: 16px 18px;
            border-bottom: 1px solid var(--border);
            flex-shrink: 0;
        }
        .fp-modal-title { font-weight: 600; font-size: 15px; flex: 1; min-width: 0; }
        .fp-modal-back {
            width: 30px; height: 30px;
            border-radius: 6px;
            display: flex; align-items: center; justify-content: center;
            cursor: pointer;
            color: var(--muted);
            flex-shrink: 0;
        }
        .fp-modal-back:hover { background: #1c2231; color: var(--ink); }
        .fp-modal-back.disabled { opacity: 0.3; pointer-events: none; }
        .fp-modal-close { width: 30px; height: 30px; border-radius: 6px; display: flex; align-items: center; justify-content: center; cursor: pointer; color: var(--muted); flex-shrink: 0; }
        .fp-modal-close:hover { background: #1c2231; color: var(--ink); }
        .fp-modal-crumb { font-size: 12px; color: var(--muted); padding: 10px 18px; border-bottom: 1px solid var(--border); white-space: nowrap; overflow-x: auto; flex-shrink: 0; }
        .fp-modal-crumb span { cursor: pointer; }
        .fp-modal-crumb span:hover { color: var(--accent); text-decoration: underline; }
        .fp-modal-crumb i { font-size: 9px; margin: 0 6px; opacity: 0.6; }
        .fp-modal-list { overflow-y: auto; flex: 1; padding: 8px; }
        .fp-item {
            display: flex;
            align-items: center;
            gap: 10px;
            padding: 12px 12px;
            border-radius: 8px;
            cursor: pointer;
            font-size: 14px;
        }
        .fp-item:hover { background: #1c2231; }
        .fp-item.active { background: rgba(124,92,255,0.18); color: var(--accent); font-weight: 600; }
        .fp-item .fp-item-icon { width: 18px; text-align: center; flex-shrink: 0; }
        .fp-item .fp-item-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
        .fp-item .fp-item-enter { flex-shrink: 0; color: var(--muted); font-size: 12px; padding: 4px 8px; border-radius: 4px; }
        .fp-item .fp-item-enter:hover { background: #1c2231; color: var(--accent); }
        .fp-modal-empty { padding: 30px 14px; font-size: 13px; color: var(--muted); text-align: center; }
        .fp-modal-footer { padding: 12px 18px; border-top: 1px solid var(--border); flex-shrink: 0; }
        .fp-modal-footer .btn-primary { margin: 0; }

        /* Profil / avatar */
        .avatar-circle {
            border-radius: 50%;
            object-fit: cover;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: 700;
            color: white;
            background: var(--accent);
            flex-shrink: 0;
            user-select: none;
            overflow: hidden;
        }
        .sidebar-profile { display: flex; align-items: center; gap: 10px; padding: 12px 10px; margin: 4px 0 10px 0; border-radius: 8px; cursor: pointer; transition: background 0.15s; touch-action: manipulation; }
        .sidebar-profile:hover { background: rgba(255,255,255,0.04); }
        .sidebar-profile-info { min-width: 0; }
        .sidebar-profile-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
        .sidebar-profile-role { font-size: 11px; color: var(--muted); }

        .account-avatar-row { display: flex; align-items: center; gap: 16px; margin: 15px 0 20px; flex-wrap: wrap; }
        .account-avatar-actions { display: flex; flex-direction: column; gap: 8px; }
        .avatar-action-btn {
            border: 1px solid var(--border);
            background: var(--panel);
            color: var(--ink);
            padding: 7px 14px;
            border-radius: 6px;
            font-size: 13px;
            font-weight: 600;
            cursor: pointer;
            min-height: 40px;
            touch-action: manipulation;
        }
        .avatar-action-btn:hover { background: #1c2231; }
        .avatar-action-btn.remove { color: var(--red); border-color: rgba(240,102,95,0.28); }
        .avatar-action-btn.remove:hover { background: rgba(240,102,95,0.13); }

        /* Recadrage avatar */
        .crop-stage {
            position: relative;
            width: 300px;
            height: 300px;
            max-width: 100%;
            margin: 15px auto 0;
            border-radius: 8px;
            overflow: hidden;
            background: #0c0e16;
            touch-action: none;
            cursor: grab;
        }
        .crop-stage:active { cursor: grabbing; }
        .crop-stage canvas { display: block; width: 100%; height: 100%; touch-action: none; }
        .crop-circle-guide {
            position: absolute;
            inset: 0;
            pointer-events: none;
            border-radius: 50%;
            box-shadow: 0 0 0 2000px rgba(0, 0, 0, 0.45);
            border: 2px solid rgba(255,255,255,0.25);
        }
        .crop-zoom-row { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
        .crop-zoom-row input[type="range"] { flex: 1; }
        .account-info-row {
            display: flex;
            justify-content: space-between;
            align-items: center;
            gap: 10px;
            padding: 10px 0;
            border-bottom: 1px solid var(--border);
            font-size: 14px;
        }
        .account-info-row:last-child { border-bottom: none; }
        .account-info-row .label { color: var(--muted); }
        .account-info-row .value { font-weight: 600; text-align: right; word-break: break-word; }
        
        /* User Management Styles */
        .user-list-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 15px;
            border-bottom: 1px solid var(--border);
        }
        .user-list-item:last-child { border-bottom: none; }
        .role-badge {
            background: #1c2231;
            padding: 2px 8px;
            border-radius: 12px;
            font-size: 12px;
            margin-left: 10px;
        }
        .role-badge.admin { background: var(--accent); color: white; }

        #toast-container { position: fixed; top: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
        #upload-progress-widget {
            position: fixed;
            bottom: 20px;
            right: 20px;
            width: 320px;
            max-width: calc(100vw - 40px);
            background: var(--panel);
            border: 1px solid var(--border);
            border-radius: 10px;
            box-shadow: 0 6px 24px rgba(0,0,0,0.18);
            z-index: 9998;
            overflow: hidden;
            display: none;
        }
        #upload-progress-widget.visible { display: block; }
        .upw-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 12px 14px;
            background: var(--accent);
            color: white;
            font-weight: 600;
            font-size: 14px;
            cursor: pointer;
            user-select: none;
        }
        .upw-header-actions { display: flex; align-items: center; gap: 10px; }
        .upw-header-actions i { cursor: pointer; opacity: 0.9; }
        .upw-header-actions i:hover { opacity: 1; }
        .upw-body { max-height: 280px; overflow-y: auto; }
        #upload-progress-widget.collapsed .upw-body { display: none; }
        .upw-item { padding: 10px 14px; border-bottom: 1px solid var(--border); }
        .upw-item:last-child { border-bottom: none; }
        .upw-item-top { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
        .upw-item-icon { font-size: 13px; color: var(--muted); flex-shrink: 0; }
        .upw-item-name { font-size: 13px; color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
        .upw-item-pct { font-size: 12px; color: var(--muted); flex-shrink: 0; }
        .upw-bar-track { height: 5px; background: var(--bg); border-radius: 3px; overflow: hidden; }
        .upw-bar-fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width 0.15s ease; width: 0%; }
        .upw-item.done .upw-bar-fill { background: var(--green); }
        .upw-item.error .upw-bar-fill { background: var(--red); }
        .upw-item.done .upw-item-icon { color: var(--green); }
        .upw-item.error .upw-item-icon { color: var(--red); }
        .toast {
            background: #1c2231; color: white; padding: 12px 18px; border-radius: 6px;
            font-size: 14px; box-shadow: 0 4px 12px rgba(0,0,0,0.2);
            opacity: 0; transform: translateY(10px); transition: opacity 0.2s ease, transform 0.2s ease;
            max-width: 320px;
        }
        .toast.show { opacity: 1; transform: translateY(0); }
        .toast.error { background: #ff8079; }
        .toast.success { background: #5cdba0; }

        /* ============ Structure mobile (tiroir sidebar) ============ */
        @media (max-width: 768px) {
            #hamburger-btn { display: flex; min-width: 44px; min-height: 44px; touch-action: manipulation; }

            .sidebar {
                position: fixed;
                top: 0; left: 0;
                height: 100vh;
                width: clamp(210px, 70vw, 300px);
                z-index: 1001;
                transform: translateX(-100%);
                transition: transform 0.25s ease;
                box-shadow: 2px 0 12px rgba(0,0,0,0.15);
                padding-top: max(20px, env(safe-area-inset-top));
                padding-bottom: max(20px, env(safe-area-inset-bottom));
            }
            .sidebar.open { transform: translateX(0); }

            .nav-item { min-height: 44px; touch-action: manipulation; }
            .sidebar-profile { min-height: 44px; }

            .header { flex-wrap: wrap; }
            .search-bar { order: 3; flex-basis: 100%; width: 100%; max-width: none; }
            .upload-btn { min-height: 44px; touch-action: manipulation; }
            .newfolder-btn { min-height: 44px; touch-action: manipulation; }

            .action-btn {
                opacity: 1;
                width: 34px;
                height: 34px;
                font-size: 15px;
            }
            .action-btn.second { right: 48px; }
            .file-select { width: 22px; height: 22px; }

            .filter-chip { min-height: 36px; touch-action: manipulation; }

            .bulk-bar { flex-wrap: wrap; }
            .bulk-bar button { min-height: 40px; padding: 8px 14px; touch-action: manipulation; }
            .avatar-action-btn { min-height: 44px; }

            #breadcrumb-bar { flex-wrap: wrap; }
            #breadcrumb-back { min-width: 32px; min-height: 32px; display: inline-flex; align-items: center; justify-content: center; }
            .user-list-item { flex-wrap: wrap; gap: 8px; }
        }
        /* ============ Tailles fluides (s'adaptent en continu, pas par palier) ============ */
        .brand { font-size: 24px; }
        .nav-item { padding: clamp(8px, 1.5vw, 10px) clamp(14px, 3vw, 20px); font-size: clamp(13px, 1.8vw, 15px); }
        #hamburger-btn span { width: clamp(18px, 5vw, 22px); }

        .header { padding: clamp(10px, 2vw, 15px) clamp(14px, 4vw, 30px); gap: clamp(8px, 2vw, 15px); }
        .search-bar { width: clamp(160px, 30vw, 400px); flex: 1 1 200px; max-width: 400px; padding: clamp(6px, 1.5vw, 8px) clamp(10px, 2vw, 15px); }
        .search-bar input { font-size: clamp(13px, 1.6vw, 15px); }
        .upload-btn { padding: clamp(8px, 1.8vw, 10px) clamp(14px, 3vw, 20px); font-size: clamp(13px, 1.6vw, 15px); white-space: nowrap; }
        .newfolder-btn { padding: clamp(8px, 1.8vw, 10px) clamp(14px, 3vw, 20px); font-size: clamp(13px, 1.6vw, 15px); white-space: nowrap; }

        .content-area { padding: clamp(14px, 3.5vw, 30px); }
        .file-grid { grid-template-columns: repeat(auto-fill, minmax(clamp(105px, 26vw, 170px), 1fr)); gap: clamp(10px, 2.2vw, 20px); }
        .file-card { padding: clamp(10px, 2.2vw, 15px); }
        .file-icon { font-size: clamp(28px, 8vw, 48px); margin-bottom: clamp(8px, 2vw, 15px); }
        .file-name { font-size: clamp(12px, 2.4vw, 14px); }
        .file-meta { font-size: clamp(10px, 1.8vw, 11px); }
        .status-badge { font-size: clamp(9px, 1.6vw, 10px); }

        .modal-content { width: clamp(280px, 90vw, 500px); padding: clamp(18px, 4vw, 30px); max-height: 88vh; overflow-y: auto; }
        .drop-zone { padding: clamp(20px, 6vw, 40px) clamp(12px, 4vw, 40px); }
        .filter-chip { font-size: clamp(11px, 1.8vw, 13px); padding: clamp(4px, 1vw, 6px) clamp(8px, 2vw, 12px); }

        #toast-container { left: clamp(10px, 3vw, 20px); right: clamp(10px, 3vw, 20px); top: max(clamp(10px, 3vw, 20px), env(safe-area-inset-top)); }
        #upload-progress-widget { left: clamp(10px, 3vw, 20px); right: clamp(10px, 3vw, 20px); width: auto; bottom: max(clamp(10px, 3vw, 20px), env(safe-area-inset-bottom)); }
        .toast { max-width: min(320px, 100%); font-size: clamp(12px, 1.8vw, 14px); }

        /* Avatars : petite version (sidebar) et grande version (modale compte) */
        .sidebar-profile .avatar-circle { width: clamp(34px, 8vw, 38px); height: clamp(34px, 8vw, 38px); font-size: clamp(13px, 3vw, 15px); }
        .avatar-circle-lg { width: clamp(56px, 18vw, 72px); height: clamp(56px, 18vw, 72px); font-size: clamp(20px, 6vw, 26px); }
        .avatar-action-btn { font-size: clamp(12px, 2vw, 13px); padding: clamp(7px, 1.8vw, 9px) clamp(12px, 3vw, 14px); }
        .account-info-row { font-size: clamp(13px, 2vw, 14px); }
        /* ============ Réglages tactiles qui doivent primer sur les tailles fluides ci-dessus ============ */
        @media (max-width: 768px) {
            .search-bar input { font-size: 16px; } /* empêche le zoom auto au focus sur iOS Safari */

            .modal { align-items: flex-end; }
            .modal-content {
                width: 100%;
                max-width: 100%;
                border-radius: 16px 16px 0 0;
                max-height: 85vh;
                padding-bottom: max(18px, env(safe-area-inset-bottom));
            }
            #folder-picker-modal .modal-content.fp-modal-content {
                width: 92vw;
                max-width: 420px;
                border-radius: 12px;
                max-height: 75vh;
            }
        }
