/* ============================================================
   Design tokens
   ============================================================ */
:root {
  --bg:           #0f1117;
  --surface:      #1a1d27;
  --surface-2:    #22263a;
  --border:       #2e3350;
  --accent:       #4f6ef7;
  --accent-hover: #3d5ae0;
  --accent-glow:  rgba(79, 110, 247, 0.25);
  --text:         #e8eaf6;
  --text-muted:   #6b7299;
  --success:      #34d399;
  --error:        #f87171;
  --radius-sm:    8px;
  --radius-md:    14px;
  --radius-lg:    22px;
  --shadow-card:  0 2px 12px rgba(0, 0, 0, 0.45);
  --shadow-input: 0 0 0 3px var(--accent-glow);
  --transition:   all 0.2s ease;
  --font:         'Segoe UI', system-ui, -apple-system, sans-serif;
}

/* ============================================================
   Reset & base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Garantisce che [hidden] vinca sempre su qualsiasi display della classe */
[hidden] { display: none !important; }

html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.6;
}

img { display: block; max-width: 100%; }

/* ============================================================
   Header
   ============================================================ */
.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(15, 17, 23, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0.85rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  text-decoration: none;
}

.logo-img {
  height: 36px;
  width: auto;
  object-fit: contain;
  /* logo.png potrebbe avere sfondo bianco — filtro per adattarlo al tema scuro */
  filter: brightness(0) invert(1);
}

.logo-text {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.stats-badge {
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.25rem 0.75rem;
  white-space: nowrap;
}

/* ============================================================
   Store Banner
   ============================================================ */
.store-banner {
  background: linear-gradient(135deg, var(--surface) 0%, #1e2340 100%);
  border-bottom: 1px solid var(--border);
}

.store-banner-inner {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0.85rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.store-logo {
  height: 52px;
  width: auto;
  object-fit: contain;
  flex-shrink: 0;
  filter: brightness(0) invert(1);
}

.store-text {
  flex: 1;
  min-width: 200px;
}

.store-tagline {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 0.25rem;
}

.store-desc {
  font-size: 0.95rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.store-desc strong { color: var(--text); }

.store-cta {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.65rem 1.3rem;
  border-radius: var(--radius-md);
  transition: var(--transition);
  white-space: nowrap;
  flex-shrink: 0;
}

.store-cta:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px var(--accent-glow);
}

@media (max-width: 600px) {
  .store-banner-inner { padding: 1.2rem 1rem; gap: 1rem; }
  .store-logo { height: 40px; }
  .store-cta { width: 100%; justify-content: center; }
}

/* ============================================================
   Hero / Search
   ============================================================ */
main { flex: 1; }

.hero {
  max-width: 720px;
  margin: 0 auto;
  padding: 3.5rem 1.5rem 3rem;
  text-align: center;
}

.hero-title {
  font-size: clamp(2rem, 5vw, 3.2rem);
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1.1;
  margin-bottom: 0.6rem;
  background: linear-gradient(135deg, #fff 0%, var(--accent) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero-subtitle {
  font-size: 1rem;
  color: var(--text-muted);
  margin-bottom: 2.5rem;
}

.search-wrapper { width: 100%; }

.search-box {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 0 1.2rem;
  transition: var(--transition);
}

.search-box:focus-within {
  border-color: var(--accent);
  box-shadow: var(--shadow-input);
}

.search-icon {
  color: var(--text-muted);
  flex-shrink: 0;
  margin-right: 0.75rem;
}

.search-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-size: 1.1rem;
  font-family: var(--font);
  color: var(--text);
  padding: 1rem 0;
  min-width: 0;
}

.search-input::placeholder { color: var(--text-muted); }
.search-input::-webkit-search-cancel-button { display: none; }

.search-clear {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0.25rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
}

.search-clear:hover { color: var(--text); background: var(--surface-2); }

/* ============================================================
   Results section
   ============================================================ */
.results-section {
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 1.5rem 4rem;
}

/* States */
.state-loading,
.state-empty,
.state-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  padding: 4rem 1rem;
  color: var(--text-muted);
  font-size: 1rem;
}

.state-error { color: var(--error); }

/* Spinner */
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Codice group */
.codice-group {
  margin-bottom: 2.5rem;
  animation: fadeInUp 0.3s ease both;
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

.codice-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding-bottom: 0.6rem;
  border-bottom: 1px solid var(--border);
}

.codice-label {
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.01em;
}

.codice-count {
  font-size: 0.78rem;
  color: var(--text-muted);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 0.15rem 0.6rem;
}

/* Photo grid */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 1rem;
}

/* Photo card */
.photo-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
}

.photo-card:hover {
  border-color: var(--accent);
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(79, 110, 247, 0.2);
}

.photo-card:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.photo-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: var(--surface-2);
}

.photo-info {
  padding: 0.6rem 0.75rem;
}

.photo-filename {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: 'Courier New', monospace;
}

/* Results summary */
.results-summary {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 1.5rem;
  padding: 0.6rem 0;
}

.results-summary strong { color: var(--accent); }

/* ============================================================
   Lightbox
   ============================================================ */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox[hidden] { display: none; }

.lightbox-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  cursor: pointer;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.lightbox-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  max-width: 92vw;
  max-height: 92vh;
}

.lightbox-img {
  max-width: 90vw;
  max-height: 80vh;
  object-fit: contain;
  border-radius: var(--radius-md);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
  animation: zoomIn 0.2s ease;
}

@keyframes zoomIn {
  from { opacity: 0; transform: scale(0.92); }
  to   { opacity: 1; transform: scale(1); }
}

.lightbox-close {
  position: absolute;
  top: -2.5rem;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text);
  transition: var(--transition);
}

.lightbox-close:hover { background: var(--surface-2); color: var(--error); }

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(26, 29, 39, 0.85);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 42px;
  height: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text);
  transition: var(--transition);
  z-index: 2;
}

.lightbox-prev { left: -3.5rem; }
.lightbox-next { right: -3.5rem; }
.lightbox-nav:hover { background: var(--accent); border-color: var(--accent); }
.lightbox-nav:disabled { opacity: 0.3; cursor: default; }

.lightbox-caption {
  margin-top: 0.85rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  font-family: 'Courier New', monospace;
  text-align: center;
}

/* ============================================================
   Footer
   ============================================================ */
.site-footer {
  text-align: center;
  padding: 1.2rem;
  font-size: 0.78rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
}
.site-footer a{
  color: var(--text-muted);
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 600px) {
  .hero { padding: 3rem 1rem 2rem; }
  .photo-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .lightbox-prev { left: -2.5rem; }
  .lightbox-next { right: -2.5rem; }
  .lightbox-nav { width: 34px; height: 34px; }
}
