/* ============================================
   Optometry Theme - Modern Style Additions
   Version: 2.0
   ============================================ */

/* Enhanced Typography */
body {
  font-feature-settings: "kern" 1, "liga" 1;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
h1, h2, h3, h4, h5, h6 { text-wrap: balance; }
p { text-wrap: pretty; }
a { text-decoration-skip-ink: auto; }

/* Smooth Scroll */
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}

/* Enhanced Buttons - composite-only transitions (no 'all') */
.sc_button,
input[type="submit"],
button:not(.mejs-button) {
  transition: transform 200ms cubic-bezier(0.4, 0, 0.2, 1),
              box-shadow 200ms cubic-bezier(0.4, 0, 0.2, 1),
              background-color 200ms cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
}
.sc_button:hover,
input[type="submit"]:hover,
button:not(.mejs-button):hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 10px -2px rgba(0, 0, 0, 0.12);
}
.sc_button:active,
input[type="submit"]:active {
  transform: translateY(0);
}

/* Enhanced Service Cards - softer transition for GPU compositing */
.sc_services_style_services-1 .sc_services_item {
  transition: transform 250ms cubic-bezier(0.4, 0, 0.2, 1),
              box-shadow 250ms cubic-bezier(0.4, 0, 0.2, 1);
  will-change: transform;
}
.sc_services_style_services-1 .sc_services_item:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px -4px rgba(0, 0, 0, 0.08);
}

/* Enhanced Header */
.top_panel_wrap {
  transition: all var(--transition-base, 300ms cubic-bezier(0.4, 0, 0.2, 1));
}
.top_panel_fixed_wrap + .top_panel_wrap.fixed {
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: var(--shadow-md, 0 4px 6px -1px rgba(0, 0, 0, 0.07));
}

/* Nav Underline Animation */
.menu_main_nav > li > a {
  position: relative;
}
.menu_main_nav > li > a::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 0;
  height: 2px;
  background-color: var(--accent-color, #4a739c);
  transition: all var(--transition-base, 300ms cubic-bezier(0.4, 0, 0.2, 1));
  transform: translateX(-50%);
}
.menu_main_nav > li > a:hover::after,
.menu_main_nav > li.current-menu-item > a::after,
.menu_main_nav > li.current-menu-ancestor > a::after {
  width: 100%;
}

/* Enhanced Dropdowns */
.menu_main_nav > li > ul {
  border-radius: var(--radius-md, 4px);
  box-shadow: var(--shadow-xl, 0 20px 25px -5px rgba(0, 0, 0, 0.1));
  border: 1px solid var(--alt-border, #ebebeb);
}

/* Enhanced Images */
.post_featured img,
.sc_image img {
  transition: transform var(--transition-slow, 500ms cubic-bezier(0.4, 0, 0.2, 1));
}
.post_featured:hover img,
.sc_image:hover img {
  transform: scale(1.03);
}
.post_featured {
  overflow: hidden;
  border-radius: var(--radius-md, 4px);
}

/* Enhanced Form Focus */
input[type="text"]:focus,
input[type="email"]:focus,
input[type="tel"]:focus,
input[type="password"]:focus,
textarea:focus {
  border-bottom-color: var(--accent-color, #4a739c);
  box-shadow: 0 1px 0 0 var(--accent-color, #4a739c);
}

/* Footer Separator */
.footer_wrap {
  position: relative;
}
.footer_wrap::before {
  content: '';
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: min(90%, var(--container-max, 1170px));
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--alt-border, #ebebeb) 20%, var(--alt-border, #ebebeb) 80%, transparent);
}

/* Skip Link */
.skip-link {
  position: absolute;
  top: -100%;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100000;
  padding: 0.75rem 1.5rem;
  background: var(--accent-color, #4a739c);
  color: var(--inverse-text, #fff);
  border-radius: 0 0 var(--radius-md, 4px) var(--radius-md, 4px);
  font-weight: 600;
  text-decoration: none;
  transition: top var(--transition-fast, 150ms);
}
.skip-link:focus {
  top: 0;
  outline: none;
}

/* Selection Color */
::selection {
  background-color: var(--accent-color, #4a739c);
  color: var(--inverse-text, #ffffff);
}

/* Page Load - safety rules to avoid stuck opacity 0
   (animazione pageLoad rimossa: causava opacity: 0 su mobile
   quando animation-fill-mode non era presente) */
html, body { display: block !important; opacity: 1 !important; visibility: visible !important; }
.page_wrap { opacity: 1 !important; visibility: visible !important; }

/* Fade-in elements (JS driven) */
.fade-in-element {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 0.6s cubic-bezier(0.4, 0, 0.2, 1), transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}
.fade-in-element.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* Hide Scrollbar */
html {
  scrollbar-width: none;
}
html::-webkit-scrollbar {
  display: none;
}

/* ============================================
   Slider / Hero Section Fix (Rev Slider v6+)
   ============================================ */

/* Darken slider backgrounds - applied on wrapper to avoid flash during transitions */
rs-sbg-px {
  filter: brightness(0.4) saturate(0.6) !important;
}
/* Slider text styling - exclude buttons */
rs-layer.BidWhiteText,
rs-layer.BidWhiteText * {
  color: #e7887b !important;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.4) !important;
}
/* Slider buttons - white text */
rs-layer.ButtonOptometry,
rs-layer.rev-btn {
  color: #fff !important;
  text-shadow: none !important;
}

/* ============================================
   Remove empty space from broken shortcodes
   ============================================ */

/* Hide raw shortcode text displayed on page */
.page_content_wrap p:empty,
.page_content_wrap br:empty {
  display: none;
}
/* Collapse sections with no rendered content */
.sc_section:empty,
.sc_columns:empty {
  display: none;
  margin: 0;
  padding: 0;
}

/* ============================================
   La Nostra Storia - dark overlay on bg image
   ============================================ */
.vc_custom_1549467301547 {
  position: relative;
}
.vc_custom_1549467301547::before {
  content: '' !important;
  display: block !important;
  position: absolute !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  background: rgba(30, 40, 55, 0.75) !important;
  z-index: 0 !important;
  pointer-events: none !important;
}
.vc_custom_1549467301547 > * {
  position: relative;
  z-index: 1;
}
/* Ensure text in this section is readable */
.vc_custom_1549467301547 .sc_section_content_wrap p,
.vc_custom_1549467301547 .sc_section_content_wrap li {
  color: #e0e0e0 !important;
}
.vc_custom_1549467301547 .sc_section_content_wrap h2 {
  color: #fff !important;
}

/* ============================================
   Gallery - fix oversized/deformed images
   ============================================ */
.wpb_gallery .wpb_gallery_slides .woocommerce-product-gallery__image img,
.wpb_gallery img,
.wpb_gallery .nivoSlider img {
  max-height: 500px !important;
  width: 100% !important;
  object-fit: cover !important;
}
.wpb_gallery .wpb_gallery_slides,
.wpb_gallery .nivoSlider {
  max-height: 500px !important;
  overflow: hidden;
}

/* Hide date on static pages (not blog posts) */
.page .post_info_posted,
.page .post_info {
  display: none;
}

/* Print Styles */
@media print {
  .top_panel_wrap, .footer_wrap, .contacts_wrap, .copyright_wrap,
  .sidebar, .breadcrumbs, .skip-link, #page_preloader {
    display: none !important;
  }
  body { font-size: 12pt; color: #000; background: #fff; }
  .content_wrap { width: 100% !important; max-width: none !important; }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  .fade-in-element {
    opacity: 1;
    transform: none;
    transition: none;
  }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============================================
   CLS / Layout Shift Prevention (v2)
   ============================================ */

/* Images safe defaults */
img {
  max-width: 100%;
  height: auto;
}
/* Slider containment to prevent jumps */
.slider_wrap, rs-module-wrap, rs-module {
  contain: layout paint;
}

/* CRITICAL FIX: Reserve space for Services section (top CLS offender at 0.179) */
.sc_services,
.sc_services_style_services-1 {
  min-height: 320px;
  contain: layout;
}
.sc_services_style_services-1 .sc_services_item {
  min-height: 260px;
  display: flex;
  flex-direction: column;
}
.sc_services_style_services-1 .sc_services_item_thumb {
  aspect-ratio: 16 / 10;
  overflow: hidden;
  background: rgba(0, 0, 0, 0.04);
}
.sc_services_style_services-1 .sc_services_item_thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Reserve vertical rhythm for WPB rows that hold dynamic content */
.vc_row, .sc_section_content_wrap {
  contain: layout style;
}

/* La Nostra Storia - reserve height to avoid shift */
.vc_custom_1549467301547 {
  min-height: 420px;
  contain: layout;
}

/* Gallery slider height reservation */
.wpb_gallery,
.wpb_gallery .wpb_gallery_slides,
.wpb_gallery .nivoSlider {
  min-height: 380px;
}

/* Cookie bar: reserve space at top of body so insertion doesn't shift */
#cookie-law-info-bar {
  contain: layout style;
  will-change: transform;
}

/* Post featured images - aspect ratio reservation */
.post_featured {
  aspect-ratio: 16 / 10;
  background-color: rgba(0, 0, 0, 0.04);
  overflow: hidden;
}
.post_featured img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Reserve space for Google Map iframe */
.sc_googlemap iframe {
  display: block;
  border: 0;
}

/* ============================================
   Chi Siamo - Page Styling
   ============================================ */

/* Styled form box "Prenota il tuo Esame" */
.page-id-5 .sc_section.sc_section_style_dark,
.page-template-default .sc_section[style*="background-color"] {
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.15);
}
/* Softer dark section styling */
.page-id-5 h2,
.page-id-5 h3 {
  margin-top: 0.5em;
  margin-bottom: 0.8em;
}
/* Improve readability of bulleted list on Chi Siamo */
.page-id-5 .wpb_text_column ul,
.page-id-5 .wpb_text_column ol {
  line-height: 1.8;
}
.page-id-5 .wpb_text_column li {
  margin-bottom: 0.5em;
}

/* ============================================
   Contatti Page - Fix oversized headings & map
   ============================================ */

/* Fluid heading sizes - responsive without media queries */
.page-template-contacts h1,
.page h1.page-title { font-size: clamp(1.75rem, 4vw, 2.5rem); }
.page-template-contacts h2,
.page-template-default h2 {
  font-size: clamp(1.5rem, 3.5vw, 2.25rem) !important;
  line-height: 1.3;
  margin-bottom: 0.8em;
}
.page-template-contacts h3,
.page-template-default h3 {
  font-size: clamp(1.25rem, 2.8vw, 1.75rem) !important;
  line-height: 1.35;
}

/* Fix Google Map fallback when API key missing */
.sc_googlemap {
  position: relative;
  background: linear-gradient(135deg, #f5f3ef 0%, #e9e6df 100%);
  min-height: 350px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  overflow: hidden;
}
.sc_googlemap::before {
  content: 'Via Montanara 45, Parma';
  position: absolute;
  bottom: 1rem;
  left: 1rem;
  padding: 0.5rem 1rem;
  background: rgba(255, 255, 255, 0.95);
  color: #333;
  font-weight: 600;
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
  z-index: 2;
  font-size: 0.9rem;
}
.sc_googlemap iframe {
  width: 100%;
  height: 100%;
  min-height: 350px;
  position: relative;
  z-index: 1;
}

/* ============================================
   MOBILE RESPONSIVE IMPROVEMENTS (v2)
   ============================================ */

/* Tablet and mobile (up to 1024px) */
@media (max-width: 1024px) {
  .sc_title, .sc_section_title { font-size: clamp(1.5rem, 4vw, 2.25rem) !important; }
  .vc_custom_1549467301547 { min-height: auto; }
  .menu_main_nav { display: none !important; }
  .menu_button { display: inline-flex !important; }
}

/* Mobile (up to 782px) */
@media (max-width: 782px) {
  /* -------- Mobile header (tema usa .header_mobile) -------- */
  .header_mobile {
    display: block !important;
    visibility: visible !important;
    min-height: 64px;
  }
  .header_mobile .logo img {
    max-height: 48px !important;
    width: auto !important;
  }
  /* Touch-friendly menu button */
  .header_mobile .menu_button,
  .menu_button, .menu_button.icon-menu {
    min-width: 44px !important;
    min-height: 44px !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
  }

  /* -------- Hero / Slider -------- */
  rs-module-wrap, rs-module { max-height: 80vh !important; }
  rs-layer.BidWhiteText,
  rs-layer.BidWhiteText * {
    font-size: clamp(1.25rem, 5vw, 2rem) !important;
    line-height: 1.2 !important;
    white-space: normal !important;
  }
  rs-layer.ButtonOptometry, rs-layer.rev-btn {
    font-size: 0.9rem !important;
    padding: 0.75rem 1.25rem !important;
  }

  /* -------- Typography -------- */
  h1, .sc_item_title, .sc_title {
    font-size: clamp(1.5rem, 6vw, 2rem) !important;
    line-height: 1.25 !important;
  }
  h2 { font-size: clamp(1.35rem, 5vw, 1.75rem) !important; line-height: 1.3 !important; }
  h3 { font-size: clamp(1.15rem, 4.5vw, 1.5rem) !important; line-height: 1.35 !important; }
  h4 { font-size: clamp(1.05rem, 4vw, 1.25rem) !important; }
  p, li, .sc_section_content_wrap p {
    font-size: 0.95rem !important;
    line-height: 1.6 !important;
  }

  /* -------- Sections / spacing -------- */
  .vc_row, .sc_section {
    padding-top: 2rem !important;
    padding-bottom: 2rem !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
  }
  .content_wrap, .container {
    padding-left: 1rem !important;
    padding-right: 1rem !important;
    max-width: 100% !important;
  }
  .page_content_wrap, .page_paddings_yes {
    padding-top: 1.5rem !important;
    padding-bottom: 1.5rem !important;
  }

  /* -------- Columns stack -------- */
  .vc_col-sm-6, .vc_col-md-6, .vc_col-lg-6,
  .vc_col-sm-4, .vc_col-md-4, .vc_col-lg-4,
  .vc_col-sm-3, .vc_col-md-3, .vc_col-lg-3,
  .wpb_column, .vc_column_container {
    width: 100% !important;
    max-width: 100% !important;
    flex: 0 0 100% !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
  }

  /* -------- Service cards -------- */
  .sc_services_style_services-1 .sc_services_item {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 0 1.25rem 0 !important;
    min-height: auto;
  }
  .sc_services_item_thumb { aspect-ratio: 16 / 10 !important; }
  .sc_services_item_title { font-size: 1.15rem !important; margin-top: 0.75rem; }

  /* -------- Gallery -------- */
  .wpb_gallery,
  .wpb_gallery .wpb_gallery_slides,
  .wpb_gallery .nivoSlider {
    max-height: 280px !important;
    min-height: 280px !important;
  }
  .wpb_gallery img, .wpb_gallery .nivoSlider img {
    max-height: 280px !important;
    object-fit: cover !important;
  }

  /* -------- La Nostra Storia -------- */
  .vc_custom_1549467301547 {
    padding: 2.5rem 1rem !important;
    min-height: 360px;
    background-attachment: scroll !important; /* parallax breaks on mobile */
  }

  /* -------- Buttons -------- */
  .sc_button, input[type="submit"], button:not(.mejs-button) {
    min-height: 44px !important;
    padding: 0.75rem 1.5rem !important;
    font-size: 0.95rem !important;
  }

  /* -------- Forms (prevent iOS zoom) -------- */
  .sc_form input, .sc_form textarea, .sc_form select,
  input[type="text"], input[type="email"], input[type="tel"],
  input[type="password"], textarea, select {
    font-size: 16px !important;
  }

  /* -------- Map -------- */
  .sc_googlemap, .sc_googlemap iframe { min-height: 260px !important; }

  /* -------- Footer -------- */
  .footer_wrap { padding: 2rem 1rem !important; }
  .footer_wrap .vc_row > div,
  .footer_wrap .wpb_column { margin-bottom: 1.5rem !important; }

  /* -------- Disable hover effects on touch -------- */
  .sc_services_style_services-1 .sc_services_item:hover { transform: none; }
  .post_featured:hover img, .sc_image:hover img { transform: none; }
  .menu_main_nav > li > a::after { display: none; }

  /* -------- No horizontal scroll -------- */
  html, body { overflow-x: hidden !important; max-width: 100vw !important; }
}

/* Small mobile (up to 480px) */
@media (max-width: 480px) {
  h1 { font-size: 1.5rem !important; }
  h2 { font-size: 1.25rem !important; }
  h3 { font-size: 1.1rem !important; }
  .vc_row, .sc_section { padding-top: 1.5rem !important; padding-bottom: 1.5rem !important; }
  .breadcrumbs { padding: 0.75rem 0 !important; font-size: 0.8rem; }
  .logo_text { font-size: 1rem !important; }
  .contact_logo .logo img { max-height: 40px !important; }
  rs-layer.BidWhiteText { font-size: clamp(1.1rem, 4.5vw, 1.5rem) !important; }
  .sc_services_item_title { font-size: 1rem !important; }
}

/* ============================================
   PERFORMANCE - Reduce main thread work
   ============================================ */

/* Use content-visibility for below-the-fold sections */
@supports (content-visibility: auto) {
  .footer_wrap,
  .vc_row.vc_custom_1572709023411,
  .vc_row.vc_custom_1460546907518 {
    content-visibility: auto;
    contain-intrinsic-size: auto 500px;
  }
}

/* Accelerate transforms with GPU */
.sc_button, .sc_services_item, rs-layer {
  transform: translateZ(0);
  backface-visibility: hidden;
}

/* ============================================
   FONT DISPLAY - Prevent FOIT & invisible text
   ============================================ */
/* Force font-display: swap on all @font-face declarations loaded after this rule.
   Google Fonts URLs should be amended server-side with &display=swap */
@font-face { font-display: swap; }
