/* =========================
   Base + Palette globale
   ========================= */
:root {
  /* Palette derivata dal footer */
  --color-bg: #fff;
  --color-text: #264159;
  --color-link: #295084;
  --color-border: #e1e6ec;
  --color-border-muted: #b5c1d1;
  --color-soft-bg: #f8fbfd;
  --color-hover-bg: #edf2f6;
  --color-hover-bg-strong: #d9e2ef;
  --color-muted: #3b5678;
  --accent: #6697c1;

  /* Ombre e overlay coerenti con footer/modal */
  --shadow-1: 0 4px 16px rgba(20,30,60,0.08);
  --shadow-2: 0 8px 32px rgba(20,30,60,0.15);
  --overlay: rgba(20, 30, 60, 0.4);

  /* Bottoni/azioni */
  --btn-bg: var(--color-link);
  --btn-bg-hover: #1f3c63;
}

/* Reset + base */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }
body {
  font-family: Arial, sans-serif;
  line-height: 1.5;
  color: var(--color-text);
  background: #f9fafc;
}

/* Link generici */
a {
  color: var(--color-link);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* =========================
   HERO (da hero.css, ripulito)
   ========================= */
#hero {
  position: relative;
  height: 50vh;
  min-height: 320px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: #fff;
  text-align: center;
  border-bottom: 4px solid var(--accent);
  border-radius: 0 0 18px 18px;
  overflow: hidden;
}
.hero-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1;
  border-radius: inherit;
  pointer-events: none;
}
/* Sopra overlay */
#hero > *:not(.hero-overlay) {
  position: relative;
  z-index: 2;
}
#hero h1 {
  font-size: 2.7rem;
  margin-bottom: .3em;
  letter-spacing: 0.04em;
  text-shadow: 0 2px 8px rgba(0,0,0,0.85), 0 0px 2px #000;
}
#hero p {
  font-size: 1.3rem;
  margin-bottom: 0;
  font-style: italic;
  text-shadow: 0 2px 8px rgba(0,0,0,0.7), 0 0px 2px #000;
}
/* Correzione typo nelle classi dedicate */
.sciname { font-weight: bold; }
.author { font-size: 1rem; margin-left: 8px; font-style: normal; }

/* =========================
   GALLERIA / SEZIONI (da schede.css, ripulito e allineato palette)
   ========================= */
#gallery {
  padding: 3em 1em;
  background: #f5f5f5;
  max-width: 1200px;
  margin: 0 auto 2em auto;
  border-radius: 15px;
  box-shadow: var(--shadow-1);
}
#gallery h2 {
  color: var(--color-link);
  text-align: center;
  font-size: 2rem;
  margin-bottom: 1.2em;
}

.carousel {
  position: relative;
  overflow: hidden;
  border-radius: 13px;
  box-shadow: 0 4px 14px rgba(0,0,0,.13);
  margin-bottom: 1em;
}

#mainPhoto {
  width: 100%;
  max-height: 65vh;
  object-fit: cover;
  transition: opacity .6s;
  border-radius: 8px;
}

.thumbs {
  margin-top: 1.5rem;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px,1fr));
  gap: 10px;
}
.thumbs img {
  width: 100%;
  height: 70px;
  object-fit: cover;
  border-radius: 5px;
  cursor: pointer;
  opacity: .8;
  border: 2px solid var(--color-border);
  transition: .3s;
}
.thumbs img:hover,
.thumbs img.active {
  opacity: 1;
  border-color: var(--accent);
  box-shadow: 0 0 5px rgba(102,151,193,0.33);
}

/* Boxed sections */
.boxed {
  background: var(--color-bg);
  border-radius: 12px;
  border: 1.5px solid var(--color-border);
  box-shadow: 0 2px 10px rgba(20,30,60,0.05);
  padding: 1.5em;
  margin-bottom: 1.5em;
}

section {
  padding: 2.3em 1.2em 1em 1.2em;
  max-width: 820px;
  margin: 0 auto;
}

h2 {
  margin-bottom: .6em;
  color: var(--color-link);
  font-size: 1.5rem;
  letter-spacing: 0.02em;
}

/* Liste */
ul { list-style: disc inside; margin-bottom: 1em; }
li { margin-bottom: .5em; }

/* Accenti “scientifici” in palette */
.sci-name { color: var(--accent); }

/* Scroll to top */
#scrollToTopBtn {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 48px;
  height: 48px;
  background-color: var(--btn-bg);
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 24px;
  cursor: pointer;
  z-index: 999;
  box-shadow: 0 4px 8px rgba(0,0,0,0.3);
  transition: opacity 0.3s ease, background-color .2s ease;
}
#scrollToTopBtn:hover { background-color: var(--btn-bg-hover); }

/* =========================
   COOKIE BANNER (da banner.css, allineato palette)
   ========================= */
/* Versione unica e centrata */
.cookie-banner {
  position: fixed;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  width: min(92vw, 640px);
  background: var(--color-bg);
  color: var(--color-text);
  padding: 1.4rem 1.2rem;
  border-radius: 10px;
  box-shadow: 0 8px 22px rgba(0,0,0,.25);
  z-index: 9999;
  font-size: .95rem;
  line-height: 1.5;
  display: none; /* nascosto di default */
  border: 2px solid var(--color-border);
}
.cookie-banner p { margin: 0 0 1rem 0; text-align: justify; }

.cookie-options {
  display: flex; flex-wrap: wrap;
  gap: 1rem 2rem;
  margin-bottom: 1.2rem;
}
.cookie-options label {
  display: flex; align-items: center; gap: .5rem;
  cursor: pointer; user-select: none;
}
.cookie-banner input[type="checkbox"] {
  accent-color: var(--color-link);
  transform: scale(1.2);
}

#cookie-save {
  display: inline-block;
  background: var(--btn-bg);
  border: none;
  color: #fff;
  padding: .75rem 1.8rem;
  border-radius: 6px;
  font-size: 1rem;
  cursor: pointer;
  transition: background .25s ease;
}
#cookie-save:hover, #cookie-save:focus {
  background: var(--btn-bg-hover);
  outline: none;
}

@media (max-width: 480px) {
  .cookie-banner { font-size: .85rem; padding: 1rem; }
  .cookie-options { flex-direction: column; gap: .6rem; }
  #cookie-save { width: 100%; text-align: center; }
}

/* =========================
   MODALI GENERICHE (footer + overlay coerenti)
   ========================= */
/* Overlay generico */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  background: var(--overlay);
  z-index: 1000;
  backdrop-filter: blur(3px);
}

/* Contenuto modale */
.modal-content {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: var(--color-bg);
  border-radius: 18px;
  box-shadow: var(--shadow-2);
  border: 2px solid var(--color-border);
  padding: 2.5rem;
  width: 100%; max-width: 700px;
  max-height: 80vh; overflow-y: auto;
}

.modal-header { text-align: center; margin-bottom: 2rem; }
.modal-title {
  color: var(--color-text);
  font-size: 2rem;
  margin-bottom: 0.5rem;
  letter-spacing: 1px;
}
.modal-body {
  color: #234;
  line-height: 1.6;
  font-size: 1.05rem;
}
.modal-body h3 {
  color: var(--color-link);
  font-size: 1.4rem;
  margin: 1.5rem 0 1rem 0;
  border-bottom: 2px solid var(--color-border);
  padding-bottom: 0.5rem;
}
.modal-body p { margin-bottom: 1.2rem; }
.modal-body a {
  color: var(--color-link);
  text-decoration: none;
  font-weight: 600;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  background: var(--color-hover-bg);
  transition: all 0.16s ease;
}
.modal-body a:hover {
  background: var(--color-hover-bg-strong);
  transform: translateY(-1px);
}

.email-protected {
  color: var(--color-link);
  text-decoration: none;
  font-weight: 600;
  padding: 0.2rem 0.4rem;
  border-radius: 4px;
  background: var(--color-hover-bg);
  cursor: pointer;
  transition: all 0.16s ease;
}
.email-protected:hover {
  background: var(--color-hover-bg-strong);
  transform: translateY(-1px);
}

.close-button {
  position: absolute; top: 1rem; right: 1.5rem;
  background: none; border: none;
  font-size: 2rem; color: var(--color-muted);
  cursor: pointer; line-height: 1;
  padding: 0.5rem; border-radius: 50%;
  transition: all 0.16s ease;
}
.close-button:hover {
  background: var(--color-hover-bg);
  color: var(--color-text);
  transform: scale(1.1);
}

/* =========================
   FOOTER (nuovo stile – sostituisce quello verde precedente)
   ========================= */
footer {
  text-align: center;
  padding: 1rem;
  background: var(--color-bg);
  border-radius: 12px;
  border: 2px solid var(--color-border);
  box-shadow: var(--shadow-1);
  margin: 2rem auto;
  max-width: 900px;
  color: var(--color-text);
  font-size: 1rem;
}
.info-link {
  color: var(--color-link);
  text-decoration: none;
  font-weight: 600;
  margin-left: 1rem;
  padding: 0.3rem 0.8rem;
  border: 1.5px solid var(--color-border-muted);
  border-radius: 8px;
  background: var(--color-soft-bg);
  transition: all 0.16s ease;
  cursor: pointer;
}
.info-link:hover {
  background: var(--color-hover-bg);
  border-color: var(--accent);
  transform: translateY(-1px);
}

/* =========================
   MODALE DI RICERCA (da search.css, armonizzato)
   ========================= */
body.search-popup-open {
  overflow: hidden !important;
  touch-action: none !important;
}

.search-popup {
  position: fixed; left: 0; top: 0;
  width: 100vw; height: 100vh;
  background: rgba(36, 65, 89, 0.16); /* coerente con palette blu */
  z-index: 9999;
  display: flex; align-items: center; justify-content: center;
  overscroll-behavior: contain;
}

.search-popup-content {
  background: var(--color-bg);
  border-radius: 18px;
  border: 2px solid var(--color-border);
  box-shadow: 0 4px 18px rgba(40,60,120,0.13), 0 2px 10px rgba(20,30,60,0.06);
  padding: 2.3em 2.3em 1.2em 2.3em;
  max-width: 420px;
  width: 97%;
  max-height: 60vh;
  overflow-y: auto;
  font-family: 'Georgia', serif;
  color: var(--color-text);
  text-align: left;
  animation: popup-fade-in 0.24s;
  position: relative;
  -webkit-overflow-scrolling: touch; /* iOS */
  box-sizing: border-box;
}

@keyframes popup-fade-in {
  from { transform: scale(.97) translateY(20px); opacity: 0; }
  to   { transform: scale(1)   translateY(0);   opacity: 1; }
}

.search-popup-content a {
  display: block;
  margin-bottom: 1.18em;
  padding: 0.65em 0.85em;
  border-radius: 12px;
  color: var(--color-link);
  background: var(--color-soft-bg);
  border: 1.5px solid var(--color-border-muted);
  text-decoration: none !important;
  font-size: 1.09em;
  transition: background 0.13s, border 0.13s, color 0.13s;
  font-family: 'Georgia', serif;
}
.search-popup-content a:hover {
  background: var(--color-hover-bg);
  border-color: var(--accent);
  color: var(--color-link);
  box-shadow: 0 2px 10px rgba(102,151,193,0.17);
}

.search-popup-content .desc {
  color: var(--color-muted);
  font-size: .96em;
  margin-top: 0.23em;
  display: block;
  line-height: 1.3;
}

/* =========================
   OVERLAY FOTO (da main-photo.css)
   ========================= */
.photo-overlay {
  position: fixed; top: 0; left: 0;
  width: 100vw; height: 100vh;
  background: rgba(0,0,0,0.8);
  display: flex; justify-content: center; align-items: center;
  z-index: 9999;
}
.photo-overlay img {
  max-width: 90vw; max-height: 90vh;
  box-shadow: 0 4px 30px rgba(0,0,0,0.7);
}

/* =========================
   RESPONSIVE
   ========================= */
@media (max-width: 768px) {
  /* Hero */
  #hero { height: 35vh; font-size: 1.1rem; }
  #hero h1 { font-size: 2rem; }

  /* Spaziature contenuti */
  #gallery, section { max-width: 98vw; padding: 1em 0.6em; }
  .carousel { max-height: 36vh; }
  #mainPhoto { max-height: 38vh; }

  /* Modali */
  .modal-content {
    padding: 1.5rem;
    margin: 1rem;
    max-width: calc(100% - 2rem);
  }
  .modal-title { font-size: 1.6rem; }
  .modal-body { font-size: 1rem; }

  /* Footer link incolonnato su mobile medio */
  .info-link {
    display: block;
    margin: 1rem auto 0;
    width: fit-content;
  }
}

@media (max-width: 600px) {
  .search-popup-content {
    max-width: 97vw !important;
    padding: 1em 0.6em 0.8em 0.6em;
  }
  .search-popup-content a {
    font-size: .98em;
    padding: 0.5em;
  }
}

@media (max-width: 480px) {
  /* Hero più compatto */
  #hero { height: 28vh; font-size: 1rem; }

  /* Contenuti */
  #gallery, section { max-width: 99vw; padding: 0.7em 0.3em; }
  .boxed { padding: 0.7em; }
  #gallery h2, h2 { font-size: 1.15rem; }
  #mainPhoto { max-height: 55vw; }

  /* Modale */
  .modal-content { padding: 1rem; }
  .close-button { top: 0.5rem; right: 1rem; font-size: 1.8rem; }
}

/* =========================
   TABELLE – stile coerente con la palette
   ========================= */

/* Contenitore scrollabile (consigliato attorno alla tabella) */
.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 1rem 0;
  background: var(--color-bg);
  border: 1.5px solid var(--color-border);
  border-radius: 12px;
  box-shadow: var(--shadow-1);
}

/* Tabella base */
table {
  width: 100%;
  border-collapse: separate;    /* permette i bordi arrotondati sulla thead */
  border-spacing: 0;
  font-size: 0.98rem;
  color: var(--color-text);
  background: var(--color-bg);
}

/* Intestazioni */
thead th {
  position: relative;
  text-align: left;
  font-weight: 700;
  color: var(--color-link);
  background: var(--color-soft-bg);
  border-bottom: 2px solid var(--color-border);
  padding: 0.75rem 0.9rem;
  white-space: nowrap;
}
thead th:first-child { border-top-left-radius: 10px; }
thead th:last-child  { border-top-right-radius: 10px; }

/* Celle */
tbody td, tfoot td, tfoot th {
  padding: 0.75rem 0.9rem;
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
}

/* Ultima riga senza bordo inferiore (se non c'è tfoot) */
tbody tr:last-child > * { border-bottom: 0; }

/* Zebra striping + hover */
tbody tr:nth-child(even) { background: var(--color-hover-bg); }
tbody tr:hover {
  background: var(--color-hover-bg-strong);
  transition: background .18s ease;
}

/* Focus accessibile quando si naviga con tastiera dentro la riga */
tbody tr:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* Link e pulsanti in tabella, coerenti con la palette */
table a {
  color: var(--color-link);
  text-decoration: none;
  font-weight: 600;
}
table a:hover { text-decoration: underline; }

/* Header “ordinabile” (se usi link/icone nel th) */
thead th a {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  color: inherit;
  text-decoration: none;
}
thead th a:hover { color: var(--color-link); text-decoration: underline; }
.sort-icon { font-size: .85em; color: var(--color-muted); }

/* Variante: header sticky (aggiungi .table--sticky a table o a .table-wrap) */
.table--sticky thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: linear-gradient(#f8fbfd, #f6f9fc);
  box-shadow: 0 2px 0 var(--color-border);
}

/* Caption */
caption {
  caption-side: top;
  text-align: left;
  padding: 0.6rem 0.2rem 0.6rem 0;
  color: var(--color-muted);
  font-size: .95rem;
}

/* Colonne e allineamenti tipici */
th.num, td.num,
th[data-type="number"], td[data-type="number"] {
  text-align: right;
  font-variant-numeric: tabular-nums;
}
th.center, td.center { text-align: center; }
th.nowrap, td.nowrap { white-space: nowrap; }
.col-narrow { width: 1%; white-space: nowrap; }

/* Badge/etichette dentro alle celle */
.badge {
  display: inline-block;
  padding: .15rem .55rem;
  border-radius: 999px;
  background: var(--color-soft-bg);
  color: var(--color-link);
  border: 1px solid var(--color-border-muted);
  font-size: .85em;
  line-height: 1.2;
}

/* Densità */
.table--compact tbody td, .table--compact thead th { padding: .5rem .6rem; }
.table--comfortable tbody td, .table--comfortable thead th { padding: 1rem 1.1rem; }

/* Bordi arrotondati anche in fondo se usi tfoot */
tfoot td:first-child, tfoot th:first-child { border-bottom-left-radius: 10px; }
tfoot td:last-child,  tfoot th:last-child  { border-bottom-right-radius: 10px; }

/* Stato “vuoto” elegante */
.table-empty {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--color-muted);
  font-style: italic;
}

/* Responsive fine-tuning */
@media (max-width: 768px) {
  table { font-size: .95rem; }
  thead th, tbody td { padding: .6rem .65rem; }
}
@media (max-width: 480px) {
  table { font-size: .92rem; }
  thead th, tbody td { padding: .5rem .55rem; }
  /* Utility per nascondere colonne su schermi piccoli */
  .hide-sm { display: none; }
}