/**
 * VeeStudio Elementor Toggle - Frontend CSS
 * 
 * @package VeeStudio\ElementorToggle
 * @version 1.0.0
 */

/* ==========================================================================
   CSS Variables
   ========================================================================== */

:root {
    /* Durata animazioni */
    --vtg-duration: 280ms;
    --vtg-duration-fast: 150ms;
    --vtg-duration-slow: 400ms;
    
    /* Easing */
    --vtg-easing: ease-in-out;
    --vtg-easing-bounce: cubic-bezier(0.68, -0.55, 0.265, 1.55);
    --vtg-easing-material: cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Overlay */
    --vtg-overlay-bg: 0.5;
    --vtg-overlay-color: rgba(0, 0, 0, var(--vtg-overlay-bg));
    --vtg-overlay-zindex: 999;
    
    /* Container */
    --vtg-container-zindex: 1000;
    
    /* Focus */
    --vtg-focus-outline: 2px solid #005cee;
    --vtg-focus-outline-offset: 2px;
    --vtg-focus-shadow: 0 0 0 3px rgba(0, 92, 238, 0.1);
}

/* Supporto per prefers-reduced-motion */
@media (prefers-reduced-motion: reduce) {
    :root {
        --vtg-duration: 100ms;
        --vtg-duration-fast: 50ms;
        --vtg-duration-slow: 150ms;
    }
}

/* ==========================================================================
   Container Base Styles
   ========================================================================== */

.vtg-container {
    /* Base reset */
    box-sizing: border-box;
    
    /* Transizioni di base (saranno override dalle animazioni JS) */
    transition: 
        opacity var(--vtg-duration) var(--vtg-easing),
        visibility var(--vtg-duration) var(--vtg-easing),
        transform var(--vtg-duration) var(--vtg-easing);
}

/* Stati del container - PIÙ SPECIFICI per override */
body .vtg-container[data-vtg-state="hidden"] {
    display: none !important;
}

body .vtg-container[data-vtg-state="shown"] {
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
}

/* Container senza stato definito - nascosti per default */
.vtg-container:not([data-vtg-state]) {
    display: none !important;
}

/* Nel frontend, i container toggle partono nascosti finché JS non li inizializza */
body:not(.elementor-editor-active) .vtg-container[data-vtg-group]:not([data-vtg-state]) {
    display: none !important;
}

/* Nell'editor Elementor, mostra sempre i container per editing */
.elementor-editor-active .vtg-container[data-vtg-state="hidden"] {
    display: block !important;
    opacity: 0.5;
    outline: 2px dashed #ff6b6b;
    outline-offset: 2px;
}

.elementor-editor-active .vtg-container[data-vtg-state="shown"] {
    display: block !important;
    opacity: 1;
    outline: 2px dashed #51cf66;
    outline-offset: 2px;
}

/* Stato durante animazione */
.vtg-container.vtg-animating {
    pointer-events: none;
}

/* ==========================================================================
   Toggle Button Styles
   ========================================================================== */

.vtg-toggle {
    /* Reset button default styles */
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    font: inherit;
    color: inherit;
    cursor: pointer;
    
    /* Layout */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    
    /* Interazione */
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    
    /* Transizioni */
    transition: 
        background-color var(--vtg-duration-fast) var(--vtg-easing),
        border-color var(--vtg-duration-fast) var(--vtg-easing),
        color var(--vtg-duration-fast) var(--vtg-easing),
        transform var(--vtg-duration-fast) var(--vtg-easing);
}

/* Contenuto del toggle */
.vtg-toggle-content {
    display: flex;
    align-items: center;
    justify-content: center;
}

.vtg-toggle-content-horizontal {
    flex-direction: row;
}

.vtg-toggle-content-vertical {
    flex-direction: column;
}

/* Stati del toggle */
.vtg-toggle:hover {
    transform: translateY(-1px);
}

.vtg-toggle:active {
    transform: translateY(0);
}

.vtg-toggle:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

/* Focus styles per accessibilità */
.vtg-toggle:focus {
    outline: none;
}

.vtg-toggle:focus-visible {
    outline: var(--vtg-focus-outline);
    outline-offset: var(--vtg-focus-outline-offset);
    box-shadow: var(--vtg-focus-shadow);
}

/* Supporto per browser che non supportano :focus-visible */
.vtg-toggle:focus:not(:focus-visible) {
    outline: none;
    box-shadow: none;
}

/* ==========================================================================
   Toggle Icon Styles
   ========================================================================== */

.vtg-toggle-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    
    /* Transizioni per cambio icona */
    transition: 
        opacity var(--vtg-duration-fast) var(--vtg-easing),
        transform var(--vtg-duration-fast) var(--vtg-easing);
}

.vtg-toggle-icon svg {
    display: block;
    width: 1em;
    height: 1em;
    fill: currentColor;
}

/* Animazione per cambio icona */
.vtg-toggle-icon-closed,
.vtg-toggle-icon-open {
    position: relative;
}

.vtg-toggle[data-vtg-sync="true"] .vtg-toggle-icon-closed,
.vtg-toggle[data-vtg-sync="true"] .vtg-toggle-icon-open {
    transition: 
        opacity var(--vtg-duration-fast) var(--vtg-easing),
        transform var(--vtg-duration-fast) var(--vtg-easing) calc(var(--vtg-duration-fast) * 0.5);
}

/* Stati delle icone durante il toggle */
.vtg-toggle.vtg-toggle-open .vtg-toggle-icon-closed {
    opacity: 0;
    transform: rotate(90deg) scale(0.8);
}

.vtg-toggle.vtg-toggle-open .vtg-toggle-icon-open {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

.vtg-toggle:not(.vtg-toggle-open) .vtg-toggle-icon-closed {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

.vtg-toggle:not(.vtg-toggle-open) .vtg-toggle-icon-open {
    opacity: 0;
    transform: rotate(-90deg) scale(0.8);
}

/* ==========================================================================
   Toggle Label Styles
   ========================================================================== */

.vtg-toggle-label {
    display: inline-block;
    
    /* Transizioni */
    transition: 
        opacity var(--vtg-duration-fast) var(--vtg-easing),
        transform var(--vtg-duration-fast) var(--vtg-easing);
}

/* Stati delle label durante il toggle */
.vtg-toggle.vtg-toggle-open .vtg-toggle-label-closed {
    opacity: 0;
    transform: translateY(-2px);
}

.vtg-toggle.vtg-toggle-open .vtg-toggle-label-open {
    opacity: 1;
    transform: translateY(0);
}

.vtg-toggle:not(.vtg-toggle-open) .vtg-toggle-label-closed {
    opacity: 1;
    transform: translateY(0);
}

.vtg-toggle:not(.vtg-toggle-open) .vtg-toggle-label-open {
    opacity: 0;
    transform: translateY(2px);
}

/* Posizioni label */
.vtg-toggle[data-label-position="before"] .vtg-toggle-content,
.vtg-toggle[data-label-position="after"] .vtg-toggle-content {
    flex-direction: row;
    gap: 0.5em;
}

.vtg-toggle[data-label-position="above"] .vtg-toggle-content,
.vtg-toggle[data-label-position="below"] .vtg-toggle-content {
    flex-direction: column;
    gap: 0.25em;
}

.vtg-toggle[data-label-position="before"] .vtg-toggle-content {
    flex-direction: row-reverse;
}

.vtg-toggle[data-label-position="above"] .vtg-toggle-content {
    flex-direction: column-reverse;
}

/* ==========================================================================
   Overlay Styles
   ========================================================================== */

.vtg-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--vtg-overlay-color);
    z-index: var(--vtg-overlay-zindex);
    
    /* Transizioni */
    transition: opacity var(--vtg-duration) var(--vtg-easing);
    
    /* Inizialmente nascosto */
    opacity: 0;
    pointer-events: auto;
    cursor: pointer;
}

.vtg-overlay.vtg-overlay-visible {
    opacity: 1;
}

/* ==========================================================================
   Body Scroll Lock
   ========================================================================== */

html.vtg-body-locked,
body.vtg-body-locked {
    overflow: hidden;
    position: fixed;
    width: 100%;
    height: 100%;
}

/* Prevenire layout shift su mobile */
@media (max-width: 768px) {
    html.vtg-body-locked,
    body.vtg-body-locked {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }
}

/* ==========================================================================
   Focus Trap Styles
   ========================================================================== */

.vtg-focus-trapped {
    /* Stili per container con focus trap attivo */
}

.vtg-focus-trapped *:focus {
    outline: var(--vtg-focus-outline);
    outline-offset: var(--vtg-focus-outline-offset);
}

/* ==========================================================================
   Animation Utilities
   ========================================================================== */

/* Classe helper per disabilitare transizioni durante setup */
.vtg-no-transition,
.vtg-no-transition * {
    transition: none !important;
    animation: none !important;
}

/* Classe helper per elementi in animazione */
.vtg-animating {
    pointer-events: none;
}

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

/* Nascondi su mobile */
@media (max-width: 767px) {
    .vtg-hide-mobile {
        display: none !important;
    }
}

/* Nascondi su tablet */
@media (min-width: 768px) and (max-width: 1024px) {
    .vtg-hide-tablet {
        display: none !important;
    }
}

/* Nascondi su desktop */
@media (min-width: 1025px) {
    .vtg-hide-desktop {
        display: none !important;
    }
}

/* ==========================================================================
   Accessibilità
   ========================================================================== */

/* Screen reader only */
.vtg-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .vtg-toggle:focus-visible {
        outline: 3px solid;
        outline-offset: 2px;
    }
    
    .vtg-overlay {
        background: rgba(0, 0, 0, 0.8);
    }
}

/* ==========================================================================
   Print Styles
   ========================================================================== */

@media print {
    .vtg-toggle,
    .vtg-overlay {
        display: none !important;
    }
    
    .vtg-container[data-vtg-state="hidden"] {
        display: block !important;
        opacity: 1 !important;
        visibility: visible !important;
    }
}

/* ==========================================================================
   Dark Mode Support
   ========================================================================== */

@media (prefers-color-scheme: dark) {
    :root {
        --vtg-focus-outline: 2px solid #66b3ff;
        --vtg-focus-shadow: 0 0 0 3px rgba(102, 179, 255, 0.1);
    }
}

/* ==========================================================================
   RTL Support
   ========================================================================== */

[dir="rtl"] .vtg-toggle[data-label-position="before"] .vtg-toggle-content {
    flex-direction: row;
}

[dir="rtl"] .vtg-toggle[data-label-position="after"] .vtg-toggle-content {
    flex-direction: row-reverse;
}

/* ==========================================================================
   Elementor Editor Compatibility
   ========================================================================== */

/* Stili per l'editor di Elementor */
.elementor-editor-active .vtg-container[data-vtg-state="hidden"] {
    display: block !important;
    opacity: 0.5 !important;
    visibility: visible !important;
}

/* ==========================================================================
   VeeToggle Widget - STANDARD ELEMENTOR
   ========================================================================== */

/* Wrapper del toggle */
.vtg-toggle-wrapper {
    /* Nessuno stile di default - lascia che i controlli Elementor gestiscano tutto */
}

/* Button base */
.vtg-toggle {
    /* Reset minimi */
    background: none;
    border: none;
    margin: 0;
    padding: 0;
    
    /* Layout base */
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    
    /* Eredita font dal parent */
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    
    /* Transizioni smooth */
    transition: all 0.3s ease;
}

/* Contenuto del button */
.vtg-toggle-content {
    display: flex;
    align-items: center;
    gap: 0.5em;
}

.vtg-toggle-content-vertical {
    flex-direction: column;
    gap: 0.25em;
}

.vtg-toggle[data-label-position="before"] .vtg-toggle-content {
    flex-direction: row-reverse;
}

.vtg-toggle[data-label-position="above"] .vtg-toggle-content {
    flex-direction: column-reverse;
}

/* Icone */
.vtg-toggle-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.vtg-toggle-icon svg {
    width: 1em;
    height: 1em;
    fill: currentColor;
}

/* Label */
.vtg-toggle-label {
    line-height: 1.2;
}

/* Stati sincronizzati */
.vtg-toggle.vtg-toggle-open .vtg-toggle-icon-closed {
    display: none;
}

.vtg-toggle.vtg-toggle-open .vtg-toggle-icon-open {
    display: inline-flex;
}

.vtg-toggle:not(.vtg-toggle-open) .vtg-toggle-icon-closed {
    display: inline-flex;
}

.vtg-toggle:not(.vtg-toggle-open) .vtg-toggle-icon-open {
    display: none;
}

.vtg-toggle.vtg-toggle-open .vtg-toggle-label-closed {
    display: none;
}

.vtg-toggle.vtg-toggle-open .vtg-toggle-label-open {
    display: inline-block;
}

.vtg-toggle:not(.vtg-toggle-open) .vtg-toggle-label-closed {
    display: inline-block;
}

.vtg-toggle:not(.vtg-toggle-open) .vtg-toggle-label-open {
    display: none;
}

.elementor-editor-active .vtg-container::before {
    content: "VeeToggle Container (Hidden)";
    display: block;
    padding: 8px;
    background: #f0f0f0;
    border: 1px dashed #ccc;
    font-size: 12px;
    color: #666;
    text-align: center;
}

.elementor-editor-active .vtg-container[data-vtg-state="shown"]::before {
    content: "VeeToggle Container (Shown)";
    background: #e8f5e8;
    border-color: #4caf50;
    color: #2e7d2e;
}

/* Previeni interazioni nell'editor */
.elementor-editor-active .vtg-toggle {
    pointer-events: none;
}

/* ==========================================================================
   Performance Optimizations
   ========================================================================== */

/* GPU acceleration per animazioni smooth */
.vtg-container,
.vtg-toggle-icon,
.vtg-toggle-label,
.vtg-overlay {
    will-change: auto;
}

.vtg-container.vtg-animating,
.vtg-toggle.vtg-toggle-transitioning .vtg-toggle-icon,
.vtg-toggle.vtg-toggle-transitioning .vtg-toggle-label,
.vtg-overlay.vtg-overlay-transitioning {
    will-change: transform, opacity;
}

/* Contenimento per migliorare performance */
.vtg-container {
    contain: layout style;
}

/* ==========================================================================
   Debugging Utilities (rimuovere in produzione)
   ========================================================================== */

.vtg-debug .vtg-container {
    outline: 2px solid red;
}

.vtg-debug .vtg-toggle {
    outline: 2px solid blue;
}

.vtg-debug .vtg-overlay {
    outline: 2px solid green;
}
