/* ==========================================================================
   Feria Agrícola Melipilla - Estilos Globales (main.css)
   Arquitectura: Modern Web Guidance (Baseline Standards & Tokens)
   ========================================================================== */

/* --------------------------------------------------------------------------
   0. Importación Tipográfica de Alta Legibilidad (Google Fonts)
   -------------------------------------------------------------------------- */
@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700;800&family=Plus+Jakarta+Sans:wght@400;500;600;700&family=Poppins:wght@400;500;600;700;800&display=swap');

/* --------------------------------------------------------------------------
   1. Tokens de Diseño & Configuración Baseline (Design Tokens)
   -------------------------------------------------------------------------- */
:root {
  /* Tipografía: Montserrat para encabezados e identidad; Plus Jakarta Sans / Poppins para cuerpo */
  --font-heading: 'Montserrat', system-ui, -apple-system, sans-serif;
  --font-body: 'Plus Jakarta Sans', 'Poppins', system-ui, -apple-system, sans-serif;

  /* Colores de identidad y accesibilidad (WCAG 1.4.3 / 1.4.11) */
  --color-brand-primary: #166534;
  --color-brand-deep: #0b3820;
  --color-brand-light: #228448;
  --color-bg-base: #f7faf8;
  --color-text-main: #12301f;
  --color-text-muted: #3d5446;
  --color-accent-lime: #84cc16;
  --color-card-border: rgba(18, 48, 31, 0.08);

  /* Scrollbars estándar (Modern Web Guidance: customize-scrollbar-color-and-thickness) */
  --scrollbar-thumb: #166534;
  --scrollbar-track: #eaf1ea;
}

/* --------------------------------------------------------------------------
   2. Base Global & Accesibilidad
   -------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  overflow-x: hidden;
  max-width: 100%;
  scroll-behavior: smooth;
  /* Scrollbar estándar moderno: Chrome 121+, Firefox 64+, Safari 18.2+ */
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
  scrollbar-width: thin;
}

body {
  margin: 0;
  font-family: var(--font-body);
  background-color: var(--color-bg-base);
  color: var(--color-text-main);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  max-width: 100%;
  overflow-wrap: break-word;
}

/* --------------------------------------------------------------------------
   3. Tipografía & Headings (Modern Web Guidance: typography & improve-text-layout-and-legibility)
   -------------------------------------------------------------------------- */
/* Headings: Montserrat geométrico + text-wrap: balance para evitar palabras huérfanas
   CRUCIAL: color: inherit garantiza que los títulos blancos del hero y fondos oscuros se mantengan blancos */
h1, h2, h3, h4, h5, h6,
.font-heading {
  font-family: var(--font-heading);
  letter-spacing: -0.02em;
  text-wrap: balance;
  overflow-wrap: break-word;
  color: inherit;
}

/* Párrafos: text-wrap: pretty para evitar "runts" o palabras huérfanas al final */
p, li {
  text-wrap: pretty;
  overflow-wrap: break-word;
}

/* Selección de texto */
::selection {
  background-color: #bef264;
  color: #14532d;
}

/* Indicador de foco accesible para navegación por teclado (WCAG 2.4.7 Focus Visible) */
:focus-visible {
  outline: 2px solid var(--color-accent-lime);
  outline-offset: 3px;
}

/* Ocultar barra de scroll en carruseles táctiles horizontales (Modern Web Guidance) */
.scrollbar-none {
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.scrollbar-none::-webkit-scrollbar {
  display: none;
}

/* Fallback de scrollbar para navegadores WebKit heredados */
@supports not (scrollbar-color: auto) {
  ::-webkit-scrollbar {
    width: 9px;
    height: 9px;
  }
  ::-webkit-scrollbar-thumb {
    background: var(--scrollbar-thumb);
    border-radius: 5px;
  }
  ::-webkit-scrollbar-track {
    background: var(--scrollbar-track);
  }
}

/* --------------------------------------------------------------------------
   4. Fondos Hero y Tipografía Fluida
   -------------------------------------------------------------------------- */
.hero {
  background: linear-gradient(100deg, rgba(4, 48, 24, 0.90) 0%, rgba(7, 74, 37, 0.66) 46%, rgba(8, 91, 45, 0.14) 100%),
              url('../images/Banner_1.webp') center/cover no-repeat;
}

.hero-index {
  background: linear-gradient(100deg, rgba(4, 48, 24, 0.90) 0%, rgba(7, 74, 37, 0.68) 48%, rgba(8, 91, 45, 0.16) 100%),
              url('../images/Banner_1.webp') center/cover no-repeat;
}

.hero h1,
.hero-index h1 {
  font-size: clamp(1.95rem, 4.2vw + 0.8rem, 4.25rem);
  line-height: 1.08;
  text-shadow: 0 2px 18px rgba(0, 0, 0, 0.28);
}

@media (max-width: 1023px) {
  body {
    padding-bottom: calc(74px + env(safe-area-inset-bottom));
  }

  /* Header móvil más ágil y compacto al hacer scroll */
  header.sticky {
    height: 72px !important;
    transition: height 0.22s ease, box-shadow 0.25s ease, background-color 0.25s ease;
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    background-color: rgba(255, 255, 255, 0.94);
  }
  header.sticky img {
    height: 3rem !important;
    transition: height 0.22s ease;
  }
  header.sticky.header-scrolled {
    height: 58px !important;
    background-color: rgba(255, 255, 255, 0.97);
  }
  header.sticky.header-scrolled img {
    height: 2.35rem !important;
  }

  /* Toast elevado sobre la barra inferior móvil para nunca solaparse */
  #toastNotification {
    left: 1rem !important;
    right: 1rem !important;
    bottom: calc(88px + env(safe-area-inset-bottom)) !important;
    margin-left: auto;
    margin-right: auto;
    max-width: 24rem;
  }

  /* Botón volver arriba respetando safe-area móvil */
  #scrollTopBtn {
    bottom: calc(88px + env(safe-area-inset-bottom));
    right: 1rem;
  }

  .hero,
  .hero-index {
    background: linear-gradient(180deg, rgba(4, 48, 24, 0.42) 0%, rgba(4, 48, 24, 0.78) 60%, rgba(4, 48, 24, 0.92) 100%),
                url('../images/Banner_1.webp') center/cover no-repeat;
  }
}

/* Evitar zoom automático en iOS/móvil al enfocar campos de formulario */
@media (max-width: 767px) {
  input:not([type="checkbox"]):not([type="radio"]),
  select,
  textarea {
    font-size: 16px !important;
  }
}

/* --------------------------------------------------------------------------
   5. Tarjetas e Interactividad
   -------------------------------------------------------------------------- */
.feature-card {
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
.feature-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px -10px rgba(11, 46, 28, 0.12);
}

.member-card {
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}
.member-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px -10px rgba(11, 46, 28, 0.12);
}

.avatar {
  background: linear-gradient(145deg, #dcebd5, #a9c99b);
}

.glass-card {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
}

.instagram-card {
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.3s ease;
}
.instagram-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 16px 30px rgba(0, 0, 0, 0.25);
}

/* --------------------------------------------------------------------------
   6. Galería Fotográfica y Videos
   -------------------------------------------------------------------------- */
.gallery-item {
  break-inside: avoid;
  backface-visibility: hidden;
  transform: translateZ(0);
  transition: transform 0.28s cubic-bezier(0.2, 0.8, 0.2, 1), box-shadow 0.28s ease;
}
.gallery-item:hover {
  transform: translateY(-4px);
  box-shadow: 0 16px 30px rgba(5, 65, 35, 0.15);
}

.gallery-img {
  opacity: 0;
  transition: opacity 0.35s ease-out, transform 0.5s ease-out;
}
.gallery-img.loaded {
  opacity: 1;
}

/* --------------------------------------------------------------------------
   7. Navegación de Escritorio y Menú Desplegable (Dropdown)
   -------------------------------------------------------------------------- */
.dropdown-menu {
  opacity: 0;
  transform: translateY(6px);
  pointer-events: none;
  visibility: hidden;
  transition: opacity 0.25s cubic-bezier(0.16, 1, 0.3, 1), transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.25s;
  transition-delay: 0.25s;
}

/* Puente invisible para evitar que el mouse pierda el foco al bajar al menú */
.dropdown-menu::before {
  content: '';
  position: absolute;
  top: -16px;
  left: 0;
  right: 0;
  height: 16px;
  background: transparent;
}

.dropdown-parent:hover .dropdown-menu,
.dropdown-parent:focus-within .dropdown-menu {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
  visibility: visible;
  transition-delay: 0s;
}

/* --------------------------------------------------------------------------
   8. Navegación Móvil Inferior (Bottom Bar tipo App Nativa)
   -------------------------------------------------------------------------- */
.bottom-nav {
  height: auto;
  min-height: 68px;
  padding-top: 4px;
  padding-bottom: calc(6px + env(safe-area-inset-bottom));
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.bottom-item {
  min-height: 58px;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: transform 0.14s ease, color 0.18s ease;
}

.bottom-item:active {
  transform: scale(0.91);
}

.bottom-item i {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.5rem;
  height: 1.75rem;
  border-radius: 9999px;
  transition: background-color 0.2s ease, transform 0.2s ease;
}

.bottom-item.text-lime-300 i {
  background-color: rgba(190, 242, 100, 0.18);
}

/* --------------------------------------------------------------------------
   9. Ventanas Emergentes, Bottom Sheet y Modales
   -------------------------------------------------------------------------- */
.sheet {
  max-width: 640px;
  margin-left: auto;
  margin-right: auto;
  transform: translateY(120%);
  opacity: 0;
  pointer-events: none;
  overscroll-behavior: contain;
  padding-bottom: calc(95px + env(safe-area-inset-bottom));
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.25s ease;
}
.sheet.open {
  transform: translateY(0);
  opacity: 1;
  pointer-events: auto;
}
.sheet.dragging {
  transition: none !important;
}

#instaModalMediaContainer {
  touch-action: pan-y;
}

.backdrop {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}
.backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

.dialog-modal {
  transform: scale(0.95) translateY(12px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease;
}
.dialog-modal.open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: auto;
}

/* --------------------------------------------------------------------------
   10. Pestañas de Días en Mapa (Localízanos)
   -------------------------------------------------------------------------- */
.tab-btn.active {
  background-color: #166534;
  color: #ffffff;
  box-shadow: 0 4px 12px rgba(22, 101, 52, 0.25);
}
.tab-btn.active span.badge {
  background-color: #bef264;
  color: #14532d;
}

/* --------------------------------------------------------------------------
   11. Adaptación de Medios en Contenidos y Modales
   -------------------------------------------------------------------------- */
#home-modal-cuerpo img,
#home-modal-cuerpo iframe,
#home-modal-cuerpo video {
  display: block;
  margin-left: auto;
  margin-right: auto;
  max-width: 100%;
  border-radius: 1rem;
}

#home-modal-cuerpo iframe {
  width: 100%;
  aspect-ratio: 16/9;
  height: auto;
}

/* --------------------------------------------------------------------------
   12. Ajustes complementarios para Tablet (768px – 1023px)
   -------------------------------------------------------------------------- */
@media (min-width: 768px) and (max-width: 1023px) {
  /* Noticias home: 2 columnas en tablet */
  #home-noticias-grid > a:nth-child(n+3) {
    display: none !important;
  }

  /* Instagram grid: máximo 3 columnas en tablet */
  #instagram-posts-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
  }
}

/* --------------------------------------------------------------------------
   13. Micro-interacciones, Elevación de Header, Progreso de Lectura y Volver Arriba
   -------------------------------------------------------------------------- */
header.sticky {
  transition: box-shadow 0.25s ease, background-color 0.25s ease, border-color 0.25s ease;
}

header.sticky.header-scrolled {
  box-shadow: 0 10px 30px -12px rgba(6, 59, 36, 0.16);
  background-color: rgba(255, 255, 255, 0.97);
}

/* Barra de progreso de lectura (detalle-noticia.html) */
#reading-progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3.5px;
  width: 0%;
  background: linear-gradient(90deg, #166534, #84cc16);
  z-index: 140;
  pointer-events: none;
  transition: width 0.08s linear;
}

/* Aparición progresiva al hacer scroll */
.reveal-on-scroll {
  opacity: 0;
  transform: translateY(18px);
  transition: opacity 0.55s cubic-bezier(0.22, 1, 0.36, 1), transform 0.55s cubic-bezier(0.22, 1, 0.36, 1);
}

.reveal-on-scroll.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* Botón flotante Volver Arriba */
#scrollTopBtn {
  position: fixed;
  right: 1rem;
  bottom: calc(5.5rem + env(safe-area-inset-bottom));
  z-index: 90;
  width: 2.75rem;
  height: 2.75rem;
  border-radius: 9999px;
  background-color: #166534;
  color: #ffffff;
  border: 2px solid rgba(190, 242, 100, 0.45);
  box-shadow: 0 10px 25px -6px rgba(6, 59, 36, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: translateY(14px) scale(0.92);
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease, background-color 0.2s ease;
  cursor: pointer;
}

#scrollTopBtn:hover {
  background-color: #14532d;
  transform: translateY(-2px) scale(1.04);
}

#scrollTopBtn.visible {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

@media (min-width: 1024px) {
  #scrollTopBtn {
    bottom: 1.75rem;
    right: 1.75rem;
  }
}

/* Acordeón FAQ nativo <details> */
.faq-item summary::-webkit-details-marker {
  display: none;
}
.faq-item[open] .faq-chevron {
  transform: rotate(180deg);
  background-color: #166534;
  color: #ffffff;
  border-color: #166534;
}

/* Enlace accesible Saltar al Contenido (teclado / lectores de pantalla) */
.skip-link {
  position: fixed;
  top: -100px;
  left: 1rem;
  z-index: 200;
  background-color: #166534;
  color: #ffffff;
  padding: 0.65rem 1.1rem;
  border-radius: 9999px;
  font-size: 0.8rem;
  font-weight: 700;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
  transition: top 0.2s ease;
}
.skip-link:focus {
  top: 1rem;
  outline: 2px solid var(--color-accent-lime);
  outline-offset: 2px;
}

/* Accesibilidad: respetar preferencia de movimiento reducido */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  .reveal-on-scroll {
    opacity: 1 !important;
    transform: none !important;
    transition: none !important;
  }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
