/**
 * Image Positioner CSS
 * Stili per il componente di riposizionamento immagini (Avatar & Cover)
 */

/* Body lock quando overlay è aperto */
body.ip-body-locked {
    overflow: hidden !important;
}

/* Overlay principale */
.image-positioner-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    box-sizing: border-box;
}

/* Backdrop semi-trasparente */
.ip-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

/* Container principale */
.image-positioner-container {
    position: relative;
    background: #1e1e2e;
    border-radius: 16px;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.5);
    max-width: 1100px;
    width: 100%;
    max-height: 92vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: ip-slideIn 0.3s ease-out;
}

@keyframes ip-slideIn {
    from {
        opacity: 0;
        transform: translateY(-30px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Header */
.ip-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.ip-title {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: #fff;
}

.ip-close-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    color: #8b8b9a;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ip-close-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

/* Image Wrapper */
.ip-image-wrapper {
    padding: 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Image Container */
.ip-image-container {
    position: relative;
    width: 100%;
    overflow: hidden;
    border-radius: 12px;
    cursor: grab;
    background: #0f0f17;
    border: 2px dashed rgba(255, 255, 255, 0.2);
    transition: border-color 0.3s ease;
}

.ip-image-container:hover {
    border-color: rgba(124, 77, 255, 0.5);
}

.ip-image-container.ip-dragging {
    cursor: grabbing;
    border-color: #7c4dff;
}

/* Dimensioni dinamiche per avatar e cover */
.ip-image-container[data-type="avatar"] {
    width: 200px;
    height: 200px;
    border-radius: 50%;
    margin: 0 auto;
}

.ip-image-container[data-type="cover"] {
    width: 100%;
    height: 0;               /* JS sets padding-bottom to enforce the real page ratio */
    padding-bottom: 40%;     /* fallback ~2.5:1 until JS measures the real element */
    border-radius: 8px;
}

/* Immagine nel modal — approccio puro transform: translate(tx%, ty%) scale(s)
   - position:absolute, top:0;left:0, width/height 100%, object-fit:cover
   - transform-origin: center center per zoom simmetrico
   - object-position fisso a 50% 50%: il posizionamento è tutto nel transform
   - UGUALE per avatar e cover nel modal (la pagina aggiunge calc(-50%+tx%) per la cover)
   - Risultato: anteprima 1:1, panning libero in entrambi gli assi */
.image-positioner-image {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: 50% 50%;
    transform-origin: center center;
    transform: translate(0%, 0%) scale(1);
    pointer-events: none;
    user-select: none;
    -webkit-user-drag: none;
    will-change: transform;
    transition: none; /* nessuna transizione durante il drag */
}

/* Griglia di allineamento */
.ip-grid {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    opacity: 0.3;
}

.ip-grid::before,
.ip-grid::after {
    content: '';
    position: absolute;
    background: rgba(255, 255, 255, 0.5);
}

/* Linee verticali */
.ip-grid::before {
    left: 33.33%;
    top: 0;
    width: 1px;
    height: 100%;
    box-shadow: calc(33.33% + 33.33% / 100 * 1px) 0 0 0 rgba(255, 255, 255, 0.5);
}

.ip-grid::after {
    left: 66.66%;
    top: 0;
    width: 1px;
    height: 100%;
}

/* Linee orizzontali via pseudo-element dell'image container */
.ip-image-container[data-type="cover"]::after {
    content: '';
    position: absolute;
    left: 0;
    top: 33.33%;
    width: 100%;
    height: 1px;
    background: rgba(255, 255, 255, 0.15);
    pointer-events: none;
    box-shadow: 0 calc(33.33%) 0 0 rgba(255, 255, 255, 0.15);
}

/* Hint text */
.ip-hint {
    margin: 15px 0 5px;
    font-size: 13px;
    color: #8b8b9a;
    text-align: center;
}

/* Controls */
.image-positioner-controls {
    padding: 16px 20px 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* Zoom controls */
.ip-zoom-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 16px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 10px;
}

.ip-zoom-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    color: #fff;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ip-zoom-btn:hover {
    background: rgba(124, 77, 255, 0.3);
}

.ip-zoom-btn:active {
    transform: scale(0.95);
}

/* Zoom slider */
.ip-zoom-slider-container {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
}

.ip-zoom-slider {
    flex: 1;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    outline: none;
    cursor: pointer;
}

.ip-zoom-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: #7c4dff;
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.ip-zoom-slider::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    box-shadow: 0 0 10px rgba(124, 77, 255, 0.5);
}

.ip-zoom-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: #7c4dff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
}

.ip-zoom-value {
    min-width: 45px;
    font-size: 13px;
    color: #8b8b9a;
    text-align: right;
}

/* Action buttons */
.ip-action-buttons {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.ip-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.ip-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.ip-btn-primary {
    background: linear-gradient(135deg, #7c4dff, #651fff);
    color: #fff;
    box-shadow: 0 4px 15px rgba(124, 77, 255, 0.3);
}

.ip-btn-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, #8e62ff, #7c4dff);
    box-shadow: 0 6px 20px rgba(124, 77, 255, 0.4);
    transform: translateY(-1px);
}

.ip-btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.ip-btn-secondary:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.15);
}

.ip-btn-reset {
    background: transparent;
    color: #8b8b9a;
    margin-right: auto;
}

.ip-btn-reset:hover:not(:disabled) {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

/* ==================================
   Position Trigger Buttons
   (Pulsante per aprire il positioner)
   ================================== */

.ip-edit-position-btn {
    position: absolute;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 7px 11px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: opacity 0.2s ease, background 0.2s ease;
    opacity: 0;
    z-index: 10;
    pointer-events: none;
    white-space: nowrap;
    width: auto;
    max-width: 140px;
}

.ip-edit-position-btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* ── Cover button: direct child of .artist_cover ── */
.artist_header .artist_cover > .ip-edit-position-btn.ip-cover-btn {
    bottom: 15px;
    left: 15px;
    right: auto;
    top: auto;
    z-index: 10;
}

/* ── Avatar button: direct child of .avatar_container ── */
.artist_user_info .avatar_container > .ip-edit-position-btn.ip-avatar-btn {
    bottom: -2px;
    left: -2px;
    right: auto;
    top: auto;
    width: 32px;
    height: 32px;
    max-width: 32px;
    padding: 6px;
    border-radius: 50%;
    justify-content: center;
    overflow: hidden;
    z-index: 100;
}

/* Mostra il pulsante al hover del container corretto */
.artist_header .artist_cover:hover > .ip-edit-position-btn,
.profile-cover:hover .ip-edit-position-btn,
.profile-avatar-wrapper:hover .ip-edit-position-btn,
.cover-image-wrapper:hover .ip-edit-position-btn,
.avatar-wrapper:hover .ip-edit-position-btn {
    opacity: 1;
    pointer-events: auto;
}

/* Avatar IP button: always visible at fixed bottom-left of circle */
.artist_user_info .avatar_container:hover > .ip-edit-position-btn,
.artist_user_info .avatar_container > .ip-edit-position-btn.ip-avatar-btn {
    opacity: 1;
    pointer-events: auto;
}

/* Container che devono avere position relative per i bottoni */
.artist_profile_cover {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
}

.ip-edit-position-btn:hover {
    background: rgba(124, 77, 255, 0.9);
    transform: scale(1.05);
}

/* Per avatar circolare */
.profile-avatar-wrapper .ip-edit-position-btn,
.avatar-wrapper .ip-edit-position-btn {
    bottom: 5px;
    right: 5px;
    padding: 6px 10px;
    border-radius: 20px;
}

/* Avatar button nel profilo artista (fallback generale) */
.ip-edit-position-btn.ip-avatar-btn {
    position: absolute;
    padding: 6px;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    max-width: 32px;
    justify-content: center;
    overflow: hidden;
    z-index: 100;
}

/* ==================================
   Applied Position Styles
   (Stili per immagini con posizione applicata)
   ================================== */

img[data-position-applied="true"] {
    object-fit: cover;
    transition: transform 0.3s ease;
}

/* -----------------------------------------------
   AVATAR: overflow hidden solo sul link/wrapper interno
   NON sul container intero (altrimenti taglia il bottone edit_cover a -2px)
------------------------------------------------ */
.artist_user_info .avatar_container > a {
    display: block;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    overflow: hidden;
}

.artist_user_info .avatar_container img {
    transform-origin: center center;
}

/* -----------------------------------------------
   COVER: la pagina usa top:50%;left:50% (tema) + il nostro transform.
   object-position rimane al 50% 50% di default (non usata per il posizionamento).
------------------------------------------------ */
.artist_header .artist_cover .artist_profile_cover img[data-position-applied] {
    transform-origin: center center;
    transition: transform 0.3s ease;
}

/* ==================================
   Responsive Design
   ================================== */

@media (max-width: 768px) {
    .image-positioner-overlay {
        padding: 10px;
    }
    
    .image-positioner-container {
        max-height: 95vh;
        border-radius: 12px;
    }
    
    .ip-header {
        padding: 12px 16px;
    }
    
    .ip-title {
        font-size: 16px;
    }
    
    .ip-image-wrapper {
        padding: 15px;
    }
    
    .ip-image-container[data-type="avatar"] {
        width: 220px;
        height: 220px;
    }
    
    .ip-image-container[data-type="cover"] {
        aspect-ratio: 3 / 1;
    }
    
    .image-positioner-controls {
        padding: 12px 16px 16px;
    }
    
    .ip-zoom-controls {
        padding: 8px 12px;
    }
    
    .ip-action-buttons {
        flex-wrap: wrap;
    }
    
    .ip-btn {
        padding: 10px 16px;
        flex: 1;
        min-width: 80px;
    }
    
    .ip-btn-reset {
        flex: 0 0 auto;
        margin-right: 0;
        order: 3;
        width: 100%;
        margin-top: 5px;
    }
}

@media (max-width: 480px) {
    .ip-image-container[data-type="avatar"] {
        width: 180px;
        height: 180px;
    }
    
    .ip-zoom-slider-container {
        display: none;
    }
    
    .ip-hint {
        font-size: 12px;
    }
}

/* ==================================
   Dark Mode Override (già default dark)
   ================================== */

/* Light mode se necessario */
body.light-mode .image-positioner-container,
body[data-theme="light"] .image-positioner-container {
    background: #fff;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.2);
}

body.light-mode .ip-header,
body[data-theme="light"] .ip-header {
    border-bottom-color: rgba(0, 0, 0, 0.1);
}

body.light-mode .ip-title,
body[data-theme="light"] .ip-title {
    color: #1a1a2e;
}

body.light-mode .ip-close-btn,
body[data-theme="light"] .ip-close-btn {
    color: #666;
}

body.light-mode .ip-close-btn:hover,
body[data-theme="light"] .ip-close-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: #1a1a2e;
}

body.light-mode .ip-image-container,
body[data-theme="light"] .ip-image-container {
    background: #f5f5f5;
    border-color: rgba(0, 0, 0, 0.1);
}

body.light-mode .ip-hint,
body[data-theme="light"] .ip-hint {
    color: #666;
}

body.light-mode .image-positioner-controls,
body[data-theme="light"] .image-positioner-controls {
    border-top-color: rgba(0, 0, 0, 0.1);
}

body.light-mode .ip-zoom-controls,
body[data-theme="light"] .ip-zoom-controls {
    background: rgba(0, 0, 0, 0.03);
}

body.light-mode .ip-zoom-btn,
body[data-theme="light"] .ip-zoom-btn {
    background: rgba(0, 0, 0, 0.05);
    color: #1a1a2e;
}

body.light-mode .ip-zoom-slider,
body[data-theme="light"] .ip-zoom-slider {
    background: rgba(0, 0, 0, 0.1);
}

body.light-mode .ip-zoom-value,
body[data-theme="light"] .ip-zoom-value {
    color: #666;
}

body.light-mode .ip-btn-secondary,
body[data-theme="light"] .ip-btn-secondary {
    background: rgba(0, 0, 0, 0.05);
    color: #1a1a2e;
}

body.light-mode .ip-btn-reset,
body[data-theme="light"] .ip-btn-reset {
    color: #666;
}
