/* ===== BASE LAYOUT ===== */

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    margin: 0;
    padding: 0;
    background: #f3f4f6;
    color: #111827;
}

/* contenitore a 3 colonne */
#app {
    display: flex;
    flex-direction: row;
    min-height: 100vh;
}

/* ordine di default (desktop) */
.sidebar {
    order: 0;
}

.main {
    order: 0;
}

.gallery-panel {
    order: 0;
}

.sidebar {
    width: 360px;
    background: #ffffff;
    border-right: 1px solid #e5e7eb;
    padding: 16px;
    box-sizing: border-box;
    overflow-y: auto;
}

h1 {
    font-size: 20px;
    margin: 0 0 4px;
}

.subtitle {
    font-size: 12px;
    color: #6b7280;
    margin-bottom: 12px;
}

.section-title {
    margin-top: 12px;
    margin-bottom: 4px;
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: #4b5563;
}

/* ===== CARNAGIONE: gallery orizzontale (usa variant-gallery--colors) ===== */

.skin-gallery {
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    overflow-x: auto;
    padding: 2px 0 10px;
}

.skin-gallery::-webkit-scrollbar {
    height: 6px;
}

.skin-gallery::-webkit-scrollbar-track {
    background: #e5e7eb;
    border-radius: 999px;
}

.skin-gallery::-webkit-scrollbar-thumb {
    background: #9ca3af;
    border-radius: 999px;
}

.skin-thumb {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    border: 1px solid #d1d5db;
    background: #f9fafb;
    padding: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-sizing: border-box;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, transform 0.05s ease;
}

.skin-thumb img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 6px;
}

.skin-thumb:hover {
    border-color: #9ca3af;
    background: #eef2ff;
}

.skin-thumb.selected {
    border-color: #2563eb;
    background: #eff6ff;
    box-shadow: 0 0 0 2px rgba(37,99,235,0.35);
    transform: translateY(-1px);
}

/* ===== CONTROLLI FORM ===== */

.control-group {
    padding: 6px 0;
    border-bottom: 1px solid #e5e7eb;
    margin-bottom: 6px;
}

.control-group label {
    font-size: 13px;
    font-weight: 600;
    display: block;
    margin-bottom: 4px;
}

/* ===== LAYOUT MAIN / AVATAR ===== */

.main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    box-sizing: border-box;
}

.avatar-wrapper {
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.08);
    padding: 16px;
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
}

#avatarCanvas {
    width: 320px;
    height: 320px;
    border-radius: 12px;
    background: #e5e7eb;
}

.buttons {
    display: flex;
    gap: 8px;
}

button {
    padding: 6px 12px;
    border-radius: 999px;
    border: none;
    cursor: pointer;
    font-size: 13px;
}

.btn-primary {
    background: #2563eb;
    color: white;
}

.btn-secondary {
    background: #e5e7eb;
    color: #111827;
}

/* ===== GALLERIA AVATAR SALVATI ===== */

.gallery-panel {
    width: 260px;
    background: #f9fafb;
    border-left: 1px solid #e5e7eb;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}

.gallery-header {
    padding: 10px 12px;
    border-bottom: 1px solid #e5e7eb;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.gallery-header-title {
    display: flex;
    flex-direction: column;
}

.gallery-header-title h2 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
}

.gallery-header-title span {
    font-size: 11px;
    color: #6b7280;
}

.gallery-header-actions {
    flex-shrink: 0;
}

.btn-danger-sm {
    background: #dc2626;
    color: #f9fafb;
    border: none;
    border-radius: 999px;
    padding: 4px 8px;
    font-size: 11px;
    cursor: pointer;
}

.btn-danger-sm:hover {
    background: #b91c1c;
}

.gallery-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
    box-sizing: border-box;
}

.gallery-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px;
    margin-bottom: 6px;
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}

.gallery-item:hover {
    background: #e5f0ff;
    transform: translateY(-1px);
}

.gallery-thumb {
    width: 64px;
    height: 64px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
}

.gallery-meta {
    flex: 1;
}

.gallery-meta .gallery-name {
    font-size: 12px;
    font-weight: 600;
    color: #111827;
    margin-bottom: 2px;
}

.gallery-meta .gallery-date {
    font-size: 11px;
    color: #6b7280;
}

.gallery-delete-btn {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 20px;
    height: 20px;
    border-radius: 999px;
    border: none;
    background: rgba(15,23,42,0.85);
    color: #f9fafb;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1;
}

.gallery-delete-btn:hover {
    background: #b91c1c;
}

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

.lightbox.hidden {
    display: none;
}

.lightbox {
    position: fixed;
    inset: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.75);
}

.lightbox-content {
    position: relative;
    z-index: 1;
    background: #0b1120;
    padding: 12px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 20px 40px rgba(0,0,0,0.50);
}

.lightbox-image {
    max-width: 70vw;
    max-height: 80vh;
    border-radius: 12px;
    background: #020617;
}

.lightbox-btn {
    background: rgba(15,23,42,0.85);
    border: none;
    color: #e5e7eb;
    width: 32px;
    height: 32px;
    border-radius: 999px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.lightbox-btn:hover {
    background: rgba(30,64,175,0.9);
}

.lightbox-close {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 28px;
    height: 28px;
    font-size: 18px;
}

/* ===== FISARMONICA / HEADER ELEMENTI ===== */

.accordion-item:last-child {
    border-bottom: none;
}

.accordion-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 6px;
    background: #f3f4f6;
}

.accordion-item.open .accordion-header {
    background: #e5e7eb;
}

.accordion-title {
    font-size: 13px;
    font-weight: 600;
    color: #111827;
}

.accordion-actions {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.accordion-toggle {
    font-size: 12px;
    color: #6b7280;
    transition: transform 0.15s ease;
}

.accordion-item.open .accordion-toggle {
    transform: rotate(180deg);
}

/* con Vue gestiamo l'apertura chiudendo via classe .open */
.accordion-body {
    display: none;
    padding: 0;
    margin-top: 0;
}

.accordion-item.open .accordion-body {
    display: block;
    padding: 4px 0 6px;
    margin-top: 4px;
}

/* lock / hide nel titolo */
.lock-label,
.hide-label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: #6b7280;
    cursor: pointer;
}

.lock-label input[type="checkbox"],
.hide-label input[type="checkbox"] {
    width: 12px;
    height: 12px;
    margin: 0;
}

.lock-label svg,
.hide-label svg {
    width: 14px;
    height: 14px;
}

.icon-only {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* ===== GENDER BUTTONS ===== */

.gender-options {
    display: flex;
    gap: 6px;
    margin-top: 2px;
}

.gender-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 6px 4px;
    border-radius: 999px;
    border: 1px solid #d1d5db;
    background: #f9fafb;
    font-size: 11px;
    color: #111827;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease, box-shadow 0.1s ease;
    box-shadow: 0 0 0 rgba(0,0,0,0);
}

.gender-btn .gender-icon {
    font-size: 16px;
    line-height: 1;
}

.gender-btn .gender-label {
    font-size: 11px;
}

.gender-btn:hover {
    background: #eef2ff;
    border-color: #9ca3af;
}

.gender-btn.selected {
    background: #dbeafe;
    border-color: #2563eb;
    color: #1d4ed8;
    box-shadow: 0 1px 3px rgba(37,99,235,0.35);
    transform: translateY(-1px);
}

/* ===== GALLERIE VARIANTI (tutte le parti ≠ gender) ===== */

.variant-gallery {
    display: flex;
    flex-wrap: nowrap;
    gap: 8px;
    overflow-x: auto;
    padding: 2px 0;
}

.variant-gallery::-webkit-scrollbar {
    height: 6px;
}

.variant-gallery::-webkit-scrollbar-track {
    background: #e5e7eb;
    border-radius: 999px;
}

.variant-gallery::-webkit-scrollbar-thumb {
    background: #9ca3af;
    border-radius: 999px;
}

.variant-thumb {
    flex: 0 0 auto;
    width: 150px;
    height: 150px;
    border-radius: 12px;
    border: 1px solid #d1d5db;
    background: #f9fafb;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-sizing: border-box;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, transform 0.05s ease;
}

.variant-thumb img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 8px;
}

.variant-thumb:hover {
    border-color: #9ca3af;
    background: #eef2ff;
}

.variant-thumb.selected {
    border-color: #2563eb;
    background: #eff6ff;
    box-shadow: 0 0 0 2px rgba(37,99,235,0.35);
    transform: translateY(-1px);
}

/* ===== GALLERY COLORI (carnagione / capelli) ===== */

.variant-gallery--colors {
    padding-bottom: 4px;
}

.variant-gallery--colors .variant-thumb {
    width: 50px;   /* quadrati 50x50 come richiesto */
    height: 50px;
    padding: 2px;
    border-radius: 10px;
}

.variant-gallery--colors .variant-thumb img {
    border-radius: 8px;
    object-fit: cover;
}

/* ===== PREVIEW CAPELLI COMPOSTI (A+B+C) ===== */

.hair-thumb-preview {
    position: relative;
    width: 100%;
    height: 100%;
}

.hair-thumb-layer {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: 8px;
}

/* ===== RESPONSIVE ===== */

/* Tablet e sotto: nascondi galleria avatar salvati per fare spazio */
@media (max-width: 1024px) {
    .gallery-panel {
        display: none;
    }
}

/* Smartphone: anteprima in alto, form sotto che scorre */
@media (max-width: 768px) {
    #app {
        flex-direction: column;
        height: 100vh;
        overflow: hidden; /* niente scroll della pagina, solo della sidebar */
    }

    .main,
    .sidebar {
        width: 100%;
    }

    .main {
        order: 0;
        flex: 0 0 auto;
        padding: 12px;
        justify-content: center;
    }

    .sidebar {
        order: 1;
        flex: 1 1 auto;
        border-right: none;
        border-top: 1px solid #e5e7eb;
        padding: 12px 16px;
        overflow-y: auto;
    }

    #avatarCanvas {
        width: 260px;
        height: 260px;
    }
}
