/* ==========================================================================
   Calculator Index — global stylesheet
   Institutional finance system. Semantic color only, greyscale everywhere else.
   Public Sans, one typeface. Hierarchy from size/weight, never color.
   ========================================================================== */

:root {
  /* ---- semantic palette (color = meaning, never decoration) ---- */
  --blue-700:  #00429E;   /* primary interactive: links, buttons, focus, active */
  --blue-800:  #003377;   /* hover / active */
  --blue-050:  #EAF1FB;   /* selected rows, info backgrounds */
  --green-600: #00785C;   /* positive figures, success (AA on white: 5.5:1) */
  --amber-600: #A85F00;   /* attention, assumptions/caveats (AA on white: 4.9:1) */
  --red-700:   #A32B02;   /* validation errors, warnings */

  --grey-900:  #1A1D21;   /* primary text */
  --grey-600:  #5A6068;   /* secondary text */
  --grey-400:  #B9BEC5;   /* border hover */
  --grey-300:  #D4D8DD;   /* borders */
  --grey-100:  #EDEFF2;   /* table stripes, disabled */
  --grey-050:  #F7F8FA;   /* page background */
  --white:     #FFFFFF;   /* surfaces */

  /* ---- role aliases (map structure to the palette) ---- */
  --bg:          var(--grey-050);
  --surface:     var(--white);
  --border:      var(--grey-300);
  --border-hover:var(--grey-400);
  --text:        var(--grey-900);
  --text-muted:  var(--grey-600);
  --link:        var(--blue-700);
  --link-hover:  var(--blue-800);
  --focus:       var(--blue-700);
  --info-bg:     var(--blue-050);

  --radius: 4px;
  --max-width: 1200px;
  --content-width: 760px;
  --font: "Public Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;

  /* neutral (grey) calculator glyph — decoration carries no meaning, so it's grey */
  --icon-calc: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235A6068' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='4' y='2' width='16' height='20' rx='2'/%3E%3Cpath d='M8 6h8M8 10h.01M12 10h.01M16 10h.01M8 14h.01M12 14h.01M16 14h.01M8 18h4'/%3E%3C/svg%3E");
  --icon-search: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235A6068' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='11' cy='11' r='7'/%3E%3Cpath d='m21 21-4.3-4.3'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

img { max-width: 100%; height: auto; }

/* interactive text = blue; everything else stays grey */
a { color: var(--link); text-decoration: none; }
a:hover { color: var(--link-hover); text-decoration: underline; }

h1, h2, h3 { line-height: 1.25; font-weight: 700; color: var(--grey-900); }
h1 { font-size: 2rem; font-weight: 700; letter-spacing: -0.02em; margin: .2em 0 .5em; }
h2 { font-size: 1.125rem; font-weight: 600; margin: 1.7em 0 .6em; }
h3 { font-size: 1rem; font-weight: 600; margin: 1.3em 0 .5em; }

/* tabular figures align on the decimal wherever numbers matter */
table, .result-main .value, .result-item .value, .num { font-variant-numeric: tabular-nums; }

/* focus ring on everything interactive */
a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--radius);
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* positive / negative figures (semantic green / red, used by calculators) */
.pos { color: var(--green-600); }
.neg { color: var(--red-700); }

/* ------------------------------------------------------------------ header */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 18px;
  height: 64px;
}

.logo {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--grey-900);
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.logo:hover { text-decoration: none; color: var(--grey-900); }
.logo img, .logo svg { width: 26px; height: 26px; display: block; }
.logo span { color: inherit; font-weight: inherit; }

.main-nav { display: flex; gap: 2px; margin-left: auto; }

.main-nav a {
  color: var(--text-muted);
  font-size: 0.9375rem;
  font-weight: 500;
  padding: 7px 12px;
  border-radius: var(--radius);
}
.main-nav a:hover,
.main-nav a[aria-current="page"] { color: var(--blue-700); background: var(--info-bg); text-decoration: none; }

/* header search (inner pages only) */
.search-wrap { position: relative; }

#calc-search {
  width: 210px;
  padding: 8px 12px 8px 34px;
  font-size: 0.9375rem;
  font-family: var(--font);
  color: var(--text);
  background: var(--surface) var(--icon-search) no-repeat 10px center;
  background-size: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
}
#calc-search:focus { border-color: var(--blue-700); }

/* shared search results dropdown */
.search-results {
  position: absolute;
  top: 112%;
  right: 0;
  width: 340px;
  max-width: 90vw;
  max-height: 360px;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: none;
  z-index: 60;
  padding: 4px;
}
.search-results.open { display: block; }
.search-results a {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 0.9375rem;
  border-radius: var(--radius);
}
.search-results a .cat { color: var(--text-muted); font-size: 0.8125rem; white-space: nowrap; }
.search-results a:hover,
.search-results a.active { background: var(--info-bg); color: var(--blue-700); text-decoration: none; }
.search-results .no-results { padding: 12px; color: var(--text-muted); font-size: 0.875rem; }

/* mobile nav */
.nav-toggle { display: none; background: none; border: none; cursor: pointer; padding: 8px; }
.nav-toggle svg { width: 24px; height: 24px; stroke: var(--grey-900); }

@media (max-width: 760px) {
  .header-inner { flex-wrap: wrap; height: auto; padding: 12px 16px; }
  .nav-toggle { display: block; margin-left: auto; order: 2; }
  .search-wrap { order: 3; width: 100%; }
  #calc-search { width: 100%; }
  .search-results { width: 100%; }
  .main-nav {
    display: none;
    order: 4;
    width: 100%;
    flex-direction: column;
    margin: 6px 0 0;
    gap: 0;
  }
  .main-nav.open { display: flex; }
  .main-nav a { padding: 11px 8px; border-bottom: 1px solid var(--border); border-radius: 0; }
}

/* ------------------------------------------------------------------ layout */
.container { max-width: var(--max-width); margin: 0 auto; padding: 0 20px; }
.content { max-width: var(--content-width); }

main { padding: 24px 0 48px; }

.breadcrumb { font-size: 0.8125rem; color: var(--text-muted); margin: 4px 0 10px; }
.breadcrumb a { color: var(--text-muted); }
.breadcrumb a:hover { color: var(--blue-700); }

.intro { font-size: 1.0625rem; color: var(--text-muted); margin-top: 0; line-height: 1.5; }

/* ============================================================ HOMEPAGE ==== */
.hero {
  min-height: 210px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 40px 20px 32px;
}
.hero h1 { font-size: 2rem; letter-spacing: -0.02em; margin: 0 0 10px; }
.hero .hero-sub { font-size: 1rem; color: var(--text-muted); margin: 0 0 22px; }

.hero-search { position: relative; width: 100%; max-width: 620px; }
#hero-search {
  width: 100%;
  height: 56px;
  padding: 0 18px 0 48px;
  font-size: 1rem;
  font-family: var(--font);
  color: var(--text);
  background: var(--surface) var(--icon-search) no-repeat 16px center;
  background-size: 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
}
#hero-search:focus { border-color: var(--blue-700); }
.hero-search .search-results { left: 0; right: 0; width: 100%; top: 108%; }

/* "Most used" block */
.popular { max-width: 940px; margin: 8px auto 0; padding: 24px 20px; }
.popular h2 {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  margin: 0 0 14px;
}
.pop-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  list-style: none;
  padding: 0; margin: 0;
}
.pop-grid a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 64px;
  padding: 12px 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9375rem;
  font-weight: 500;
  text-align: center;
}
.pop-grid a::before {
  content: "";
  width: 18px; height: 18px;
  background: var(--icon-calc) center/contain no-repeat;
}
.pop-grid a:hover { border-color: var(--blue-700); background: var(--info-bg); color: var(--blue-700); text-decoration: none; }
@media (max-width: 640px) { .pop-grid { grid-template-columns: repeat(2, 1fr); } }

/* category doors */
.doors { max-width: 940px; margin: 0 auto; padding: 12px 20px 40px; }
.door-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
  list-style: none;
  padding: 0; margin: 0;
}
.door-grid a {
  display: block;
  padding: 20px 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
}
.door-grid a:hover { border-color: var(--blue-700); background: var(--info-bg); text-decoration: none; }
.door-grid .door-name { display: block; font-size: 1.0625rem; font-weight: 600; color: var(--grey-900); }
.door-grid .door-count { font-size: 0.8125rem; color: var(--text-muted); font-weight: 500; margin-left: 8px; }
.door-grid .door-desc { display: block; font-size: 0.875rem; color: var(--text-muted); margin-top: 6px; line-height: 1.45; }
@media (max-width: 640px) { .door-grid { grid-template-columns: 1fr; } }

/* ===================================================== CATEGORY PAGES ==== */
.section-nav {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  margin: 0 0 20px;
  overflow-x: auto;
}
/* the only shadow in the system: sticky nav, on scroll */
.section-nav.scrolled { box-shadow: 0 2px 0 rgba(0,0,0,0.06); }
.section-nav ul {
  display: flex;
  gap: 4px;
  list-style: none;
  margin: 0 auto;
  padding: 8px 20px;
  max-width: var(--max-width);
}
.section-nav a {
  display: block;
  padding: 6px 12px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-muted);
  border-radius: var(--radius);
  white-space: nowrap;
}
.section-nav a:hover { color: var(--blue-700); background: var(--info-bg); text-decoration: none; }

.category-section { margin: 30px 0; scroll-margin-top: 60px; }
.category-section h2 {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-size: 1.125rem;
  font-weight: 600;
  margin: 0 0 14px;
}
.category-section h2 .see-all { font-size: 0.8125rem; font-weight: 500; color: var(--text-muted); }
.category-section h2 .see-all:hover { color: var(--blue-700); }

/* dense calculator grid */
.calc-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
  padding: 0;
  list-style: none;
  margin: 0;
}
.calc-grid a {
  display: block;
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px 14px 44px;
  color: var(--text);
  height: 100%;
}
.calc-grid a::before {
  content: "";
  position: absolute;
  left: 16px;
  top: 15px;
  width: 18px; height: 18px;
  background: var(--icon-calc) center/contain no-repeat;
}
.calc-grid a:hover { border-color: var(--blue-700); background: var(--info-bg); text-decoration: none; }
.calc-grid .calc-name { display: block; font-weight: 600; font-size: 1rem; line-height: 1.3; color: var(--grey-900); }
.calc-grid .calc-desc {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 0.8125rem;
  font-weight: 400;
  color: var(--text-muted);
  margin-top: 3px;
  line-height: 1.45;
}

/* -------------------------------------------------------------- calculator */
.calc-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin: 20px 0 26px;
}

.calc-form { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
@media (max-width: 600px) { .calc-form { grid-template-columns: 1fr; } }
.calc-form .full { grid-column: 1 / -1; }

.field label { display: block; font-size: 0.875rem; font-weight: 600; margin-bottom: 4px; color: var(--grey-900); }

.field input,
.field select,
.field textarea {
  width: 100%;
  padding: 10px 12px;
  font-size: 1rem;
  font-family: var(--font);
  color: var(--text);
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--blue-700); }
.field .hint { font-size: 0.8125rem; color: var(--text-muted); margin-top: 3px; line-height: 1.4; }

.unit-wrap { position: relative; }
.unit-wrap input { padding-left: 28px; }
.unit-wrap .unit {
  position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); font-size: 0.95rem; pointer-events: none;
}
.unit-wrap.suffix input { padding-left: 12px; padding-right: 52px; }
.unit-wrap.suffix .unit { left: auto; right: 11px; }

.btn {
  display: inline-block;
  background: var(--blue-700);
  color: var(--white);
  font-size: 1rem;
  font-weight: 600;
  font-family: var(--font);
  padding: 12px 28px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .12s;
}
.btn:hover { background: var(--blue-800); color: var(--white); text-decoration: none; }

/* secondary buttons (exports) */
.btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--white);
  color: var(--blue-700);
  font-size: 0.9375rem;
  font-weight: 600;
  font-family: var(--font);
  padding: 9px 16px;
  border: 1px solid var(--blue-700);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .12s;
}
.btn-secondary:hover:not(:disabled) { background: var(--info-bg); text-decoration: none; }
.btn-secondary:disabled { color: var(--grey-600); border-color: var(--grey-300); background: var(--grey-100); cursor: not-allowed; }
.btn-secondary svg { width: 16px; height: 16px; }

.export-bar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 16px; }
.export-note { font-size: 0.8125rem; color: var(--text-muted); flex-basis: 100%; margin: 0; }
.export-confirm { font-size: 0.875rem; color: var(--green-600); font-weight: 500; }
.export-confirm[hidden] { display: none; }

.radio-row { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; }
.radio-row label { display: flex; align-items: center; gap: 6px; font-size: 0.9375rem; font-weight: 500; cursor: pointer; }

/* results */
.results { margin-top: 22px; display: none; }
.results.show { display: block; }

/* the ONE emphasized element: white card, 2px blue left border, neutral figure */
.result-main {
  background: var(--white);
  border: 1px solid var(--border);
  border-left: 2px solid var(--blue-700);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 14px;
}
.result-main .label { font-size: 0.8125rem; color: var(--text-muted); font-weight: 500; }
.result-main .value { font-size: 2rem; font-weight: 700; color: var(--grey-900); line-height: 1.2; }
.result-main .sub { font-size: 0.9375rem; color: var(--text-muted); }

.result-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; }
.result-item { background: var(--grey-050); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; }
.result-item .label { font-size: 0.8125rem; color: var(--text-muted); font-weight: 500; }
.result-item .value { font-size: 1.15rem; font-weight: 700; color: var(--grey-900); }

.error-msg { color: var(--red-700); font-size: 0.9375rem; margin-top: 10px; display: none; }
.error-msg.show { display: block; }

/* ------------------------------------------------------------------ tables */
.table-wrap { overflow-x: auto; margin: 14px 0; }
table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.9375rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
th, td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { background: var(--grey-100); font-size: 0.8125rem; font-weight: 700; color: var(--grey-900); }
tbody tr:nth-child(even) td { background: var(--grey-050); }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; }

/* ----------------------------------------------------------------- article */
.formula-box {
  background: var(--grey-050);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin: 14px 0;
  font-family: var(--mono);
  font-size: 0.9375rem;
  overflow-x: auto;
}
.example-box {
  background: var(--info-bg);
  border: 1px solid var(--grey-300);
  border-radius: var(--radius);
  padding: 14px 18px;
  margin: 14px 0;
  font-size: 0.9375rem;
}
.example-box .ex-title { font-weight: 700; margin-bottom: 6px; }

/* FAQ */
.faq details {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 8px 0;
  padding: 0 16px;
}
.faq summary {
  font-weight: 600;
  padding: 12px 0;
  cursor: pointer;
  list-style: none;
  position: relative;
  padding-right: 24px;
}
.faq summary::after {
  content: "+";
  position: absolute; right: 2px; top: 50%; transform: translateY(-50%);
  color: var(--blue-700); font-size: 1.2rem; font-weight: 700;
}
.faq details[open] summary::after { content: "\2212"; }
.faq details p { margin: 0 0 14px; color: var(--text-muted); }

/* related calculators */
.related-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 10px;
  margin: 14px 0;
  padding: 0;
  list-style: none;
}
.related-grid a {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 14px;
  font-size: 0.9375rem;
  font-weight: 500;
  color: var(--link);
}
.related-grid a:hover { border-color: var(--blue-700); background: var(--info-bg); color: var(--blue-700); text-decoration: none; }

/* disclaimers / caveats — semantic amber accent */
.disclaimer-note {
  font-size: 0.8125rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  border-left: 3px solid var(--amber-600);
  background: var(--grey-050);
  margin-top: 30px;
  padding: 12px 14px;
  border-radius: 0 var(--radius) var(--radius) 0;
  line-height: 1.5;
}
.disclaimer-note strong { color: var(--amber-600); }
.updated { font-size: 0.8125rem; color: var(--text-muted); }

/* --------------------------------------------------------------- ad slots */
.ad-slot { margin: 22px auto; text-align: center; min-height: 0; }
.ad-slot:empty { display: none; margin: 0; }

/* -------------------------------------------------------------------- blog */
.post-list { list-style: none; padding: 0; }
.post-list li {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 14px;
}
.post-list li:hover { border-color: var(--border-hover); }
.post-list h2 { margin: 0 0 6px; font-size: 1.15rem; }
.post-list p { margin: 0; color: var(--text-muted); font-size: 0.9375rem; }
.post-meta { font-size: 0.8125rem; color: var(--text-muted); margin-bottom: 6px; }

.post-body { max-width: var(--content-width); }
.post-body h2 { margin-top: 1.8em; }
.post-body p, .post-body li { line-height: 1.6; }
.post-body blockquote {
  border-left: 3px solid var(--grey-400);
  margin: 14px 0;
  padding: 8px 18px;
  background: var(--grey-050);
  border-radius: 0 var(--radius) var(--radius) 0;
  color: var(--grey-900);
}

.cta-box {
  background: var(--info-bg);
  border: 1px solid var(--grey-300);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin: 20px 0;
}
.cta-box a { font-weight: 600; }

/* ------------------------------------------------------------------ footer */
.site-footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  margin-top: 40px;
  padding: 30px 0 20px;
  font-size: 0.875rem;
  color: var(--text-muted);
}
.footer-cols {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 20px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 20px;
}
.footer-cols h3 { font-size: 0.9375rem; margin: 0 0 10px; color: var(--grey-900); }
.footer-cols ul { list-style: none; padding: 0; margin: 0; }
.footer-cols li { margin: 6px 0; }
.footer-cols a { color: var(--text-muted); }
.footer-cols a:hover { color: var(--blue-700); }
.footer-bottom {
  max-width: var(--max-width);
  margin: 22px auto 0;
  padding: 14px 20px 0;
  border-top: 1px solid var(--border);
  font-size: 0.8125rem;
  line-height: 1.5;
}

/* ------------------------------------------------------------------- misc */
.skip-link {
  position: absolute;
  left: -9999px;
  background: var(--blue-700);
  color: var(--white);
  padding: 8px 14px;
}
.skip-link:focus { left: 8px; top: 8px; z-index: 100; }

@media print {
  .site-header, .site-footer, .ad-slot, .btn, .btn-secondary, .export-bar, .faq, .related-grid, .section-nav { display: none !important; }
}
