: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}

/* Info Box & Buttons */
.info-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--primary);
    color: #ffffff;
    border: none;
    font-family: serif;
    font-style: italic;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    margin-left: 8px;
    vertical-align: middle;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: background 0.2s, transform 0.1s;
}

.info-btn:hover {
    background: #1e40af;
    transform: scale(1.05);
}
.info-box {
    background: #f0f9ff;
    border: 1px solid #bae6fd;
    color: var(--ink);
    padding: 12px;
    border-radius: 8px;
    margin-top: 8px;
    font-size: 14px;
    line-height: 1.5;
    display: none;
}
.info-box.visible {
    display: block;
}

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

/* Image Preview */
.image-preview-box {
    margin-top: 12px;
    padding: 12px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
}
.image-preview-box h3 {
    margin: 0 0 10px 0;
    font-size: 15px;
    color: #334155;
}
#previewContainer {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}
.preview-item {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid #cbd5e1;
}
.preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ======== 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:#009E60}
.c-rosso{background:#FF4500}
.c-marrone{background:#8B5A2B}
.c-marrone-scuro{background:#5c352f}
.c-giallo{background:#FFD700}
.c-arancio{background:#FF8C00}
.c-blu{background:#0047AB}
.c-azzurro{background:#4DA6FF}
.c-rosso-mattone{background:#A52A2A}
.c-viola{background:#9400D3}

/* ======== SPECIES CARDS ======== */
.species-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    margin-top: 16px;
}

.species-card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
}

.species-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    border-color: var(--primary);
}

.species-card-img-container {
    height: 180px;
    background-color: #f1f5f9;
    position: relative;
}

.species-card-header {
    padding: 12px;
    border-bottom: 1px solid #e2e8f0;
    background: #f8fafc;
}

.species-common-name {
    display: block;
    font-weight: 700;
    font-size: 16px;
    color: #1e293b;
    margin-bottom: 2px;
}

.species-sci-name {
    display: block;
    font-size: 13px;
    color: #64748b;
    font-style: italic;
}

.species-card-body {
    padding: 12px;
    font-size: 14px;
    color: #334155;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.species-recognition {
    margin-bottom: 12px;
    line-height: 1.4;
}

.species-select-btn {
    width: 100%;
    margin-top: auto;
    font-size: 14px;
    padding: 8px;
}

/* Single Species View (Legacy but used) */
.species-images {
    display: flex;
    gap: 12px;
    margin-bottom: 12px;
}
.img-block {
    flex: 1;
    text-align: center;
}
.img-block img {
    width: 100%;
    height: auto;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
}
.caption {
    font-size: 12px;
    color: #64748b;
    margin-top: 4px;
}

/* Gallery Navigation Buttons */
.gallery-nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(0,0,0,0.1);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
    font-size: 18px;
    color: #1e293b;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: background 0.2s;
}

.gallery-nav-btn:hover {
    background: #fff;
    box-shadow: 0 4px 6px rgba(0,0,0,0.15);
}

.gallery-prev {
    left: 8px;
}

.gallery-next {
    right: 8px;
}

/* Lightbox */
.lightbox {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.95);
  display: none;
  justify-content: center;
  align-items: center;
  z-index: 10000;
  overflow: hidden; /* Prevent body scroll interactions */
}

.lightbox.visible {
  display: flex;
}

.lightbox-content {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden; /* Contain the zoomed image */
}

#lightboxImage {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  transition: transform 0.1s ease-out; /* Smooth zoom */
  cursor: grab;
  touch-action: none; /* Disable default touch actions for custom gestures */
  transform-origin: center center;
}

#lightboxImage:active {
  cursor: grabbing;
}

.lightbox-close {
  position: absolute;
  top: 20px;
  right: 20px;
  color: white;
  font-size: 40px;
  cursor: pointer;
  z-index: 10002;
  background: none;
  border: none;
  padding: 10px;
  line-height: 1;
  text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

.lightbox-prev, .lightbox-next {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255, 255, 255, 0.2);
  color: white;
  border: none;
  font-size: 24px;
  padding: 15px 10px;
  cursor: pointer;
  z-index: 10001;
  transition: background 0.2s;
}

.lightbox-prev:hover, .lightbox-next:hover {
  background: rgba(255, 255, 255, 0.4);
}

.lightbox-prev { left: 10px; }
.lightbox-next { right: 10px; }

.lightbox-delete {
  position: absolute;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: #ef4444;
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 4px;
  cursor: pointer;
  z-index: 10001;
  font-size: 14px;
}

/* Success Overlay */
#successOverlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 10000;
    justify-content: center;
    align-items: center;
}

#successModal {
    background: white;
    padding: 30px;
    border-radius: 12px;
    text-align: center;
    max-width: 90%;
    width: 400px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
}

#successCheck {
    width: 60px;
    height: 60px;
    background: #10b981;
    color: white;
    font-size: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 16px;
}

#successModal h2 {
    margin: 0 0 10px;
    color: #1f2937;
    font-size: 22px;
}

#successModal p {
    color: #4b5563;
    line-height: 1.5;
    margin: 0;
}

/* Phenology Chart (Rounded Boxes - Copied from UCCELLI) */
.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;
  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; }

/* Partial phenology backgrounds (for consistency) */
.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%); }
