/* products.css - Modular styles for the Products Section
   ------------------------------------------------------
   Purpose: Provide a standalone, themeable and responsive
   products/categories section for TopNet. This file is
   intentionally scoped and uses CSS variables from
   variables.css. Import this file from index.html.

   Notes:
   - Avoids global selectors to prevent collisions.
   - Uses CSS Grid for responsive layout and flexbox
     inside cards for equal-height content.
*/

.products-section {
  padding: var(--spacing-2xl, 48px) 1.5rem;
  background: var(--bg-products);
  color: var(--color-gray-dark);
  text-align: center;
}

.products-section .section-inner {
  max-width: var(--container-max-width);
  margin: 0 auto;
  padding: 0 1rem;
}

.products-section h2 {
  font-family: var(--font-primary);
  font-size: var(--font-size-3xl);
  margin: 0 auto;
  letter-spacing: -0.5px;
  color: var(--color-gray-dark);
}

.products-section p.lead {
  color: var(--color-gray-medium);
  max-width: 860px;
  margin: 0.75rem auto 0;
  font-size: var(--font-size-lg);
}

/* SOLUCIÓN RADICAL DEFINITIVA: CSS simplificado para structure JavaScript */
.categories-grid {
  margin-top: 2.25rem;
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
}

/* Estilos para las filas creadas por JavaScript */
.categories-row,
.categories-row-centered {
  display: flex;
  gap: 28px;
  margin-bottom: 28px;
}

.categories-row {
  justify-content: space-between;
}

.categories-row-centered {
  justify-content: center;
  max-width: 680px;
  margin-left: auto;
  margin-right: auto;
}

/* Asegurar que las tarjetas tengan el tamaño correcto */
.category-card {
  flex: 1;
  max-width: 320px;
  min-width: 280px;
}

/* Responsive design para el nuevo sistema de filas */
@media (max-width: 1024px) {
  .categories-row {
    flex-wrap: wrap;
    justify-content: center;
  }
  
  .categories-row-centered {
    flex-wrap: wrap;
    max-width: 100%;
  }
  
  .category-card {
    flex: 1 1 calc(50% - 14px);
    min-width: 280px;
    max-width: 400px;
  }
}

@media (max-width: 768px) {
  .categories-row,
  .categories-row-centered {
    flex-direction: column;
    align-items: center;
  }
  
  .category-card {
    flex: none;
    width: 100%;
    max-width: 400px;
  }
}

/* Category card - visual treatment */
.category-card {
  background: linear-gradient(135deg, var(--color-navy), var(--color-navy-dark));
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 16px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 220px;
  transition: transform 320ms var(--transition-normal),
              box-shadow 320ms var(--transition-normal),
              background 320ms var(--transition-normal);
  cursor: default;
  position: relative;
  overflow: hidden;
}

/* Decorative accent shape using clip-path */
.category-card::before {
  content: "";
  position: absolute;
  right: -20%;
  top: -30%;
  width: 140%;
  height: 120%;
  background: linear-gradient(135deg, rgba(37, 99, 235, 0.3), rgba(30, 58, 95, 0.2));
  transform: rotate(20deg);
  clip-path: polygon(0 0, 100% 0, 70% 100%, 0% 75%);
  pointer-events: none;
}

.category-card:focus-within,
.category-card:hover {
  transform: translateY(-10px) scale(1.01);
  box-shadow: 0 18px 40px rgba(30, 58, 95, 0.4);
  background: linear-gradient(135deg, var(--color-navy-light), var(--color-navy));
}

/* Ensure keyboard accessibility: outline visible */
.category-card:focus-within {
  outline: 3px solid rgba(59,130,246,0.18);
  outline-offset: 4px;
}

/* Card content layout */
.category-card .cat-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.category-card .cat-title {
  font-size: var(--font-size-xl);
  font-weight: 600;
  color: #ffffff;
  margin: 0;
}

.category-card .cat-desc {
  color: rgba(255, 255, 255, 0.95);
  font-size: var(--font-size-base);
  margin-top: 4px;
  flex: 1 1 auto; /* allow description to take remaining space */
}

/* Expandable details - hidden by default, reveal on hover/focus */
.category-card .cat-meta {
  margin-top: 12px;
  font-size: var(--font-size-sm);
  color: rgba(255,255,255,0.85);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 260ms var(--transition-normal), transform 260ms var(--transition-normal);
  pointer-events: none;
}

.category-card:hover .cat-meta,
.category-card:focus-within .cat-meta,
.category-card.revealed .cat-meta {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* Small CTA inside card (progressive enhancement, non-actionable) */
.category-card .cat-cta {
  margin-top: 14px;
  align-self: flex-start;
  background: rgba(255,255,255,0.15);
  border-radius: 10px;
  padding: 8px 12px;
  color: #ffffff;
  font-weight: 600;
  font-size: var(--font-size-sm);
  border: 1px solid rgba(255,255,255,0.25);
  transition: background 220ms ease, transform 220ms ease;
}

.category-card .cat-cta:focus,
.category-card .cat-cta:hover {
  transform: translateY(-3px);
  background: rgba(255,255,255,0.25);
  border-color: rgba(255,255,255,0.4);
}

/* CTA as an accessible button (visuals only) */
.category-card .cat-cta {
  border: 1px solid rgba(255,255,255,0.25);
  background: rgba(255,255,255,0.15);
  color: #ffffff;
  cursor: pointer;
}

/* Reveal helper classes used by JS */
.category-card.hidden {
  opacity: 0;
  transform: translateY(18px);
}

.category-card.fade-in {
  animation: fadeIn 620ms cubic-bezier(.2,.9,.3,1) forwards;
}

/* Responsive tweaks */
@media (max-width: 768px) {
  .products-section {
    padding: var(--spacing-lg) 1rem;
  }
  .category-card { min-height: 180px; padding: 16px; }
  .products-section h2 { font-size: var(--font-size-2xl); }
}

/* Utility: subtle border at the bottom of the section */
.products-section .section-divider {
  height: 1px;
  background: linear-gradient(90deg, rgba(255,255,255,0.02), rgba(255,255,255,0.04), rgba(255,255,255,0.02));
  margin-top: 2.5rem;
}

/* End of products.css */

/* Modal styles - scoped to avoid collisions with global site styles */
.product-modal {
  --overlay-bg: rgba(2,6,23,0.65);
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1100;
}
.product-modal[aria-hidden="false"] {
  display: flex;
}
.product-modal__overlay {
  position: absolute;
  inset: 0;
  background: var(--overlay-bg);
}

/* Centered blur shape: creates a blurred area only under the dialog instead of blurring the whole page */
.product-modal__blur {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1115; /* between overlay and dialog */
  pointer-events: none; /* allow clicks to reach overlay/dialog */
}
.product-modal__blur .modal-blur-shape {
  width: min(900px, calc(100% - 48px));
  max-height: 86vh;
  border-radius: 12px;
  /* backdrop-filter applies blur to the area behind this element only */
  backdrop-filter: blur(8px) saturate(120%);
  -webkit-backdrop-filter: blur(8px) saturate(120%);
  background: rgba(6,8,20,0.45);
  box-shadow: 0 8px 30px rgba(2,6,23,0.55);
}

@media (max-width: 520px) {
  .product-modal__blur .modal-blur-shape { width: calc(100% - 28px); border-radius: 10px; }
}
.product-modal__dialog {
  position: relative;
  width: min(820px, calc(100% - 48px));
  max-height: 86vh;
  overflow: auto;
  background: linear-gradient(180deg, #0f1724, #061127);
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(2,6,23,0.7);
  padding: 18px;
  z-index: 1120;
  color: #e6eefb;
}

/* Strong visual centering for dialogs with optional transform for pixel-perfect middle */
.product-modal__dialog {
  /* ensure the dialog is visually centered, even when content height is less than viewport */
  display: block;
  transform: translateY(0);
}

/* Smooth open animation */
.product-modal[aria-hidden="false"] .product-modal__dialog {
  animation: modalEnter 220ms cubic-bezier(.2,.9,.25,1) both;
}

@keyframes modalEnter {
  from { opacity: 0; transform: translateY(8px) scale(.995); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* Scroll-lock helper: when modal-open is applied to root/body, prevent background scroll
   and ensure smooth modal experience without layout shift */
:root.modal-open, 
html.modal-open,
body.modal-open {
  height: 100%;
  overflow: hidden;
}

/* Ensure modal doesn't affect document flow when body is position:fixed */
body.modal-open {
  /* Additional insurance for scroll lock - prevent any potential scroll */
  touch-action: none;
  -webkit-overflow-scrolling: touch;
}

/* When modal is open, add a small right padding equal to scrollbar width via inline style
   set from JS. This selector ensures no unexpected overflow */
.product-modal__dialog { box-sizing: border-box; }
.product-modal__header { /* header layout: media | info | close */
  display: flex;
  align-items: flex-start; /* align top so title sits next to media */
  gap: 12px;
}
/* media block on the left: fixed size, centered content, hide overflow */
.product-modal__media {
  flex: 0 0 110px;
  width: 110px;
  height: 80px;
  margin-right: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: transparent; /* ensure no white box */
  border-radius: 8px;
  /* hide by default; JS will show when explicit modal media is present */
  display: none;
}
.product-modal__image, .product-modal__lottie { width: 100%; height: 100%; object-fit: contain; border-radius: 8px; background: transparent; }

.product-modal__lottie {
  width: 100%;
  height: 320px;
  display: none; /* hidden until Lottie is loaded */
}

/* Defensive: SVGs used inside media should not have forced white backgrounds/fills */
.product-modal__media svg { background: transparent; }
.product-modal__media svg path { fill: currentColor; }

/* Inlined SVG shim: make sure it fits and has no background */
.product-modal__media-inline { width: 100%; height: 100%; display: flex; align-items:center; justify-content:center; }
.product-modal__media-inline svg { width: 100%; height: 100%; display: block; background: transparent; }
.product-modal__media-inline svg rect { fill: none !important; }

/* Aggressive safeguard: hide white rectangles or white fills that may come from external SVGs
   Scoped to product modal media to avoid global side-effects. */
.product-modal__media rect[fill="#fff"],
.product-modal__media rect[fill="#ffffff"],
.product-modal__media rect[fill="white"]{
  display: none !important;
}
.product-modal__media [fill="#fff"],
.product-modal__media [fill="#ffffff"],
.product-modal__media [fill="white"]{
  fill: none !important;
}
.product-modal__shortdesc { margin: 6px 0 0; color: rgba(230,238,251,0.85); }
.product-modal__content { margin-top: 8px; color: rgba(230,238,251,0.95); line-height: 1.5; }

/* Rich modal content styles */
.product-modal article { padding: 6px 0; }
.product-modal .modal-section { margin: 14px 0; border-left: 3px solid rgba(255,255,255,0.04); padding-left: 12px; }
.product-modal .modal-section h3 { margin: 0 0 6px; color: #eef6ff; }
.product-modal .help-block { background: rgba(255,255,255,0.02); padding: 10px; border-radius: 8px; margin-top: 8px; color: rgba(230,238,251,0.9); }

/* CTA inside modal */
.modal-cta { background: linear-gradient(90deg,#4f46e5,#06b6d4); border: none; color: #fff; padding: 10px 14px; border-radius: 10px; font-weight:700; cursor:pointer; box-shadow: 0 8px 20px rgba(6,8,30,0.35); transition: transform 200ms ease, box-shadow 200ms ease; }
.modal-cta:hover { transform: translateY(-4px); box-shadow: 0 18px 40px rgba(6,8,30,0.45); }
.modal-cta:active { transform: translateY(-1px); }

/* Reveal-item base for GSAP/JS to animate elements inside modal (fallback CSS animation) */
.reveal-item { opacity: 0; transform: translateY(8px); transition: opacity 360ms ease, transform 360ms ease; }
.reveal-item.visible { opacity: 1; transform: translateY(0); }

/* modal footer styling */
.product-modal .modal-footer { margin-top: 12px; display:flex; align-items:center; justify-content:space-between; gap:12px; }

@media (max-width: 520px) {
  /* On very small screens stack header: media on top, then content */
  .product-modal__header { flex-direction: column; align-items: stretch; }
  .product-modal__media { display: block; width: 100%; height: 140px; margin: 0 0 10px 0; flex: 0 0 auto; }
  .product-modal__dialog { padding: 12px; }
}
.product-modal__header > div { flex: 1 1 auto; min-width: 0; }
.product-modal__close {
  background: transparent;
  border: none;
  color: #dbeafe;
  font-size: 1.1rem;
  cursor: pointer;
}
.product-modal__body { margin-top: 10px; }
.product-modal__footer { margin-top: 14px; text-align: right; }

/* Small responsive tweak */
@media (max-width: 520px) {
  .product-modal__dialog { padding: 14px; }
}

/* Map modal specific animation (reuses product-modal structure) */
.map-modal {
  opacity: 0;
  transition: opacity 260ms ease;
}
.map-modal.is-open { opacity: 1; }
.map-modal .product-modal__overlay { opacity: 0; transition: opacity 260ms ease; }
.map-modal.is-open .product-modal__overlay { opacity: 1; }
.map-modal .product-modal__dialog { transform: translateY(6px) scale(0.998); transition: transform 260ms cubic-bezier(.2,.9,.25,1), opacity 220ms ease; opacity: 0; }
.map-modal.is-open .product-modal__dialog { transform: translateY(0) scale(1); opacity: 1; }

/* Ensure transitions don't trigger layout shifts on unlock */
html.modal-open { scroll-behavior: auto; }
