/* Reset & Base */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  line-height: 1.6;
  color: #333;
  background: #fff;
}

/* Focus visible per accessibilità (WCAG 2.1) */
*:focus-visible {
  outline: 3px solid #8B4513;
  outline-offset: 2px;
}

/* Hero */
.hero {
  background: linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5)), url('img/hero.jpg') center/cover;
  min-height: 60vh;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 4rem 1rem;
}

.hero-content {
  max-width: 800px;
}

.hero h1 {
  font-size: 2.5rem;
  margin-bottom: 1rem;
  color: white;
}

.hero p {
  font-size: 1.25rem;
  margin-bottom: 2rem;
  color: #f0f0f0;
}

.cta-btn {
  display: inline-block;
  background: #8B4513;
  color: white;
  padding: 1rem 2rem;
  border-radius: 6px;
  text-decoration: none;
  font-weight: 600;
  transition: background 0.3s ease;
}

.cta-btn:hover {
  background: #6B340A;
}

/* Progetti */
.progetti {
  padding: 4rem 1rem;
  max-width: 1200px;
  margin: 0 auto;
}

.progetti h2 {
  text-align: center;
  font-size: 2rem;
  margin-bottom: 2rem;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1.5rem;
}

.card {
  background: white;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  cursor: pointer;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  position: relative; /* Importante per z-index */
}

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

.card img {
  width: 100%;
  height: 220px;
  object-fit: cover;
}

.card-info {
  padding: 1.25rem;
  cursor: pointer; /* Mantiene pointer della card */
  z-index: 1; /* Assicura che sia clickabile */
}

.card-info h3 {
  font-size: 1.2rem;
  margin-bottom: 0.5rem;
}

.card-info p {
  font-size: 0.9rem;
  color: #666;
  line-height: 1.5;
  margin-bottom: 0.5rem;
}

.card-info .tags {
  font-size: 0.8rem;
  color: #888;
}

/* Contatti */
.contatti {
  padding: 4rem 1rem;
  background: #f8f9fa;
}

.contatti h2 {
  text-align: center;
  font-size: 2rem;
  margin-bottom: 2rem;
}

.contact-form {
  max-width: 600px;
  margin: 0 auto 2rem;
  display: grid;
  gap: 1rem;
}

.contact-form input,
.contact-form textarea {
  padding: 1rem;
  border: 2px solid #ddd;
  border-radius: 8px;
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.3s ease;
}

.contact-form input:focus,
.contact-form textarea:focus {
  border-color: #8B4513;
  outline: none;
}

.contact-form button {
  background: #8B4513;
  color: white;
  border: none;
  padding: 1rem 2rem;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.3s ease;
}

.contact-form button:hover {
  background: #6B340A;
}

.contact-info {
  text-align: center;
}

.contact-info p {
  margin: 0.5rem 0;
}

/* Footer */
footer {
  background: #1a1a1a;
  color: #ccc;
  padding: 2rem 1rem;
}

footer p {
  margin: 0;
  font-size: 0.9rem;
}

/* Navbar */
.navbar {
  background: #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
  position: sticky;
  top: 0;
  z-index: 10000;
}

.nav-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logo {
  font-size: 1.5rem;
  font-weight: 700;
  color: #8B4513;
  text-decoration: none;
}

.nav-menu {
  display: flex;
  list-style: none;
  gap: 2rem;
}

.nav-menu a {
  text-decoration: none;
  color: #333;
  font-weight: 500;
  transition: color 0.3s ease;
}

.nav-menu a:hover {
  color: #8B4513;
}

.nav-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.5rem;
}

.hamburger {
  display: block;
  width: 25px;
  height: 2px;
  background: #333;
  position: relative;
}

.hamburger::before,
.hamburger::after {
  content: '';
  position: absolute;
  width: 25px;
  height: 2px;
  background: #333;
  left: 0;
}

.hamburger::before {
  top: -7px;
}

.hamburger::after {
  top: 7px;
}

/* Modal Avanzato - Progetto con Galleria */
.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.95);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  padding: 1rem;
}

.modal[data-visible="true"] {
  display: flex;
  animation: fadeIn 0.2s ease;
}

.modal-content {
  background: #1a1a1a;
  border-radius: 12px;
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  user-select: text;
  -webkit-user-drag: none;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background: #2a2a2a;
  border-top-left-radius: 12px;
  border-top-right-radius: 12px;
}

.modal-header h2 {
  color: #f0f0f0;
  font-size: 1.4rem;
  font-weight: 600;
  margin: 0;
  line-height: 1.3;
  max-width: 70%;
}

.modal-close {
  background: rgba(255,255,255,0.1);
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 1.75rem;
  cursor: pointer;
  color: #f0f0f0;
  font-weight: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.2s;
  flex-shrink: 0;
}

.modal-close:hover {
  background: rgba(255,255,255,0.2);
  transform: scale(1.1);
}

.modal-close:focus-visible {
  outline: 3px solid #8B4513;
  outline-offset: 4px;
}

.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: -1;
}

.modal-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 1rem;
}

.project-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.5rem;
  background: #2a2a2a;
  border-bottom: 1px solid #3a3a3a;
  flex-wrap: wrap;
}

.category-badge {
  padding: 0.4rem 0.8rem;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 500;
  color: white;
  white-space: nowrap;
}

.project-meta time {
  color: #aaa;
  font-size: 0.9rem;
  white-space: nowrap;
}

.project-meta .author {
  color: #888;
  font-size: 0.9rem;
  white-space: nowrap;
}

.modal-main-container {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 1rem;
}

.modal-image {
  width: 100%;
  max-width: 100%;
  max-height: 60vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  object-position: center;
}

/* Preload normalizzazione dimensioni - CSS puro */
.modal-image.preload {
  width: 800px !important;
  height: 800px !important;
  max-height: none !important;
  max-width: none !important;
  object-fit: contain;
  object-position: center;
}

.modal-image.loaded {
  width: 100%;
  max-height: 60vh;
  height: auto;
  object-fit: contain;
  object-position: center;
  min-height: 100px;
}
/* Controls Galleria */
.gallery-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 0.75rem;
  padding: 0.75rem 1rem;
  background: #2a2a2a;
  border-radius: 8px;
  width: 100%;
  justify-content: center;
}

.nav-btn {
  background: #4a4a4a;
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  color: #f0f0f0;
  font-size: 1.25rem;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-btn:hover {
  background: #5a5a5a;
  transform: scale(1.05);
}

.nav-btn:focus-visible {
  outline: 3px solid #8B4513;
  outline-offset: 2px;
}

.counter {
  color: #aaa;
  font-size: 0.85rem;
  min-width: 100px;
  text-align: center;
}

/* Dots Navigation */
.dots-nav {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
  justify-content: center;
}

.dot-btn {
  background: #4a4a4a;
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  color: #aaa;
  font-size: 0.85rem;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.dot-btn:hover {
  background: #5a5a5a;
  color: #f0f0f0;
}

.dot-btn.active {
  background: #8B4513;
  color: white;
}

.dot-btn:focus-visible {
  outline: 3px solid #8B4513;
  outline-offset: 2px;
}

/* Descrizione Progetto */
.project-description {
  padding: 1.5rem 1.5rem 1.5rem;
  background: #2a2a2a;
  border-bottom-left-radius: 12px;
  border-bottom-right-radius: 12px;
  color: #ccc;
  font-size: 0.95rem;
  line-height: 1.7;
}

.modal-footer {
  padding: 1rem 1.5rem;
  background: #2a2a2a;
  border-top: 1px solid #3a3a3a;
}

.modal-footer .tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.modal-footer .tag {
  background: #3a3a3a;
  color: #aaa;
  padding: 0.3rem 0.8rem;
  border-radius: 20px;
  font-size: 0.8rem;
}

/* Loading spinner */
.loading {
  position: relative;
  text-align: center;
  padding: 2rem;
  color: #666;
}

.loading::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 24px;
  height: 24px;
  border: 3px solid #8B4513;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Responsive */
@media (max-width: 768px) {
  .nav-menu {
    display: none;
  }

  .nav-toggle {
    display: block;
  }

  .hero h1 {
    font-size: 1.8rem;
  }

  .hero p {
    font-size: 1rem;
  }

  .grid {
    grid-template-columns: 1fr;
  }

  footer {
    grid-template-columns: 1fr;
    text-align: center;
  }

  .modal-header {
    flex-direction: column;
    gap: 0.5rem;
    text-align: center;
  }

  .modal-header h2 {
    max-width: 100%;
  }

  .modal-close {
    align-self: flex-end;
  }

  .modal-main-container {
    padding: 0.5rem;
  }

  .modal-image {
    max-height: 50vh;
  }

  .gallery-controls {
    padding: 0.5rem;
    gap: 0.5rem;
  }

  .counter {
    min-width: auto;
    font-size: 0.8rem;
  }

  .nav-btn {
    width: 38px;
    height: 38px;
  }

  .dot-btn {
    width: 32px;
    height: 32px;
    font-size: 0.8rem;
  }

  .project-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
    padding: 0.75rem;
  }

  .project-description {
    font-size: 0.9rem;
    padding: 1rem;
  }
}

/* Mobile nav aperto */
.nav-menu.active {
  display: flex;
  flex-direction: column;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: white;
  padding: 1rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.nav-menu.active li {
  padding: 0.5rem 0;
  border-bottom: 1px solid #eee;
}

.nav-menu.active li:last-child {
  border-bottom: none;
}