/* ==========================================================================
   1. VARIÁVEIS DE CORES E DESIGN TOKENS
   ========================================================================== */
:root {
  --primary: #1d4ed8;
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
  --radius: 18px;
}

/* VARIÁVEIS PARA O DARK MODE */
body.dark-mode {
  --bg: #0f172a;
  --card: #111827;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --border: #1e293b;
}

/* ==========================================================================
   2. RESET & ACESSIBILIDADE
   ========================================================================== */
* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  padding: 0;
  font-family: Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.7;
  transition: background-color 0.3s ease, color 0.3s ease;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

::selection {
  background: rgba(29, 78, 216, 0.18);
}

a:focus,
button:focus,
input:focus,
textarea:focus,
select:focus {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

/* ==========================================================================
   3. UI BASE & LAYOUT CONTÊINER
   ========================================================================== */
.container {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 30px 16px 40px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px;
  box-shadow: var(--shadow);
  margin-bottom: 24px;
}

.post-card { 
  background: var(--card); 
  border: 1px solid var(--border); 
  border-radius: var(--radius); 
  padding: 24px; 
  margin-bottom: 20px; 
  box-shadow: var(--shadow); 
  transition: transform 0.3s ease, box-shadow 0.3s ease; 
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 220px;
  padding: 14px 18px;
  border-radius: 12px;
  background: var(--primary);
  color: #fff;
  text-decoration: none;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: transform 0.2s ease, opacity 0.2s ease, box-shadow 0.2s ease;
}

.btn:hover {
  opacity: 0.94;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(29, 78, 216, 0.2);
}

.link-texto {
  font-weight: 600;
  color: var(--primary);
  text-decoration: none;
}

/* ==========================================================================
   4. COMPONENTE: HEADER (CABEÇALHO)
   ========================================================================== */
.header {
  width: 100%;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.header-wrap {
  max-width: 760px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.brand {
  display: flex;
  align-items: center;
  text-decoration: none;
}

.logo-desktop {
  height: 46px;
  width: auto;
  display: block;
}

.logo-mobile {
  display: none;
  width: 34px;
  height: 34px;
  object-fit: contain;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-header {
  padding: 8px 12px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.2s ease, color 0.2s ease, transform 0.2s ease;
}

.btn-header:hover {
  background: rgba(29, 78, 216, 0.08);
  color: var(--primary);
  transform: translateY(-1px);
}

.btn-header.destaque {
  background: var(--primary);
  color: white;
}

.btn-header.destaque:hover {
  background: rgba(29, 78, 216, 0.9);
  color: white;
}

.dark-toggle {
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 10px;
  background: rgba(29, 78, 216, 0.08);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}

.dark-toggle:hover {
  background: rgba(29, 78, 216, 0.14);
  transform: translateY(-1px);
}

/* ==========================================================================
   5. SISTEMA DE BUSCA NO HEADER (INLINE)
   ========================================================================== */
.search-toggle {
  width: 42px !important;
  height: 42px !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  border: none !important;
  border-radius: 10px !important;
  background: rgba(29, 78, 216, 0.08) !important;
  color: var(--primary) !important;
  font-size: 18px !important;
  cursor: pointer !important;
  flex-shrink: 0 !important;
  transition: background 0.2s ease, transform 0.2s ease;
}

.search-toggle:hover {
  background: rgba(29, 78, 216, 0.16) !important;
  transform: translateY(-1px);
}

.search-bar {
  display: none;
  width: 100%;
  border-top: 1px solid var(--border);
  background: var(--card);
}

.search-bar.show {
  display: block;
}

.search-container {
  max-width: 760px;
  margin: 0 auto;
  padding: 16px;
  position: relative;
}

/* Campo de busca moderno */
.search-container input[type="search"],
.search-container input[type="text"] {
  width: 100%;
  height: 46px;

  padding: 0 16px;

  border: 1px solid var(--border);
  border-radius: 14px;

  background: var(--bg);

  color: var(--text);

  font-size: 15px;

  outline: none;

  appearance: none;
  -webkit-appearance: none;

  transition: all 0.2s ease;
}

/* Focus moderno */
.search-container input[type="search"]:focus,
.search-container input[type="text"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(29, 78, 216, 0.12);
}

#searchResults {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  max-height: 320px;
  overflow-y: auto;
  padding: 6px;
}

.search-result-item {
  display: flex;
  flex-direction: column;
  padding: 12px 16px;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  text-decoration: none;
  border: 1px solid transparent;
  transition: background 0.2s ease, border-color 0.2s ease;
}

.search-result-item:hover {
  background: var(--bg);
  border-color: var(--border);
}

.search-badge {
  font-size: 10px;
  font-weight: bold;
  letter-spacing: 0.8px;
  margin-bottom: 4px;
  text-transform: uppercase;
}

.cat-energia .search-badge { color: #eab308; }
.cat-agua .search-badge { color: #3b82f6; }
.cat-automacao .search-badge { color: #a855f7; }

.search-item-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
}

.search-item.empty {
  padding: 16px;
  text-align: center;
  color: var(--muted);
  font-size: 14px;
  font-style: italic;
}

/* ==========================================================================
   6. TRAVA INTELIGENTE DE IMAGENS E CONTEÚDO (NUNCA ESTOURA / 1200x630)
   ========================================================================== */
.hero-image-container, .img-container {
  width: 100%;
  overflow: hidden;
  border-radius: 14px;
  margin-bottom: 24px;
  background: var(--border);
}

/* Força qualquer imagem principal ou interna a respeitar os limites sem distorcer */
.hero-image, .img-container img, .post-body img {
  width: 100%;
  max-width: 100%;
  height: auto;
  object-fit: cover;
  display: block;
}

.hero-section {
  text-align: center;
  padding: 55px 0 45px;
}

.hero-section h1 {
  margin-bottom: 20px;
  font-size: 46px;
  line-height: 1.15;
}

.hero-section p {
  max-width: 620px;
  margin: 0 auto 24px;
  font-size: 18px;
  color: var(--muted);
}

.hero-buttons {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 14px;
}

.share-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 30px;
}

.share-btn {
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--card);
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  font-size: 14px;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.share-btn:hover {
  transform: translateY(-2px);
  border-color: var(--primary);
}

/* GRIDS E CARDS DA HOME */
.home-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
  margin: 10px 0 40px;
}

.home-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px;
  box-shadow: var(--shadow);
  transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.home-card:hover {
  transform: translateY(-4px);
  border-color: rgba(29, 78, 216, 0.25);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
}

.home-card h3 { margin-top: 0; margin-bottom: 12px; }
.home-card p { color: var(--muted); margin-bottom: 18px; }

/* ARTIGOS RELACIONADOS */
.related-posts { margin-top: 50px; }
.related-posts h2 { margin-bottom: 20px; }
.related-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.related-card {
  display: block;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card);
  text-decoration: none;
  color: inherit;
  transition: transform 0.2s ease, border-color 0.2s ease;
}

.related-card:hover {
  transform: translateY(-3px);
  border-color: var(--primary);
}

/* TIPOGRAFIA & AUXILIARES */
h1, h2, h3 { margin-top: 0; word-break: break-word; }
h2 { color: var(--primary); margin-bottom: 12px; }
p, li, a { word-break: break-word; }
p { line-height: 1.8; }
.small { font-size: 14px; color: var(--muted); }
.text-muted { color: var(--muted); line-height: 1.8; }

/* ==========================================================================
   7. SISTEMA MODERNO DE AFILIADOS (PRODUTO EM BLOCOS GRID)
   ========================================================================== */
.product-box {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin: 24px 0;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 24px;
  align-items: center;
  transition: transform 0.3s ease, box-shadow 0.3s ease, border-color 0.3s ease;
}

.product-box:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
  border-color: var(--primary);
}

/* Ajuste perfeito para a caixa da imagem do afiliado */
.product-image-wrap {
  width: 160px;
  height: 160px;
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
}

.product-box img {
  width: 100%;
  height: 100%;
  object-fit: contain; /* Evita cortar o produto */
  display: block;
}

.product-info {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.product-title {
  color: var(--text);
  font-size: 19px;
  font-weight: bold;
  text-decoration: none;
  line-height: 1.4;
  margin: 0;
}

.product-title:hover {
  color: var(--primary);
}

.product-desc {
  font-size: 15px;
  color: var(--muted);
  margin: 0;
  line-height: 1.6;
}

.cta-container {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 8px;
}

.btn-main-cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--primary);
  color: #ffffff !important;
  text-decoration: none;
  font-weight: bold;
  padding: 12px 22px;
  border-radius: 10px;
  font-size: 15px;
  transition: transform 0.2s, box-shadow 0.2s, opacity 0.2s;
}

.btn-main-cta:hover {
  opacity: 0.95;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(29, 78, 216, 0.3);
}

/* ==========================================================================
   8. LINKS DE NAVEGAÇÃO INTERNA & BREADCRUMB
   ========================================================================== */
.breadcrumb {
  max-width: 760px;
  margin: 20px auto 0;
  padding: 0 16px;
  font-size: 13px;
  color: var(--muted);
}
.breadcrumb a {
  color: var(--primary);
  text-decoration: none;
  font-weight: bold;
}

.nav-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 20px;
}
.nav-links a {
  text-decoration: none;
  background: rgba(29, 78, 216, 0.06);
  color: var(--primary);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: bold;
  transition: transform 0.2s, background-color 0.2s;
}
.nav-links a:hover {
  transform: translateY(-2px);
  background: rgba(29, 78, 216, 0.12);
}

/* ==========================================================================
   9. TABELAS DE COMPARAÇÃO DO CONTEÚDO
   ========================================================================== */
.table-wrap {
  overflow-x: auto;
  margin: 24px 0;
  border-radius: 14px;
  border: 1px solid var(--border);
}

.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  overflow: hidden;
}

.table th, .table td {
  padding: 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

.table th {
  background: var(--primary);
  color: #ffffff;
  font-weight: 600;
}

.destaque-table {
  font-weight: bold;
  color: var(--primary);
}

/* LISTAS DE VANTAGENS */
.post-body ul { list-style-type: none; padding-left: 0; }
.post-body ul li { position: relative; padding-left: 1.5rem; margin-bottom: 0.6rem; }
.post-body ul li::before { content: "✓"; position: absolute; left: 0; color: #10b981; font-weight: bold; }
.post-body .list-vantage li::before { content: "💡"; }

/* BOXES DE ALERTA */
.info-box { background: rgba(29, 78, 216, 0.08); border: 1px solid rgba(29, 78, 216, 0.14); border-radius: 12px; padding: 18px; margin-top: 20px; }
.alert-box { background: rgba(255, 193, 7, 0.10); border-left: 4px solid #f59e0b; border-radius: 10px; padding: 16px; margin-top: 20px; }

/* LEGADO SUPOSTAMENTE USADO EM OUTRAS PÁGINAS */
.search-section { width: 100%; margin-top: 20px; }
.search-card { display: flex; gap: 1rem; text-decoration: none; background: var(--card); border: 1px solid var(--border); border-radius: 16px; overflow: hidden; transition: transform 0.2s ease, border-color 0.2s ease; margin-bottom: 16px; }
.search-card:hover { transform: translateY(-2px); border-color: var(--primary); }
.search-card img { width: 140px; height: 100%; object-fit: cover; }
.search-card-content { padding: 1rem; }
.search-category { display: inline-block; margin-bottom: 0.6rem; font-size: 0.8rem; opacity: 0.7; }
.search-card h3 { margin-bottom: 0.6rem; font-size: 1rem; color: var(--text); }
.search-card p { font-size: 0.92rem; line-height: 1.5; opacity: 0.8; color: var(--muted); }
.search-empty { padding: 1rem; border-radius: 14px; border: 1px solid var(--border); background: var(--card); text-align: center; color: var(--muted); }

/* SISTEMA DOCK COMPLETO E ANÚNCIOS (ANTI-CLS / ADSENSE READY) */

.dashboard-chart-wrapper {
  position: relative;
  width: 100%;
  max-width: 900px;
  margin: 0 auto 2rem auto;
  aspect-ratio: 16 / 10;
  min-height: 360px;
  background-color: var(--bg-card-skeleton, #f8fafc);
  border-radius: 8px;
}

.dashboard-chart-wrapper canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* SLOT DE ANÚNCIOS (NEUTRO, SEM PLACEHOLDER VISUAL) */
.ads-container {
  display: block;
  width: 100%;
  margin: 1.5rem 0;
  overflow: hidden;
  position: relative;
}

/* SLOT DE ANÚNCIOS (ADSENSE READY - SEM ESPAÇO VISÍVEL) */

.ads-horizontal,
.ads-rectangle {
  width: 100%;
  min-height: 0;
  display: block;
}

/* ==========================================================================
   10. COMPONENTE: FOOTER (RODAPÉ)
   ========================================================================== */
.global-footer {
  margin-top: auto; 
  background-color: var(--card);
  color: var(--text);
  border-top: 1px solid var(--border);
  transition: background-color 0.3s ease, border-color 0.3s ease;
}

.footer-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 24px 32px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 32px;
}

.footer-brand { flex: 1 1 280px; max-width: 360px; }
.footer-brand h3 { margin-top: 0; margin-bottom: 12px; color: var(--primary); font-size: 20px; }
.footer-brand p { font-size: 14px; line-height: 1.7; color: var(--muted); }
.footer-links { display: flex; flex-direction: column; min-width: 140px; flex: 1 1 140px; }
.footer-links h4 { margin-top: 0; margin-bottom: 16px; color: var(--text); font-size: 15px; }
.footer-links a { width: fit-content; margin-bottom: 12px; font-size: 14px; color: var(--muted); text-decoration: none; transition: color 0.2s ease, transform 0.2s ease; }
.footer-links a:hover { color: var(--primary); transform: translateX(3px); }
.footer-bottom { border-top: 1px solid var(--border); padding: 24px 16px; text-align: center; font-size: 14px; color: var(--muted); }

/* BACK TO TOP */
.back-to-top {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--primary);
  color: #ffffff;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px);
  transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s ease, background-color 0.2s ease;
  z-index: 999;
}

.back-to-top.show { opacity: 1; visibility: visible; transform: translateY(0); }
.back-to-top:hover { transform: translateY(-3px); box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15); }

/* BANNER DE COOKIES (LGPD) */
.cookie-consent-banner { position: fixed; bottom: -100px; left: 0; width: 100%; background-color: var(--card); border-top: 1px solid var(--border); box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.05); z-index: 9999; padding: 16px; transition: bottom 0.4s ease-in-out; }
.cookie-consent-banner.show { bottom: 0; }
.cookie-container { max-width: 1100px; margin: 0 auto; display: flex; flex-direction: column; gap: 16px; align-items: center; }
.cookie-text { font-size: 14px; line-height: 1.5; color: var(--foreground); text-align: center; margin: 0; }
.cookie-text a { color: var(--primary); text-decoration: underline; font-weight: 500; }
.cookie-buttons { display: flex; gap: 12px; width: 100%; justify-content: center; }
.btn-cookie-accept { background-color: var(--primary); color: #ffffff; border: none; padding: 10px 20px; font-size: 14px; font-weight: bold; border-radius: var(--radius); cursor: pointer; transition: opacity 0.2s ease; }
.btn-cookie-accept:hover { opacity: 0.9; }

/* ==========================================================================
   11. RESPONSIVIDADE E ACERTOS DE LAYOUT MOBILE
   ========================================================================== */
@media (max-width: 768px) {
  .footer-container { gap: 40px 20px; }
  .cookie-container { flex-direction: column; }
}

@media (max-width: 640px) {
  .search-card { flex-direction: column; }
  .search-card img { width: 100%; height: 180px; }
}

@media (max-width: 600px) {
  .logo-desktop { display: none; }
  .logo-mobile { display: block; }
  .header-wrap { flex-direction: column; justify-content: center; }
  .header-actions { flex-wrap: wrap; justify-content: center; width: 100%; }
  .hero-section { padding: 40px 0 30px; }
  .hero-section h1 { font-size: 32px; }
  .hero-section p { font-size: 16px; }
  .btn { width: 100%; min-width: unset; }
  .footer-container { flex-direction: column; gap: 30px; }
  .footer-links a:hover { transform: none; }
  
  /* QUEBRA DO BLOCO DE AFILIADOS EM UMA COLUNA NO CELULAR */
  .product-box {
    grid-template-columns: 1fr;
    text-align: center;
    justify-items: center;
    padding: 16px;
  }
  .product-image-wrap {
    width: 140px;
    height: 140px;
  }
  .cta-container {
    justify-content: center;
    width: 100%;
  }
  .btn-main-cta {
    width: 100%;
  }

  .back-to-top {
    right: 18px;
    bottom: 18px;
    width: 48px;
    height: 48px;
    font-size: 20px;
  }
}

@media (min-width: 768px) {
  .cookie-container { flex-direction: row; justify-content: space-between; gap: 24px; padding: 0 16px; }
  .cookie-text { text-align: left; }
  .cookie-buttons { width: auto; }

  /* ==========================================================================
   LEGACY POSTS NORMALIZATION
   Corrige posts antigos automaticamente
   ========================================================================== */

/* Impede estouro horizontal */
html,
body {
  overflow-x: hidden;
}

/* Imagens nunca ultrapassam o container */
img,
video,
iframe,
table {
  max-width: 100%;
}

/* Segurança para imagens antigas */
img {
  height: auto;
  display: block;
}

/* Containers antigos */
main,
article,
section {
  width: 100%;
}

/* Tabelas antigas */
table {
  width: 100%;
  display: block;
  overflow-x: auto;
}

/* Cards antigos */
.card,
.product-box,
.home-card,
.related-card {
  overflow: hidden;
}

/* Botões antigos */
.btn,
.btn-main-cta,
a[class*="btn"] {
  max-width: 100%;
  word-break: break-word;
}

/* Textos antigos */
p,
li,
h1,
h2,
h3,
h4,
h5,
h6,
a,
span {
  word-break: break-word;
}

/* Afiliados antigos */
.product-box img {
  max-width: 100% !important;
  object-fit: contain !important;
}

/* Segurança geral */
* {
  min-width: 0;
}

/* Iframes antigos */
iframe {
  border: 0;
}

/* Ads antigos */
.ads-container {
  overflow: hidden;
}

/* Busca antiga */
.search-card {
  overflow: hidden;
}

/* Evita elementos maiores que viewport */
.post-body > * {
  max-width: 100%;
}
}