/* MODULE
@module: MagentaDesignSystem
@path: public/css/magenta/magenta-responsive.css
@domain: styling, ui, design-system
@feature: magenta-responsive
@purpose: Responsive overrides for mobile devices and other media queries
@exports: Media query blocks
@consumes: CSS variables (--mg-*)
@touches: All Magenta UI components, layout
@owner: magenta-ui
@risk: MEDIUM
@tests: Responsive design
*/

/**
 * Magenta Design System - File 3/3 - Stili Responsive
 *
 * Contiene:
 * 8.  Stili Responsive (Media Queries)
 * ... e tutti gli altri blocchi @media per mobile e accessibilità
 */

/* ==========================================================================
   8. Stili Responsive (Media Queries)
   ========================================================================== */

/* Tablet & Smaller Desktops */
@media (max-height: 900px) {
    .mg-workspace--toolbar {
        --mg-workspace-toolbar-inset: var(--mg-space-lg);
    }
    :root {
        --mg-panel-width: 320px;
    }
    .mg-workspace {
        padding: var(--mg-space-lg);
    }
    .mg-canvas-container {
        max-width: 600px;
    }
}

/* Mobile - BLOCCO CONSOLIDATO */
@media (max-width: 768px) {
    .mg-customizer-logo {
        max-width: 120px;
    }

    /* --- Layout Mobile --- */
    .mg-sidebar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: var(--mg-bottom-bar-height);
        background: var(--mg-mobile-sidebar-bg); /* <-- MODIFICATO */
        box-shadow: 0 -2px 8px var(--mg-overlay-dark-medium); /* <-- MODIFICATO */
        z-index: 200;
        padding: 8px 0;
        border-top: 1px solid var(--mg-mobile-sidebar-border); /* <-- MODIFICATO */
    }
    .mg-sidebar .mg-sidebar__tabs {
        flex-direction: row;
        justify-content: space-around;
        align-items: center;
        width: 100%;
        height: 100%;
        padding: 0 16px;
        gap: 8px;
    }
    #mg-workspace-container {
        grid-column: 1 / -1;
        height: calc(100vh - var(--mg-header-height) - var(--mg-bottom-bar-height));
        overflow: hidden;
        bottom: 0;
    }
    .mg-workspace {
        justify-content: center;
        padding: 1rem 1rem calc(var(--mg-bottom-bar-height) + 90px) 1rem;
    }

    /* --- Pannello Mobile --- */
    #mg-panel-container, .mg-panel-container {
        top: var(--mg-header-height);
        left: 0;
        width: 100%;
        height: calc(100vh - var(--mg-header-height) - var(--mg-bottom-bar-height));
        z-index: 150;
        transform: translateY(100%);
        transition: transform var(--mg-transition-liquid);
        background: var(--mg-glass-radial);
        backdrop-filter: var(--mg-glass-blur);
        -webkit-backdrop-filter: var(--mg-glass-blur);
        box-shadow: 0 -8px 32px var(--mg-overlay-dark-strong), var(--mg-glass-inset-glow);
    }
    #mg-panel-container.active, .mg-panel-container.active {
        transform: translateY(0);
    }
    .mg-panel__header {
        display: flex;
        background: transparent;
        padding: 16px 20px;
        border-bottom: 1px solid var(--mg-panel-border-glow);
        position: sticky;
        top: 0;
        z-index: 10;
    }
    .mg-panel-container::before {
        content: '';
        position: absolute;
        top: 12px;
        left: 50%;
        transform: translateX(-50%);
        width: 48px;
        height: 5px;
        background: var(--mg-text-muted);
        opacity: 0.5;
        border-radius: var(--mg-radius-pill);
        z-index: 10;
    }

    /* --- Canvas Mobile --- */
    .mg-canvas-wrapper {
        width: 100%;
        justify-content: center;
        padding: 0;
    }
    .mg-canvas-container {
        width: auto;
        max-width: 400px;
        aspect-ratio: 4 / 4;
        flex-shrink: 1;
        min-height: 0;
        padding: var(--mg-space-sm);
        position: relative;
        top: -40px;
    }

    /* --- Mobile Tabs --- */
    .mg-tab {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 4px 8px;
        cursor: pointer;
        transition: all 0.3s ease;
        background: transparent;
        color: var(--mg-mobile-tab-color); /* <-- MODIFICATO */
        text-decoration: none;
        position: relative;
        border: none;
    }
    .mg-tab:hover {
        background: var(--mg-mobile-tab-hover-bg); /* <-- MODIFICATO */
        color: var(--mg-mobile-tab-hover-color); /* <-- MODIFICATO */
    }
    .mg-tab.active {
        background: var(--mg-mobile-tab-active-bg); /* <-- MODIFICATO */
        color: var(--mg-primary); /* <-- MODIFICATO */
    }
    .mg-tab.active::before {
        content: '';
        position: absolute;
        left: 50%;
        transform: translateX(-50%);
        top: 0;
        width: 40px;
        height: 3px;
        background: var(--mg-primary); /* <-- MODIFICATO */
        border-radius: 0 0 2px 2px;
    }
    .mg-tab__icon {
        width: 24px;
        height: 24px;
        margin-bottom: 4px;
        fill: currentColor;
    }
    .mg-tab__label {
        font-size: 11px;
        font-weight: 500;
        text-align: center;
    }

    /* --- Quick Actions Mobile --- */
    .mg-quick-actions {
        position: fixed;
        bottom: calc(var(--mg-bottom-bar-height) + 25px);
        right: 16px;
        left: 16px;
        width: auto;
        justify-content: center;
        z-index: 100;
        min-height: 56px;
        transform: none;
    }
    
    /* --- Color Picker Mobile --- */
    .mg-color-picker {
        position: fixed;
        bottom: calc(var(--mg-bottom-bar-height) + 100px);
        left: 50%;
        transform: translateX(-50%);
        max-width: calc(100vw - 32px);
        padding: 10px 12px;
        gap: 8px;
        flex-direction: row !important; /* Force horizontal on mobile too */
    }
    
    .mg-color-option {
        width: 40px;
        height: 40px;
    }
    
    /* --- Position Picker Mobile --- */
    .mg-position-picker {
        position: fixed;
        bottom: calc(var(--mg-bottom-bar-height) + 100px);
        left: 50%;
        transform: translateX(-50%);
        max-width: calc(100vw - 32px);
        padding: 10px 12px;
        gap: 6px;
        flex-direction: row !important; /* Force horizontal on mobile too */
    }
    
    .mg-position-option {
        width: 40px;
        height: 40px;
    }
    
    .mg-position-option svg {
        width: 24px;
        height: 24px;
    }
    
    .mg-quick-action {
        width: 56px;
        height: 56px;
        border-radius: 50% !important;
    }
    .mg-quick-action svg {
        width: 32px !important;
        height: 32px !important;
    }

    /* --- Remove Background Button Mobile --- */
    .mg-remove-background-btn {
        top: 16px;
        left: 12px;
        width: auto;
        height: 40px;
    }
    
    .mg-remove-background-btn svg {
        width: 18px;
        height: 18px;
    }
    
    /* Adjust position when variant switch button is present on mobile */
    .mg-variant-switch-btn ~ .mg-remove-background-btn,
    .mg-canvas-container:has(.mg-variant-switch-btn) .mg-remove-background-btn {
        left: 62px;
    }

    /* --- Loading Spinner Mobile --- */
    .mg-spinner-ring {
        width: 40px;
        height: 40px;
        border: 3px solid var(--mg-overlay-dark-medium);
        border-top: 3px solid var(--mg-primary);
    }

    /* --- Canvas Switch Buttons Mobile --- */
    .mg-canvas-switch-buttons {
        bottom: 12px;
        left: 12px;
    }
    
    .mg-canvas-switch-btn {
        width: 40px;
        height: 40px;
    }

    /* --- Component Hiding on Mobile --- 
    .mg-text-control-group .mg-text-control-label,
    .mg-text-control-group .mg-text-align-buttons {
        display: none !important;
    }*/

    /* --- Pickr Mobile --- */
    .mg-pickr-container .pcr-app {
        position: fixed !important;
        top: 50% !important;
        left: 50% !important;
        transform: translate(-50%, -50%) !important;
        width: 280px !important;
        max-width: 90vw !important;
        max-height: 80vh !important;
        z-index: 10000;
    }
    .mg-pickr-container .pcr-app .pcr-interaction .pcr-save,
    .mg-pickr-container .pcr-app .pcr-interaction .pcr-cancel,
    .mg-pickr-container .pcr-app .pcr-interaction .pcr-clear {
        padding: var(--mg-space-sm) var(--mg-space-md);
        font-size: 14px;
        min-height: 44px;
    }
    .mg-color-picker-open::before {
        content: '';
        position: fixed;
        inset: 0;
        background: var(--mg-overlay-backdrop); /* <-- MODIFICATO */
        z-index: 9998;
        display: block;
    }
    
    /* Responsive: Adjust positioning on mobile (from section 4) */
    .mg-design-actions-wrapper {
      top: 8px;
      right: 8px;
    }
    
    .mg-design-toggle {
      width: 40px;
      height: 40px;
    }
    
    .mg-design-strip__btn {
      width: 48px;
      height: 48px;
    }
    
    .mg-design-strip__btn svg {
      width: 26px;
      height: 26px;
    }
    
    .mg-help-toggle {
      width: 40px;
      height: 40px;
    }
    
    .mg-help-icon {
      width: 22px;
      height: 22px;
    }
    
    .mg-help-toggle {
      bottom: 12px !important;
      right: 12px !important;
    }
    
    /* Mobile: Hide text, show larger icons (from section 5) */
    .mg-btn--icon-only .mg-btn-text,
    .mg-btn--responsive-icon .mg-btn-text {
        display: none !important;
    }
    
    .mg-btn--icon-only .mg-btn-icon,
    .mg-btn--responsive-icon .mg-btn-icon {
        display: block !important;
        width: 22px;
        height: 22px;
    }
    
    .mg-btn--icon-only,
    .mg-btn--responsive-icon {
        padding: 0 !important;
        width: 44px !important;
        height: 44px !important;
        min-width: 44px !important;
        min-height: 44px !important;
        border-radius: 50% !important;
        display: flex !important;
        align-items: center;
        justify-content: center;
    }
    
    .mg-btn--icon-only .mg-btn-icon,
    .mg-btn--responsive-icon .mg-btn-icon {
        display: block !important;
        width: 24px !important;
        height: 24px !important;
        margin: 0 !important;
    }
    
    /* Enhanced mobile button states */
    .mg-btn--icon-only:active {
        transform: scale(0.92);
        transition-duration: 0.1s;
    }

    /* Mobile Responsive for Stage Selector (from section 9) */
    .mg-stage-tabs {
        padding: 2px;
        gap: 2px;
    }
    
    .mg-stage-tab {
        padding: 6px 12px;
        font-size: 13px;
        min-width: 60px;
    }
    
    .mg-header__center {
        flex: 1;
        margin: 0 12px;
    }

    /* === MOBILE: più altezza ai tab + pannelli che scrollano bene su iOS === */
    /* 1) Alza la barra dei tab in basso (se usi una bottom bar) */
    :root {
      /* se prima era 72px, portiamola a ~96px */
      --mg-bottom-bar-height: 96px;
    }

    /* 2) Pannelli scrollabili (AI/Upload): vera altezza e inerzia iOS */
    .mg-panel .mg-panel__body {
      min-height: 0;  /* fondamentale se il parent è flex/grid */
      height: calc(100vh - var(--mg-header-height, 60px) - var(--mg-bottom-bar-height, 96px));
      overflow-y: auto;
      -webkit-overflow-scrolling: touch;

      /* non far “cadere” gli ultimi item sotto i tab */
      padding-bottom: calc(var(--mg-bottom-bar-height, 96px) + env(safe-area-inset-bottom));
      /* fallback iOS vecchi */
      padding-bottom: calc(var(--mg-bottom-bar-height, 96px) + constant(safe-area-inset-bottom));

      /* comodo per anchor/scrollIntoView */
      scroll-padding-bottom: calc(var(--mg-bottom-bar-height, 96px) + env(safe-area-inset-bottom));
    }

    /* 3) “Spazio virtuale” in coda: permette di scrollare una riga in più
          anche quando il contenuto è al limite o quasi vuoto (AI senza immagini) */
    .mg-panel .mg-panel__body::after {
      content: "";
      display: block;
      height: 140px; /* ~una riga di card/thumbnail extra; regola a gusto (72–128px) */
      flex: 0 0 auto;
    }

    /* 4) Se i tab sono a sinistra (sidebar verticale), un po’ di margine extra non guasta */
    .mg-sidebar .mg-sidebar__tabs {
      padding-bottom: 24px; /* piccolo buffer in fondo */
    }

    /* Mobile strip positioning */
    .mg-design-strip {
      position: absolute;
      top: 90px;
      right: 0;
    }

    /* Responsive breakpoints for desktop/mobile actions */
    .mg-design-actions--desktop {
      display: none;
    }
    
    .mg-design-actions--mobile {
      display: flex;
    }
} /* Chiusura @media (max-width: 768px) CONSOLIDATO */


/* Small Mobile */
@media (max-width: 380px) {
    .mg-tab__label {
        font-size: 10px;
    }
    .mg-tab__icon {
        width: 20px;
        height: 20px;
    }
}

/* Landscape Mobile */
@media (max-width: 768px) and (orientation: landscape) {
    :root {
        --mg-bottom-bar-height: 60px;
    }
    .mg-tab__label {
        display: none;
    }
    .mg-tab {
        justify-content: center;
    }
    .mg-tab__icon {
        margin-bottom: 0;
    }
}

/* Larger Desktops */
@media (min-width: 1400px) {
    .mg-canvas-container {
        max-width: 900px;
    }
    .mg-workspace {
        max-width: none;
        width: 100%;
        margin-inline: 0;
    }
}

/* BLOCCO CONSOLIDATO */
@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
        animation: none !important;
    }

    /* (from section 9) */
    .mg-stage-tab,
    .mg-stage-loading::after {
        transition: none !important;
        animation: none !important;
    }
    
    .mg-stage-tab:hover {
        transform: none !important;
    }

    /* (from AI PANEL TOGGLE) */
    .mg-ai-mode-btn,
    .mg-ai-mode-container,
    .mg-ai-mode-interface,
    .mg-ai-source-container,
    .mg-ai-source-overlay,
    .mg-ai-source-change,
    .mg-gallery-item__actions,
    .mg-gallery-item__action {
        transition: none !important;
        animation: none !important;
    }
    
    .mg-ai-source-change:hover,
    .mg-gallery-item__action:hover {
        transform: none !important;
    }
}

/* High Contrast Mode for Accessibility (from section 9) */
@media (prefers-contrast: high) {
    .mg-stage-tab {
        border-width: 2px;
    }
    
    .mg-stage-tab--active {
        border-width: 2px;
        box-shadow: 0 0 0 2px var(--mg-primary-overlay-backdrop); /* <-- MODIFICATO */
    }
}


/* ✅ RESPONSIVE: Mobile optimizations for toggle (from AI PANEL TOGGLE) */
@media (max-width: 480px) {
    .mg-ai-mode-btn {
        padding: 10px 8px;
        font-size: 13px;
    }
    
    .mg-ai-mode-text {
        font-size: 13px;
    }
    
    .mg-ai-mode-icon {
        font-size: 14px;
        display: none;
    }
    
    .mg-ai-source-container {
        min-height: 100px;
    }
    
    .mg-ai-source-image {
        height: 100px;
    }
    
    .mg-gallery-item__action {
        width: 20px;
        height: 20px;
        font-size: 10px;
    }
}


/* ==========================================================================
   🎨 DESIGN ACTIONS HEADER - Mobile Specific Styles
   ========================================================================== */

/* Mobile actions wrapper (toggle + strip) */
.mg-design-actions--mobile {
  display: none;
  position: relative;
}

/* Toggle icon animations */
.mg-design-toggle__icon {
  transition: all 0.2s;
}

.mg-design-toggle__icon--close {
  display: none;
  position: absolute;
}

.mg-design-toggle.active .mg-design-toggle__icon--menu {
  display: none;
}

.mg-design-toggle.active .mg-design-toggle__icon--close {
  display: block;
}

/* Responsive breakpoints for desktop/mobile actions */
@media (min-width: 769px) {
  .mg-design-actions--mobile {
    display: none !important;
  }
  
  .mg-design-actions--desktop {
    display: flex;
  }
}
/* Bundle header: constrain long product names without pushing header controls. */
.mg-header__center--bundle {
    min-width: 0;
}

.mg-bundle-product-badge {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
    padding: 4px 12px;
    border: 1px solid rgba(0, 0, 0, .05);
    border-radius: 8px;
    background: rgba(255, 255, 255, .05);
    font-family: var(--mg-font-family, system-ui, sans-serif);
    text-align: center;
}

.mg-bundle-product-badge__eyebrow {
    font-size: .65rem;
    line-height: 1;
    letter-spacing: .08em;
    text-transform: uppercase;
    opacity: .7;
}

.mg-bundle-product-badge__name {
    display: block;
    max-width: 100%;
    overflow: hidden;
    color: var(--mg-color-primary, #3b82f6);
    font-size: .9rem;
    font-weight: 700;
    line-height: 1.2;
    white-space: nowrap;
}

@media (max-width: 768px) {
    .mg-bundle-product-badge--hide-name .mg-bundle-product-badge__name {
        display: none;
    }
}

.mg-bundle-side-notice {
    font-size: .7rem;
    line-height: 1.2;
}

@media (max-width: 768px) {
    .mg-header__center--bundle {
        margin-inline: 6px;
    }

    .mg-bundle-product-badge {
        max-width: min(38vw, 180px);
        padding: 2px 4px;
        border: 0;
        border-radius: 0;
        background: transparent;
    }

    .mg-bundle-product-badge__name {
        font-size: .75rem;
        line-height: 1.2;
    }

    .mg-bundle-product-badge__eyebrow,
    .mg-bundle-side-notice:not(.mg-bundle-side-notice--error) {
        display: none;
    }
}

/* Compact workspace chrome: keep the side selector on the canvas. */
@media (max-width: 768px) {
    /* The actual sidebar is fixed to the viewport bottom. Remove its desktop
       grid wrapper so its unused first-column box cannot peek above workspace. */
    #mg-sidebar-container {
        display: contents;
    }

    .mg-workspace--toolbar {
        --mg-workspace-toolbar-inset: 1rem;
        padding-top: 0;
    }
    .mg-workspace--toolbar .mg-canvas-container {
        top: 0;
    }
    .mg-workspace-toolbar {
        margin-bottom: 4px;
    }
    .mg-workspace-toolbar .mg-workspace-control-label {
        font-size: 11px;
    }
    .mg-workspace-toolbar .mg-design-actions-wrapper {
        top: auto;
        right: auto;
        gap: 6px;
    }
    .mg-workspace--toolbar .mg-quick-actions-bar {
        gap: 6px;
        padding: 8px;
    }
    .mg-workspace--toolbar .mg-quick-action {
        width: 52px;
        height: 52px;
        touch-action: manipulation;
    }
}
