/* ============================================================
   EnergiaBarata.eu — Premium Design Layer (2026)

   REVERSIBLE: Remove this file + premium.js from HTML to revert.
   This file ONLY adds/overrides — never removes existing styles.
   ============================================================ */

/* === Premium Typography === */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&family=DM+Sans:ital,wght@0,400;0,500;0,700;1,400&display=swap');

:root {
  /* Brand colors (preserved) */
  --c-primary: #00A651;
  --c-primary-dark: #008C42;
  --c-primary-light: #00D966;
  --c-accent: #fdc814;
  --c-dark: #004D2C;

  /* Premium additions */
  --c-surface: #ffffff;
  --c-surface-raised: #f8faf9;
  --c-text: #1a1a2e;
  --c-text-muted: #6b7280;
  --c-border: #e5e7eb;
  --c-glow: rgba(0, 166, 81, 0.15);

  /* Typography */
  --font-heading: 'Inter', system-ui, -apple-system, sans-serif;
  --font-body: 'DM Sans', system-ui, -apple-system, sans-serif;

  /* Spacing rhythm */
  --space-section: clamp(4rem, 8vw, 7rem);

  /* Transitions */
  --ease-premium: cubic-bezier(0.22, 1, 0.36, 1);
  --duration-fast: 200ms;
  --duration-normal: 350ms;
  --duration-slow: 600ms;
}

/* === Base Typography Upgrade === */
body {
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, h5, h6,
.font-bold, .font-extrabold, .font-black {
  font-family: var(--font-heading);
  letter-spacing: -0.02em;
}

/* Improved reading experience for body text */
article p,
.prose p,
main section p {
  font-size: 1.0625rem;
  line-height: 1.75;
}

/* === Reading Progress Bar === */
.reading-progress {
  position: fixed;
  top: 0;
  left: 0;
  width: 0%;
  height: 3px;
  background: linear-gradient(90deg, var(--c-primary), var(--c-primary-light), var(--c-accent));
  z-index: 9999;
  transition: width 100ms linear;
  border-radius: 0 2px 2px 0;
}

/* === Sticky Navbar with Glassmorphism === */
header nav,
nav[aria-label="Navegacion principal"] {
  transition: all var(--duration-normal) var(--ease-premium);
}

header.scrolled nav,
.nav-scrolled {
  background: rgba(255, 255, 255, 0.85) !important;
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05), 0 8px 24px rgba(0, 0, 0, 0.04);
  border-bottom: 1px solid rgba(229, 231, 235, 0.5);
}

header {
  position: sticky;
  top: 0;
  z-index: 1000;
  transition: all var(--duration-normal) var(--ease-premium);
}

/* === Scroll Reveal Animations === */
/* Suppress transition during viewport pre-check to prevent FOIC */
.no-transition,
.no-transition * {
  transition: none !important;
}

.reveal {
  opacity: 0;
  transform: translateY(30px);
  transition: opacity var(--duration-slow) var(--ease-premium),
              transform var(--duration-slow) var(--ease-premium);
}

.reveal.visible {
  opacity: 1;
  transform: translateY(0);
}

.reveal-left {
  opacity: 0;
  transform: translateX(-30px);
  transition: opacity var(--duration-slow) var(--ease-premium),
              transform var(--duration-slow) var(--ease-premium);
}

.reveal-left.visible {
  opacity: 1;
  transform: translateX(0);
}

.reveal-right {
  opacity: 0;
  transform: translateX(30px);
  transition: opacity var(--duration-slow) var(--ease-premium),
              transform var(--duration-slow) var(--ease-premium);
}

.reveal-right.visible {
  opacity: 1;
  transform: translateX(0);
}

/* Staggered children animation */
.stagger-children > * {
  opacity: 0;
  transform: translateY(20px);
  transition: opacity 400ms var(--ease-premium),
              transform 400ms var(--ease-premium);
}

.stagger-children.visible > *:nth-child(1) { transition-delay: 0ms; }
.stagger-children.visible > *:nth-child(2) { transition-delay: 80ms; }
.stagger-children.visible > *:nth-child(3) { transition-delay: 160ms; }
.stagger-children.visible > *:nth-child(4) { transition-delay: 240ms; }
.stagger-children.visible > *:nth-child(5) { transition-delay: 320ms; }
.stagger-children.visible > *:nth-child(6) { transition-delay: 400ms; }
.stagger-children.visible > *:nth-child(7) { transition-delay: 480ms; }
.stagger-children.visible > *:nth-child(8) { transition-delay: 560ms; }

.stagger-children.visible > * {
  opacity: 1;
  transform: translateY(0);
}

/* === Premium Card Effects === */
.card-hover {
  transition: all var(--duration-normal) var(--ease-premium);
  border: 1px solid var(--c-border);
}

.card-hover:hover {
  transform: translateY(-6px);
  box-shadow:
    0 4px 6px -1px rgba(0, 166, 81, 0.06),
    0 20px 40px -8px rgba(0, 166, 81, 0.12);
  border-color: rgba(0, 166, 81, 0.3);
}

.card-hover::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  opacity: 0;
  transition: opacity var(--duration-normal) var(--ease-premium);
  background: linear-gradient(135deg, rgba(0, 166, 81, 0.03), transparent);
  pointer-events: none;
}

.card-hover:hover::after {
  opacity: 1;
}

/* === Premium Button Styles === */
.btn-premium {
  position: relative;
  overflow: hidden;
  transition: all var(--duration-normal) var(--ease-premium);
}

.btn-premium::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  transition: width 500ms var(--ease-premium), height 500ms var(--ease-premium);
}

.btn-premium:hover::before {
  width: 300px;
  height: 300px;
}

/* CTA glow effect */
.btn-glow {
  box-shadow: 0 0 0 0 rgba(0, 166, 81, 0.4);
  animation: btn-pulse 2.5s ease-in-out infinite;
}

@keyframes btn-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(0, 166, 81, 0.4); }
  50% { box-shadow: 0 0 0 12px rgba(0, 166, 81, 0); }
}

/* === Improved Hero Section === */
.hero-gradient {
  position: relative;
}

.hero-gradient::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 40%;
  background: linear-gradient(to top, rgba(0, 77, 44, 0.3), transparent);
  pointer-events: none;
}

/* Hero stats counter animation */
.stat-number {
  display: inline-block;
  font-variant-numeric: tabular-nums;
}

/* === Section Spacing Improvement === */
main > section {
  scroll-margin-top: 80px;
}

/* === Improved Silo Cards === */
.silo-card {
  position: relative;
  overflow: hidden;
  transition: all var(--duration-normal) var(--ease-premium);
  border-radius: 1rem;
}

.silo-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--c-primary), var(--c-primary-light));
  transform: scaleX(0);
  transform-origin: left;
  transition: transform var(--duration-normal) var(--ease-premium);
}

.silo-card:hover::before {
  transform: scaleX(1);
}

.silo-card:hover {
  transform: translateY(-8px);
  box-shadow: 0 20px 40px -12px rgba(0, 166, 81, 0.15);
}

/* === FAQ Premium Enhancement === */
.faq-answer {
  transition: max-height 500ms var(--ease-premium),
              padding 500ms var(--ease-premium),
              opacity 300ms ease;
}

/* === Trust Badges Improvement === */
.trust-badge {
  transition: all var(--duration-normal) var(--ease-premium);
  border-radius: 1rem;
}

.trust-badge:hover {
  transform: translateY(-4px) scale(1.02);
  box-shadow: 0 12px 24px -8px rgba(0, 0, 0, 0.1);
}

/* === Gradient Borders (Premium Detail) === */
.gradient-border {
  position: relative;
  border: none !important;
}

.gradient-border::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  padding: 1px;
  background: linear-gradient(135deg, var(--c-primary), var(--c-primary-light), var(--c-accent));
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

/* === Smooth Scroll Shadows (for tables, overflow) === */
.scroll-shadow {
  background:
    linear-gradient(90deg, white 30%, rgba(255, 255, 255, 0)),
    linear-gradient(90deg, rgba(255, 255, 255, 0), white 70%) 100% 0,
    radial-gradient(farthest-side at 0 50%, rgba(0, 0, 0, 0.08), transparent),
    radial-gradient(farthest-side at 100% 50%, rgba(0, 0, 0, 0.08), transparent) 100% 0;
  background-repeat: no-repeat;
  background-size: 40px 100%, 40px 100%, 14px 100%, 14px 100%;
  background-attachment: local, local, scroll, scroll;
}

/* === Core Web Vitals: Content Visibility === */
main > section:not(:first-child) {
  content-visibility: auto;
  contain-intrinsic-size: auto 600px;
}

/* === Improved Footer === */
footer {
  position: relative;
}

footer::before {
  content: '';
  position: absolute;
  top: 0;
  left: 10%;
  right: 10%;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--c-primary), transparent);
}

/* === Mobile Improvements === */
@media (max-width: 768px) {
  /* Larger touch targets */
  .mobile-menu a {
    min-height: 48px;
    display: flex;
    align-items: center;
    padding: 12px 16px;
  }

  /* Better mobile card spacing */
  .card-hover:hover {
    transform: none;
  }

  /* Disable hover effects on touch */
  @media (hover: none) {
    .card-hover:hover,
    .silo-card:hover,
    .trust-badge:hover {
      transform: none;
      box-shadow: none;
    }
  }
}

/* === Dark Mode Ready (opt-in via class) === */
@media (prefers-color-scheme: dark) {
  /* Only activates if .dark-mode class is on <html> */
  html.dark-mode {
    --c-surface: #0f1419;
    --c-surface-raised: #1a1f26;
    --c-text: #e4e8ec;
    --c-text-muted: #9ca3af;
    --c-border: #2d3640;
  }
}

/* === Print Styles === */
@media print {
  .reading-progress,
  .skip-nav,
  header,
  footer,
  .mobile-menu,
  .btn-glow {
    display: none !important;
  }

  body {
    font-size: 12pt;
    line-height: 1.6;
    color: #000;
  }

  a {
    color: #000;
    text-decoration: underline;
  }

  a[href]::after {
    content: " (" attr(href) ")";
    font-size: 0.8em;
    color: #666;
  }
}

/* ===================================================
   AFFILIATE SECTION — "Dónde comprar al mejor precio"
   Constrain width to match article content (max-w-4xl)
   =================================================== */
details.affiliate-section,
.affiliate-section {
  max-width: 56rem; /* matches Tailwind max-w-4xl */
  margin-left: auto !important;
  margin-right: auto !important;
  box-sizing: border-box;
}

/* ===================================================
   STICKY ARTICLE READING BAR
   Appears below the main nav when the h1 scrolls out
   =================================================== */
.article-reading-bar {
  position: fixed;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border-bottom: 2px solid var(--c-primary);
  padding: 0.6rem 1rem;
  z-index: 999; /* just below main header (1000) */
  transform: translateY(-110%);
  transition: transform 300ms var(--ease-premium);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.07);
  pointer-events: none;
}

.article-reading-bar.show {
  transform: translateY(0);
  pointer-events: auto;
}

.article-reading-bar__title {
  font-family: var(--font-heading);
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--c-text);
  max-width: 56rem;
  margin: 0 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  line-height: 1.4;
}

.article-reading-bar__title::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c-primary);
  flex-shrink: 0;
}

/* === Subtle Background Texture === */
.bg-texture {
  background-image:
    radial-gradient(circle at 25% 25%, rgba(0, 166, 81, 0.03) 0%, transparent 50%),
    radial-gradient(circle at 75% 75%, rgba(253, 200, 20, 0.02) 0%, transparent 50%);
}

/* === Number Counter Animation === */
@keyframes countUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.count-up {
  animation: countUp 600ms var(--ease-premium) forwards;
}

/* === Tooltip Enhancement === */
[data-tooltip] {
  position: relative;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: var(--c-dark);
  color: white;
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 0.75rem;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: all var(--duration-fast) var(--ease-premium);
}

[data-tooltip]:hover::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* === Hero Video (homepage) === */
.hero-video {
  width: 300px;
  height: auto;
  max-height: 460px;
  object-fit: contain;
  border-radius: 1rem;
  /* Blend dark/black backgrounds into the hero so the animation
     appears to float without a box — same technique as PNG transparency */
  /* Background replaced with hero green (#00A651) in the video itself.
     No blend mode needed — the color matches the hero section background. */
  pointer-events: none;
  /* Subtle entrance */
  animation: heroVideoFadeIn 800ms var(--ease-premium) both;
  animation-delay: 400ms;
}

@keyframes heroVideoFadeIn {
  from { opacity: 0; transform: scale(0.96) translateY(12px); }
  to   { opacity: 1; transform: scale(1)    translateY(0);     }
}

@media (max-width: 1024px) {
  .hero-video { display: none !important; }
}

/* ===================================================
   SILO CARDS — color top border by category
   Uses href attribute selector so no extra HTML needed
   =================================================== */
.silo-card { border-top: 4px solid transparent; }

.silo-card[href*="precio-de-la-luz"]  { border-top-color: var(--silo-luz,      #2563eb); }
.silo-card[href*="precio-gasolina"]   { border-top-color: var(--silo-gasolina,  #ea580c); }
.silo-card[href*="ahorrar-factura"]   { border-top-color: var(--silo-ahorro,    #16a34a); }
.silo-card[href*="energia-solar"]     { border-top-color: var(--silo-solar,     #ca8a04); }
.silo-card[href*="coche-electrico"]   { border-top-color: var(--silo-coche,     #9333ea); }
.silo-card[href*="gas-calefaccion"]   { border-top-color: var(--silo-gas,       #dc2626); }

/* ===================================================
   HERO SECTION — "Hora a Hora" subtitle contrast fix
   gradient-title over green background needs light colors
   =================================================== */
#hero .gradient-title {
  background: linear-gradient(135deg, #ffffff 0%, var(--c-accent, #fdc814) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ===================================================
   LIVE PRICE WIDGET — hero stat card (price)
   =================================================== */
.hero-price-card {
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-premium);
}
.hero-price-card:hover { background: rgba(255,255,255,0.22) !important; }

.price-pulse {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: #4ade80;
  animation: pricePulse 2s ease-in-out infinite;
}
@keyframes pricePulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(74,222,128,0.5); }
  50%       { box-shadow: 0 0 0 6px rgba(74,222,128,0);  }
}

/* Color states for live price badge */
.price-state-cheap  { color: #4ade80; }
.price-state-normal { color: #fcd34d; }
.price-state-expensive { color: #f87171; }

/* ===================================================
   NEWSLETTER SECTION
   =================================================== */
.newsletter-section {
  background: linear-gradient(135deg, #0d1117 0%, #003d1f 50%, #0d1117 100%);
}

.newsletter-input {
  background: rgba(255,255,255,0.10);
  border: 1px solid rgba(255,255,255,0.20);
}

.newsletter-input:focus {
  outline: none;
  background: rgba(255,255,255,0.15);
  border-color: rgba(253,200,20,0.7);
  box-shadow: 0 0 0 3px rgba(253,200,20,0.25);
}
