/* ===== TOOL PAGE STYLES ===== */

.tool-page {
  min-height: 100vh;
  padding-top: 64px;
}

/* ===== TOOL HERO ===== */
.tool-hero {
  padding: 50px 5% 36px;
  border-bottom: 1px solid var(--border);
  max-width: 1200px;
  margin: 0 auto;
}

.tool-hero .breadcrumb {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--text3);
  margin-bottom: 18px;
}

.tool-hero .breadcrumb a {
  color: var(--text3);
  text-decoration: none;
  transition: color var(--transition);
  pointer-events: all !important;
}

.tool-hero .breadcrumb a:hover { color: var(--accent); }

.tool-hero h1 {
  font-family: var(--font-head);
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  font-weight: 800;
  margin-bottom: 10px;
}

.tool-hero p {
  color: var(--text2);
  font-size: 0.95rem;
  max-width: 560px;
  line-height: 1.7;
}

/* ===== TOOL LAYOUT: SIDEBAR + MAIN ===== */
.tool-layout {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 28px;
  max-width: 1200px;
  margin: 32px auto;
  padding: 0 5%;
  align-items: start;
  position: relative;
  z-index: 1; /* always below navbar z-index 99999 */
}

/* Left column: calculator + info */
.tool-main {
  position: relative;
  z-index: 1;
}

/* Right column: ads sidebar */
.tool-sidebar {
  position: sticky;
  top: 80px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  z-index: 1; /* below navbar, never on top of it */
}

/* ===== ADSENSE SLOTS — SAFE PLACEMENT ===== */

/* Sidebar ad — desktop only, stays in column, never overlaps navbar */
.ad-sidebar {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 250px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 1; /* well below navbar */
  isolation: isolate; /* prevent auto ads from interfering */
}

.ad-sidebar ins {
  display: block;
  width: 300px;
  height: 250px;
  max-width: 100%;
}

/* Banner below calculator — between sections only */
.ad-banner-mid {
  width: 100%;
  margin: 24px 0;
  text-align: center;
  overflow: hidden;
  position: relative;
  z-index: 1;
  clear: both;
  isolation: isolate; /* prevent auto ads from interfering */
}

.ad-banner-mid ins {
  display: block;
  max-width: 100%;
}

/* 
  Mobile sticky bottom ad — 
  z-index 900 so it's BELOW navbar (99999) always
  but above normal content
*/
.ad-mobile-bottom {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 900; /* intentionally below navbar z-index 99999 */
  background: var(--bg2);
  border-top: 1px solid var(--border);
  padding: 6px;
  text-align: center;
  pointer-events: all;
  isolation: isolate; /* prevent auto ads from interfering */
}

.ad-mobile-bottom ins {
  display: block;
  margin: 0 auto;
  max-width: 100%;
}

/* Top banner on tool page (below hero) */
.ad-tool-top {
  max-width: 1200px;
  margin: 24px auto 0;
  padding: 0 5%;
  text-align: center;
  position: relative;
  z-index: 1;
  clear: both;
  isolation: isolate; /* prevent auto ads from interfering */
}

.ad-tool-top ins {
  display: block;
  max-width: 100%;
}

/* ===== CALCULATOR CONTAINER ===== */
.calc-wrapper {
  margin-bottom: 24px;
  position: relative;
  z-index: 1;
  isolation: isolate; /* prevent ads injecting inside */
}

.calc-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  position: relative;
  isolation: isolate; /* ads cannot inject inside calc card */
}

.calc-card-header {
  padding: 20px 26px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
  z-index: 1;
}

.calc-card-icon { font-size: 22px; }

.calc-card-title {
  font-family: var(--font-head);
  font-size: 1rem;
  font-weight: 700;
}

.calc-body {
  padding: 26px;
  position: relative;
  z-index: 1;
}

/* ===== FORM FIELDS ===== */
.field-group { margin-bottom: 20px; }

.field-group label {
  display: block;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text2);
  margin-bottom: 8px;
  letter-spacing: 0.03em;
}

.field-row { position: relative; }

.field-prefix, .field-suffix {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text3);
  font-size: 0.9rem;
  pointer-events: none;
}

.field-prefix { left: 14px; }
.field-suffix { right: 14px; }

.field-row input,
.field-row select,
.field-row textarea {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 13px 16px;
  font-family: var(--font-body);
  font-size: 1rem;
  color: var(--text);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  z-index: 1;
  pointer-events: all !important;
}

.field-row textarea {
  resize: vertical;
  min-height: 80px;
}

.field-row.has-prefix input { padding-left: 32px; }
.field-row.has-suffix input { padding-right: 36px; }

.field-row input:focus,
.field-row select:focus,
.field-row textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

/* Select arrow */
.field-row select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%238B90A0' d='M1 1l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
}

/* Tip / option buttons */
.tip-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.tip-btn {
  flex: 1;
  min-width: 56px;
  padding: 10px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text2);
  font-family: var(--font-body);
  font-size: 0.88rem;
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
  position: relative;
  z-index: 1;
  pointer-events: all !important;
}

.tip-btn:hover,
.tip-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ===== CALCULATE BUTTON ===== */
.calc-btn {
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 15px;
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  margin-top: 8px;
  letter-spacing: 0.03em;
  position: relative;
  z-index: 2;
  pointer-events: all !important;
}

.calc-btn:hover {
  background: var(--accent-dark);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0,200,150,0.3);
}

/* ===== RESULTS ===== */
.result-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 20px 22px;
  margin-top: 20px;
  display: none;
  animation: fadeInUp 0.3s ease both;
  position: relative;
  z-index: 1;
  isolation: isolate;
}

.result-card.show { display: block; }

.result-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}

.result-row:last-child { border-bottom: none; padding-bottom: 0; }

.result-label {
  font-size: 0.85rem;
  color: var(--text2);
}

.result-value {
  font-family: var(--font-head);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.result-row.highlight .result-value {
  font-size: 1.4rem;
  color: var(--accent);
}

.result-row.highlight .result-label {
  font-weight: 600;
  color: var(--text);
}

/* ===== INFO SECTION ===== */
.tool-info {
  margin-top: 48px;
  padding-top: 32px;
  border-top: 1px solid var(--border);
}

.tool-info h2 {
  font-family: var(--font-head);
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 10px;
  margin-top: 28px;
}

.tool-info h2:first-child { margin-top: 0; }

.tool-info p {
  color: var(--text2);
  font-size: 0.88rem;
  line-height: 1.8;
  margin-bottom: 10px;
}

.tool-info ul {
  color: var(--text2);
  font-size: 0.88rem;
  line-height: 1.8;
  padding-left: 20px;
  margin-bottom: 10px;
}

/* ===== RELATED TOOLS ===== */
.related-tools {
  margin-top: 0;
}

.related-tools h3 {
  font-family: var(--font-head);
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.72rem;
}

.related-tools-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.related-tool-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text);
  transition: all var(--transition);
  font-size: 0.85rem;
  pointer-events: all !important;
  position: relative;
  z-index: 1;
}

.related-tool-card:hover {
  border-color: rgba(0,200,150,0.3);
  background: var(--accent-glow);
  color: var(--accent);
}

.related-tool-card .r-icon { font-size: 18px; }

/* ===== SITE MAP SIDEBAR ===== */
.site-map-sidebar {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-top: 20px;
  max-height: 400px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--accent) var(--card-bg);
}

.site-map-sidebar::-webkit-scrollbar {
  width: 6px;
}

.site-map-sidebar::-webkit-scrollbar-track {
  background: var(--card-bg);
}

.site-map-sidebar::-webkit-scrollbar-thumb {
  background: var(--accent);
  border-radius: 3px;
}

.site-map-sidebar h3 {
  font-family: var(--font-head);
  font-weight: 700;
  margin-bottom: 10px;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.7rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
  position: sticky;
  top: 0;
  background: var(--card-bg);
  z-index: 10;
}

.site-map-section {
  margin-bottom: 12px;
}

.site-map-section:last-child {
  margin-bottom: 0;
}

.site-map-section h4 {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 6px;
  cursor: pointer;
  user-select: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.site-map-section h4::after {
  content: '▼';
  font-size: 0.6rem;
  transition: transform 0.2s;
}

.site-map-section.collapsed h4::after {
  transform: rotate(-90deg);
}

.site-map-section.collapsed .site-map-links {
  display: none;
}

.site-map-links {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.site-map-links a {
  font-size: 0.75rem;
  color: var(--text2);
  text-decoration: none;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  pointer-events: all !important;
  position: relative;
  z-index: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.site-map-links a:hover {
  background: var(--accent-glow);
  color: var(--accent);
  padding-left: 12px;
}

/* ===== TOOL PAGE FOOTER ===== */
.tool-footer {
  background: var(--bg2);
  border-top: 1px solid var(--border);
  padding: 30px 5%;
  margin-top: 40px;
  position: relative;
  z-index: 2;
}

.tool-footer-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.tool-footer a {
  color: var(--text3);
  font-size: 0.82rem;
  text-decoration: none;
  transition: color var(--transition);
  pointer-events: all !important;
}

.tool-footer a:hover { color: var(--accent); }

.tool-footer .tfoot-logo {
  font-family: var(--font-head);
  font-size: 1rem;
  font-weight: 800;
  color: var(--text);
}

.tool-footer .tfoot-logo span { color: var(--accent); }

.tfoot-links {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.tool-footer-copy {
  width: 100%;
  text-align: center;
  color: var(--text3);
  font-size: 0.78rem;
  margin-top: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}

.tool-footer-copy a {
  color: var(--accent);
  text-decoration: none;
  pointer-events: all !important;
}

/* ===== SCIENTIFIC CALCULATOR ===== */
.sci-display {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 18px 16px;
  text-align: right;
  margin-bottom: 16px;
}

.sci-expr {
  font-size: 0.8rem;
  color: var(--text3);
  min-height: 20px;
  word-break: break-all;
}

.sci-val {
  font-family: var(--font-head);
  font-size: 2rem;
  font-weight: 700;
  color: var(--text);
  word-break: break-all;
}

.sci-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 6px;
}

.sci-btn {
  padding: 12px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text2);
  font-family: var(--font-body);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
  position: relative;
  z-index: 1;
  pointer-events: all !important;
}

.sci-btn:hover { background: var(--bg2); color: var(--text); }
.sci-btn.op { background: var(--bg2); color: var(--accent); }
.sci-btn.fn { color: var(--text); font-size: 0.75rem; }
.sci-btn.eq { background: var(--accent); color: #fff; border-color: var(--accent); }
.sci-btn.eq:hover { background: var(--accent-dark); }
.sci-btn.clr { background: rgba(255,80,80,0.15); color: #ff5050; border-color: rgba(255,80,80,0.2); }

/* ===== MATRIX CALCULATOR ===== */
.matrix-inputs {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.matrix-box {
  flex: 1;
  min-width: 140px;
}

.matrix-box h4 {
  font-size: 0.8rem;
  color: var(--text3);
  margin-bottom: 8px;
  font-weight: 600;
}

.matrix-grid {
  display: grid;
  gap: 4px;
}

.matrix-cell {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  font-size: 0.85rem;
  color: var(--text);
  outline: none;
  text-align: center;
  font-family: var(--font-body);
  pointer-events: all !important;
}

.matrix-cell:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.matrix-result-grid {
  display: grid;
  gap: 4px;
  margin-top: 12px;
}

.matrix-result-cell {
  background: var(--accent-glow);
  border: 1px solid rgba(0,200,150,0.2);
  border-radius: 6px;
  padding: 8px;
  font-family: var(--font-head);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent);
  text-align: center;
}

/* ===== AMORTIZATION TABLE ===== */
.amort-table-wrap {
  overflow-x: auto;
  margin-top: 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.amort-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.amort-table th {
  background: var(--bg3);
  color: var(--text2);
  font-weight: 600;
  padding: 10px 12px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.amort-table th:first-child { text-align: left; }

.amort-table td {
  padding: 9px 12px;
  text-align: right;
  border-bottom: 1px solid var(--border);
  color: var(--text2);
}

.amort-table td:first-child { text-align: left; color: var(--text3); }
.amort-table tr:last-child td { border-bottom: none; }
.amort-table tr:hover td { background: var(--bg3); }

/* ===== RESPONSIVE TOOL PAGE ===== */
@media (max-width: 900px) {
  .tool-layout {
    grid-template-columns: 1fr;
    gap: 24px;
  }

  .tool-sidebar {
    position: static;
  }

  .site-map-sidebar {
    max-height: 300px;
  }

  /* Hide desktop sidebar ad on mobile */
  .ad-sidebar {
    display: none;
  }

  /* Show mobile sticky bottom ad */
  .ad-mobile-bottom {
    display: block;
    /* Add bottom padding to page so content isn't hidden behind sticky ad */
  }

  /* Push footer above mobile sticky ad */
  .tool-footer {
    margin-bottom: 70px;
  }

  /* Ensure mid banner is full width and responsive */
  .ad-banner-mid {
    margin: 16px 0;
  }

  .ad-banner-mid ins {
    width: 100% !important;
    max-width: 100% !important;
  }

  /* Ensure tool page content has proper spacing */
  .tool-main {
    min-height: 400px; /* Ensure space for auto ads */
  }
}

@media (max-width: 600px) {
  .calc-body { padding: 18px; }
  .tip-btn { min-width: 48px; font-size: 0.82rem; }
  .sci-grid { grid-template-columns: repeat(4, 1fr); }
  .tool-hero { padding: 40px 5% 28px; }

  .site-map-sidebar {
    max-height: 250px;
    padding: 12px;
  }

  .site-map-sidebar h3 {
    font-size: 0.65rem;
  }

  .site-map-section h4 {
    font-size: 0.7rem;
  }

  .site-map-links a {
    font-size: 0.7rem;
    padding: 3px 6px;
  }

  /* On small screens, ad-tool-top should be compact */
  .ad-tool-top {
    padding: 0 3%;
    margin-top: 16px;
  }

  /* Ensure calculator is always clickable and visible */
  .calc-wrapper {
    position: relative;
    z-index: 10;
  }

  .calc-card {
    position: relative;
    z-index: 10;
  }

  /* Add space at bottom for mobile sticky ad */
  .tool-page {
    padding-bottom: 80px;
  }
}