/* =========================================
   FODUS BAFFO - PREMIUM UI/UX (FINAL FIX)
   ========================================= */

:root {
    /* Palette Colori */
    --bg-panna: #FDFBF7; /* Bianco panna caldo e premium */
    --surface: #FFFFFF;
    
    --primary: #007AFF; /* Apple Light Blue */
    --primary-hover: #005ce6;
    --primary-light: rgba(0, 122, 255, 0.1);
    
    --accent: #FF6B6B; /* Arancione Corallo */
    --accent-light: rgba(255, 107, 107, 0.15);
    
    --text-main: #1C1C1E; /* Quasi nero, molto leggibile */
    --text-muted: #8E8E93;
    
    --border-soft: rgba(0, 0, 0, 0.05);
    
    /* Colori Countdown */
    --color-safe: #34C759; /* Verde iOS */
    --color-medium: #FF9500; /* Arancio iOS */
    --color-danger: #FF3B30; /* Rosso iOS */
    
    /* Ombre Soft-UI */
    --shadow-card: 0 12px 32px rgba(0, 0, 0, 0.04), 0 2px 8px rgba(0, 0, 0, 0.02);
    --shadow-btn: 0 8px 20px rgba(0, 122, 255, 0.25);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Space Grotesk', -apple-system, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

/* =========================================
   BLOCCO SCROLL E FIX ALTEZZE MOBILE
   ========================================= */
body {
    background-color: var(--bg-panna);
    color: var(--text-main);
    display: flex;
    justify-content: center;
    
    /* FIX CRUCIALE: Usa 100dvh e blocca lo scroll globale elastico di iOS */
    height: 100dvh;
    overflow: hidden;
    overscroll-behavior-y: none;
    touch-action: pan-x pan-y;
}

.app-container {
    width: 100%;
    max-width: 420px;
    height: 100dvh; /* Altezza dinamica perfetta per mobile */
    display: flex;
    flex-direction: column;
    position: relative;
    padding: 0 20px 20px 20px;
}

/* =========================================
   HEADER GLASSMORPHISM
   ========================================= */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    margin: 0 -20px 20px -20px; /* Estende ai bordi */
    position: sticky;
    top: 0;
    z-index: 100;
    /* Effetto vetro sfocato iOS */
    background: rgba(253, 251, 247, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-soft);
}

.app-header h1 {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 1.35rem;
    letter-spacing: -0.5px;
}

.title-fodus { font-weight: 800; color: var(--primary); }
.title-baffo { font-weight: 300; color: var(--accent); }

.countdown-badge {
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: #fff;
    background-color: var(--color-safe);
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    transition: all 0.3s ease;
}

/* =========================================
   VIEWS & SCROLL INTERNO
   ========================================= */
.view {
    display: none;
    flex: 1;
    flex-direction: column;
    /* Abilita lo scroll interno SOLO per schermate lunghe (es. Calendario) */
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; 
    animation: slideUpFade 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.view.active { display: flex; }

@keyframes slideUpFade {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ECCEZIONE: La fotocamera deve essere bloccata, centrata e senza slideUp (animazione semplice) */
#view-camera {
    overflow: hidden;
    justify-content: center;
    padding-bottom: 20px; 
    animation: simpleFade 0.25s ease-out forwards;
}

@keyframes simpleFade {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* =========================================
   CARDS & DASHBOARD
   ========================================= */
.card, .stat-card, .action-card {
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: 24px;
    box-shadow: var(--shadow-card);
    padding: 28px 24px;
    text-align: center;
    transition: transform 0.2s ease;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card {
    padding: 20px 16px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.stat-title { 
    font-size: 0.75rem; 
    color: var(--text-muted); 
    text-transform: uppercase; 
    letter-spacing: 1px; 
    font-weight: 600;
}

.stat-value { 
    font-size: 1.8rem; 
    font-weight: 800; 
    color: var(--primary); 
    margin: 8px 0; 
    line-height: 1;
}

.stat-desc { font-size: 0.8rem; color: var(--text-muted); font-weight: 500;}

.action-card {
    margin-bottom: 24px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 32px 20px;
}

.action-card h3 { font-size: 1.5rem; font-weight: 700; color: var(--text-main); }

/* =========================================
   INPUTS & BUTTONS INTERATTIVI
   ========================================= */
input {
    width: 100%;
    padding: 18px;
    background: var(--bg-panna);
    border: 2px solid transparent;
    color: var(--text-main);
    border-radius: 16px;
    font-size: 1.1rem;
    text-align: center;
    font-weight: 500;
    margin-bottom: 20px;
    outline: none;
    transition: all 0.2s ease;
}

input:focus { 
    border-color: var(--primary); 
    background: var(--surface);
    box-shadow: 0 0 0 4px var(--primary-light);
}

input::placeholder { color: #C7C7CC; font-weight: 400; }

.btn-primary, .btn-secondary, .btn-admin {
    width: 100%;
    padding: 18px;
    border-radius: 16px;
    border: none;
    font-weight: 700;
    font-size: 1.05rem;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.btn-primary { 
    background: var(--primary); 
    color: #fff; 
    box-shadow: var(--shadow-btn); 
}
.btn-primary:active { transform: scale(0.96); box-shadow: 0 4px 10px rgba(0, 122, 255, 0.15); }

.btn-secondary { 
    background: var(--primary-light); 
    color: var(--primary); 
}
.btn-secondary:active { transform: scale(0.96); background: rgba(0, 122, 255, 0.15); }

.btn-admin { 
    background: #FFF0F0; 
    color: var(--color-danger); 
    margin-top: 10px; 
}

.btn-text-only { 
    background: none; border: none; 
    color: var(--text-muted); font-weight: 600; 
    cursor: pointer; padding: 12px; margin-top: 16px;
    transition: color 0.2s;
}
.btn-text-only:active { color: var(--text-main); }

.error-msg { color: var(--color-danger); font-size: 0.9rem; margin-top: 12px; font-weight: 600; }
.hidden { display: none !important; }

/* =========================================
   CAMERA PREMIUM (Stile App Nativa)
   ========================================= */
.camera-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 3/4; /* era 9/16 — meno stretto, meno crop, più campo visivo */
    background: #000;
    border-radius: 32px;
    overflow: hidden;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.2);
}
#camera-stream, #camera-canvas {
    width: 100%;
    height: 100%;
    object-fit: cover; /* Mantiene proporzioni perfette senza stretch */
}

#camera-stream { transform: scaleX(-1); }

.ghost-overlay {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none;
    opacity: 0.45;
    background-size: cover;
    background-position: center;
    mix-blend-mode: screen; 
}

.camera-actions { 
    margin-top: 30px; 
    display: flex; 
    justify-content: center; 
    width: 100%; 
}

/* Bottone Scatto - Replicato perfetto iOS */
.btn-shutter {
    width: 80px; height: 80px; 
    border-radius: 50%;
    border: 4px solid var(--accent); /* Richiamo Corallo */
    background: #fff;
    padding: 4px;
    box-shadow: 0 8px 24px var(--accent-light);
    position: relative;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-shutter::after {
    content: '';
    display: block;
    width: 100%; height: 100%;
    border-radius: 50%;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    transition: all 0.15s ease;
}

.btn-shutter:active::after {
    transform: scale(0.85); /* Il cerchio interno si restringe al click */
    background: #f0f0f0;
}

#retake-actions { 
    display: flex; gap: 16px; width: 100%; 
}

/* =========================================
   CALENDARIO & FEED
   ========================================= */
.section-title { 
    margin-bottom: 24px; 
    font-size: 1.6rem; 
    font-weight: 800; 
    letter-spacing: -0.5px;
    color: var(--text-main);
}

.calendar-list { 
    overflow-y: auto; 
    display: flex; flex-direction: column; 
    gap: 32px; padding-bottom: 20px; 
}

.day-group { 
    background: transparent;
}

.day-title { 
    font-size: 1.2rem; 
    font-weight: 800; 
    margin-bottom: 16px; 
    color: var(--primary); 
    display: flex;
    align-items: center;
}

.day-title::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-soft);
    margin-left: 12px;
}

.photo-grid { 
    display: grid; 
    grid-template-columns: 1fr 1fr; 
    gap: 16px; 
}

.photo-item { 
    position: relative; 
    border-radius: 20px; 
    overflow: hidden; 
    aspect-ratio: 3/4; /* era 9/16 — stessa forma della camera, coerenza nel calendario */
    box-shadow: var(--shadow-card);
    background: var(--surface);
}
.photo-item img { 
    width: 100%; height: 100%; 
    object-fit: cover; 
}

.photo-author { 
    position: absolute; 
    bottom: 0; left: 0; right: 0; 
    background: linear-gradient(to top, rgba(0,0,0,0.8) 0%, rgba(0,0,0,0) 100%); 
    color: #fff; 
    padding: 24px 12px 12px 12px; 
    font-size: 0.85rem; 
    font-weight: 600; 
    text-align: center; 
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}


/* =========================================
   EFFETTO RETINA FLASH
   ========================================= */
#screen-flash {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: #FFFFFF;
    z-index: 9999; /* Deve stare sopra a TUTTO */
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease-out; /* Dissolvenza in uscita morbida */
}

#screen-flash.flash-active {
    opacity: 1;
    transition: none; /* Appare all'istante, senza transizioni */
}
