/* ==========================================================================
   1. CSS VARIABLES FOR THEMING
   ========================================================================== */
:root {
  --bg: #f7f9fc;
  --text: #333;
  --card-bg: white;
  --header-bg: #16325b;
  --header-text: white;
  --border: #ccc;
  --accent: #1a3a6e;
  --link: #3498db;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  --ad-bg: #eee;
  --ad-border: #ccc;
  --footer-bg: #1a3a6e;
}

[data-theme="dark"] {
  --bg: #121212;
  --text: #e0e0e0;
  --card-bg: #1e1e1e;
  --header-bg: #1a2733;
  --header-text: #fff;
  --border: #444;
  --accent: #3a6ea5;
  --link: #5ca0d3;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
  --ad-bg: #2a2a2a;
  --ad-border: #555;
  --footer-bg: #1a2733;
}
/* END: CSS VARIABLES */


/* ==========================================================================
   2. RESET & GLOBALS
   ========================================================================== */
* {
  box-sizing: border-box;
  transition: background-color 0.3s ease, color 0.3s ease;
}

body, html {
  margin: 0;
  padding: 0;
  font-family: 'Segoe UI', sans-serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
}
/* END: RESET & GLOBALS */


/* ==========================================================================
   3. LAYOUT
   ========================================================================== */
.container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
/* END: LAYOUT */


/* ==========================================================================
   4. HEADER & NAVIGATION
   ========================================================================== */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--header-bg);
  color: var(--header-text);
  padding: 0.8rem 2rem;
  gap: 1rem;
}

header .logo {
  font-size: 1.5rem;
  font-weight: bold;
}

header .logo img {
  height: 40px;
  vertical-align: middle;
}

nav ul {
  list-style: none;
  display: flex;
  margin: 0;
  padding-right: 50px;
  gap: 1.5rem;
}

nav a {
  color: var(--header-text);
  text-decoration: none;
  font-size: 1rem;
}

nav a:hover {
  text-decoration: underline;
}

/* Dark Mode Toggle */
.theme-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  margin-left: auto;
}

.theme-toggle button {
  background: none;
  border: 1px solid var(--border);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  cursor: pointer;
  color: var(--header-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
}

.theme-toggle button:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* Header Ad */
.header-ad {
  flex-grow: 1;
  text-align: right;
}

.ad-banner {
  width: 100%;
  max-width: 100vw;
  height: 90px;
  background: inherit;
  border: 0px dashed var(--ad-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  color: #666;
}

/* Mobile Menu Toggle */
.menu-toggle {
  display: none;
  background: none;
  border: 1px solid var(--border);
  width: 40px;
  height: 40px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1.4rem;
  color: var(--header-text);
  justify-content: center;
  align-items: center;
}

/* Mobile Menu */
.mobile-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--header-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  z-index: 1000;
}

.mobile-menu.active {
  display: block;
}

.mobile-menu ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
}

.mobile-menu li {
  border-bottom: 1px solid var(--border);
  width: 100%;
}

.mobile-menu a {
  display: block;
  color: var(--header-text);
  padding: 14px 16px;
  text-decoration: none;
  font-size: 1rem;
  transition: background 0.2s;
}

.mobile-menu a:hover {
  background: rgba(255, 255, 255, 0.1);
}

.mobile-menu {
  max-height: 70vh;
  overflow-y: auto;
}

.mobile-theme-toggle {
  border-top: 1px solid var(--border);
  padding: 8px 0;
  text-align: center;
}

/* Desktop-only wrapper */
.desktop-only {
  display: flex;
}

/* END: HEADER & NAVIGATION */


/* ==========================================================================
   4.1 HEADER & MOBILE RESPONSIVE
   ========================================================================== */
@media (max-width: 768px) {
  /* Ensure header sticks to top */
  header {
    position: sticky;
    top: 0;
    z-index: 1000;
    padding: 0.7rem 1rem;
    flex-wrap: nowrap;
    gap: 0.5rem;
    background: var(--header-bg);
    margin: 0;
  }

  .logo {
    max-width: 160px;
    font-size: 1.3rem;
  }

  /* Hide desktop nav and ad */
  .desktop-nav,
  .header-ad,
  .desktop-only {
    display: none;
  }

  /* Show hamburger */
  .menu-toggle {
    display: flex;
  }

  /* Mobile theme toggle */
  #themeToggleMobile {
    width: 36px;
    height: 36px;
    font-size: 1.1rem;
  }

  #themeIconMobile {
    margin: 0;
  }

  /* Prevent layout shift on other pages */
  body, html, .container, main {
    margin-top: 0;
    padding-top: 0;
  }
}
/* END: HEADER & MOBILE RESPONSIVE */


/* ==========================================================================
   5. PAGE LAYOUTS (Calculator & Content)
   ========================================================================== */
/* Calculator Page */
main.main-layout-calculator {
  display: grid;
  grid-template-columns: 280px 1fr 220px;
  grid-template-areas: "form results ads";
  gap: 2rem;
  padding: 2rem;
  min-height: 600px;
}

/* Content Pages (How To, About, etc.) */
main.main-layout-content {
  display: grid;
  grid-template-columns: 220px 1fr 220px;
  grid-template-areas: "ads-left results ads-right";
  gap: 1.5rem;
  padding: 2rem;
  min-height: 600px;
}

/* Tablet: 1024px and below */
@media (max-width: 1024px) {
  main {
    grid-template-columns: 260px 1fr;
    grid-template-areas:
      "form results"
      "ads results";
  }
}

/* Mobile: 768px and below */
@media (max-width: 768px) {
  main {
    grid-template-columns: 1fr;
    grid-template-areas:
      "form"
      "results";
    padding: 1rem;
    gap: 1.5rem;
  }

  .ads-section,
  .ads-section-left,
  .ads-section-right,
  .header-ad,
  .optional-ad,
  .ad-below-results,
  .mobile-ad,
  .footer-ad {
    display: none !important;
  }/* ==========================================================================
   13. MOBILE: HIDE ALL ADS COMPLETELY
   ========================================================================== */
@media (max-width: 768px) {
  /* Hide all ad sections */
  .ads-section,
  .ads-section-left,
  .ads-section-right,
  .header-ad,
  .optional-ad,
  .ad-below-results,
  .footer-ad,
  .ad-vertical,
  .ad-full,
  .ad-mobile-unit,
  .mobile-ad {
    display: none !important;
    height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    overflow: hidden;
  }

  /* Ensure no layout impact */
  .ads-section,
  .ads-section-left,
  .ads-section-right {
    visibility: hidden;
    position: static;
    float: none;
  }
}

  .mobile-ad {
    display: block;
    padding: 1rem;
    text-align: center;
  }
}
/* END: PAGE LAYOUTS */


/* ==========================================================================
   6. GRID AREAS & COMPONENTS
   ========================================================================== */
/* Assign Grid Areas */
.form-section {
  grid-area: form;
  width: 280px;
  min-width: 280px;
}

.results-section {
  grid-area: results;
  padding: inherit;
}

.ads-section,
.ads-section-left,
.ads-section-right {
  grid-area: ads;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* Ad Styling */
.ad-vertical {
  width: 160px;
  height: 600px;
  background: inherit;
  border: 0px dashed var(--ad-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  margin: 0 auto;
}

.ad-full {
  width: 100%;
  max-width: 1200px;
  height: 90px;
  background: var(--ad-bg);
  border: 0px dashed var(--ad-border);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
}

.ad-mobile-unit {
  width: 100%;
  max-width: 320px;
  height: 100px;
  background: var(--ad-bg);
  border: 0px dashed var(--ad-border);
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
}

.ad-below-results,
.optional-ad {
  padding: 1rem 2rem;
  text-align: center;
}
/* END: GRID AREAS & COMPONENTS */


/* ==========================================================================
   7. FORM STYLES
   ========================================================================== */
.form-section {
  background: var(--card-bg);
  padding: 1rem;
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-size: 0.95rem;
}

.form-section h2 {
  margin-top: 0.5rem;
  margin-bottom: 1rem;
  font-size: 1.25rem;
  color: var(--accent);
}

.form-group {
  margin-bottom: 0.6rem;
}

#contactForm .form-group textarea {
  width: 100% !important;
  min-height: 120px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.95rem;
  box-sizing: border-box;
  resize: vertical;
}

label {
  display: block;
  margin-bottom: 0.3rem;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
}

input, select {
  width: 100%;
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.95rem;
  box-sizing: border-box;
}

input::placeholder, select {
  color: #888;
}

button {
  background: var(--accent);
  color: white;
  border: none;
  padding: 10px 20px;
  font-size: 1rem;
  border-radius: 5px;
  cursor: pointer;
  width: 100%;
  margin-top: 0.6rem;
  font-weight: 500;
}

button:hover {
  background: #2c5aa0;
}
/* END: FORM STYLES */


/* ==========================================================================
   8. RESULTS SECTION
   ========================================================================== */
.results-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin: 0;
  padding: 0;
}

@media (max-width: 768px) {
  .results-grid {
    grid-template-columns: 1fr;
  }
}
/*temp*/
@media (max-width: 768px) {
  /* Ensure results-grid stretches full width of its parent */
  .results-grid {
    width: 100% !important;
    max-width: none;
    padding: 0;
    margin: 0;
    box-sizing: border-box;
  }

  /* Ensure each result-box also stretches */
  .result-box {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 1rem;
    box-sizing: border-box;
  }

  /* Table inside should also stretch */
  .result-box table {
    width: 100%;
    margin: 0;
    padding: 0;
  }
}
.results-grid { width: 100%; }
/* end temp */

.result-box {
  background: var(--card-bg);
  padding: 1rem;
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.result-box h3 {
  margin-top: 0;
  color: var(--accent);
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  padding: 6px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  background: #f1f3f5;
}

[data-theme="dark"] th {
  background: #2d2d2a;
}
/* END: RESULTS SECTION */


/* ==========================================================================
   9. FOOTER
   ========================================================================== */
footer {
  background: var(--footer-bg);
  color: var(--header-text);
  padding: 2rem;
  text-align: center;
}

.footer-content {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.footer-links a {
  color: #ddd;
  margin: 0 0.8rem;
  text-decoration: none;
}

.footer-links a:hover {
  text-decoration: underline;
}

.footer-info {
  font-size: 0.9rem;
  color: #bbb;
}

.footer-ad {
  display: inline-block;
  width: 320px;
  height: 50px;
  background: inherit;
  border-radius: 4px;
  margin-left: 1rem;
}
/* END: FOOTER */


/* ==========================================================================
   10. INTERACTIVE COMPONENTS (Tooltips, Calculator Panel)
   ========================================================================== */
/* Tooltip */
.tooltip-container,
.tooltip-wrapper,
.calc-wrapper {
  position: relative;
  display: inline-block;
}

.tooltip-trigger,
.calc-trigger {
  cursor: help;
  margin-left: 0.3rem;
  font-size: 0.9em;
  color: #3498db;
  background: none;
  border: none;
  padding: 0;
}

.tooltip-trigger:focus,
.calc-trigger:focus {
  outline: none;
  box-shadow: 0 0 0 2px #3498db;
}

.tooltip-content {
  position: absolute;
  left: 100%;
  top: 50%;
  transform: translateY(-50%);
  background: #1a3a6e;
  color: white;
  padding: 14px 18px;
  border-radius: 8px;
  font-size: 0.85rem;
  min-width: 320px;
  max-width: 360px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
  line-height: 1.6;
  pointer-events: none;
  white-space: normal;
  word-wrap: break-word;
}

.tooltip-container:hover .tooltip-content,
.tooltip-content:hover {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.tooltip-content a {
  color: #6fc3ff;
  text-decoration: underline;
  transition: color 0.2s ease;
}

.tooltip-content a:hover {
  color: #a5dbff;
  text-shadow: 0 0 2px rgba(111, 195, 255, 0.4);
}

.tooltip-content a:visited {
  color: #8ca5e0;
}

.tooltip-content a:visited:hover {
  color: #b8c8f0;
}

.tooltip-content a:focus {
  outline: 2px solid #6fc3ff;
  outline-offset: 2px;
}

/* Mobile: Center tooltip */
@media (max-width: 768px) {
  .tooltip-content {
    position: fixed; /* Relative to viewport */
    left: 40%;
    top: 43%;
    transform: translateX(-40%) translateY(-30%);
    /* Optional: nudge it up a bit so it doesn’t cover trigger */
    /* top: 40%; */
    /* transform: translateX(-50%) translateY(-60%); */
    max-width: 90vw; /* Responsive width */
    /* min-width: auto; */
    padding: 16px;
    z-index: 1001; /* Ensure it's above everything */
  }

  /* Optional: Add backdrop or prevent body scroll when tooltip open */
  .tooltip-container:hover .tooltip-content,
  .tooltip-content:hover {
    pointer-events: auto;
  }
}

/* Solar Calculator Panel */
.solar-calc-panel {
  position: absolute;
  left: 100%;
  top: 0;
  transform: translateY(0);
  width: 300px;
  max-width: 90vw;
  background: white;
  border: 1px solid #ddd;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s;
  font-size: 0.875rem;
  color: #333;
  overflow: hidden;
  margin-left: 12px;
}

.calc-wrapper:hover .solar-calc-panel,
.solar-calc-panel:hover {
  opacity: 1;
  visibility: visible;
}

.solar-calc-panel .solar-calc-header {
  background: #f1f3f5;
  padding: 10px 14px;
  border-bottom: 1px solid #e0e0e0;
  font-size: 0.95rem;
  font-weight: 600;
  color: #1a3a6e;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.solar-calc-panel .close-btn {
  cursor: pointer;
  font-size: 1.1rem;
  color: #999;
  width: 24px;
  text-align: center;
  line-height: 1;
}

.solar-calc-panel .close-btn:hover {
  color: #333;
}

.solar-calc-panel .solar-calc-body {
  padding: 16px;
  background: white;
}

.solar-calc-panel .solar-calc-body > div {
  margin-bottom: 12px;
}

.solar-calc-panel label {
  display: block;
  font-weight: 600;
  margin-bottom: 4px;
  font-size: 0.85rem;
  color: #333;
}

.solar-calc-panel input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  font-size: 0.9rem;
  background: #fdfdfd;
  color: #333;
}

.solar-calc-panel input:focus {
  border-color: #3498db;
  outline: none;
  box-shadow: 0 0 0 2px rgba(52, 152, 219, 0.2);
}

#fillCapacity {
  background: #1a3a6e;
  color: white;
  border: none;
  padding: 10px 14px;
  font-size: 0.95rem;
  border-radius: 4px;
  cursor: pointer;
  width: 100%;
  font-weight: 500;
}

#fillCapacity:hover {
  background: #2c5aa0;
}

@media (max-width: 768px) {
  .solar-calc-panel {
    left: 50%;
    top: 100%;
    transform: translateX(-50%);
    margin-left: 24px;
    margin-top: 8px;
  }
}
/* END: INTERACTIVE COMPONENTS */


/* ==========================================================================
   11. OTHER COMPONENTS
   ========================================================================== */
/* Loading Spinner */
.spinner {
  display: inline-block;
  width: 50px;
  height: 50px;
  border: 5px solid #f3f3f3;
  border-top: 5px solid var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 20px auto;
  font-size: 0.8rem;
  color: var(--text);
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Conservative Estimate Note */
.disclaimer-note {
  margin-top: 1rem;
  padding: 12px 16px;
  background: #f8f9fa;
  border-left: 4px solid #3498db;
  font-size: 0.85rem;
  color: #555;
  line-height: 1.5;
  border-radius: 0 4px 4px 0;
}

.disclaimer-note h4 {
  margin: 0 0 0.5rem 0;
  font-size: 0.95rem;
  color: #1a3a6e;
  font-weight: 600;
}

.disclaimer-note strong {
  color: #d35400;
}

/* Policy Content */
.policy-content {
  color: #666;
  font-family: 'Arial', 'Helvetica', sans-serif;
  font-size: 0.75rem;
  line-height: 1;
  padding: 1.5rem;
  padding-left: 3rem;
  padding-right: 3rem;
}

.policy-content h1,
.policy-content h2 {
  color: #666;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  font-size: 0.7rem;
  font-weight: 300;
  letter-spacing: -0.05em;
  word-spacing: -0.1em;
  margin-top: 1.5rem;
  margin-bottom: 0.5rem;
  line-height: 1.3;
}

.policy-content h1 { font-size: 1.4rem; }
.policy-content h2 { font-size: 1.2rem; }

.policy-content p,
.policy-content ul,
.policy-content ol {
  margin-bottom: 0.8rem;
}

.policy-content ul,
.policy-content ol {
  padding-left: 1.2rem;
}

.policy-content li {
  margin-bottom: 0.4rem;
}

/* Buttons */
.btn-primary {
  display: inline-block;
  background: var(--accent);
  color: white;
  padding: 10px 20px;
  border-radius: 5px;
  text-decoration: none;
  margin-top: 1rem;
}

.btn-primary:hover {
  background: #2c5aa0;
}

/* Export Button */
#exportCsv {
  background: #27ae60;
  color: white;
  border: none;
  padding: 10px 16px;
  font-size: 0.95rem;
  border-radius: 5px;
  cursor: pointer;
  margin-top: 1rem;
  width: 100%;
}

#exportCsv:hover:not([disabled]) {
  background: #2ecc71;
}

#exportCsv[disabled] {
  background: #95a5a6;
  cursor: not-allowed;
}
/* END: OTHER COMPONENTS */


/* ==========================================================================
   12. MOBILE FINAL FIXES (Order, Alignment, Overflow)
   ========================================================================== */
@media (max-width: 768px) {
  /* Layout */
  main.main-layout-calculator,
  main.main-layout-content {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    padding: 1rem;
    min-height: auto;
  }

  /* Form: Full-width, first */
  .form-section {
    order: 1;
    width: 100%;
    max-width: none;
    padding: 1rem;
    margin: 0;
  }

  /* Results: Second */
  .results-section {
    order: 2;
    width: 100%;
    padding: 0;
    margin: 0;
  }

  /* Results Grid */
  .results-grid {
    width: 100%;
    margin: 0;
    padding: 0;
    box-sizing: border-box;
  }
  /* Result Box */
  .result-box {
    width: 100%;
    max-width: 100%;
    padding: 1rem;
    margin: 0;
  }

  /* Table */
  .result-box table {
    width: 100%;
    margin: 0;
  }

  .result-box th,
  .result-box td {
    padding: 6px 8px;
    text-align: center;
  }

  /* Full-width responsive ads */
  .ad-banner,
  .ad-full,
  .ad-vertical,
  .ad-mobile-unit {
    max-width: 100%;
    width: 100%;
    height: auto;
    min-height: 60px;
    overflow: hidden;
  }

  /* Prevent horizontal scroll */
  body, html, .container, main, .form-section, .results-section {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  /* Responsive policy */
  .policy-content {
    font-size: 0.85rem;
    line-height: 1.35;
    padding: 1rem;
  }
  @media (max-width: 768px) {
  .form-section,
  .results-section {
    padding: 0;
    margin: 0;
    width: 100%;
  }

  .form-section,
  .result-box {
    padding: 1rem; /* ✅ All inner boxes now control their own padding */
  }
  }
  
  .policy-content h1 { font-size: 1.25rem; }
  .policy-content h2 { font-size: 1.1rem; }
}
/* END: MOBILE FINAL FIXES */

/* ==========================================================================
   MOBILE: FULLY COLLAPSE ADS TO PREVENT GAPS
   ========================================================================== */
@media (max-width: 768px) {
  .ads-section,
  .ads-section-left,
  .ads-section-right,
  .header-ad,
  .optional-ad,
  .ad-below-results,
  .footer-ad,
  .ad-vertical,
  .ad-full,
  .ad-mobile-unit {
    display: none !important;
    height: 0 !important;
    margin: 0 !important;
    padding: 0 !important;
    overflow: hidden;
  }
}