/* CSS Variables for easier maintenance */
:root {
  --primary-color: #007bff;
  --secondary-color: green;
  --secondary-color-dark: darkgreen;
  --border-color: #ccc;
  --border-color-light: #ddd;
  --background-light: #f4f4f4;
  --text-color-dark: #333;
  --text-color-medium: #444;
  --text-color-light: #777;
  --error-color: red;
  --link-color: rgb(0, 140, 255);
  --shadow-color: rgba(0, 0, 0, 0.1);

  --spacing-extra-small: 3px;
  --spacing-small: 5px;
  --spacing-medium: 10px;
  --spacing-large: 15px;
  --spacing-extra-large: 20px;
  --spacing-jumbo: 30px;

  --section-padding: var(--spacing-jumbo) var(--spacing-extra-large);
  --column-gap: var(--spacing-extra-large);
  --column-padding: var(--spacing-large);
}

/* Body Styles */
body {
  font-family: "Open Sans", sans-serif, Arial, sans-serif;
  margin: 0;
  padding: 0;
  /* IMPORTANT: Set padding-top to account for the largest header height at load */
  padding-top: 160px !important; /* This should always be the max initial height */
  display: block;
  min-height: 100vh;
  background-color: transparent;
  position: relative;
}

html {
  scroll-padding-top: 160px !important; /* Match scroll padding to body padding */
  scroll-behavior: smooth;
}

.hidden {
  display: none !important;
}

/* Sticky Header Styles */
#sticky-header {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  background-color: white;
  padding: var(--spacing-medium) var(--spacing-extra-large); /* 10px 20px */
  box-shadow: 0 2px 5px var(--shadow-color);
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: center;

  /* NEW: Define initial height and add smooth transition for height changes */
  height: 140px; /* Default desktop height: 120px (logo) + 20px (padding) */
  transition: height 0.3s ease-in-out, background-color 0.3s ease-in-out, box-shadow 0.3s ease-in-out;
}

.header-container {
  width: 100%;
  max-width: 1200px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 100%; /* Ensure container takes full height of sticky-header */
}

.logo {
  margin-right: var(--spacing-extra-large);
  display: flex;
  align-items: center;
}

.logo a {
  text-decoration: none;
}

.logo img {
  display: block;
  height: 120px;
  width: auto;
  margin: 0;
  padding: 0;
  /* NEW: Add transition for logo height */
  transition: height 0.3s ease-in-out;
}

/* MODIFIED: Default state for .main-nav - Hidden by default globally */
.main-nav {
  display: none; /* ADDED: Hidden by default globally for mobile-first approach */
  position: absolute; /* Needed for slide animation on mobile */
  top: 100%; /* Position below header initially */
  left: 0;
  width: 100%;
  background-color: white;
  box-shadow: 0 2px 5px var(--shadow-color);
  flex-direction: column; /* Default to column for mobile first */
  align-items: flex-start;
  padding: var(--spacing-medium) var(--spacing-extra-large);
  transition: transform 0.3s ease-in-out;
  transform: translateY(-100%); /* Visually off-screen initially */
  z-index: 1000;
}

.main-nav ul {
  list-style: none;
  padding: 0;
  margin: 0;
  /* MODIFIED: display: flex; for main-nav ul will be set in desktop media query */
  gap: var(--spacing-large);
  align-items: center;
}

.main-nav a {
  text-decoration: none;
  color: var(--text-color-dark);
  font-size: 1em;
  padding: var(--spacing-small) var(--spacing-medium);
  transition: color 0.3s ease, font-size 0.3s ease, padding 0.3s ease; /* NEW: Add transition for font-size and padding */
}

.main-nav a:hover {
  color: var(--primary-color);
}

.cta-button {
  display: inline-block;
  padding: var(--spacing-medium) var(--spacing-large);
  background-color: var(--secondary-color);
  color: white;
  font-size: 1em;
  font-weight: bold;
  text-decoration: none;
  border: none;
  border-radius: var(--spacing-small);
  cursor: pointer;
  margin-left: var(--spacing-extra-large);
  /* NEW: Add transition for padding and font-size */
  transition: background-color 0.3s ease, padding 0.3s ease, font-size 0.3s ease;
}

.cta-button:hover {
  background-color: var(--secondary-color-dark);
}

.hamburger-icon {
  display: none; /* Hidden by default (for desktop) */
  background: none;
  border: none;
  font-size: 1.8em;
  color: var(--text-color-dark);
  cursor: pointer;
  padding: var(--spacing-small);
  z-index: 1001;
  margin-left: var(--spacing-medium);
}

/* MODIFIED: The .main-nav.show is now effectively controlled by JS direct styles */
/* This rule can still be here as a fallback or for visual clarity, but JS takes precedence */

/* NEW: Styles for the sticky header state - THIS IS THE FIX FOR CLS */

/* Adjust logo size within the sticky header */

/* Adjust nav links within the sticky header */

/* Adjust CTA button within the sticky header */


/* Intro Section */
.intro-section {
  padding: var(--section-padding);
  padding-bottom: 0px;
  text-align: center;
  margin-bottom: 0px;
  max-width: 800px;
  margin-left: auto;
  margin-right: auto;
}

/* --- START: This block has been added to fix the "Uses deprecated APIs" warning --- */
.intro-section h1 {
  color: var(--primary-color);
  font-size: 3em !important; /* Adjusted to resolve the warning with !important */
  margin-bottom: var(--spacing-medium);
  line-height: 1.2; /* Added for readability */
}

/* Optional: If you have h1s in other sections, you could also add a general rule */
section h1 {
  font-size: 2.5em !important; /* This ensures all h1s inside any <section> have a defined font-size with !important */
}

/* Example for smaller screens, if you use media queries */
@media (max-width: 768px) {
  .intro-section h1 {
    font-size: 2.2em !important; /* Adjust for mobile with !important */
  }
}
/* --- END: Added CSS block --- */


.intro-section p {
  color: var(--text-color-dark);
  font-size: 1.2em;
  line-height: 1.6;
  margin-bottom: 0px;
  text-align: left;
}

/* Form */
form {
  width: 80%;
  max-width: 800px;
  background: white;
  padding: var(--spacing-extra-large);
  border-radius: 8px;
  box-shadow: 0px 4px 6px var(--shadow-color);
  margin-top: 0px;
  margin-left: auto;
  margin-right: auto;
}

.radio-group {
  display: flex;
  align-items: center;
  gap: var(--spacing-medium);
  margin-bottom: var(--spacing-large);
}

.input-group {
  display: flex;
  flex-direction: column;
  margin-bottom: var(--spacing-large);
}

.input-group.text-input-box:not(.hidden) {
  min-height: 150px;
  transition: min-height 0.3s ease;
}

.input-group.file-input-box:not(.hidden) {
  display: flex;
  flex-direction: column;
  min-height: auto;
}

textarea {
  width: 100%;
  height: 120px;
  resize: vertical;
  padding: 8px;
  border-radius: var(--spacing-small);
  border: 1px solid var(--border-color);
  font-size: 1.1em;
}

textarea.is-invalid {
  border-color: var(--error-color);
}

input[type="email"] {
  width: 50%;
  padding: 8px;
  border-radius: var(--spacing-small);
  border: 1px solid var(--border-color);
  font-size: 1.1em;
}

.file-input-box {
  display: block;
}

.file-input-box input[type="file"] {
  display: none;
}

.file-input-box label {
  display: inline-block;
  padding: var(--spacing-medium);
  background-color: var(--background-light);
  border: 1px solid var(--border-color);
  border-radius: var(--spacing-small);
  cursor: pointer;
}

.file-input-box input[type="file"]:focus + label {
  border-color: var(--secondary-color);
}

.terms-container {
  display: flex;
  align-items: center;
  gap: var(--spacing-medium);
  margin-top: var(--spacing-medium);
}

.terms-container input[type="checkbox"] {
  margin: 0;
  width: 18px;
  height: 18px;
}

.terms-container label {
  font-size: 14px;
}

.terms-container a {
  color: var(--link-color);
  text-decoration: underline;
  cursor: pointer;
}

.submit-button {
  width: 100%;
  padding: var(--spacing-medium);
  background-color: var(--secondary-color);
  color: white;
  font-size: 16px;
  border: none;
  border-radius: var(--spacing-small);
  cursor: pointer;
  margin-top: var(--spacing-large);
}

.submit-button:hover:not(:disabled) {
  background-color: var(--secondary-color-dark);
}

/* Style for disabled button */
.submit-button:disabled {
  background-color: #cccccc; /* Lighter grey */
  cursor: not-allowed;
}

.error-message {
  font-size: 0.8em;
  margin-top: var(--spacing-small);
  color: var(--error-color); /* Kept this as it was also in Team A's version */
}

/* RE-ADDED: Classes for script.js displayMessage function to restore colors */
/* END RE-ADDED CLASSES */

/* Styles for the message container itself */
.message-container {
  /* Ensure it has space and height */
  padding: var(--spacing-medium) var(--spacing-large); /* Adds internal padding */
  margin: var(--spacing-large) auto; /* Centers with top/bottom margin */
  border-radius: var(--spacing-small);
  text-align: center;
  font-size: 1.1em;
  max-width: 600px; /* Limits width for better readability */
  box-shadow: 0 2px 5px var(--shadow-color); /* Light shadow */
  box-sizing: border-box; /* Includes padding in width/height calculation */
  display: block; /* Ensures it's always a block when not hidden */
}

/* Specific styles for message types (like success, error, info) */
.message-container.success {
  background-color: #e6ffe6; /* Light green background */
  border: 1px solid var(--secondary-color); /* Green border */
  color: var(--secondary-color-dark); /* Darker green text */
}

.message-container.error {
  background-color: #ffe6e6; /* Light red background */
  border: 1px solid var(--error-color); /* Red border */
  color: var(--error-color); /* Red text */
}

/* Styles for the close button inside the message container */
.message-container .close-button {
  float: right; /* Position to the right */
  font-size: 1.5em;
  font-weight: bold;
  line-height: 1;
  color: var(--text-color-dark);
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  margin-left: var(--spacing-medium);
}

.message-container .close-button:hover {
  color: black;
}

.input-info {
  font-size: 0.9em;
  color: var(--text-color-light);
  margin-top: var(--spacing-extra-small);
}

/* MODIFIED: Styling for success message - color now handled by .text-success */

.required-info {
  font-size: 0.9em;
  color: var(--text-color-medium);
  margin-bottom: var(--spacing-medium);
}

/* Section Styles */
.how-it-works-columns,
.support-all-subjects,
.testimonials-columns,
.about-us {
  padding: var(--section-padding);
  text-align: center;
  border-bottom: 1px solid var(--border-color-light);
  margin-bottom: var(--spacing-jumbo);
  margin-top: var(--spacing-jumbo);
}

.how-it-works-columns h2,
.support-all-subjects h2,
.testimonials-columns h2,
.about-us h2 {
  color: var(--primary-color);
  margin-bottom: var(--spacing-large);
  font-size: 36px;
}

.how-it-works-columns .columns,
.support-all-subjects .columns,
.testimonials-columns .columns {
  display: flex;
  flex-direction: row;
  gap: var(--column-gap);
  justify-content: space-around;
  margin-top: var(--spacing-extra-large);
}

.how-it-works-columns .column,
.support-all-subjects .column,
.testimonials-columns .column {
  flex: 1;
  padding: var(--column-padding);
  border: 1px solid var(--border-color-light);
  border-radius: var(--spacing-small);
}

.how-it-works-columns .column img,
.support-all-subjects .column img,
.testimonials-columns .column img {
  display: block;
  object-fit: contain;
}

.how-it-works-columns .column img {
  margin: 0 auto var(--spacing-large) auto;
}

.support-all-subjects .column img {
  margin: 0 auto var(--spacing-small) auto;
}

.testimonials-columns .column img {
  margin: 0 auto var(--spacing-small) auto;
}

.how-it-works-columns .column {
  text-align: center;
}

.how-it-works-columns .column h3 {
  margin-top: 0;
  color: var(--text-color-dark);
  font-size: 1.5em;
}

.how-it-works-columns .column p {
  text-align: left;
}

.support-all-subjects .column {
  text-align: left;
}

.support-all-subjects .column h3 {
  color: var(--text-color-dark);
  margin-top: 0;
  font-size: 1.5em;
  line-height: 1.2;
  text-align: center;
}

.support-all-subjects p {
  line-height: 1.6;
  margin-bottom: var(--spacing-medium);
}

.support-all-subjects ul {
  list-style: none;
  padding: 0;
  margin-top: var(--spacing-large);
  display: inline-block;
  text-align: left;
}

.support-all-subjects ul li {
  margin-bottom: 8px;
}

.testimonials-columns .column {
  text-align: left;
}

.testimonials-columns .column p:first-child {
  font-weight: bold;
  color: var(--text-color-medium);
  margin-bottom: var(--spacing-small);
}

.about-us p {
  line-height: 1.6;
}

/* Media Queries */
@media (min-width: 769px) and (max-width: 1024px) {
  #sticky-header {
    padding: var(--spacing-medium) var(--spacing-large);
    overflow: visible;
    height: 140px; /* Ensure height consistency */
  }

  .header-container {
    display: flex;
    gap: var(--spacing-large);
    justify-content: space-between;
    align-items: center;
    flex-wrap: nowrap;
    overflow: visible;
  }

  .main-nav ul {
    gap: var(--spacing-small);
  }

  .main-nav a {
    padding: var(--spacing-small) 8px;
    display: block;
  }

  .cta-button {
    padding: var(--spacing-small) 22px;
    font-size: 1em;
    margin-left: 16px;
    flex-shrink: 0;
    white-space: nowrap;
    overflow: visible;
    max-width: none;
  }

  .logo img {
    height: 110px; /* This was 120px !important, overriding to 110px for this range */
    width: auto;
  }

  body {
    padding-top: 140px; /* Adjusted to 110px logo + 20px padding */
  }

  html {
    scroll-padding-top: 140px;
  }
}

@media (min-width: 769px) { /* ADDED: Desktop specific styles for .main-nav */
  .main-nav {
    display: flex; /* MODIFIED: Only show main-nav as flex on desktop */
    position: static; /* Reset position for desktop */
    top: auto;
    left: auto;
    width: auto;
    background-color: transparent;
    box-shadow: none;
    flex-direction: row; /* Desktop navigation is row */
    align-items: center;
    padding: 0;
    transform: none; /* Reset transform for desktop */
  }

  .main-nav ul {
    display: flex; /* Explicitly flex for desktop list */
    flex-direction: row;
    align-items: center;
    gap: var(--spacing-large);
  }

  .hamburger-icon {
    display: none; /* Hide hamburger on desktop */
  }

  .cta-button-mobile {
    display: none !important; /* Hide mobile CTA on desktop */
  }
}

@media (max-width: 768px) {
  #sticky-header {
    padding: var(--spacing-small) var(--spacing-medium);
    height: 150px; /* Mobile header height: 140px (logo) + 10px (padding) */
  }

  .header-container {
    flex-direction: row;
    justify-content: space-between;
  }

  .logo {
    margin-right: 0;
    flex-shrink: 0;
  }

  .logo img {
    height: 140px !important; /* This was conflicting with 100px. Keeping 140px as it was !important */
    width: auto;
  }

  body {
    padding-top: 160px !important; /* Ensure this matches max header height */
  }

  html {
    scroll-padding-top: 160px !important;
  }

  .hamburger-icon {
    display: block; /* Show hamburger icon on mobile */
  }

  .main-nav {
    /* These rules are already set globally for .main-nav,
       but kept here for clarity within the media query.
       They ensure correct mobile menu behavior. */
    /* display: none; */
    /* position: absolute; */
    /* top: 100%; */
    /* left: 0; */
    /* width: 100%; */
    /* background-color: white; */
    /* box-shadow: 0 2px 5px var(--shadow-color); */
    /* flex-direction: column; */
    /* align-items: flex-start; */
    /* padding: var(--spacing-medium) var(--spacing-extra-large); */
    /* transition: transform 0.3s ease-in-out; */
    /* transform: translateY(-100%); */
    /* z-index: 1000; */
  }

  .main-nav ul {
    flex-direction: column;
    width: 100%;
    gap: var(--spacing-small);
  }

  .main-nav li {
    width: 100%;
    border-bottom: 1px solid var(--border-color-light);
    padding: var(--spacing-medium) 0;
  }

  .main-nav a {
    width: 100%;
  }

  /* --- ADDED STYLE FOR MOBILE COLUMN STACKING --- */
  .how-it-works-columns .columns,
  .support-all-subjects .columns,
  .testimonials-columns .columns {
    flex-direction: column;
    /* The gap variable will now apply vertically between columns */
  }
  /* -------------------------------------------- */

  /* NEW: Improved visibility for the terms checkbox on mobile */
  .terms-container input[type="checkbox"] {
    -webkit-appearance: checkbox; /* Ensure it's rendered as a standard checkbox for Webkit browsers */
    -moz-appearance: checkbox; /* For Firefox */
    appearance: checkbox; /* Standard property */
    width: 24px; /* Slightly larger for better tap target */
    height: 24px; /* Slightly larger */
    border: 2px solid var(--text-color-dark); /* Explicit dark border */
    background-color: white; /* Explicit white background */
    cursor: pointer;
    vertical-align: middle; /* Helps align with text */
    margin-right: 8px; /* Add some space between checkbox and label */
    flex-shrink: 0; /* Prevent it from shrinking */
  }

  /* NEW: Style for the checked state of the checkbox */
  .terms-container input[type="checkbox"]:checked {
    background-color: var(--secondary-color); /* Green background when checked */
    border-color: var(--secondary-color-dark); /* Darker green border when checked */
  }
}

/* === Final Mobile Adjustments Only === */
@media (max-width: 768px) {
  #sticky-header .cta-button {
    display: none !important;
  }

  .cta-button-mobile {
    display: block !important;
    margin: 5px auto 5px auto !important;
    padding: 10px 20px !important;
    max-width: 260px;
    text-align: center;
  }

  .intro-section {
    margin-top: 0 !important;
    padding-top: 0 !important;
  }

  form {
    margin-top: 0 !important;
  }

  /* This rule was setting logo height to 140px, already handled by earlier media query */
  /* .logo img {
     height: 140px !important;
     width: auto;
   } */

  /* Body padding adjusted earlier */
  /* body {
     padding-top: 160px !important;
   }

   html {
     scroll-padding-top: 160px !important;
   } */
}

/* Desktop hides mobile CTA - now handled by the general desktop media query */
/* @media (min-width: 1025px) {
   .cta-button-mobile {
     display: none !important;
   }
 } */


/* Removed redundant media query, logic moved to (min-width: 769px) */
/* @media (min-width: 769px) {
   .cta-button-mobile {
     display: none !important;
   }
 } */


/* === Prevent Header Cutoff in 1025px–1150px Range === */
@media (min-width: 1025px) and (max-width: 1150px) {
  .header-container {
    flex-wrap: wrap;
    gap: var(--spacing-small);
    justify-content: space-between;
    row-gap: 10px;
  }

  .main-nav ul {
    flex-wrap: wrap;
    gap: var(--spacing-small);
  }

  .logo img {
    height: 100px;
    width: auto;
  }

  .cta-button {
    padding: 8px 18px;
    font-size: 0.95em;
    white-space: nowrap;
    flex-shrink: 0;
  }
}


/* === FINAL TWEAKS === */

/* Restore mobile CTA visibility (only show below 769px) */
@media (max-width: 768px) {
  .cta-button-mobile {
    display: block !important;
    margin: 5px auto !important;
    padding: 10px 20px !important;
    max-width: 260px;
    text-align: center;
  }

  .hamburger-icon {
    margin-left: 0 !important;
  }
}

/* Enlarge logo slightly for tablet view */
@media (min-width: 769px) and (max-width: 1024px) {
  .logo img {
    height: 120px !important;
  }
}

/* NEW: Loading Spinner and Processing Message Styles */
#loading-spinner {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 15px;
}

#loading-spinner.hidden {
  display: none !important; /* Ensure it's hidden when the class is present */
}

.spinner {
  border: 4px solid rgba(0, 0, 0, 0.1);
  border-left-color: var(--primary-color); /* Using your primary color from variables */
  border-radius: 50%;
  width: 28px;
  height: 28px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* --- Additional CSS for the "Ultimi Articoli" section --- */

/* 1. Apply general section styling to match other homepage sections */
.latest-articles-section {
  padding: var(--section-padding); /* Uses predefined section padding */
  text-align: center;
  border-bottom: 1px solid var(--border-color-light); /* Adds a light border at the bottom */
  margin-bottom: var(--spacing-jumbo); /* Uses predefined spacing */
  margin-top: var(--spacing-jumbo); /* Uses predefined spacing */
}

/* Style the section title to match other h2 elements */
.latest-articles-section h2 {
  color: var(--primary-color); /* Uses primary color (blue) */
  margin-bottom: var(--spacing-large); /* Uses predefined spacing */
  font-size: 36px; /* Matches the explicit size for other section h2s */
  font-weight: bold; /* Explicitly use 'bold' keyword for consistency */
  /* Reconfirming font-family from body */
  font-family: "Open Sans", sans-serif, Arial, sans-serif;
}

/* 2. Style the grid container for articles to achieve horizontal alignment */
.latest-articles-section .article-grid {
  display: flex;
  flex-direction: row; /* Arranges articles horizontally */
  gap: var(--column-gap); /* Uses the defined gap between columns */
  justify-content: center; /* Center items to handle fewer than 3 on a row */
  margin-top: var(--spacing-extra-large); /* Uses predefined spacing */
  flex-wrap: wrap; /* Allows articles to wrap to the next line if space is limited */
}

/* Style individual article cards to mimic the appearance of other columns */
.latest-articles-section .article-grid .article-card-container {
  flex: 0 1 32%; /* Allows cards to flex but prefers a width of approx 1/3 */
  min-width: 280px; /* Adjusted min-width for better date fit. Was 300px. */
  max-width: 380px; /* Added max-width to prevent cards from becoming too wide on large screens */
  padding: var(--column-padding); /* Uses predefined padding for columns */
  border: 1px solid var(--border-color-light); /* Uses predefined border color */
  border-radius: var(--spacing-small); /* Uses predefined border radius */
  text-align: left; /* Align text within the card */
  display: flex; /* Use flexbox for internal layout of card content */
  flex-direction: column; /* Stack content (title, date, excerpt, link) vertically */
  justify-content: space-between; /* Pushes the 'Leggi di più' link to the bottom */
  background-color: white; /* Give cards a white background as seen in screenshot */
  box-shadow: 0px 4px 6px var(--shadow-color); /* Add subtle shadow to match form/other elements */
  box-sizing: border-box; /* Include padding in the width calculation */
}

/* Style for the article title within each card */
.latest-articles-section .article-grid .article-card-container .article-card-title {
    margin-top: 0;
    margin-bottom: var(--spacing-small); /* Uses predefined spacing */
}

/* Fix: 2. Titles of the articles should be blue (similar to links color) */
.latest-articles-section .article-grid .article-card-container .article-card-title a {
    color: var(--link-color); /* Changed to link color (blue) */
    font-size: 1.5em; /* Matches h3 in other column sections */
    line-height: 1.2;
    text-decoration: none; /* Remove underline from title link */
    /* Ensure font weight is consistent if it's implicitly inheriting something else */
    font-weight: 700;
}

.latest-articles-section .article-grid .article-card-container .article-card-title a:hover {
    text-decoration: underline; /* Add underline on hover */
}

/* Style for the article snippet/content paragraph within each card */
.latest-articles-section .article-grid .article-card-container .article-card-snippet {
    line-height: 1.6;
    margin-bottom: var(--spacing-medium); /* Uses predefined spacing */
    flex-grow: 1; /* Allows the main content paragraph to take up available space */
}

/* Style for the "Leggi di più" link inside each article card */
.latest-articles-section .article-grid .article-card-container .article-card-read-more {
    display: inline-block;
    margin-top: var(--spacing-medium); /* Uses predefined spacing */
    color: var(--link-color); /* Uses predefined link color */
    text-decoration: none;
    font-weight: bold;
}

.latest-articles-section .article-grid .article-card-container .article-card-read-more:hover {
    text-decoration: underline;
}

/* Styling for the "Vedi tutti gli articoli" button */
.latest-articles-section .view-all-button {
    margin-top: var(--spacing-jumbo); /* Provides space below the articles grid */
    text-align: center;
}

.latest-articles-section .view-all-button .button {
    display: inline-block;
    padding: var(--spacing-medium) var(--spacing-large); /* Uses predefined spacing */
    background-color: var(--primary-color); /* Uses predefined primary color */
    color: white;
    font-size: 1em;
    font-weight: bold;
    text-decoration: none;
    border: none;
    border-radius: var(--spacing-small); /* Uses predefined border radius */
    cursor: pointer;
    transition: background-color 0.3s ease;
}

.latest-articles-section .view-all-button .button:hover {
    background-color: var(--secondary-color-dark); /* A darker shade on hover */
}

/* Media Query: Ensure articles stack vertically on mobile, consistent with other column layouts */
@media (max-width: 768px) {
  .latest-articles-section .article-grid {
    flex-direction: column; /* Stacks articles vertically on smaller screens */
  }

  /* Reset min-width and make cards take full width when stacked on mobile */
  .latest-articles-section .article-grid .article-card-container {
      min-width: unset;
      width: 100%;
      max-width: 100%; /* Ensure it takes full width */
  }

  /* On mobile, allow the date to wrap normally if a single line is too restrictive */
  .latest-articles-section .article-grid .article-card-container .article-card-meta {
      white-space: normal !important; /* Allow normal wrapping behavior on mobile */
      overflow: visible; /* Show full text */
      text-overflow: unset; /* Remove ellipsis */
      display: block; /* Revert to block display for normal wrapping */
  }
}

/* Blog Page Specific Styles */

/* Main container for the blog list page */
.blog-list-main {
  padding: var(--spacing-jumbo) var(--spacing-extra-large);
  max-width: 1200px;
  margin: 0 auto;
}

.blog-list-container {
  display: flex;
  flex-direction: column;
  gap: var(--spacing-jumbo);
}

/* Blog header styles */
.blog-list-header {
  text-align: center;
  margin-bottom: 0; /* AGGRESSIVELY REMOVED ALL MARGIN BELOW HEADER */
  padding-bottom: 0; /* Also remove padding */
}

.blog-list-title {
  color: var(--primary-color);
  font-size: 3em;
  margin-bottom: var(--spacing-medium);
}

.blog-list-description {
  color: var(--text-color-dark);
  font-size: 1.2em;
  line-height: 1.6;
  max-width: 800px;
  margin: 0 auto 0 auto; /* Removed bottom margin */
}

/* New styles for the separate Categories section */
.categories-section {
  padding-top: 0; /* AGGRESSIVELY REMOVED PADDING-TOP */
  padding-bottom: var(--spacing-large); /* Keep some padding at the bottom of the section */
  padding-left: var(--spacing-extra-large);
  padding-right: var(--spacing-extra-large);
  text-align: center;
  border-bottom: 1px solid var(--border-color-light);
  margin-bottom: var(--spacing-medium); /* Reduced space below categories */
  margin-top: 0; /* AGGRESSIVELY REMOVED ALL MARGIN ABOVE CATEGORIES */
}

.categories-section .categories-title {
  color: var(--primary-color);
  margin-top: 0; /* AGGRESSIVELY REMOVED MARGIN-TOP */
  margin-bottom: var(--spacing-large);
  font-size: 36px;
}

.categories-list-container {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--spacing-medium);
  list-style: none;
  padding: 0;
  margin: 0;
}

.categories-list-container .category-pill {
  display: inline-block;
  background-color: var(--secondary-color); /* Full green background */
  color: white; /* White text */
  border: none; /* Removed border to make it solid green */
  padding: var(--spacing-small) var(--spacing-large);
  border-radius: var(--spacing-large);
  text-decoration: none;
  font-size: 1.1em;
  transition: background-color 0.3s ease, color 0.3s ease;
  white-space: nowrap;
}

.categories-list-container .category-pill:hover {
  background-color: var(--secondary-color-dark); /* Darker green on hover */
  color: white;
}


/* Wrapper for the latest articles and sidebar */
.latest-articles-content-sidebar-wrapper {
  display: flex;
  flex-direction: column; /* ALWAYS STACK: Articles then Tags, both on desktop and mobile */
  gap: var(--column-gap); /* Gap between sections when stacked */
  align-items: flex-start; /* Align items to the start when stacked */
}

/* Specific styles for the "Ultimi Articoli" section on the blog page */
.latest-articles-section {
  flex-grow: 1; /* Allow it to grow if in a flex container */
  width: 100%; /* Ensure it takes full width */
  padding: 0;
  border-bottom: none;
  margin-bottom: 0;
  margin-top: var(--spacing-medium); /* Reduced margin-top to bring it closer */
}

.latest-articles-section .latest-articles-title {
  color: var(--primary-color);
  margin-bottom: var(--spacing-large);
  font-size: 36px;
  text-align: center; /* Confirmed already centered */
}

/* Main articles grid and individual card adjustments for blog page */
.latest-articles-section .article-grid {
  display: flex;
  flex-direction: row; /* Articles will try to go horizontal */
  flex-wrap: wrap; /* Allow articles to wrap to the next line */
  justify-content: center; /* Center articles horizontally within the grid */
  gap: var(--spacing-large); /* Space between article cards */
  margin-top: var(--spacing-extra-large);
}

.latest-articles-section .article-grid .article-card-container {
  min-width: 280px; /* Ensure a minimum width for cards */
  width: 100%; /* Default to full width for small screens/initial flex calculation */
  flex: 1 1 calc(33.333% - var(--spacing-large) * 2 / 3); /* Try for three columns, accounting for gap */
  max-width: calc(33.333% - var(--spacing-large) * 2 / 3); /* Max width for three columns */
  margin: 0; /* Reset margin from previous auto */
  box-sizing: border-box;
}


/* Sidebar Styles */
.blog-sidebar {
  width: 100%; /* Take full width when stacked */
  background-color: var(--background-light);
  padding: var(--spacing-large);
  border-radius: var(--spacing-small);
  box-shadow: 0 2px 5px var(--shadow-color);
  box-sizing: border-box;
  margin-top: var(--spacing-jumbo); /* Add space above Tags section */
  display: none; /* HIDE BY DEFAULT FOR MOBILE */
}

.blog-sidebar .sidebar-title {
  color: var(--primary-color);
  font-size: 1.8em;
  margin-top: 0;
  margin-bottom: var(--spacing-large);
  text-align: center; /* Centered for consistency */
}

.sidebar-tags-container {
  display: flex;
  flex-wrap: wrap;
  gap: var(--spacing-small);
  justify-content: center; /* Center tags within the sidebar */
}

.sidebar-tag-pill {
  background-color: var(--secondary-color); /* Tags color changed to green */
  color: white;
  padding: var(--spacing-small) var(--spacing-medium);
  border-radius: var(--spacing-large);
  text-decoration: none;
  font-size: 0.9em;
  transition: background-color 0.3s ease;
}

.sidebar-tag-pill:hover {
  background-color: var(--secondary-color-dark); /* Darker green on hover */
}

/* Styles for "Tutti gli Articoli" section */
.all-articles-wrapper {
  width: 100%;
}

.all-articles-section {
  padding: 0;
  text-align: center;
  border-bottom: none;
  margin-top: var(--spacing-jumbo);
  margin-bottom: var(--spacing-jumbo);
}

.all-articles-section .all-articles-title {
  color: var(--primary-color);
  margin-bottom: var(--spacing-large);
  font-size: 36px;
}

.all-articles-section .article-grid {
  display: flex;
  flex-direction: row; /* Try to put articles in a row */
  flex-wrap: wrap;
  justify-content: center; /* Center them */
  gap: var(--spacing-large); /* Consistent gap */
  margin-top: var(--spacing-extra-large);
}

.all-articles-section .article-grid .article-card-container {
  min-width: 280px;
  width: 100%;
  flex: 1 1 calc(33.333% - var(--spacing-large) * 2 / 3); /* Try for three columns */
  max-width: calc(33.333% - var(--spacing-large) * 2 / 3);
  margin: 0;
  box-sizing: border-box;
}

/* Pagination Styles */
.pagination {
  margin-top: var(--spacing-jumbo);
  text-align: center;
}

.pagination-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  justify-content: center;
  gap: var(--spacing-medium);
  flex-wrap: wrap;
}

.pagination-link {
  display: inline-block;
  padding: var(--spacing-small) var(--spacing-medium);
  background-color: var(--background-light);
  border: 1px solid var(--border-color);
  border-radius: var(--spacing-small);
  color: var(--text-color-dark);
  text-decoration: none;
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

.pagination-link:hover {
  background-color: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

/* Article Card Date/Meta Info */
.article-card-meta {
  font-size: 0.9em;
  color: var(--text-color-light);
  margin-bottom: var(--spacing-small);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Modal Styles */
.article-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.6);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 2000;
  padding: var(--spacing-medium);
  box-sizing: border-box;
}

.article-modal-content {
  background-color: white;
  padding: var(--spacing-extra-large);
  border-radius: 8px;
  max-width: 900px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.3);
}

.modal-close-button {
  position: absolute;
  top: var(--spacing-medium);
  right: var(--spacing-medium);
  background: none;
  border: none;
  font-size: 2em;
  cursor: pointer;
  color: var(--text-color-dark);
}

.modal-close-button:hover {
  color: black;
}

.modal-article-content h2 {
  color: var(--primary-color);
  font-size: 2.2em;
  margin-bottom: var(--spacing-medium);
}

.modal-article-content .article-meta {
  color: var(--text-color-light);
  font-size: 0.9em;
  margin-bottom: var(--spacing-large);
}

.modal-article-content .article-body {
  line-height: 1.7;
  color: var(--text-color-dark);
}

/* Media Queries for Blog Page */

/* Desktop layout: Articles and Tags are now stacked vertically. */
@media (min-width: 769px) {
  /* Remove flex direction from wrapper, allowing children to stack naturally */
  .latest-articles-content-sidebar-wrapper {
    flex-direction: column; /* Ensure stacking on desktop as well */
    align-items: center; /* Center the stacked sections */
  }

  .latest-articles-section {
    width: 100%; /* Take full available width */
    margin-right: 0; /* Remove side margin */
  }

  .blog-sidebar {
    width: 100%; /* Take full available width */
    max-width: 100%; /* Remove max-width restriction for full width stacking */
    position: static; /* No longer sticky, stacks below articles */
    margin-top: var(--spacing-jumbo); /* Add space between articles and tags */
    display: block; /* SHOW ON DESKTOP */
  }

  .blog-sidebar .sidebar-title {
    text-align: center; /* Center tags title when full width */
  }

  .sidebar-tags-container {
    justify-content: center; /* Center tags within the full-width sidebar */
  }

  .latest-articles-section .article-grid {
    /* Articles are already set to flex-direction: row; and justify-content: center; */
    /* This will now attempt to lay them out horizontally in the full available width. */
  }

  /* Adjust article card width to try and fit 3 on a line in the new full width */
  .latest-articles-section .article-grid .article-card-container {
    flex: 1 1 calc(33.333% - var(--spacing-large) * 2 / 3); /* Try for three columns, accounting for gap */
    max-width: calc(33.333% - var(--spacing-large) * 2 / 3);
  }

  .all-articles-section .article-grid {
    justify-content: center; /* Center articles */
  }

  .all-articles-section .article-grid .article-card-container {
    flex: 1 1 calc(33.333% - var(--column-gap) * 2 / 3);
    max-width: calc(33.333% - var(--column-gap) * 2 / 3);
  }
}

/* Tablet adjustments for article grid (still two columns) */
@media (min-width: 769px) and (max-width: 1024px) {
  .latest-articles-section .article-grid .article-card-container,
  .all-articles-section .article-grid .article-card-container {
    flex: 1 1 calc(50% - var(--column-gap) / 2); /* Two columns with gap */
    max-width: calc(50% - var(--column-gap) / 2);
  }
}

/* Mobile adjustments */
@media (max-width: 768px) {
  .categories-section .categories-title {
    font-size: 2em;
  }

  .categories-list-container {
    justify-content: center;
  }

  .categories-list-container .category-pill {
    font-size: 1em;
    padding: var(--spacing-small) var(--spacing-medium);
  }

  /* Tags sidebar behavior on mobile: hidden */
  .blog-sidebar {
    order: 2; /* Ensures it stays below the articles if it were visible */
    margin-top: var(--spacing-jumbo); /* Add space above sidebar when stacked */
    display: none; /* HIDE ON MOBILE */
  }

    .latest-articles-section {
    order: 1;
  }

  .latest-articles-section .article-grid {
    flex-direction: column; /* Ensure articles stack vertically on mobile */
    justify-content: center;
  }

  .latest-articles-section .article-grid .article-card-container {
      min-width: unset;
      width: 100%;
      max-width: 100%; /* Ensure it takes full width */
  }
}

/* Styles for Single Article Page (post.njk) */

/* Main container for the article content, ensuring it's not full page width */
.blog-post-main {
  padding: var(--spacing-jumbo) var(--spacing-extra-large); /* Consistent padding around the main content area */
  max-width: 1200px; /* Max width for the overall main section, similar to blog list */
  margin: 0 auto; /* Center the main blog post area */
}

.blog-article-container {
  max-width: 800px; /* Set a maximum width for the article content itself, adjust as needed */
  margin: 0 auto; /* Center the article content within the main section */
  background-color: white; /* Optional: A background color for the article card area */
  padding: var(--spacing-extra-large); /* Padding inside the article container */
  border-radius: var(--spacing-small); /* Slightly rounded corners */
  box-shadow: 0 4px 10px var(--shadow-color); /* Subtle shadow for depth */
  box-sizing: border-box; /* Include padding in element's total width and height */
}

/* Header styles for the single post */
.post-header {
  text-align: center;
  margin-bottom: var(--spacing-jumbo);
}

.post-title {
  color: var(--primary-color);
  font-size: 2.8em; /* Larger title for article page */
  margin-bottom: var(--spacing-medium);
  line-height: 1.2;
}

.post-meta {
  color: var(--text-color-light);
  font-size: 0.9em;
  margin-bottom: var(--spacing-large);
}

.post-tags-container {
  margin-top: var(--spacing-large);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--spacing-small);
}

.post-tag-pill {
  display: inline-block;
  background-color: var(--secondary-color); /* Green tags */
  color: white;
  padding: var(--spacing-small) var(--spacing-medium);
  border-radius: var(--spacing-large);
  text-decoration: none;
  font-size: 0.85em;
  transition: background-color 0.3s ease;
}

.post-tag-pill:hover {
  background-color: var(--secondary-color-dark);
}

/* Image styling */
.post-image-figure {
  margin: var(--spacing-jumbo) 0; /* Space above and below image figure */
  text-align: center; /* Center the image */
}

.post-image {
  max-width: 100%; /* Ensure image is responsive */
  height: auto;
  display: block; /* Remove extra space below image */
  border-radius: var(--spacing-small); /* Match container border-radius */
  box-shadow: 0 2px 5px var(--shadow-color);
}

.post-image-caption {
  color: var(--text-color-medium);
  font-size: 0.85em;
  margin-top: var(--spacing-medium);
}

/* Article body content styling */
.post-content-body {
  line-height: 1.8; /* Improved readability */
  color: var(--text-color-dark);
  font-size: 1.1em;
}

.post-content-body h1,
.post-content-body h2,
.post-content-body h3 {
  color: var(--primary-color);
  margin-top: var(--spacing-jumbo);
  margin-bottom: var(--spacing-large);
  line-height: 1.3;
}

.post-content-body h2 { font-size: 2em; }
.post-content-body h3 { font-size: 1.7em; }

.post-content-body p {
  margin-bottom: var(--spacing-large);
}

.post-content-body ul,
.post-content-body ol {
  margin-bottom: var(--spacing-large);
  padding-left: var(--spacing-jumbo);
}

.post-content-body li {
  margin-bottom: var(--spacing-small);
}

/* Call to action section */
.post-cta-section {
  text-align: center;
  background-color: var(--background-light);
  padding: var(--spacing-jumbo);
  border-radius: var(--spacing-small);
  margin-top: var(--spacing-jumbo);
  margin-bottom: var(--spacing-jumbo);
  box-shadow: 0 2px 5px var(--shadow-color);
}

.post-cta-title {
  color: var(--primary-color);
  font-size: 2em;
  margin-bottom: var(--spacing-medium);
}

.post-cta-description {
  color: var(--text-color-dark);
  margin-bottom: var(--spacing-jumbo);
}

/* Related articles section */
.related-articles-section {
  margin-top: var(--spacing-jumbo);
  text-align: center;
}

.related-articles-title {
  color: var(--primary-color);
  font-size: 2em;
  margin-bottom: var(--spacing-jumbo);
}

.related-articles-grid {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--spacing-large); /* Matches the article grid gap */
  margin-top: var(--spacing-extra-large);
}

/* Individual article cards in related section will use existing .article-card-container styles */
.related-articles-grid .article-card-container {
  flex: 1 1 calc(50% - var(--spacing-large) / 2); /* Two columns for related articles */
  max-width: calc(50% - var(--spacing-large) / 2);
}

.all-articles-link-container {
  margin-top: var(--spacing-jumbo);
}

.all-articles-link {
  display: inline-block;
  padding: var(--spacing-medium) var(--spacing-large);
  background-color: var(--primary-color);
  color: white;
  text-decoration: none;
  border-radius: var(--spacing-small);
  transition: background-color 0.3s ease;
}

.all-articles-link:hover {
  background-color: var(--secondary-color-dark);
}

/* Media Queries for single article page responsiveness */
@media (max-width: 768px) {
  .blog-post-main {
    padding: var(--spacing-extra-large) var(--spacing-medium);
  }

  .blog-article-container {
    padding: var(--spacing-large);
  }

  .post-title {
    font-size: 2em;
  }

  .post-cta-title {
    font-size: 1.5em;
  }

  .related-articles-grid .article-card-container {
    flex: 1 1 100%; /* Stack related articles vertically on mobile */
    max-width: 100%;
  }
  .post-tags-container {
    display: none;
  } 
}

/* Styling for images within blog posts */
.post-image-figure {
    margin: var(--spacing-large) auto; /* Add vertical margin, auto for horizontal centering if figure has a max-width */
    max-width: 100%; /* Ensure it doesn't overflow its container */
    text-align: center; /* Center the image and figcaption */
}

.post-image {
    max-width: 100%; /* Ensure image is responsive */
    height: auto; /* Maintain aspect ratio */
    display: block; /* Important for margin: auto to work */
    margin: 0 auto; /* Center the image itself if it's smaller than its container */
    border-radius: var(--spacing-small); /* Optional: rounded corners */
    box-shadow: var(--shadow-color) 0px 4px 8px; /* Optional: subtle shadow */
}

.post-image-caption {
    font-style: italic;
    font-size: 0.9em;
    color: var(--text-color-light);
    margin-top: var(--spacing-small);
}