:root{
  --primary:#1d4ed8;
  --card:#d6e7ff;
  --ink:#12458c;
  --bg:#2461b7;
  --ring:rgba(29,78,216,.18);
  --line:#9cb5dd;
}
*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font-family:Inter,system-ui,-apple-system,"Segoe UI",Roboto,Helvetica,Arial,sans-serif;
  background:var(--bg);
  color:var(--ink);
}
.page{min-height:100%;display:flex;justify-content:center;align-items:flex-start;padding:24px 12px}
.card{
  width:100%;max-width:760px;background:var(--card);border-radius:12px;
  padding:20px 18px 28px;box-shadow:0 6px 20px rgba(0,0,0,.12)
}
h1{margin:0 0 4px;text-align:center;font-size:24px}
.sub{margin:0 0 18px;text-align:center}
.row{margin:12px 0}
label{display:block;font-weight:600;margin-bottom:6px}
.help{font-size:13px;color:#2c5fa6}
input[type="text"],input[type="email"],input[type="date"],input[type="file"],select,textarea{
  width:100%;max-width:310px;padding:8px;border:1px solid var(--line);border-radius:6px;background:#fff
}
textarea{min-height:90px;max-width:100%}
.inline{display:flex;gap:14px;flex-wrap:wrap}
.inline label{font-weight:500;display:inline-flex;gap:6px;align-items:center}
hr{border:none;border-bottom:1px solid var(--line);margin:16px 0}

.btn{display:inline-flex;justify-content:center;align-items:center;padding:10px 16px;border:none;border-radius:8px;
     background:var(--primary);color:#fff;font-weight:700;cursor:pointer;transition:background .12s,transform .05s,box-shadow .12s}
.btn:hover{background:#1e40af;transform:translateY(-1px);box-shadow:0 2px 8px rgba(15,23,42,.2)}
.btn:disabled{background:#9ca3af;cursor:default;box-shadow:none}
.btn-full{width:100%;max-width:310px}

.btn-outline {
  background: transparent;
  border: 1px solid var(--primary);
  color: var(--primary);
  border-radius: 20px;
  padding: 6px 16px;
  text-transform: uppercase;
  font-weight: 600;
}
.btn-outline:hover {
  background: rgba(30, 64, 175, 0.05);
  transform: translateY(-1px);
  box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.codici-display {
  margin-top: 6px;
  font-size: 15px;
  color: #334155;
  font-weight: 400;
}

.warning{font-size:13px;color:#b91c1c;margin-top:6px;display:none}
.warning.visible{display:block}

#map{
  width:100%;
  height:320px;
  border:1px solid var(--line);
  border-radius:8px;
  background:#eef5ff;
  overflow:hidden;
}

/* ======== COLOR GRID (transparent, compact, no labels, sharp splits) ======== */
.color-section-title{font-weight:700;margin:8px 0 8px}
.color-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(64px,1fr));gap:10px;width:100%}
@media (max-width:420px){.color-grid{grid-template-columns:repeat(auto-fill,minmax(56px,1fr));gap:8px}}
.color-btn{
  display:flex;align-items:center;justify-content:center;padding:6px;border-radius:10px;
  background:transparent;border:1px solid transparent;cursor:pointer;
  transition:box-shadow .12s ease, transform .05s ease, border-color .12s ease;
  -webkit-tap-highlight-color: transparent;
}
.color-btn:active{transform:translateY(1px);box-shadow:0 2px 6px rgba(0,0,0,.12)}
.color-btn:hover{box-shadow:0 3px 10px rgba(15,23,42,.18)}
.color-btn.selected{border-color:var(--primary);box-shadow:0 0 0 3px var(--ring) inset}

.swatch{width:100%;height:28px;border-radius:8px;overflow:hidden;display:flex;border:1px solid rgba(18,69,140,.25)}
.part{height:100%}

/* Solid colors */
.c-nero{background:#000000}
.c-bianco{background:#ffffff}
.c-grigio{background:#8c8c8c}
.c-beige{background:#cbb592}
.c-verde{background:#447c43}
.c-rosso{background:#c9362e}
.c-marrone{background:#705241}
.c-marrone-scuro{background:#5c352f}
.c-giallo{background:#f6f069}
.c-arancio{background:#f28a3c}
.c-blu{background:#2a82da}

/* Info btn */
.info-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--primary); /* Il blu del tuo tema */
  color: #fff;
  font-family: "Times New Roman", Times, serif; /* Font serif per la 'i' classica */
  font-style: italic;
  font-weight: bold;
  font-size: 14px;
  margin-left: 8px;
  cursor: pointer;
  border: none;
  transition: transform 0.1s, background 0.2s;
  vertical-align: middle; /* Allinea col testo */
}

.info-btn:hover {
  background: #1e40af; /* Blu più scuro al passaggio */
  transform: scale(1.1);
}

/* Info box */
.info-box {
  display: none; /* Nascosto di base */
  background: #eff6ff; /* Azzurro chiarissimo */
  border-left: 4px solid var(--primary);
  padding: 12px;
  margin-top: 8px;
  margin-bottom: 8px;
  border-radius: 4px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink);
  box-shadow: 0 2px 5px rgba(0,0,0,0.05);
  animation: slideDown 0.2s ease-out;
}

.info-box.visible {
  display: block; /* Diventa visibile quando cliccato */
}

/* Animazione fluidità */
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-5px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Image preview box (A2-style) */
.image-preview-box{
  margin-top:12px;
  padding:12px;
  border:1px solid var(--line);
  border-radius:8px;
  background:#fff;
}
.image-preview-box h3{
  margin:0 0 10px;
  font-size:15px;
  color:var(--ink);
}
#previewContainer{
  display:flex;
  flex-wrap:wrap;
  gap:10px;
}
.preview-item{
  position:relative;
  width:80px;
  height:80px;
  border-radius:6px;
  overflow:hidden;
  border:1px solid #ccc;
  background:#f9fafb;
}
.preview-item img, .preview-item video{
  width:100%;
  height:100%;
  object-fit:cover;
}
.preview-item .thumbnail-delete{
  position:absolute;
  top:2px;
  right:2px;
  background:#ef4444;
  color:#fff;
  border:none;
  border-radius:50%;
  width:24px;
  height:24px;
  cursor:pointer;
  font-size:14px;
  font-weight:bold;
  display:flex;
  align-items:center;
  justify-content:center;
  transition:background 0.2s;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}
.preview-item .thumbnail-delete:hover{
  background:#dc2626;
}

/* Tendina Nome specie (verticale, agganciata sotto il campo) */
.species-autocomplete {
  display: none;
  background: #ffffff;
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(0,0,0,.18);
  border: 1px solid #dce3f1;
  max-height: 220px;
  overflow-y: auto;
}

.species-autocomplete-item { background-color: white !important; 
  display: block;
  padding: 11px 14px;
  width: 100%;
  text-align: left;
  border-bottom: 1px solid #eef3ff;
  color: #1e3a8a;
  font-size: 18px;
  line-height: 1.4;
}

.species-autocomplete-item:last-child {
  border-bottom: none;
}

.species-autocomplete-item:hover {
  background: #e8edff;
}

/* === MODALE DI CONFERMA INVIO === */
#successOverlay{
  position:fixed;
  inset:0;
  width:100vw;
  height:100vh;
  background:rgba(0,0,0,0.55);
  display:none;
  align-items:center;
  justify-content:center;
  z-index:9999;
}

#successModal{
  background:#ffffff;
  padding:24px 26px;
  border-radius:16px;
  max-width:320px;
  width:80%;
  text-align:center;
  box-shadow:0 10px 35px rgba(0,0,0,0.18);
  animation:successFadeUp .4s ease-out;
}

#successCheck{
  width:60px;
  height:60px;
  border-radius:50%;
  margin:0 auto 12px auto;
  display:flex;
  align-items:center;
  justify-content:center;
  background:#16a34a;
  color:#fff;
  font-size:32px;
  box-shadow:0 4px 14px rgba(22,163,74,0.55);
}

#successModal h2{
  margin:0;
  font-size:20px;
  font-weight:700;
  color:var(--ink);
}

#successModal p{
  margin-top:8px;
  font-size:14px;
  color:#374151;
  line-height:1.4;
}

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

/* .species-box removed */
.species-box {
  display: contents; /* Just in case */
}
#speciesFieldsContainer {
  background: transparent;
  border: none;
  box-shadow: none;
  padding: 0;
}

/* .cavita-row style removed */
.cavita-row {
  margin-top: 10px;
}
.cavita-row label {
  color: var(--ink);
}

/* Modale Codici Atlante */
.modal-backdrop {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,0.5); z-index: 10000;
  display: flex; align-items: center; justify-content: center;
}
.modal-content {
  background: #fff; padding: 20px; border-radius: 8px;
  width: 90%; max-width: 500px; max-height: 80vh; overflow-y: auto;
  position: relative;
}
.close-modal {
  position: absolute; top: 10px; right: 15px; font-size: 24px; cursor: pointer; font-weight: bold;
}

/* SPECIES CARDS REDESIGN (Inspired by FARFALLE) */
#speciesCardsContainer {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
  margin-top: 20px;
}

.species-card {
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
  display: flex;
  flex-direction: column;
}

.species-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 16px rgba(0,0,0,0.15);
}

.species-card-img-container {
  width: 100%;
  height: 200px;
  overflow: hidden;
  background-color: #f3f4f6;
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: zoom-in;
  position: relative;
}

/* Blurred backdrop overlay - DISABLED to use JS technique (Verzellino style) */
/*
.species-card-img-container::before {
  content: '';
  position: absolute;
  inset: 0;
  background: inherit; 
  filter: blur(8px) brightness(0.9);
  transform: scale(1.1); 
  z-index: 1;
}
*/

.species-card-img-container img {
  position: absolute; /* Changed from relative to absolute to match JS injection */
  top: 0;
  left: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  object-fit: contain; 
  background-color: transparent;
  transition: transform 0.3s ease;
  /* box-shadow: 0 0 15px rgba(0,0,0,0.2); Lift image from background */
}

.species-card:hover .species-card-img-container img {
  transform: scale(1.05);
}

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

.species-card-header {
  padding: 12px 16px 8px;
  background: #fff;
}

.species-common-name {
  display: block;
  font-size: 16px;
  font-weight: 700;
  color: #0056b3; /* Bold Blue */
  margin-bottom: 2px;
}

.species-sci-name {
  display: block;
  font-size: 14px;
  font-style: italic;
  color: #555;
}

.species-recognition {
  margin-bottom: 15px;
  font-size: 14px;
  color: var(--ink);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

.species-habitat {
  margin-bottom: 15px;
  font-size: 14px;
  color: var(--ink);
  line-height: 1.5;
  /* Optional: Limit to 3-4 lines if content is long, or let it flow */
  /* display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden; */
}

#submitButton:disabled {
  background: #9ca3af !important;
  cursor: not-allowed;
  box-shadow: none;
  opacity: 0.7;
}

/* Google Maps Search Box */
#mapSearch { max-width: 100%; }

/* Selettore dimensione/colore */
.filter-section-title {
  font-weight: 700;
  margin: 12px 0 6px 0;
  color: var(--ink);
}
.filter-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.filter-btn {
  background: #fff;
  border: 1px solid var(--line);
  padding: 6px 12px;
  border-radius: 16px;
  font-size: 14px;
  cursor: pointer;
  transition: all 0.2s;
}
.filter-btn:hover {
  background: #f0f7ff;
}
.filter-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

/* ========= LIGHTBOX ========= */
#lightbox {
  position: fixed;
  z-index: 10000;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.85);
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  backdrop-filter: blur(5px);
}

#lightbox.visible {
  opacity: 1;
  visibility: visible;
}

#lightbox img {
  max-width: 90%;
  max-height: 90%;
  border-radius: 8px;
  box-shadow: 0 5px 30px rgba(0,0,0,0.5);
  object-fit: contain;
}

.close-button {
  position: absolute;
  top: 20px;
  right: 20px;
  color: white;
  font-size: 40px;
  cursor: pointer;
  z-index: 10001;
  font-weight: bold;
  background: rgba(0,0,0,0.5);
  width: 50px;
  height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}
.close-button:hover {
  background: rgba(255,255,255,0.2);
}

/* Lightbox Delete Button */
.lightbox-delete {
    position: absolute;
    top: 20px;
    left: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(220, 38, 38, 0.9);
    color: #fff;
    font-weight: bold;
    font-size: 28px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    border: 2px solid #fff;
    z-index: 10001;
    transition: 0.2s;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    padding: 0;
    line-height: 1;
}

.lightbox-delete:hover {
    background: rgba(185, 28, 28, 1);
    transform: scale(1.1);
}

/* Lightbox Navigation Arrows */
.lightbox-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10001;
  padding: 0;
  line-height: 1;
  transition: background 0.2s, transform 0.15s;
}

.lightbox-arrow:hover {
  background: rgba(0, 0, 0, 0.75);
  transform: translateY(-50%) scale(1.05);
}

.lightbox-prev {
  left: 16px;
}

.lightbox-next {
  right: 16px;
}

@media (max-width: 640px) {
    .lightbox-delete {
        width: 34px;
        height: 34px;
        font-size: 24px;
        top: 12px;
        left: 16px;
    }
    .lightbox-arrow {
      width: 34px;
      height: 34px;
      font-size: 22px;
    }
}

/* Phenology Chart Redesign (Rounded Boxes) */
.phenology-container {
  display: flex;
  gap: 2px;
  width: 96%;
  margin-left: 2%;
  margin-right: 2%;
  margin-top: 12px;
  margin-bottom: 2px;
  border: none;
}

.phen-month-box {
  position: relative;
  flex: 1;
  aspect-ratio: 1.3; /* Shorter/Smaller (Wider than tall) */
  background: #e5e7eb; /* Default Inactive Gray */
  border-radius: 2px;
  overflow: hidden;
  display: flex;
}

.phen-decade {
  flex: 1;
  height: 100%;
  border: none;
}

.phen-letter {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #374151; /* Dark Grey Text */
  z-index: 2;
}

/* Colors */
.phen-green { background-color: #8cc63f; }
.phen-yellow { background-color: #fff200; }
.phen-white { background-color: #e5e7eb; } /* Match inactive gray */

/* Legacy Gradient Classes (remapped to simple colors or kept for backward compat if used elsewhere) */
/* We rely on 3-decade split now, so gradients might not be needed inside a decade, 
   but keeping them just in case existing logic produces them for a single decade slot. */
.phen-green-yellow { background: linear-gradient(to right, #8cc63f 50%, #fff200 50%); }
.phen-yellow-green { background: linear-gradient(to right, #fff200 50%, #8cc63f 50%); }

/* Remove old table styles if no longer needed, or override them above */


/* Partial phenology backgrounds */
.phen-green-yellow {
  background: linear-gradient(to right, #8cc63f 50%, #fff200 50%);
}
.phen-yellow-green {
  background: linear-gradient(to right, #fff200 50%, #8cc63f 50%);
}
.phen-white-green {
  background: linear-gradient(to right, #ffffff 50%, #8cc63f 50%);
}
.phen-green-white {
  background: linear-gradient(to right, #8cc63f 50%, #ffffff 50%);
}
.phen-white-yellow {
  background: linear-gradient(to right, #ffffff 50%, #fff200 50%);
}
.phen-yellow-white {
  background: linear-gradient(to right, #fff200 50%, #ffffff 50%);
}

/* Fractional Phenology (25% / 75%) */

/* Green-Yellow (Presence <-> Nesting) */
.phen-green-yellow-25 { background: linear-gradient(to right, #8cc63f 25%, #fff200 25%); } /* 1/4 Green, 3/4 Yellow */
.phen-green-yellow-75 { background: linear-gradient(to right, #8cc63f 75%, #fff200 75%); } /* 3/4 Green, 1/4 Yellow */
.phen-yellow-green-25 { background: linear-gradient(to right, #fff200 25%, #8cc63f 25%); } /* 1/4 Yellow, 3/4 Green */
.phen-yellow-green-75 { background: linear-gradient(to right, #fff200 75%, #8cc63f 75%); } /* 3/4 Yellow, 1/4 Green */

/* White-Green (Absence <-> Presence) */
.phen-white-green-25 { background: linear-gradient(to right, #ffffff 25%, #8cc63f 25%); } /* 1/4 White, 3/4 Green */
.phen-white-green-75 { background: linear-gradient(to right, #ffffff 75%, #8cc63f 75%); } /* 3/4 White, 1/4 Green */
.phen-green-white-25 { background: linear-gradient(to right, #8cc63f 25%, #ffffff 25%); } /* 1/4 Green, 3/4 White */
.phen-green-white-75 { background: linear-gradient(to right, #8cc63f 75%, #ffffff 75%); } /* 3/4 Green, 1/4 White */

/* White-Yellow (Absence <-> Nesting) */
.phen-white-yellow-25 { background: linear-gradient(to right, #ffffff 25%, #fff200 25%); }
.phen-white-yellow-75 { background: linear-gradient(to right, #ffffff 75%, #fff200 75%); }
.phen-yellow-white-25 { background: linear-gradient(to right, #fff200 25%, #ffffff 25%); }
.phen-yellow-white-75 { background: linear-gradient(to right, #fff200 75%, #ffffff 75%); }

/* Special Mixes */
.phen-mix-aug-pigliamosche {
  background: linear-gradient(to right, #fff200 25%, #ffffff 25%, #ffffff 50%, #8cc63f 50%);
}
