* {
  box-sizing: border-box;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  margin: 0;
  padding: 0;
}

body {
  background-color: #0f172a;
  color: #f8fafc;
  padding: 0;
  margin: 0;
}

/* Header sticky con padding uniforme al main */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(15, 23, 42, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid #334155;
  padding: 15px 20px;
  width: 100%;
}

/* Main full-width con lo stesso padding laterale dell'header */
main {
  width: 100%;
  padding: 20px;
}

.controls {
  display: flex;
  gap: 10px;
  margin-bottom: 25px;
  flex-wrap: wrap;
}

input, select, textarea {
  padding: 10px;
  border-radius: 6px;
  border: 1px solid #334155;
  background-color: #1e293b;
  color: #fff;
  width: 100%;
}

.controls input, .controls select {
  width: auto;
  flex: 1;
  min-width: 150px;
}

button {
  padding: 10px 16px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-weight: bold;
}

.btn-primary {
  background-color: #2563eb;
  color: white;
}

.btn-primary:hover {
  background-color: #1d4ed8;
}

/* Grid layout per le schede */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
}

.card {
  background-color: #1e293b;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #334155;
  display: flex;
  flex-direction: column;
}

.card img {
  width: 100%;
  height: 280px;
  object-fit: cover;
  background-color: #0f172a;
}

.card-body {
  padding: 15px;
  display: flex;
  flex-direction: column;
  flex-grow: 1;
}

.card-badge {
  font-size: 0.75rem;
  text-transform: uppercase;
  background-color: #3b82f6;
  color: white;
  padding: 3px 8px;
  border-radius: 4px;
  align-self: flex-start;
  margin-bottom: 8px;
}

.card-title {
  font-size: 1.1rem;
  margin-bottom: 5px;
}

.card-details {
  font-size: 0.85rem;
  color: #94a3b8;
  margin-top: auto;
}

.card-details p {
  margin-top: 4px;
}

/* Modale */
.modal {
  position: fixed;
  top: 0; left: 0; width: 100%; height: 100%;
  background-color: rgba(0,0,0,0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-content {
  background-color: #1e293b;
  padding: 25px;
  border-radius: 8px;
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}

.close {
  position: absolute;
  top: 15px; right: 15px;
  font-size: 24px;
  cursor: pointer;
}

.hidden { display: none !important; }
.dettagli-group { margin-top: 15px; padding-top: 10px; border-top: 1px dashed #334155; }
.dettagli-group input { margin-top: 8px; }

/* ==========================================
   OTTIMIZZAZIONE RESPONSIVE PER SMARTPHONE
   ========================================== */

@media (max-width: 768px) {
  
  /* 1. Header fluido in colonna */
  header {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 12px 15px;
  }

  /* Logo centrato */
  .brand-logo {
    justify-content: center;
    width: 100%;
  }

  /* Contenitore ricerca e pulsanti auth */
  header > div:last-child {
    flex-direction: column;
    width: 100%;
    gap: 10px;
  }

  /* Barra ricerca utente a tutta larghezza */
  header > div:last-child > div:first-child {
    width: 100%;
    min-width: 100% !important;
  }

  /* PULSANTI HEADER: Griglia equa per 3 pulsanti perfetti */
  #auth-section {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr); /* 3 colonne identiche */
    gap: 6px;
  }

  #auth-section button, 
  #btn-my-collection {
    width: 100%;
    display: flex;
    flex-direction: column; /* Icona sopra, testo sotto se necessario */
    align-items: center;
    justify-content: center;
    text-align: center;
    font-size: 0.7rem;
    line-height: 1.1;
    padding: 8px 4px;
    min-height: 44px;
    box-sizing: border-box;
    white-space: normal; /* Permette il flow naturale del testo */
  }

  /* 2. Sezione Controlli / Filtri a tutta larghezza */
  .controls {
    flex-direction: column;
    gap: 10px;
  }

  .controls input, 
  .controls select, 
  .controls button {
    width: 100% !important;
    min-width: 100% !important;
  }

  /* 3. Sezione Analisi & Statistiche (Fix Titolo e Freccia) */
  #analytics-section > div:first-child {
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 6px;
  }

  #analytics-section h3 {
    font-size: 0.95rem !important;
    text-align: center;
  }

  #chart-toggle-icon {
    font-size: 0.8rem !important;
  }

  /* 4. Barra Info Profilo (Visite & Likes) */
  #profile-info-bar {
    flex-direction: column;
    align-items: stretch;
    text-align: center;
  }

  #profile-info-bar > div {
    justify-content: center;
  }

  #btn-like-profile {
    width: 100%;
    justify-content: center;
  }

  /* 5. Tessere Statistiche (2 per riga su smartphone) */
  #stats-bar > div {
    min-width: calc(50% - 6px) !important;
  }

  /* 6. Griglia Copertine (2 per riga su schermi piccoli) */
  .grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 12px;
  }

  .card img {
    height: 220px;
  }
}