/* ============================================================
   All-in-One Calculators — Main Stylesheet
   Mobile-first, accessible, AdSense-friendly
   ============================================================ */

/* ── Reset & variables ─────────────────────────────────── */
:root {
  --primary:       #2563eb;
  --primary-dark:  #1d4ed8;
  --primary-light: #dbeafe;
  --accent:        #f59e0b;
  --success:       #16a34a;
  --error:         #dc2626;
  --text:          #1e293b;
  --text-muted:    #64748b;
  --border:        #e2e8f0;
  --bg:            #f8fafc;
  --bg-card:       #ffffff;
  --shadow-sm:     0 1px 3px rgba(0,0,0,.08);
  --shadow-md:     0 4px 16px rgba(0,0,0,.1);
  --radius:        10px;
  --radius-sm:     6px;
  --font:          'Segoe UI', system-ui, -apple-system, sans-serif;
  --font-mono:     'Fira Code', 'Cascadia Code', 'Courier New', monospace;
  --max-w:         1200px;
  --transition:    .2s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ── Typography ─────────────────────────────────────────── */
h1, h2, h3, h4, h5 { line-height: 1.25; font-weight: 700; }
h1 { font-size: clamp(1.6rem, 4vw, 2.25rem); margin-bottom: .75rem; }
h2 { font-size: clamp(1.25rem, 3vw, 1.75rem); margin-bottom: .6rem; }
h3 { font-size: 1.2rem; margin-bottom: .5rem; }
p  { margin-bottom: 1rem; }
a  { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; color: var(--primary-dark); }
code, pre { font-family: var(--font-mono); }
pre { white-space: pre-wrap; }

/* ── Layout ─────────────────────────────────────────────── */
.container { max-width: var(--max-w); margin: 0 auto; padding: 0 1rem; }
.main-content { flex: 1; padding: 1.5rem 0 3rem; }

.page-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
}
@media (min-width: 900px) {
  .page-grid { grid-template-columns: 1fr 300px; }
}

/* ── Header ─────────────────────────────────────────────── */
.site-header {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .75rem 1rem;
  max-width: var(--max-w);
  margin: 0 auto;
}
.site-logo {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--primary);
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
}
.site-logo span { color: var(--accent); }

/* Search bar in header */
.header-search {
  flex: 1;
  max-width: 480px;
  position: relative;
}
.header-search input {
  width: 100%;
  padding: .5rem 2.5rem .5rem .85rem;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  font-size: .9rem;
  background: var(--bg);
  transition: border-color var(--transition);
}
.header-search input:focus {
  outline: none;
  border-color: var(--primary);
  background: #fff;
}
.header-search-icon {
  position: absolute;
  right: .75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}
.search-suggestions {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  z-index: 200;
  max-height: 320px;
  overflow-y: auto;
  display: none;
}
.search-suggestions.active { display: block; }
.suggestion-item {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .6rem 1rem;
  cursor: pointer;
  font-size: .9rem;
  border-bottom: 1px solid var(--border);
}
.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:hover { background: var(--primary-light); }
.suggestion-cat { font-size: .75rem; color: var(--text-muted); margin-left: auto; }

/* ── Navigation ─────────────────────────────────────────── */
.site-nav { background: var(--primary); }
.site-nav ul {
  list-style: none;
  display: flex;
  gap: 0;
  max-width: var(--max-w);
  margin: 0 auto;
  overflow-x: auto;
  padding: 0 .5rem;
}
.site-nav a {
  display: block;
  padding: .55rem .85rem;
  color: rgba(255,255,255,.85);
  font-size: .875rem;
  font-weight: 500;
  white-space: nowrap;
  transition: color var(--transition), background var(--transition);
  border-radius: var(--radius-sm);
}
.site-nav a:hover, .site-nav a.active {
  color: #fff;
  background: rgba(255,255,255,.15);
  text-decoration: none;
}

/* ── Breadcrumb ─────────────────────────────────────────── */
.breadcrumb { margin: 1rem 0 .5rem; }
.breadcrumb ol { list-style: none; display: flex; flex-wrap: wrap; gap: .25rem; font-size: .85rem; }
.bc-item::after { content: '›'; margin-left: .25rem; color: var(--text-muted); }
.bc-item:last-child::after { display: none; }
.bc-item a { color: var(--primary); }
.bc-current { color: var(--text-muted); }

/* ── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card-body { padding: 1.25rem; }
.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: .5rem;
}
.card-header h2 { margin: 0; font-size: 1.1rem; }

/* ── Category grid on homepage ──────────────────────────── */
.cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
}
.cat-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .5rem;
  padding: 1.25rem 1rem;
  background: var(--bg-card);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  text-align: center;
  text-decoration: none;
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}
.cat-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  text-decoration: none;
  color: var(--primary);
}
.cat-icon { font-size: 2rem; line-height: 1; }
.cat-name { font-weight: 600; font-size: .95rem; }
.cat-count { font-size: .78rem; color: var(--text-muted); }

/* ── Calculator list ────────────────────────────────────── */
.calc-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: .85rem;
}
.calc-item {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  padding: .85rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.calc-item:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow-sm);
  text-decoration: none;
}
.calc-item-title { font-weight: 600; font-size: .9rem; margin-bottom: .2rem; }
.calc-item-desc  { font-size: .8rem; color: var(--text-muted); }
.calc-item-arrow { margin-left: auto; color: var(--text-muted); flex-shrink: 0; }

/* ── Calculator page ────────────────────────────────────── */
.calc-page-title { margin-bottom: .25rem; }
.calc-page-desc  { color: var(--text-muted); margin-bottom: 1.25rem; }

/* ── Form ───────────────────────────────────────────────── */
.calc-form { display: flex; flex-direction: column; gap: .85rem; }
.form-group { display: flex; flex-direction: column; gap: .35rem; }
.form-label { font-weight: 600; font-size: .9rem; }
.req { color: var(--error); }

.input-wrap { position: relative; display: flex; align-items: center; }
.form-control {
  width: 100%;
  padding: .55rem .75rem;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: var(--font);
  background: #fff;
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
.form-control.error { border-color: var(--error); }
.form-control:invalid:not(:placeholder-shown) { border-color: var(--error); }

.input-unit {
  position: absolute;
  right: .75rem;
  font-size: .85rem;
  color: var(--text-muted);
  pointer-events: none;
}
.form-control:has(+ .input-unit) { padding-right: 2.5rem; }

.form-help  { font-size: .8rem; color: var(--text-muted); }
.form-error { font-size: .8rem; color: var(--error); min-height: 1.1em; display: none; }
.form-error.visible { display: block; }

.form-actions { display: flex; gap: .75rem; flex-wrap: wrap; margin-top: .5rem; }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .6rem 1.4rem;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: .95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  text-decoration: none;
}
.btn:active { transform: scale(.97); }
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); color: #fff; }
.btn-ghost {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--border);
}
.btn-ghost:hover { background: var(--primary-light); }
.btn-lg { padding: .75rem 2rem; font-size: 1.05rem; }
.btn-sm { padding: .35rem .85rem; font-size: .82rem; }

/* ── Result block ───────────────────────────────────────── */
.result-block {
  background: linear-gradient(135deg, #f0f7ff 0%, #e8f0fe 100%);
  border: 1.5px solid #bfdbfe;
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-top: 1.5rem;
  animation: fadeSlide .3s ease;
}
@keyframes fadeSlide {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.result-primary {
  text-align: center;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid #bfdbfe;
  margin-bottom: 1.25rem;
}
.result-label { font-size: .9rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: .25rem; }
.result-value { font-size: clamp(2rem, 5vw, 3rem); font-weight: 800; color: var(--primary); line-height: 1.1; }
.result-unit  { font-size: .9rem; color: var(--text-muted); }

.result-secondary {
  display: grid;
  grid-template-columns: 1fr;
  gap: .5rem;
  margin-bottom: 1rem;
}
@media (min-width: 480px) {
  .result-secondary { grid-template-columns: 1fr 1fr; }
}
.result-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: .5rem;
  padding: .4rem .6rem;
  background: rgba(255,255,255,.6);
  border-radius: var(--radius-sm);
  font-size: .9rem;
}
.result-row-label { color: var(--text-muted); }
.result-row-value { font-weight: 600; }

.result-formula {
  background: rgba(255,255,255,.7);
  border-radius: var(--radius-sm);
  padding: .6rem .85rem;
  margin-bottom: .85rem;
  font-size: .88rem;
}
.result-formula code {
  color: var(--primary-dark);
  font-size: .9em;
}

.result-steps { margin-bottom: 1rem; }
.result-steps summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--primary);
  font-size: .9rem;
  list-style: none;
  display: flex;
  align-items: center;
  gap: .4rem;
}
.result-steps summary::before { content: '▶'; font-size: .7rem; transition: transform .2s; }
.result-steps[open] summary::before { transform: rotate(90deg); }
.steps-list { margin-top: .6rem; padding-left: 1.5rem; }
.steps-list li { margin-bottom: .4rem; font-size: .88rem; }

.result-disclaimer { font-size: .78rem; color: var(--text-muted); margin-top: .75rem; font-style: italic; }
.result-actions { display: flex; gap: .5rem; margin-top: .75rem; }

.result-error {
  padding: 1rem 1.25rem;
  border-radius: var(--radius-sm);
  background: #fef2f2;
  border: 1px solid #fca5a5;
  color: var(--error);
  font-weight: 500;
}

/* ── Alert ──────────────────────────────────────────────── */
.alert { padding: .85rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1rem; }
.alert-success { background: #f0fdf4; border: 1px solid #86efac; color: #15803d; }
.alert-error   { background: #fef2f2; border: 1px solid #fca5a5; color: var(--error); }
.alert-info    { background: #eff6ff; border: 1px solid #93c5fd; color: #1d4ed8; }

/* ── Ad slots ───────────────────────────────────────────── */
.ad-slot {
  background: #f1f5f9;
  border: 1px dashed #cbd5e1;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #94a3b8;
  font-size: .78rem;
  text-align: center;
}
.ad-slot-header    { min-height: 90px; width: 100%; }
.ad-slot-in-content{ min-height: 250px; width: 100%; margin: 1.5rem 0; }
.ad-slot-sidebar   { min-height: 600px; width: 100%; }
.ad-slot-footer    { min-height: 90px; width: 100%; }

/* ── Sidebar ────────────────────────────────────────────── */
.sidebar { display: flex; flex-direction: column; gap: 1rem; }
.sidebar-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.sidebar-box-title {
  font-size: .85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
}
.sidebar-box ul { list-style: none; padding: .5rem 0; }
.sidebar-box li a {
  display: block;
  padding: .45rem 1rem;
  font-size: .88rem;
  color: var(--text);
  transition: background var(--transition), color var(--transition);
}
.sidebar-box li a:hover { background: var(--primary-light); color: var(--primary); text-decoration: none; }

/* ── Hero ───────────────────────────────────────────────── */
.hero {
  background: linear-gradient(135deg, var(--primary) 0%, #1e40af 100%);
  color: #fff;
  padding: 2.5rem 1rem;
  text-align: center;
  margin-bottom: 2rem;
}
.hero h1 { color: #fff; font-size: clamp(1.6rem, 4vw, 2.5rem); margin-bottom: .5rem; }
.hero p  { color: rgba(255,255,255,.85); max-width: 520px; margin: 0 auto 1.5rem; }
.hero-search {
  display: flex;
  max-width: 500px;
  margin: 0 auto;
  gap: 0;
}
.hero-search input {
  flex: 1;
  padding: .75rem 1.1rem;
  border: none;
  border-radius: var(--radius-sm) 0 0 var(--radius-sm);
  font-size: 1rem;
}
.hero-search button {
  padding: .75rem 1.25rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-weight: 700;
  cursor: pointer;
}
.hero-search input:focus { outline: 2px solid var(--accent); }

/* ── Section headings ───────────────────────────────────── */
.section-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.section-title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Footer ─────────────────────────────────────────────── */
.site-footer {
  background: #1e293b;
  color: #94a3b8;
  padding: 2.5rem 1rem 1.5rem;
  margin-top: auto;
}
.footer-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1.5rem;
  max-width: var(--max-w);
  margin: 0 auto 2rem;
}
@media (min-width: 640px)  { .footer-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) { .footer-grid { grid-template-columns: repeat(4, 1fr); } }

.footer-col h4 { color: #e2e8f0; font-size: .95rem; margin-bottom: .75rem; }
.footer-col ul { list-style: none; }
.footer-col li { margin-bottom: .4rem; }
.footer-col a  { color: #94a3b8; font-size: .875rem; transition: color var(--transition); }
.footer-col a:hover { color: #fff; text-decoration: none; }
.footer-bottom {
  text-align: center;
  padding-top: 1.5rem;
  border-top: 1px solid #334155;
  font-size: .82rem;
}

/* ── Table (amortization etc) ───────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: .85rem; margin-top: 1rem; }
.data-table th, .data-table td {
  padding: .45rem .65rem;
  border: 1px solid var(--border);
  text-align: right;
}
.data-table th { background: var(--primary); color: #fff; font-weight: 600; }
.data-table tr:nth-child(even) { background: var(--bg); }
.table-responsive { overflow-x: auto; border-radius: var(--radius-sm); }

/* ── FAQ ────────────────────────────────────────────────── */
.faq-list { display: flex; flex-direction: column; gap: .6rem; }
.faq-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.faq-item summary {
  cursor: pointer;
  padding: .75rem 1rem;
  font-weight: 600;
  font-size: .95rem;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-card);
}
.faq-item summary::after { content: '+'; font-size: 1.2rem; color: var(--primary); transition: transform .2s; }
.faq-item[open] summary::after { content: '−'; }
.faq-answer { padding: .75rem 1rem; background: #fafbfc; font-size: .9rem; border-top: 1px solid var(--border); }

/* ── Print ──────────────────────────────────────────────── */
@media print {
  .site-header, .site-nav, .site-footer, .sidebar, .print-hide, .ad-slot { display: none !important; }
  .page-grid { grid-template-columns: 1fr; }
  .result-block { border: 1px solid #999; background: #fff; }
}

/* ── Utilities ──────────────────────────────────────────── */
.text-center { text-align: center; }
.text-muted  { color: var(--text-muted); }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mb-2 { margin-bottom: 1rem; }
.hidden { display: none; }
.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  border: 0;
}

/* ── Cookie banner ──────────────────────────────────────── */
.cookie-banner {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: #1e293b;
  color: #e2e8f0;
  padding: 1rem;
  z-index: 999;
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  font-size: .88rem;
  box-shadow: 0 -4px 24px rgba(0,0,0,.2);
}
.cookie-banner.hidden { display: none; }
.cookie-banner a { color: #93c5fd; }
.cookie-banner .btn { flex-shrink: 0; }

/* ── Loading spinner ────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 1.2rem; height: 1.2rem;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Search results page ────────────────────────────────── */
.search-results-list { display: flex; flex-direction: column; gap: .75rem; }
.search-result-item {
  padding: 1rem 1.25rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.search-result-item h3 { font-size: 1rem; margin-bottom: .25rem; }
.search-result-item h3 a { color: var(--primary); }
.search-result-item p { font-size: .875rem; color: var(--text-muted); margin: 0; }
.search-result-cat { font-size: .75rem; background: var(--primary-light); color: var(--primary); padding: .15rem .5rem; border-radius: 99px; }
