:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --bg-dark: #0f172a;
    --bg-card: #1e293b;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: #334155;
    --danger: #ef4444;
    --success: #22c55e;
    --radius: 8px;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Segoe UI', system-ui, sans-serif; }

body { background-color: var(--bg-dark); color: var(--text-main); height: 100vh; display: flex; flex-direction: column; overflow: hidden; }

.hidden { display: none !important; }
.btn { padding: 0.6rem 1.2rem; border-radius: var(--radius); border: none; cursor: pointer; font-weight: 600; transition: 0.2s; display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; font-size: 0.9rem; }
.btn-primary { background-color: var(--primary); color: white; }
.btn-primary:hover { background-color: var(--primary-hover); }
.btn-danger { background-color: var(--danger); color: white; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text-muted); }
.btn-outline:hover { border-color: var(--text-main); color: var(--text-main); }
input, select, textarea { background: var(--bg-dark); border: 1px solid var(--border); color: var(--text-main); padding: 0.6rem; border-radius: var(--radius); outline: none; width: 100%; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); }

#login-view { position: fixed; inset: 0; background: var(--bg-dark); z-index: 100; display: flex; align-items: center; justify-content: center; }
.login-card { background: var(--bg-card); padding: 2.5rem; border-radius: var(--radius); width: 100%; max-width: 400px; box-shadow: var(--shadow); border: 1px solid var(--border); text-align: center; }
.login-card h1 { margin-bottom: 1.5rem; color: var(--primary); }
.form-group { margin-bottom: 1rem; text-align: left; }
.form-group label { display: block; margin-bottom: 0.4rem; font-size: 0.9rem; color: var(--text-muted); }
#captcha-label { font-weight: 600; color: var(--primary); }
.login-hint { margin-top: 1rem; font-size: 0.8rem; color: var(--text-muted); text-align: left; background: rgba(255,255,255,0.05); padding: 0.5rem; border-radius: 4px; }

#dashboard-view { display: flex; flex-direction: column; height: 100%; }

header { background: var(--bg-card); border-bottom: 1px solid var(--border); padding: 1rem 2rem; display: flex; justify-content: space-between; align-items: center; flex-shrink: 0; }
.brand { font-size: 1.25rem; font-weight: bold; display: flex; align-items: center; gap: 0.5rem; }
.user-menu { display: flex; align-items: center; gap: 1rem; }
.role-badge { font-size: 0.75rem; padding: 0.2rem 0.5rem; border-radius: 4px; background: #334155; text-transform: uppercase; letter-spacing: 0.5px; }
.role-admin { background: rgba(99, 102, 241, 0.2); color: #818cf8; }

.toolbar { padding: 1rem 2rem; display: flex; align-items: center; border-bottom: 1px solid var(--border); flex-shrink: 0; }

.input-group { display: flex; align-items: stretch; width: 100%; max-width: 700px; }
.input-group > * { border-radius: 0; }
.input-group > :first-child { border-top-left-radius: var(--radius); border-bottom-left-radius: var(--radius); }
.input-group > :last-child { border-top-right-radius: var(--radius); border-bottom-right-radius: var(--radius); }
.input-group > :not(:last-child) { border-right: 1px solid var(--border); }

.search-box { flex: 1; min-width: 0; position: relative; background: var(--bg-dark); }
.search-box input { width: 100%; padding-left: 2.5rem; border: 1px solid var(--border); height: 100%; background: var(--bg-dark); }
.search-box input:focus { border-color: var(--primary); position: relative; z-index: 1; }
.search-icon { position: absolute; left: 0.8rem; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; z-index: 2; }

.gallery-container { flex-grow: 1; overflow-y: auto; padding: 2rem; }
.gallery-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1.5rem; }

.img-card { background: var(--bg-card); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); transition: transform 0.2s; position: relative; display: flex; flex-direction: column; }
.img-card:hover { transform: translateY(-4px); border-color: var(--primary); }

.img-wrapper { position: relative; width: 100%; height: 200px; background: #000; cursor: pointer; }
.img-thumb { width: 100%; height: 100%; object-fit: cover; display: block; }

.overlay-actions {
    position: absolute; inset: 0;
    background: rgba(0,0,0,0.6);
    display: flex; flex-direction: column;
    justify-content: center; align-items: center;
    gap: 0.5rem;
    opacity: 0;
    transition: opacity 0.2s ease;
}
.img-wrapper:hover .overlay-actions { opacity: 1; }

.overlay-btn {
    background: rgba(255,255,255,0.2); border: 1px solid rgba(255,255,255,0.4);
    color: white; padding: 0.5rem 1rem; border-radius: 20px;
    cursor: pointer; backdrop-filter: blur(4px); font-size: 0.85rem;
    display: flex; align-items: center; gap: 0.4rem;
    transition: 0.2s;
}
.overlay-btn:hover { background: var(--primary); border-color: var(--primary); }

.img-info { padding: 0.8rem; background: var(--bg-card); flex-grow: 1; }
.img-title { font-weight: 600; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 0.4rem; }
.img-tags { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.tag { font-size: 0.7rem; background: rgba(255,255,255,0.1); padding: 0.1rem 0.4rem; border-radius: 4px; color: var(--text-muted); }
.img-stats { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.3rem; }

/* --- Multi-select --- */
.ms { position: relative; min-width: 180px; background: var(--bg-dark); }
.ms-trigger { display: flex; align-items: center; padding: 0.6rem; border: 1px solid var(--border); cursor: pointer; height: 100%; background: var(--bg-dark); color: var(--text-muted); font-size: 0.9rem; gap: 0.4rem; user-select: none; }
.ms-trigger:hover, .ms.open .ms-trigger { border-color: var(--primary); color: var(--text-main); }
.ms.open .ms-trigger { border-color: var(--primary); position: relative; z-index: 1; }
.ms-values { flex: 1; display: flex; flex-wrap: wrap; gap: 0.2rem; overflow: hidden; min-width: 0; }
.ms-chip { display: inline-flex; align-items: center; gap: 0.2rem; background: var(--primary); color: #fff; font-size: 0.75rem; padding: 0.1rem 0.4rem; border-radius: 3px; }
.ms-chip-remove { cursor: pointer; font-size: 0.8rem; line-height: 1; opacity: 0.7; }
.ms-chip-remove:hover { opacity: 1; }
.ms-placeholder { color: var(--text-muted); font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ms-arrow { font-size: 0.7rem; transition: transform 0.2s; flex-shrink: 0; }
.ms.open .ms-arrow { transform: rotate(180deg); }
.ms-dropdown { position: absolute; top: 100%; left: 0; right: 0; z-index: 100; background: var(--bg-card); border: 1px solid var(--border); border-top: none; border-radius: 0 0 var(--radius) var(--radius); max-height: 250px; display: flex; flex-direction: column; }
.ms-search { border: none; border-bottom: 1px solid var(--border); border-radius: 0; padding: 0.6rem; font-size: 0.85rem; background: var(--bg-dark); color: var(--text-main); outline: none; }
.ms-search:focus { border-bottom-color: var(--primary); }
.ms-options { overflow-y: auto; flex: 1; }
.ms-opt { display: flex; align-items: center; gap: 0.5rem; padding: 0.5rem 0.6rem; cursor: pointer; font-size: 0.85rem; color: var(--text-main); transition: 0.1s; }
.ms-opt:hover { background: rgba(99, 102, 241, 0.15); }
.ms-opt.selected { background: rgba(99, 102, 241, 0.1); color: var(--primary); }
.ms-opt input[type="checkbox"] { accent-color: var(--primary); pointer-events: none; }
.ms-no-results { padding: 0.6rem; color: var(--text-muted); font-size: 0.85rem; text-align: center; }

.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.8); z-index: 50; display: flex; align-items: center; justify-content: center; backdrop-filter: blur(4px); opacity: 0; pointer-events: none; transition: 0.3s; }
.modal-overlay.active { opacity: 1; pointer-events: all; }

.modal { background: var(--bg-card); width: 90%; max-width: 600px; border-radius: var(--radius); border: 1px solid var(--border); display: flex; flex-direction: column; max-height: 90vh; }
.modal-header { padding: 1rem 1.5rem; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-body { padding: 1.5rem; overflow-y: auto; }
.modal-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 0.5rem; }

.upload-area { border: 2px dashed var(--border); border-radius: var(--radius); padding: 2rem; text-align: center; cursor: pointer; transition: 0.2s; margin-bottom: 1rem; }
.upload-area:hover { border-color: var(--primary); background: rgba(99, 102, 241, 0.05); }
.preview-container { display: flex; gap: 1rem; margin-top: 1rem; display: none; }
.preview-img { width: 100px; height: 100px; object-fit: cover; border-radius: 4px; border: 1px solid var(--border); }
.stats-box { font-size: 0.8rem; color: var(--text-muted); display: flex; flex-direction: column; justify-content: center; }
.compressed-stat { color: var(--success); font-weight: bold; }

.detail-layout { display: flex; flex-direction: column; gap: 1rem; }

.public-link-wrapper { margin-bottom: 0.5rem; }
.public-link-label { font-size: 0.8rem; color: var(--text-muted); margin-bottom: 0.3rem; display: block; }
.public-link-box { background: #0f172a; padding: 0.8rem; border-radius: 4px; border: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; word-break: break-all; }
.link-text { font-family: monospace; font-size: 0.85rem; color: var(--primary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-right: 1rem; }

.detail-image-wrapper { width: 100%; background: #000; border-radius: var(--radius); overflow: hidden; display: flex; justify-content: center; align-items: center; min-height: 200px; border: 1px solid var(--border); }
.detail-image { max-width: 100%; max-height: 50vh; object-fit: contain; }
.detail-meta h3 { margin-bottom: 0.5rem; font-size: 1.1rem; }
.detail-meta p { margin-bottom: 0.5rem; color: var(--text-muted); font-size: 0.9rem; }

.edit-modal { max-width: 500px; }

.docs-content { font-size: 0.9rem; line-height: 1.6; color: #cbd5e1; }
.docs-content h1 { color: #fff; margin: 1rem 0 0.5rem; font-size: 1.5rem; }
.docs-content h2 { color: #fff; margin: 1.5rem 0 0.5rem; border-bottom: 1px solid var(--border); padding-bottom: 0.3rem; font-size: 1.2rem; }
.docs-content code { background: rgba(255,255,255,0.1); padding: 0.1rem 0.3rem; border-radius: 3px; font-family: monospace; }
.docs-content pre { background: #0f172a; padding: 1rem; border-radius: var(--radius); overflow-x: auto; border: 1px solid var(--border); margin: 1rem 0; font-family: monospace; }
.docs-content ul { padding-left: 1.5rem; margin-bottom: 1rem; }
.docs-content li { margin-bottom: 0.5rem; }
.docs-content ol { padding-left: 1.5rem; margin-bottom: 1rem; }

.toast { position: fixed; bottom: 20px; right: 20px; background: var(--bg-card); border-left: 4px solid var(--primary); padding: 1rem; border-radius: 4px; box-shadow: var(--shadow); transform: translateY(100px); transition: 0.3s; z-index: 200; display: flex; align-items: center; gap: 1rem; }
.toast.show { transform: translateY(0); }
.toast-success { border-color: var(--success); }
.toast-error { border-color: var(--danger); }

/* ===== Pagination ===== */
.pagination { display: flex; align-items: center; justify-content: center; gap: 0.3rem; margin-top: 2rem; flex-wrap: wrap; }
.page-btn { background: var(--bg-card); border: 1px solid var(--border); color: var(--text-main); padding: 0.4rem 0.8rem; border-radius: var(--radius); cursor: pointer; font-size: 0.85rem; transition: 0.15s; min-width: 2rem; text-align: center; }
.page-btn:hover { border-color: var(--primary); color: var(--primary); }
.page-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; pointer-events: none; }
.page-btn.disabled { opacity: 0.3; pointer-events: none; }
.page-dots { color: var(--text-muted); padding: 0 0.2rem; font-size: 0.9rem; user-select: none; }

/* Lazy image placeholder */
.lazy-img { background: var(--bg-card); min-height: 100%; }

/* ===== User Management ===== */
.user-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.user-table th { text-align: left; padding: 0.6rem 0.5rem; border-bottom: 2px solid var(--border); color: var(--text-muted); font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.5px; }
.user-table td { padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--border); }
.user-table tr:hover td { background: rgba(99,102,241,0.03); }
.user-actions { white-space: nowrap; }
#user-form select, .user-input { width: 100%; padding: 0.6rem; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-dark); color: var(--text-main); font-size: 0.9rem; outline: none; }
#user-form select:focus { border-color: var(--primary); }
@media (max-width: 600px) {
    .user-table th:nth-child(3), .user-table td:nth-child(3),
    .user-table th:nth-child(5), .user-table td:nth-child(5),
    .hide-mobile { display: none; }
    .user-table th:nth-child(4), .user-table td:nth-child(4) { display: none; }
}

/* Phone input with flag */
.phone-group { display: flex; gap: 0; align-items: stretch; }
.phone-country { padding: 0.5rem; border: 1px solid var(--border); border-right: none; border-radius: var(--radius) 0 0 var(--radius); background: var(--bg-dark); color: var(--text-main); font-size: 0.9rem; cursor: pointer; outline: none; min-width: 85px; }
.phone-country:focus { border-color: var(--primary); }
.phone-input { padding: 0.6rem; border: 1px solid var(--border); border-radius: 0 var(--radius) var(--radius) 0; background: var(--bg-dark); color: var(--text-main); font-size: 0.9rem; outline: none; width: 100%; }
.phone-input:focus { border-color: var(--primary); }

/* ===== Responsive ===== */

/* Tablette & mobile (< 768px) */
@media (max-width: 768px) {
    header { padding: 0.75rem 1rem; }
    .toolbar { padding: 0.75rem 1rem; }
    .gallery-container { padding: 1rem; }
    .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 1rem; }
    .modal-body { padding: 1rem; }

    .input-group { flex-wrap: wrap; }
    .input-group > * { border-radius: 0; }
    .input-group > :first-child { border-top-left-radius: var(--radius); border-top-right-radius: var(--radius); border-bottom-left-radius: 0; }
    .input-group > :last-child { border-bottom-left-radius: 0; }
    .search-box { flex: 1 1 100%; }
    .search-box input { border-bottom: none; }
    .ms { flex: 1; }
    .ms-trigger { border-bottom: none; }
    .ms-dropdown { border-top: none; }

    .detail-image-wrapper { min-height: 150px; }
    .upload-area { padding: 1.5rem; }
    .docs-content h1 { font-size: 1.2rem; }
    .docs-content h2 { font-size: 1rem; }
}

/* < 700px — ajustement du groupe bouton + ms */
@media (max-width: 700px) {
    .input-group { max-width: 100%; }
}

/* Mobile (< 480px) */
@media (max-width: 480px) {
    header { padding: 0.5rem 0.75rem; }
    .toolbar { padding: 0.5rem 0.75rem; }
    .gallery-container { padding: 0.75rem; }
    .gallery-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 0.75rem; }
    .brand { font-size: 1rem; }
    .user-menu { gap: 0.5rem; }

    .ms { flex: 1 1 100%; }
    .ms-trigger { border-bottom: 1px solid var(--border); }
    .input-group > :last-child { border-bottom-left-radius: var(--radius); border-bottom-right-radius: var(--radius); }
    .ms-dropdown { position: fixed; left: 0.5rem; right: 0.5rem; top: auto; max-height: 40vh; border-radius: var(--radius); border: 1px solid var(--border); box-shadow: var(--shadow); }

    .modal { width: 95%; }
    .modal-header { padding: 0.75rem 1rem; }
    .modal-body { padding: 0.75rem; }
    .modal-footer { padding: 0.75rem 1rem; }
    .login-card { padding: 1.5rem; }
    .preview-img { width: 80px; height: 80px; }
    .detail-image-wrapper { min-height: 120px; }

    .img-wrapper { height: 150px; }
    .img-title { font-size: 0.85rem; }

    .public-link-box { flex-direction: column; gap: 0.5rem; }
    .link-text { white-space: normal; margin-right: 0; }

    .toast { left: 10px; right: 10px; bottom: 10px; }
}

/* Appareils tactiles : overlay toujours visible */
@media (hover: none) {
    .overlay-actions { opacity: 1; background: linear-gradient(transparent 40%, rgba(0,0,0,0.85)); }
    .overlay-btn { font-size: 0.75rem; padding: 0.3rem 0.7rem; }
}

/* ===== Upload Queue ===== */
.upload-queue { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 0.75rem; margin-bottom: 1rem; }
.upload-queue-item { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; position: relative; transition: border-color 0.2s; }
.upload-queue-item:hover { border-color: var(--primary); }
.upload-queue-item .uq-thumb { width: 100%; height: 120px; object-fit: cover; display: block; background: #000; }
.upload-queue-item .uq-body { padding: 0.5rem; }
.upload-queue-item .uq-name-input { font-size: 0.75rem; width: 100%; background: transparent; border: 1px solid transparent; color: var(--text-main); padding: 0.1rem 0.2rem; border-radius: 3px; outline: none; box-sizing: border-box; }
.upload-queue-item .uq-name-input:focus { border-color: var(--primary); background: rgba(255,255,255,0.05); }
.upload-queue-item .uq-size { font-size: 0.7rem; color: var(--text-muted); }
.upload-queue-item .uq-actions { display: flex; gap: 0.2rem; padding: 0.3rem 0.5rem; border-top: 1px solid var(--border); }
.upload-queue-item .uq-actions button { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 0.2rem; font-size: 0.8rem; border-radius: 3px; transition: 0.15s; display: inline-flex; align-items: center; gap: 0.2rem; }
.upload-queue-item .uq-actions button:hover { background: rgba(255,255,255,0.1); color: var(--text-main); }
.upload-queue-item .uq-actions .uq-del:hover { color: var(--danger); }
.upload-queue-item .uq-status { position: absolute; top: 0.3rem; right: 0.3rem; font-size: 0.65rem; background: rgba(0,0,0,0.7); color: var(--text-muted); padding: 0.15rem 0.4rem; border-radius: 3px; }
.upload-queue-item.uq-done { border-color: var(--success); }
.upload-queue-item.uq-done .uq-status { color: var(--success); }
.upload-queue-item.uq-error { border-color: var(--danger); }
.upload-queue-item.uq-error .uq-status { color: var(--danger); }
.upload-queue-item.uq-processing { border-color: var(--primary); }
.upload-queue-item.uq-processing .uq-status { color: var(--primary); }


.upload-settings { background: rgba(255,255,255,0.03); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 0.5rem; }

/* ===== Progress Bar ===== */
.progress-track { width: 100%; height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.progress-bar { height: 100%; width: 0%; background: linear-gradient(90deg, var(--primary), #818cf8); border-radius: 3px; transition: width 0.3s ease; }

/* ===== Crop Modal ===== */
.crop-layout { display: flex; gap: 1rem; min-height: 350px; }
.crop-canvas-wrap { flex: 1; background: #000; border-radius: var(--radius); overflow: hidden; display: flex; align-items: center; justify-content: center; min-height: 300px; position: relative; border: 1px solid var(--border); }
.crop-canvas-wrap canvas { max-width: 100%; max-height: 55vh; cursor: crosshair; }
.crop-controls { width: 220px; flex-shrink: 0; display: flex; flex-direction: column; gap: 0.75rem; }
.crop-section { background: rgba(255,255,255,0.03); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem; }
.crop-inputs { display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem; }
.crop-inputs div label { display: block; font-size: 0.7rem; color: var(--text-muted); margin-bottom: 0.15rem; }
.crop-num { padding: 0.35rem; font-size: 0.8rem; width: 100%; }
.crop-preview { width: 100%; height: 100px; border-radius: 4px; border: 1px solid var(--border); background: #000; object-fit: contain; }

/* Crop overlay rectangle */
.crop-rect { position: absolute; border: 2px dashed var(--primary); background: rgba(99,102,241,0.15); cursor: move; pointer-events: auto; }
.crop-rect-handle { position: absolute; width: 10px; height: 10px; background: var(--primary); border: 2px solid #fff; border-radius: 50%; }
.crop-rect-handle.nw { top: -5px; left: -5px; cursor: nw-resize; }
.crop-rect-handle.ne { top: -5px; right: -5px; cursor: ne-resize; }
.crop-rect-handle.sw { bottom: -5px; left: -5px; cursor: sw-resize; }
.crop-rect-handle.se { bottom: -5px; right: -5px; cursor: se-resize; }

@media (max-width: 700px) {
    .crop-layout { flex-direction: column; }
    .crop-controls { width: 100%; flex-direction: row; flex-wrap: wrap; }
    .crop-section { flex: 1; min-width: 140px; }
    .upload-queue { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
}
