/* =========================================
   STENCIL AR - FRONTEND CSS CLEAN REWRITE
   ========================================= */

/* CSS Variables - Clean Color System */
.stencil-ar-app {
    /* Primary Colors */
    --ar-primary: #818cf8;
    --ar-primary-dark: #6366f1;
    --ar-primary-light: #a5b4fc;
    --ar-secondary: #fbbf24;
    --ar-success: #34d399;
    --ar-danger: #f87171;

    /* Background Colors */
    --ar-bg-primary: #1a1a1a;
    --ar-bg-secondary: #262626;
    --ar-bg-tertiary: #333333;
    --ar-bg-light: #ffffff;
    --ar-bg-light-alt: #f8f9fa;

    /* Text Colors - Fixed for dark theme */
    --ar-text-primary: #ffffff;        /* White text for dark backgrounds */
    --ar-text-secondary: #d1d5db;      /* Light gray for dark backgrounds */
    --ar-text-muted: #9ca3af;
    --ar-text-dark: #1a1a1a;           /* Dark text for light backgrounds */
    --ar-text-dark-secondary: #6b7280;

    /* Border and Shadow */
    --ar-border: #e5e7eb;
    --ar-border-dark: #404040;
    --ar-shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --ar-shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --ar-shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
    --ar-shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1);

    /* Border Radius */
    --ar-radius-sm: 0.375rem;
    --ar-radius-md: 0.5rem;
    --ar-radius-lg: 0.75rem;
    --ar-radius-xl: 1rem;

    /* Transitions */
    --ar-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);

    /* Base Styles */
    position: relative;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    color: var(--ar-text-primary);
    line-height: 1.6;
    background: var(--ar-bg-primary);
}

.stencil-ar-app * {
    box-sizing: border-box;
}

/* =========================================
   HERO SECTION
   ========================================= */

.ar-hero-section {
    text-align: center;
    padding: 2rem 1rem;
    background: linear-gradient(135deg, var(--ar-bg-primary) 0%, var(--ar-bg-secondary) 100%);
}

.ar-logo-container {
    margin-bottom: 1.5rem;
}

.ar-hero-title {
    font-size: 2.25rem;
    font-weight: 800;
    margin-bottom: 0.75rem;
    color: var(--ar-text-primary);
    background: linear-gradient(135deg, var(--ar-primary), var(--ar-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.ar-hero-subtitle {
    font-size: 1.125rem;
    color: var(--ar-text-secondary);
    margin: 0 auto;
    max-width: 850px;
}

/* =========================================
   UPLOAD CONTAINER
   ========================================= */

.ar-upload-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 1rem;
}

.ar-upload-card {
    background: var(--ar-bg-secondary);
    border-radius: var(--ar-radius-xl);
    box-shadow: var(--ar-shadow-lg);
    overflow: hidden;
    margin-bottom: 2rem;
    border: 1px solid var(--ar-border-dark);
}

/* Desktop Layout - Side by Side */
@media (min-width: 1024px) {
    .ar-upload-container {
        max-width: 1200px;
    }

    .ar-upload-card {
        display: flex;
        align-items: stretch;
        min-height: 350px;
    }

    .ar-upload-main-section {
        flex: 2;
        display: flex;
        flex-direction: column;
    }

    .ar-compatibility-sidebar {
        flex: 1;
        background: var(--ar-bg-tertiary);
        border-left: 1px solid var(--ar-border-dark);
        display: flex;
        flex-direction: column;
        justify-content: center;
        padding: 1.5rem;
        position: relative;
    }

    .ar-upload-area {
        margin: 1.5rem 1.5rem 1rem 1.5rem;
        flex: 1;
        min-height: 250px;
    }

    .ar-actions {
        margin: 0 1.5rem 1.5rem 1.5rem;
    }

    .ar-compatibility {
        padding: 0;
        background: transparent;
        border: none;
        height: 100%;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }

    /* Desktop Click Highlighting - Elegante ma evidente */
    .ar-compatibility-sidebar.highlight {
        background: linear-gradient(135deg,
            rgba(129, 140, 248, 0.15) 0%,
            rgba(99, 102, 241, 0.1) 100%);
        border-left: 4px solid var(--ar-primary);
        transform: translateX(-6px) scale(1.03);
        box-shadow:
            0 0 0 3px rgba(129, 140, 248, 0.3),
            0 8px 25px rgba(129, 140, 248, 0.25),
            0 0 50px rgba(129, 140, 248, 0.15);
        animation: gentleGlow 2s ease-in-out infinite;
        transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 100;
        position: relative;
    }

    .ar-compatibility-sidebar.highlight::before {
        content: '💡';
        position: absolute;
        top: -30px;
        left: 50%;
        transform: translateX(-50%);
        background: var(--ar-primary);
        color: white;
        padding: 8px 12px;
        border-radius: 15px;
        font-size: 0.8rem;
        box-shadow: 0 4px 12px rgba(129, 140, 248, 0.4);
        animation: subtleBounce 2s ease-in-out infinite;
    }

    @keyframes gentleGlow {
        0%, 100% {
            box-shadow:
                0 0 0 3px rgba(129, 140, 248, 0.3),
                0 8px 25px rgba(129, 140, 248, 0.25),
                0 0 50px rgba(129, 140, 248, 0.15);
        }
        50% {
            box-shadow:
                0 0 0 5px rgba(129, 140, 248, 0.4),
                0 12px 35px rgba(129, 140, 248, 0.35),
                0 0 70px rgba(129, 140, 248, 0.25);
        }
    }

    @keyframes subtleBounce {
        0%, 100% { transform: translateX(-50%) translateY(0); }
        50% { transform: translateX(-50%) translateY(-3px); }
    }
}

/* =========================================
   UPLOAD AREA
   ========================================= */

.ar-upload-area {
    position: relative;
    padding: 2rem 1.5rem;
    border: 2px dashed var(--ar-border-dark);
    border-radius: var(--ar-radius-lg);
    margin: 1.5rem;
    cursor: pointer;
    transition: var(--ar-transition);
    background: var(--ar-bg-tertiary);
    text-align: center;
}

.ar-upload-area:hover {
    border-color: var(--ar-primary-light);
    background: var(--ar-bg-secondary);
}

.ar-upload-area.dragover {
    border-color: var(--ar-primary);
    background: rgba(129, 140, 248, 0.05);
    transform: scale(1.02);
}

.ar-upload-content h3 {
    font-size: 1.25rem;
    color: var(--ar-text-primary);
    margin-bottom: 0.5rem;
}

.ar-upload-content p {
    color: var(--ar-text-secondary);
    margin-bottom: 1.5rem;
}

.ar-upload-link {
    color: var(--ar-primary);
    text-decoration: underline;
    font-weight: 600;
    cursor: pointer;
}

.ar-upload-link:hover {
    color: var(--ar-primary-dark);
}

/* Format Badges */
.ar-format-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    margin: 0 0.25rem;
    background: var(--ar-bg-light-alt);
    color: var(--ar-text-secondary);
    border: 1px solid var(--ar-border);
    border-radius: var(--ar-radius-sm);
    font-size: 0.875rem;
    font-weight: 500;
}

/* =========================================
   PREVIEW SECTION
   ========================================= */

.ar-preview-section {
    margin-top: 1.5rem;
    padding: 1rem;
    background: var(--ar-bg-light) !important;
    border: 2px solid var(--ar-border) !important;
    border-radius: var(--ar-radius-lg);
    text-align: center;
    /* Assicura che sia sempre visibile nel tema scuro */
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
}

.ar-preview-container {
    position: relative;
    display: inline-block;
    max-width: 180px;
    margin: 0 auto 0.75rem auto;
    background: var(--ar-bg-light) !important;
    padding: 0.5rem;
    border-radius: var(--ar-radius-md);
    box-shadow: var(--ar-shadow-md);
}

.ar-preview-image {
    max-width: 100%;
    max-height: 160px;
    width: auto;
    height: auto;
    border-radius: var(--ar-radius-sm);
    background: var(--ar-bg-light) !important;
    display: block;
    margin: 0 auto;
    /* SVG rendering fixes */
    object-fit: contain;
    object-position: center;
    /* Dimensioni minime */
    min-height: 80px;
    min-width: 80px;
}

.ar-preview-overlay {
    position: absolute;
    top: 0.25rem;
    right: 0.25rem;
    opacity: 0;
    transition: var(--ar-transition);
}

.ar-preview-container:hover .ar-preview-overlay {
    opacity: 1;
}

.ar-preview-remove {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(248, 113, 113, 0.9);
    color: white;
    border: 2px solid white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 16px;
    transition: var(--ar-transition);
    box-shadow: var(--ar-shadow-sm);
}

.ar-preview-remove:hover {
    background: var(--ar-danger);
    transform: scale(1.1);
}

.ar-file-details {
    text-align: center;
}

.ar-file-name {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--ar-text-dark) !important;
    margin-bottom: 0.25rem;
    word-break: break-all;
    max-width: 200px;
    margin-left: auto;
    margin-right: auto;
}

.ar-file-size {
    font-size: 0.75rem;
    color: var(--ar-text-dark-secondary) !important;
}

/* Fallback specifico per immagini precaricate */
#ar-preview-section {
    background: white !important;
    border: 2px solid #e5e7eb !important;
    padding: 1rem !important;
    margin: 1rem auto !important;
    border-radius: 1rem !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15) !important;
}

#ar-preview-image {
    background: white !important;
    max-height: 160px !important;
    max-width: 100% !important;
    /* Fix per SVG rendering */
    object-fit: contain !important;
    height: auto !important;
    width: auto !important;
    /* Dimensioni minime per SVG */
    min-height: 80px !important;
    min-width: 80px !important;
    border-radius: 8px !important;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1) !important;
}

#ar-file-name {
    color: #1a1a1a !important;
    font-weight: 600 !important;
}

.ar-preview-actions {
    margin-top: 1rem;
    text-align: center;
}

.ar-preview-actions .ar-button {
    width: 100%;
    justify-content: center;
}

#ar-file-size {
    color: #6b7280 !important;
}

/* =========================================
   BUTTONS
   ========================================= */

.ar-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 600;
    text-decoration: none;
    border: 2px solid transparent;
    border-radius: var(--ar-radius-lg);
    cursor: pointer;
    transition: var(--ar-transition);
    position: relative;
    overflow: hidden;
}

.ar-button-primary {
    background: var(--ar-primary);
    color: #ffffff;
    border-color: var(--ar-primary);
}

.ar-button-primary:hover {
    background: var(--ar-primary-dark);
    border-color: var(--ar-primary-dark);
    transform: translateY(-2px);
    box-shadow: var(--ar-shadow-lg);
}

.ar-button-primary:disabled {
    background: var(--ar-text-muted);
    border-color: var(--ar-text-muted);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* AR Button States */
.ar-button.checking-device {
    background: linear-gradient(45deg, var(--ar-primary), var(--ar-secondary));
    animation: deviceCheckPulse 1.5s ease-in-out infinite;
    pointer-events: none;
}

@keyframes deviceCheckPulse {
    0%, 100% {
        background: linear-gradient(45deg, var(--ar-primary), var(--ar-secondary));
        box-shadow: 0 4px 15px rgba(129, 140, 248, 0.4);
    }
    50% {
        background: linear-gradient(45deg, var(--ar-secondary), var(--ar-primary));
        box-shadow: 0 6px 20px rgba(251, 191, 36, 0.6);
    }
}

.ar-button.device-error {
    background: var(--ar-danger);
    animation: errorShake 0.5s ease-in-out;
}

@keyframes errorShake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-3px); }
    20%, 40%, 60%, 80% { transform: translateX(3px); }
}

.ar-button-light {
    background: var(--ar-bg-light);
    color: var(--ar-text-dark);
    border-color: var(--ar-border);
}

.ar-button-light:hover {
    background: var(--ar-bg-light-alt);
    border-color: var(--ar-primary);
    transform: translateY(-1px);
}

/* =========================================
   FEATURES GRID
   ========================================= */

.ar-features-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
    margin: 2rem auto;
    max-width: 1200px;
    padding: 0 1rem;
}

@media (max-width: 1024px) {
    .ar-features-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 640px) {
    .ar-features-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
}

.ar-feature-card {
    text-align: center;
    padding: 1.5rem 1rem;
    background: var(--ar-bg-secondary);
    border: 1px solid var(--ar-border-dark);
    border-radius: var(--ar-radius-lg);
    transition: var(--ar-transition);
}

.ar-feature-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--ar-shadow-xl);
    border-color: var(--ar-primary-light);
}

.ar-feature-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.ar-feature-card h4 {
    font-size: 1.25rem;
    color: var(--ar-text-primary);
    margin-bottom: 0.75rem;
}

.ar-feature-card p {
    color: var(--ar-text-secondary);
    font-size: 0.875rem;
}

/* =========================================
   COMPATIBILITY SECTION
   ========================================= */

.ar-compatibility {
    padding: 1.5rem 2rem;
    background: var(--ar-bg-tertiary);
    border-top: 1px solid var(--ar-border-dark);
    text-align: center;
}

.ar-compat-checking {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    color: var(--ar-text-secondary);
}

.ar-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--ar-border-dark);
    border-top-color: var(--ar-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* =========================================
   AR CONTROLS (Dark Background Elements)
   ========================================= */

.ar-viewer-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: #000;
    z-index: 9999;
}

.ar-controls-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

.ar-controls-overlay * {
    color: var(--ar-text-light);
}

.ar-top-bar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    pointer-events: auto;
    background: linear-gradient(to bottom, rgba(0,0,0,0.5), transparent);
}

.ar-bottom-controls {
    position: absolute;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 1rem;
    pointer-events: auto;
}

.ar-control-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.7);
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: var(--ar-text-light);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--ar-transition);
}

.ar-control-btn:hover {
    background: rgba(0, 0, 0, 0.85);
    border-color: rgba(255, 255, 255, 0.5);
    transform: scale(1.1);
}

.ar-control-primary {
    width: 72px;
    height: 72px;
    background: var(--ar-primary);
    border-color: var(--ar-primary);
}

/* =========================================
   TUTORIAL OVERLAY
   ========================================= */

.ar-tutorial-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: auto;
    color: var(--ar-text-light);
}

.ar-tutorial-content {
    text-align: center;
    max-width: 400px;
    padding: 2rem;
}

.ar-tutorial-skip {
    position: absolute;
    bottom: 2rem;
    right: 2rem;
    background: rgba(255, 255, 255, 0.95);
    color: var(--ar-text-dark);
    border: 2px solid var(--ar-border);
    padding: 0.75rem 1.5rem;
    border-radius: var(--ar-radius-lg);
    cursor: pointer;
    font-weight: 600;
    transition: var(--ar-transition);
}

.ar-tutorial-skip:hover {
    background: var(--ar-bg-light);
    transform: translateY(-2px);
    box-shadow: var(--ar-shadow-md);
}

/* =========================================
   MODAL STYLES
   ========================================= */

.ar-desktop-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.ar-desktop-modal.show {
    opacity: 1;
}

.ar-modal-content {
    background: var(--ar-bg-light);
    padding: 2rem;
    border-radius: var(--ar-radius-xl);
    max-width: 500px;
    margin: 1rem;
    box-shadow: var(--ar-shadow-xl);
    text-align: center;
}

.ar-modal-content h2 {
    color: var(--ar-text-dark);
    margin-bottom: 1rem;
}

.ar-modal-content p {
    color: var(--ar-text-dark-secondary);
    margin-bottom: 1.5rem;
}

.ar-modal-close {
    background: var(--ar-primary);
    color: #ffffff;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: var(--ar-radius-lg);
    cursor: pointer;
    font-weight: 600;
    transition: var(--ar-transition);
}

.ar-modal-close:hover {
    background: var(--ar-primary-dark);
}

/* =========================================
   RESPONSIVE DESIGN
   ========================================= */

/* Mobile/Tablet - Keep single column layout */
@media (max-width: 1023px) {
    .ar-upload-main-section {
        display: block !important;
    }

    .ar-compatibility-sidebar {
        display: none !important;
    }

    .ar-upload-card {
        display: block !important;
    }

    .ar-upload-area {
        margin: 2rem !important;
    }

    .ar-actions {
        margin: 0 2rem 2rem 2rem !important;
    }

    .ar-compatibility {
        display: block !important;
        padding: 1.5rem 2rem !important;
        background: var(--ar-bg-tertiary) !important;
        border-top: 1px solid var(--ar-border-dark) !important;
    }
}

@media (max-width: 768px) {
    .ar-hero-title {
        font-size: 2rem;
    }

    .ar-hero-subtitle {
        font-size: 1rem;
    }

    .ar-features-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .ar-upload-area {
        padding: 2rem 1rem;
        margin: 1rem;
    }

    .ar-bottom-controls {
        bottom: 1rem;
        gap: 0.5rem;
    }

    .ar-control-btn {
        width: 48px;
        height: 48px;
    }

    .ar-control-primary {
        width: 60px;
        height: 60px;
    }

    .ar-tutorial-skip {
        bottom: 1rem;
        right: 1rem;
        padding: 0.75rem 1.25rem;
        font-size: 0.875rem;
    }

    /* Preview più piccola su mobile */
    .ar-preview-container {
        max-width: 150px;
    }

    .ar-preview-image {
        max-height: 120px;
    }

    .ar-file-name {
        max-width: 150px;
        font-size: 0.8rem;
    }
}

/* =========================================
   ANIMATIONS
   ========================================= */

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

.ar-upload-icon-wrapper {
    animation: pulse 2s infinite;
}

/* =========================================
   UTILITY CLASSES
   ========================================= */

.ar-loading {
    opacity: 0.6;
    pointer-events: none;
}

.ar-hidden {
    display: none !important;
}

.ar-text-center {
    text-align: center;
}

.ar-mb-4 {
    margin-bottom: 1rem;
}

.ar-mt-4 {
    margin-top: 1rem;
}