/* ======================================= */
/* === RESET CSS CORRETTO === */
/* ======================================= */
*,
*::before,
*::after {
box-sizing: border-box;
padding: 0;
margin: 0;
}

html {
/* Abilita lo scroll-behavior fluido (opzionale ma carino) */
scroll-behavior: smooth;
font-family: 'Open Sans', sans-serif;
}

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;600;800&display=swap');

:root {
  --bg-color: #141414;
  --bg-card: #1f1f1f;
  --text-color: #e5e5e5;
  --text-muted: #aaaaaa;
  --accent-color: #e50914;
  --accent-hover: #b80710;
  --nav-bg: rgba(20, 20, 20, 0.85);
  --border-color: #333333;
}

/* ======================================= */
/* === STILI GENERALI === */
/* ======================================= */
body {
background-color: var(--bg-color);
font-family: 'Inter', sans-serif;
color: var(--text-color);

/* * LA SOLUZIONE PRINCIPALE:
* Aggiungiamo padding al body per fare spazio
* all'header fisso. 100px è una misura di sicurezza
* per il desktop.
*/
padding-top: 100px;
}

.container {
max-width: 1200px;
margin: 20px auto;
padding: 0 15px;
}

/* ======================================= */
/* === HEADER FISSO === */
/* ======================================= */
header {
background-color: var(--nav-bg);
backdrop-filter: blur(10px);
-webkit-backdrop-filter: blur(10px);
border-bottom: 1px solid var(--border-color);
color: #fff;
padding: 15px 0;
text-align: center;
position: fixed;
top: 0;
left: 0;
width: 100%;
z-index: 1000;
}

header h1 {
margin: 0;
font-size: 2em;
}

header nav {
margin: 0 auto;
max-width: 1200px;
padding: 0 15px;
display: flex;
justify-content: space-between; /* MODIFICATO */
align-items: center;
flex-wrap: nowrap; /* MODIFICATO */
gap: 20px;
}

/* NUOVO: Contenitore menu per desktop */
.nav-menu {
display: flex;
align-items: center;
gap: 20px;
}

.nav-search form {
display: flex;
}

.nav-search input[type="text"] {
padding: 8px 12px;
border: 1px solid #555;
border-radius: 5px 0 0 5px;
font-size: 1em;
min-width: 300px;
background-color: #2c2c2c;
color: #e0e0e0;
}

.nav-search button {
padding: 8px 15px;
border: none;
background-color: var(--accent-color);
color: white;
cursor: pointer;
border-radius: 0 5px 5px 0;
font-size: 1em;
font-weight: bold;
transition: background-color 0.2s ease;
}
.nav-search button:hover {
background-color: var(--accent-hover);
}

.nav-links {
display: flex;
align-items: center; /* Allinea i select */
gap: 15px;
}

.btn-aggiungi, .btn-gestione {
display: inline-block;
padding: 10px 15px;
border-radius: 5px;
text-decoration: none;
font-weight: bold;
color: white;
transition: background-color 0.3s;
white-space: nowrap; /* Aggiunto */
}

.btn-aggiungi {
background-color: #28a745;
}
.btn-aggiungi:hover {
background-color: #218838;
}

.btn-gestione {
background-color: #007bff;
}
.btn-gestione:hover {
background-color: #0056b3;
}

/* ======================================= */
/* === GRIGLIA FILM === */
/* ======================================= */
.griglia-film {
display: grid;
/* MODIFICA: 5 colonne di default (desktop) */
grid-template-columns: repeat(5, 1fr);
gap: 20px;
}

/* Card del Film */
.card-film {
    display: block;
    background-color: var(--bg-card);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    text-decoration: none;
    transition: transform 0.3s, box-shadow 0.3s, border-color 0.3s;
    height: 100%;
    color: #e0e0e0;
    position: relative;
    border: 1px solid var(--border-color);
}

.card-film:hover {
    transform: scale(1.05);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.8);
    border-color: var(--accent-color);
    z-index: 2;
}

.card-film img {
    width: 100%;
    height: 100%;
    aspect-ratio: 2 / 3;
    object-fit: cover;
    display: block;
}

.descrizione-veloce {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: linear-gradient(to top, rgba(20,20,20,1) 0%, rgba(20,20,20,0.8) 50%, transparent 100%);
    padding: 30px 10px 15px 10px;
    opacity: 0;
    transition: opacity 0.3s;
    text-align: center;
}

.card-film:hover .descrizione-veloce {
    opacity: 1;
}

.descrizione-veloce h3,
.titolo_cover_index {
    margin: 0;
    font-size: 1rem;
    color: #fff;
    font-weight: 600;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-shadow: 1px 1px 3px rgba(0,0,0,0.8);
}
.descrizione-veloce p {
    font-size: 0.8em;
    color: #bbb;
    margin-top: 5px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ======================================= */
/* === STILI FILTRI SELECT === */
/* =Spostati qui per pulizia */
/* ======================================= */

.nav-links form {
/* Mantiene l'allineamento nella nav-links flexbox */
display: flex;
align-items: center;
}

/* 1. Stili Base: Applicati a ENTRAMBI i SELECT */
.nav-links select[name="serie_id"],
.nav-links select[name="stagione_num"] {
/* 1. Reset Aspetto del Browser */
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;

/* 2. Colori e Forma */
background-color: #2c2c2c; /* Coerente con lo sfondo dell'input di ricerca */
color: #e0e0e0; /* Testo chiaro */
border: 1px solid #555; /* Bordo discreto */
border-radius: 5px; /* Angoli arrotondati */
padding: 8px 30px 8px 12px; /* Aumenta il padding a destra per la freccia */

/* 3. Tipografia e Interattività */
font-size: 1em;
cursor: pointer;
transition: all 0.2s ease;

/* 4. Freccia Personalizzata (SVG bianco) */
background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="%23e0e0e0" viewBox="0 0 16 16"><path d="M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592c.859 0 1.318 1.013.753 1.658l-4.796 5.482a1 1 0 0 1-1.506 0z"/></svg>');
background-repeat: no-repeat;
background-position: right 8px center;
}

/* 5. Effetto Hover e Focus: Applicato a ENTRAMBI i SELECT */
.nav-links select[name="serie_id"]:hover,
.nav-links select[name="serie_id"]:focus,
.nav-links select[name="stagione_num"]:hover,
.nav-links select[name="stagione_num"]:focus {
border-color: #007bff; /* Blu acceso al passaggio del mouse/focus */
background-color: #383838;
outline: none;
box-shadow: 0 0 5px rgba(0, 123, 255, 0.5);
}

/* 6. Stile Opzioni: Applicato a ENTRAMBI i SELECT */
.nav-links select[name="serie_id"] option,
.nav-links select[name="stagione_num"] option {
background-color: #383838;
color: #e0e0e0;
}


/* ======================================= */
/* === LOADER E PAGINAZIONE === */
/* ======================================= */
.paginazione {
/* Questo è per la vecchia paginazione, la teniamo nascosta */
display: none;
text-align: center;
margin-top: 30px;
padding-bottom: 20px;
}
.btn-pag {
display: inline-block;
padding: 8px 15px;
margin: 0 5px;
background-color: #333;
border-radius: 5px;
text-decoration: none;
color: #e0e0e0;
}
.btn-pag.active {
background-color: #e50914;
color: white;
}

/* Stile per il loader (ricordando di NON usare display:none) */
#loader {
text-align: center;
padding: 20px;
color: #e0e0e0;
font-size: 1.2em;
}

/* Stili per altri bottoni (li raggruppo qui) */
.btn-salva, .btn-salva-db {
padding: 10px 20px;
background-color:#28a745;
color: white;
border: none;
border-radius: 5px;
font-weight: bold;
font-size: 1em;
cursor: pointer;
transition: background-color 0.3s;
vertical-align: middle;
margin-left: 5px;
}
.btn-salva:hover, .btn-salva-db:hover {
background-color: #218838; /* Verde più scuro */
}

.h1_index{
margin-bottom: 15px;
}

/* ======================================= */
/* === MEDIA QUERIES (RESPONSIVE) === */
/* ======================================= */

/* Nascondi checkbox e icona su desktop */
#hamburger-toggle,
.hamburger-icon {
display: none;
}


/* Tablet e telefoni (fino a 992px) - ATTIVAZIONE HAMBURGER */
@media (max-width: 992px) {
body {
/* Header più compatto */
padding-top: 80px;
}
header {
padding: 15px 0;
}

/* Mostra l'icona hamburger */
.hamburger-icon {
display: block;
cursor: pointer;
padding: 10px;
z-index: 1001; /* Sopra tutto */
}
.hamburger-icon span {
display: block;
width: 25px;
height: 3px;
background-color: #fff;
margin: 5px 0;
transition: all 0.3s ease;
}

/* Nascondi il menu desktop */
.nav-menu {
display: none;
position: absolute;
top: 100%; /* Sotto l'header (es. 78px) */
left: 0;
width: 100%;
background-color: #1f1f1f;
box-shadow: 0 5px 10px rgba(0,0,0,0.5);
flex-direction: column;
align-items: center;
padding: 20px;
gap: 20px;
}

/* Quando la checkbox è cliccata, mostra il menu */
#hamburger-toggle:checked ~ .nav-menu {
display: flex;
}

/* Animazione icona (opzionale ma carina) */
#hamburger-toggle:checked ~ .hamburger-icon span:nth-child(1) {
transform: rotate(45deg) translate(5px, 5px);
}
#hamburger-toggle:checked ~ .hamburger-icon span:nth-child(2) {
opacity: 0;
}
#hamburger-toggle:checked ~ .hamburger-icon span:nth-child(3) {
transform: rotate(-45deg) translate(5px, -5px);
}

/* Adatta gli elementi interni del menu */
.nav-links {
flex-direction: column;
align-items: center;
width: 100%;
gap: 20px;
}
.nav-links form {
flex-direction: column;
align-items: center;
gap: 15px;
width: 100%;
margin-right: 0; /* Resetta il margine */
}
.nav-links select {
width: 80%;
max-width: 300px;
}
.nav-search input[type="text"] {
min-width: 250px;
font-size: 1em;
}

/* La griglia passa a 3 colonne */
.griglia-film {
grid-template-columns: repeat(3, 1fr);
gap: 15px;
}
}


/* Tablet verticale e smartphone (fino a 768px) */
@media (max-width: 768px) {
.nav-search input[type="text"] {
min-width: 200px;
font-size: 0.9em;
}

/* Adattamento filtri select */
.nav-links select[name="serie_id"],
.nav-links select[name="stagione_num"] {
font-size: 0.9em;
width: 80%;
max-width: 280px;
}

.descrizione-veloce h3,
.titolo_cover_index {
font-size: 0.9em;
}
}


/* Mobile (fino a 480px) → 3 colonne */
@media (max-width: 480px) {
/* L'header è ancora più alto se i bottoni vanno a capo */
body {
padding-top: 140px;
}

/* Griglia resta a 3 colonne, come da richiesta */
.griglia-film {
grid-template-columns: repeat(3, 1fr);
gap: 10px;
}

.descrizione-veloce {
padding: 5px;
}
.descrizione-veloce h3,
.titolo_cover_index {
font-size: 0.8em;
text-align: center;
}
.descrizione-veloce p {
font-size: 0.7em;
}
.titolo_cover_index {
font-size: 9px;
}
.nav-search input[type="text"] {
min-width: 180px; /* Ancora più piccolo */
font-size: 0.85em;
}
}

/* ======================================= */
/* === FORM E GESTIONE DATI (DARK MODE) === */
/* ======================================= */
.form-container,
.gestione-box {
    background: var(--bg-card);
    padding: 30px;
    border-radius: 12px;
    border: 1px solid var(--border-color);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
    margin-top: 20px;
}
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}
.form-grid .full-width {
    grid-column: 1 / -1;
}

.gestione-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 30px;
    margin-top: 20px;
}

h1.h1_aggiungi_manuale, h1.h1_gestione_dati, h1.h1_index {
    text-align: center;
    margin-bottom: 25px;
    margin-top: 20px;
    color: var(--text-color);
    font-size: 2rem;
    font-weight: 800;
}

h2 {
    font-size: 1.4rem;
    color: var(--text-color);
    border-bottom: 1px solid var(--accent-color);
    padding-bottom: 10px;
    margin-bottom: 20px;
    margin-top: 15px;
}
h2:first-of-type {
    margin-top: 0;
}

label {
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-muted);
    display: block;
}

input[type="text"],
input[type="number"],
input[type="date"],
input[type="url"],
input[type="file"],
textarea, select {
    width: 100%;
    padding: 10px 12px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: #111;
    color: var(--text-color);
    font-size: 1rem;
    transition: border-color 0.3s, box-shadow 0.3s;
    font-family: inherit;
}
input:focus, textarea:focus, select:focus {
    border-color: var(--accent-color);
    outline: none;
    box-shadow: 0 0 5px rgba(229, 9, 20, 0.5);
}
input[readonly] {
    background: #1a1a1a;
    color: #666;
    cursor: not-allowed;
}

.btn, .btn-salva-db, .btn-add {
    display: inline-block;
    padding: 12px 25px;
    background-color: var(--accent-color);
    color: white;
    text-decoration: none;
    font-weight: bold;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    transition: 0.3s;
    font-size: 1rem;
    text-align: center;
}
.btn:hover, .btn-salva-db:hover, .btn-add:hover {
    background-color: var(--accent-hover);
    transform: translateY(-2px);
}
.btn-salva-db {
    width: 100%;
    margin-top: 30px;
    background: linear-gradient(135deg, var(--accent-color), #8b0000);
}

.btn-delete { background: #dc3545; color: white; border: none; padding: 6px 12px; font-size: 0.9em; border-radius: 4px; cursor: pointer; margin-left: 5px; font-weight: bold; }
.btn-delete:hover { background: #c82333; }
.btn-mod { background: #333; color: white; border: 1px solid #555; padding: 6px 12px; font-size: 0.9em; border-radius: 4px; cursor: pointer; margin-left: 5px; }
.btn-mod:hover { background: #444; border-color: #777;}

.lista-dati { 
    max-height: 400px; 
    overflow-y: auto; 
    border: 1px solid var(--border-color); 
    border-radius: 8px; 
    padding: 10px; 
    background: #111;
}
.lista-dati ul { list-style: none; padding: 0; margin: 0; }
.lista-dati li { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    padding: 12px 10px; 
    border-bottom: 1px solid var(--border-color); 
}
.lista-dati li:last-child {
    border-bottom: none;
}

.form-group {
    grid-column: 1 / -1;
    background: rgba(255, 255, 255, 0.03);
    padding: 20px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Messaggi */
.messaggio, #messaggio_stato {
    padding: 15px 20px;
    margin: 15px auto;
    max-width: 900px;
    border-radius: 8px;
    text-align: center;
    font-weight: 600;
    font-size: 1rem;
}
.success, #messaggio_stato {
    color: #4CAF50;
    background-color: rgba(76, 175, 80, 0.1);
    border: 1px solid #4CAF50;
}
.error {
    color: #f44336;
    background-color: rgba(244, 67, 54, 0.1);
    border: 1px solid #f44336;
}

.form-aggiungi {
    display: flex; gap: 10px; margin-bottom: 20px; 
}
.form-aggiungi input { flex-grow: 1; }

@media (max-width: 768px) {
    .form-grid {
        grid-template-columns: 1fr;
    }
}