/* ============================================
   CineMatch - Modern Dark Theme Styles
   ============================================ */

/* CSS Variables */
:root {
/* NUOVI COLORI VIOLA */
    --primary: #8B5CF6;       /* Viola principale */
    --primary-hover: #7C3AED; /* Viola leggermente pi첫 scuro per l'hover */
    --primary-dark: #6D28D9;  /* Viola scuro per il click */
    
    /* Il resto rimane uguale, ma controlla --danger */
    --bg-primary: #0f0f0f;
    --bg-secondary: #1a1a1a;
    --bg-tertiary: #2a2a2a;
    --bg-card: #1f1f1f;
    --text-primary: #ffffff;
    --text-secondary: #b3b3b3;
    --text-muted: #666666;
    --border-color: #333333;
    --success: #46d369;
    --warning: #e87c03;
    --danger: #e50914;
    --radius-sm: 6px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --transition: all 0.2s ease;
}

/* Reset & Base */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* ============================================
   AUTHENTICATION PAGES
   ============================================ */

.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    background: linear-gradient(135deg, var(--bg-primary) 0%, #1a0a0a 100%);
}

.auth-container {
    width: 100%;
    max-width: 420px;
}

.auth-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: 40px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
}

.auth-header {
    text-align: center;
    margin-bottom: 32px;
}

.auth-header .logo {
    display: flex;
    justify-content: center;
    margin-bottom: 16px;
}

.auth-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.auth-header p {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* Auth Tabs */
.auth-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    background: var(--bg-tertiary);
    padding: 4px;
    border-radius: var(--radius-md);
}

.tab-btn {
    flex: 1;
    padding: 12px 16px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.tab-btn:hover {
    color: var(--text-primary);
}

.tab-btn.active {
    background: var(--primary);
    color: white;
}

/* Auth Forms */
.auth-form {
    display: none;
}

.auth-form.active {
    display: block;
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-group input {
    width: 100%;
    padding: 14px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 1rem;
    transition: var(--transition);
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.3);
}

.form-group input::placeholder {
    color: var(--text-muted);
}

.form-group .hint {
    display: block;
    margin-top: 6px;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.form-message {
    margin-top: 16px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    text-align: center;
    display: none;
}

.form-message.error {
    display: block;
    background: rgba(229, 9, 20, 0.15);
    color: #ff6b6b;
    border: 1px solid rgba(229, 9, 20, 0.3);
}

.form-message.success {
    display: block;
    background: rgba(70, 211, 105, 0.15);
    color: var(--success);
    border: 1px solid rgba(70, 211, 105, 0.3);
}

.auth-footer {
    text-align: center;
    margin-top: 24px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.4);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--border-color);
}

.btn-danger {
    background: transparent;
    color: var(--danger);
    border: 1px solid var(--danger);
}

.btn-danger:hover:not(:disabled) {
    background: rgba(229, 9, 20, 0.1);
}

.btn-sm {
    padding: 8px 16px;
    font-size: 0.85rem;
}

.btn-full {
    width: 100%;
}

.btn-loader {
    width: 18px;
    height: 18px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.btn-loader.hidden,
.btn-text.hidden {
    display: none;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================
   APP LAYOUT
   ============================================ */

.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: rgba(15, 15, 15, 0.95);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-color);
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-left h1 {
    font-size: 1.25rem;
    font-weight: 700;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.user-greeting {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.main-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: space-around;
    background: rgba(15, 15, 15, 0.98);
    backdrop-filter: blur(10px);
    z-index: 100;

    /* LA LINEA: deve essere l'unico elemento di contatto in alto */
    border-top: 1px solid var(--border-color); 
    
    /* PADDING BILANCIATO: 
       15px sopra per staccare i bottoni dalla linea 
       15px (o più) sotto per estetica e comodità */
    padding: 15px 16px; 
    
    /* Ottimo per i telefoni moderni senza tasti fisici */
    padding-bottom: max(15px, env(safe-area-inset-bottom)); 
}

.nav-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 16px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-size: 0.75rem;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
}

.nav-btn svg {
    transition: var(--transition);
}

.nav-btn:hover {
    color: var(--text-secondary);
}

.nav-btn.active {
    color: var(--primary);
}

.nav-btn.active svg {
    stroke: var(--primary);
}

.badge {
    position: absolute;
    top: 4px;
    right: 1px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: var(--primary);
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.badge.hidden {
    display: none;
}

/* Main Content */
.main-content {
    padding: 80px 16px 100px;
    max-width: 1400px;
    margin: 0 auto;
}

/* Views */
.view {
    display: none;
}

.view.active {
    display: block;
}

.view-header {
    margin-bottom: 24px;
}

.view-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 8px;
}

.view-header .subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* Search Bar */
.search-bar {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

.search-bar input {
    flex: 1;
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.95rem;
}

.search-bar input:focus {
    outline: none;
    border-color: var(--primary);
}

/* Category Tabs */
.category-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    overflow-x: auto;
    padding-bottom: 8px;
    scrollbar-width: none;
}

.category-tabs::-webkit-scrollbar {
    display: none;
}

.cat-btn {
    padding: 10px 20px;
    border: none;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: var(--transition);
    white-space: nowrap;
}

.cat-btn:hover {
    background: var(--border-color);
    color: var(--text-primary);
}

.cat-btn.active {
    background: var(--primary);
    color: white;
}

/* ============================================
   MOVIES GRID
   ============================================ */

.movies-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

@media (min-width: 480px) {
    .movies-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (min-width: 768px) {
    .movies-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 20px;
    }
}

@media (min-width: 1024px) {
    .movies-grid {
        grid-template-columns: repeat(5, 1fr);
    }
}

@media (min-width: 1400px) {
    .movies-grid {
        grid-template-columns: repeat(6, 1fr);
    }
}

/* Movie Card */
.movie-card {
    cursor: pointer;
    transition: var(--transition);
}

.movie-card:hover {
    transform: translateY(-4px);
}

.movie-poster {
    position: relative;
    aspect-ratio: 2/3;
    border-radius: var(--radius-md);
    overflow: hidden;
    background: var(--bg-tertiary);
}

.movie-poster img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: var(--transition);
}

.movie-card:hover .movie-poster img {
    transform: scale(1.05);
}

.movie-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(to top, rgba(0,0,0,0.9) 0%, transparent 50%);
    opacity: 0;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    padding: 12px;
    gap: 8px;
}

.movie-card:hover .movie-overlay {
    opacity: 1;
}

.like-btn,
.info-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: rgba(255,255,255,0.15);
    backdrop-filter: blur(4px);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.like-btn:hover,
.info-btn:hover {
    background: rgba(255,255,255,0.25);
    transform: scale(1.1);
}

.like-btn.liked {
    background: var(--primary);
    color: white;
}

.like-btn.liked:hover {
    background: var(--primary-dark);
}

.movie-info {
    padding: 12px 4px;
}

.movie-title {
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 6px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.movie-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.movie-rating {
    display: flex;
    align-items: center;
    gap: 4px;
    color: #ffd700;
}

/* Match Card */
.match-card .movie-poster::after {
    content: '';
    position: absolute;
    inset: 0;
    border: 2px solid var(--primary);
    border-radius: var(--radius-md);
    pointer-events: none;
}

.match-badge {
    position: absolute;
    top: 8px;
    left: 8px;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 6px 10px;
    background: var(--primary);
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
}

/* ============================================
   STATES
   ============================================ */

.loading-state,
.empty-state,
.error-state {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 16px;
}

.loading-state p {
    color: var(--text-secondary);
}

.empty-state svg {
    color: var(--text-muted);
    margin-bottom: 20px;
}

.empty-state h3 {
    font-size: 1.25rem;
    margin-bottom: 8px;
}

.empty-state p {
    color: var(--text-secondary);
    margin-bottom: 24px;
    max-width: 300px;
}

.error-state h3 {
    font-size: 1.25rem;
    margin-bottom: 8px;
    color: #ff6b6b;
}

.error-state p {
    color: var(--text-secondary);
    margin-bottom: 20px;
}

/* ============================================
   MODAL
   ============================================ */

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    backdrop-filter: blur(8px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    position: relative;
    width: 100%;
    max-width: 900px;
    max-height: 90vh;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    overflow: hidden;
    overflow-y: auto;
    transform: scale(0.95);
    transition: var(--transition);
}

.modal.active .modal-content {
    transform: scale(1);
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    border-radius: 50%;
    z-index: 10;
    transition: var(--transition);
}

.modal-close:hover {
    background: rgba(0, 0, 0, 0.8);
}

/* Modal Movie Content */
.modal-movie {
    position: relative;
}

.modal-backdrop {
    position: relative;
    height: 300px;
    overflow: hidden;
}

.modal-backdrop::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(to bottom, transparent 0%, var(--bg-secondary) 100%);
}

.modal-backdrop img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.modal-movie-content {
    display: flex;
    gap: 24px;
    padding: 0 24px 24px;
    margin-top: -100px;
    position: relative;
    z-index: 1;
}

.modal-poster {
    flex-shrink: 0;
    width: 150px;
    border-radius: var(--radius-md);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

.modal-poster img {
    width: 100%;
    height: auto;
    display: block;
}

.modal-movie-info {
    flex: 1;
    padding-top: 100px;
}

.modal-movie-info h2 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 12px;
}

.modal-meta {
    display: flex;
    gap: 16px;
    margin-bottom: 16px;
    font-size: 0.95rem;
}

.modal-meta .rating {
    display: flex;
    align-items: center;
    gap: 4px;
    color: #ffd700;
}

.modal-movie-info .overview {
    color: var(--text-secondary);
    line-height: 1.7;
    margin-bottom: 24px;
}

.like-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.like-action-btn.liked {
    background: var(--success);
}

@media (min-width: 768px) {
    .modal-poster {
        width: 200px;
    }
    
    .modal-movie-info h2 {
        font-size: 2.25rem;
    }
}

/* ============================================
   PARTNER VIEW
   ============================================ */

.partner-form {
    max-width: 400px;
    margin: 0 auto;
    text-align: center;
    padding: 40px 20px;
}

.partner-icon {
    display: flex;
    justify-content: center;
    color: var(--text-muted);
    margin-bottom: 24px;
}

.partner-form h3 {
    font-size: 1.25rem;
    margin-bottom: 8px;
}

.partner-form p {
    color: var(--text-secondary);
    margin-bottom: 24px;
}

.partner-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 40px;
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    text-align: center;
}

.partner-avatar {
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    border-radius: 50%;
    color: var(--text-secondary);
}

.partner-info h3 {
    font-size: 1.25rem;
    margin-bottom: 8px;
}

.partner-status {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
}

.partner-status.pending {
    background: rgba(232, 124, 3, 0.2);
    color: var(--warning);
}

.partner-status.active {
    background: rgba(70, 211, 105, 0.2);
    color: var(--success);
}

.partner-actions {
    display: flex;
    gap: 12px;
    margin-top: 8px;
}

.pending-text {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Matches Header */
.matches-header {
    margin-bottom: 24px;
}

.match-count {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

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

@media (min-width: 768px) {
    .app-header {
        padding: 16px 32px;
    }
    
    .main-content {
        padding: 100px 32px 100px;
    }
    
    .main-nav {
        position: fixed;
        top: 0;
        left: auto;
        right: 200px;
        bottom: auto;
        background: transparent;
        border: none;
        padding: 15px;
        gap: 8px;
    }
    
    .nav-btn {
        flex-direction: row;
        padding: 10px 20px;
        font-size: 0.9rem;
        border-radius: var(--radius-md);
    }
    
    .nav-btn:hover,
    .nav-btn.active {
        background: var(--bg-tertiary);
    }
    
    .nav-btn.active {
        color: var(--primary);
    }
}

/* ============================================
   ANIMATIONS
   ============================================ */

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

.movie-card {
    animation: fadeIn 0.3s ease forwards;
}

/* Stagger animation for grid items */
.movies-grid .movie-card:nth-child(1) { animation-delay: 0.05s; }
.movies-grid .movie-card:nth-child(2) { animation-delay: 0.1s; }
.movies-grid .movie-card:nth-child(3) { animation-delay: 0.15s; }
.movies-grid .movie-card:nth-child(4) { animation-delay: 0.2s; }
.movies-grid .movie-card:nth-child(5) { animation-delay: 0.25s; }
.movies-grid .movie-card:nth-child(6) { animation-delay: 0.3s; }


/* ============================================
   MOBILE OPTIMIZATIONS (Incolla alla fine del file)
   ============================================ */

@media (max-width: 768px) {

    /* 1. GRIGLIA FILM: Titoli sotto, non dentro */
    .movies-grid {
        grid-template-columns: repeat(2, 1fr); /* 2 colonne fisse */
        gap: 12px;
        padding-bottom: 100px; /* Spazio extra per la nav bar */
    }

    .movie-card {
        background: transparent;
        border-radius: 0;
    }

    .movie-poster {
        border-radius: var(--radius-md);
        box-shadow: var(--shadow-sm);
        aspect-ratio: 2/3;
    }

    /* Nascondiamo i bottoni hover su mobile (si usa il modale) */
    .movie-overlay {
        display: none !important; 
    }

    .movie-info {
        padding: 8px 0 0 0;
    }

    .movie-title {
        font-size: 0.9rem;
        white-space: normal; /* Titolo su più righe se serve */
        line-height: 1.3;
        max-height: 2.6em; /* Max 2 righe */
        margin-bottom: 4px;
    }

    .movie-meta {
        font-size: 0.75rem;
    }

    /* 2. BARRA DI NAVIGAZIONE: Stile App Nativa */
    .main-nav {
        background: rgba(15, 15, 15, 0.95);
        border-top: 1px solid rgba(255,255,255,0.1);
        padding-bottom: max(10px, env(safe-area-inset-bottom)); /* Per iPhone X+ */
        height: auto;
    }

    .nav-btn {
        padding: 8px 0;
        flex: 1; /* Distribuisci spazio equamente */
    }

    .nav-btn svg {
        width: 24px;
        height: 24px;
        margin-bottom: 2px;
    }
    
    .nav-btn span {
        font-size: 0.7rem;
    }

    /* 3. MODALE: Full Screen Style */
    .modal {
        padding: 0;
        z-index: 9999; /* Sopra a tutto */
    }

    .modal-content {
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        display: flex;
        flex-direction: column;
    }

    .modal-close {
        top: 15px;
        right: 15px;
        background: rgba(0,0,0,0.6);
        width: 36px;
        height: 36px;
        z-index: 20;
    }

    /* Immagine modale grande in alto */
    .modal-movie {
        flex: 1;
        display: flex;
        flex-direction: column;
        overflow-y: auto;
        padding-bottom: 80px; /* Spazio per il bottone fisso */
    }

    .modal-backdrop {
        height: 40vh; /* 40% dello schermo */
        flex-shrink: 0;
    }

    .modal-movie-content {
        margin-top: -60px; /* Sovrapposizione minore */
        flex-direction: column;
        padding: 0 20px 20px;
        gap: 15px;
    }

    .modal-poster {
        width: 100px; /* Locandina più piccola nel dettaglio */
        border: 2px solid var(--bg-secondary);
        box-shadow: var(--shadow-lg);
    }

    .modal-movie-info {
        padding-top: 0;
    }

    .modal-movie-info h2 {
        font-size: 1.5rem;
        line-height: 1.2;
    }

    /* Bottone LIKE fisso in basso (Sticky Footer) */
    .like-action-btn {
        position: fixed;
        bottom: 20px;
        left: 20px;
        right: 20px;
        width: auto;
        padding: 16px;
        font-size: 1.1rem;
        border-radius: 50px; /* Pillola */
        box-shadow: 0 4px 20px rgba(139, 92, 246, 0.4);
        z-index: 100;
        justify-content: center;
    }

    /* Nascondiamo la scrollbar orizzontale delle categorie */
    .category-tabs {
        padding: 0 16px 8px;
        margin: 0 -16px 20px; /* Full bleed */
    }
    
    .cat-btn {
        font-size: 0.85rem;
        padding: 8px 16px;
    }
}
