/* ==========================================================================
   SterlingCalc UK — styles.css
   Zero-dependency, mobile-first, light/dark themed stylesheet.
   ========================================================================== */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #16202c;
  --text-muted: #566373;
  --border: #dde2e8;
  --accent: #0b6e4f;
  --accent-strong: #08563e;
  --accent-soft: #e3f3ec;
  --accent-2: #c2410c;
  --warn-bg: #fff7e6;
  --warn-border: #f0c36d;
  --warn-text: #7a4b00;
  --chart-grid: #e6e9ee;
  --chart-a: #0b6e4f;
  --chart-b: #6b7a8c;
  --chart-c: #c2410c;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .05);
  --radius: 14px;
  --radius-sm: 9px;
  --maxw: 1200px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0e1319;
  --surface: #161d26;
  --surface-2: #1d2631;
  --text: #e7ecf2;
  --text-muted: #9aa8b8;
  --border: #2a3542;
  --accent: #34c08f;
  --accent-strong: #5ad6a8;
  --accent-soft: #15342a;
  --accent-2: #fb8a4e;
  --warn-bg: #2d2412;
  --warn-border: #6d5422;
  --warn-text: #f3cf86;
  --chart-grid: #26303c;
  --chart-a: #34c08f;
  --chart-b: #8a9aae;
  --chart-c: #fb8a4e;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

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

[hidden] { display: none !important; }

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

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

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

img, canvas, svg { max-width: 100%; display: block; }

a { color: var(--accent); text-underline-offset: 2px; }
a:hover { color: var(--accent-strong); }

h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: clamp(1.6rem, 3.5vw, 2.3rem); }
h2 { font-size: clamp(1.25rem, 2.4vw, 1.55rem); }
h3 { font-size: 1.1rem; }
p { margin: 0 0 1em; }

.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--accent); color: #fff; padding: .5rem 1rem; z-index: 100;
}
.skip-link:focus { left: 1rem; top: 1rem; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

.container { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 1rem; }

/* ---------- Header ---------- */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
@media (max-width: 639px) { .site-header { position: static; } }
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; min-height: 64px; flex-wrap: wrap;
}
.brand {
  display: flex; align-items: center; gap: .55rem;
  font-weight: 800; font-size: 1.15rem; color: var(--text); text-decoration: none;
}
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center; font-size: 1.1rem; font-weight: 800;
}
:root[data-theme="dark"] .brand-mark { color: #0e1319; }
.brand small { font-weight: 600; color: var(--text-muted); font-size: .8rem; }

.site-nav { display: flex; align-items: center; gap: .25rem; flex-wrap: wrap; }
.site-nav a {
  color: var(--text-muted); text-decoration: none; font-weight: 600; font-size: .93rem;
  padding: .45rem .7rem; border-radius: 8px;
}
.site-nav a:hover { color: var(--text); background: var(--surface-2); }
.site-nav a[aria-current="page"] { color: var(--accent); background: var(--accent-soft); }

.theme-toggle {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  border-radius: 999px; padding: .4rem .75rem; cursor: pointer; font: inherit;
  font-size: .88rem; font-weight: 600; display: inline-flex; gap: .35rem; align-items: center;
}
.theme-toggle:hover { border-color: var(--accent); }

/* ---------- Ad slots (CLS-safe: fixed min-heights reserved before ads load) ---------- */
.ad-slot {
  position: relative;
  display: flex; align-items: center; justify-content: center;
  width: 100%;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  contain: layout;
}
.ad-slot::before {
  content: "Advertisement";
  position: absolute; top: 4px; left: 8px;
  font-size: .68rem; letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-muted);
}
.ad-slot ins.adsbygoogle { display: block; width: 100%; }
.ad-slot[data-slot="header"]     { min-height: 100px; margin: 1rem 0; }   /* 320x100 mobile */
.ad-slot[data-slot="in-content"] { min-height: 280px; margin: 2rem 0; }   /* 336x280 / responsive */
.ad-slot[data-slot="sidebar"]    { min-height: 250px; }                   /* 300x250 mobile */

@media (min-width: 768px) {
  .ad-slot[data-slot="header"] { min-height: 90px; }                      /* 728x90 leaderboard */
}
@media (min-width: 1024px) {
  .ad-slot[data-slot="sidebar"] { min-height: 600px; }                    /* 300x600 half-page */
}

/* ---------- Layout ---------- */
.page-grid {
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 1.5rem;
  padding-bottom: 3rem;
}
@media (min-width: 1024px) {
  .page-grid { grid-template-columns: minmax(0, 1fr) 300px; }
  .sidebar-inner { position: sticky; top: 84px; }
}
.sidebar { display: flex; flex-direction: column; gap: 1.25rem; }

.hero { padding: 1.5rem 0 .5rem; }
.hero p.lead { color: var(--text-muted); font-size: 1.05rem; max-width: 60ch; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1.25rem;
}
@media (min-width: 640px) { .card { padding: 1.6rem; } }
.card + .card { margin-top: 1.25rem; }

.tool-card h2 { display: flex; align-items: center; gap: .5rem; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }
@media (min-width: 600px) { .form-grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 900px) { .form-grid.cols-3 { grid-template-columns: repeat(3, 1fr); } }

.field { display: flex; flex-direction: column; gap: .3rem; }
.field label { font-weight: 600; font-size: .9rem; }
.field .hint { font-size: .8rem; color: var(--text-muted); }

.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap .prefix, .input-wrap .suffix {
  position: absolute; color: var(--text-muted); font-size: .92rem; pointer-events: none;
}
.input-wrap .prefix { left: .75rem; }
.input-wrap .suffix { right: .75rem; }
.input-wrap input.has-prefix { padding-left: 1.7rem; }
.input-wrap input.has-suffix { padding-right: 3.6rem; }

input[type="number"], input[type="text"], select {
  width: 100%; font: inherit; font-size: 1rem;
  color: var(--text); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .65rem .75rem; min-height: 44px;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type="number"] { -moz-appearance: textfield; }
input::-webkit-outer-spin-button, input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.toggle-row {
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
  padding: .75rem; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.switch { position: relative; display: inline-flex; align-items: center; gap: .6rem; cursor: pointer; font-weight: 600; font-size: .92rem; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track {
  width: 44px; height: 24px; border-radius: 999px; background: var(--border);
  position: relative; transition: background .2s; flex: none;
}
.switch .track::after {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px;
  border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(20px); }
.switch input:focus-visible + .track { outline: 3px solid var(--accent); outline-offset: 2px; }
.toggle-row { align-items: flex-start; }
.toggle-row .switch { flex: 1 1 100%; }
.toggle-row .field { flex: 1 1 160px; }
.toggle-row .field[hidden] { display: none; }

.notice {
  margin-top: 1rem; padding: .7rem .9rem; border-radius: var(--radius-sm);
  background: var(--warn-bg); border: 1px solid var(--warn-border); color: var(--warn-text);
  font-size: .9rem;
}
.notice[hidden] { display: none; }

/* ---------- Results ---------- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; margin: 1.5rem 0; }
@media (min-width: 760px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .85rem;
  min-height: 84px;
}
.stat .label { font-size: .78rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: clamp(1.1rem, 2.4vw, 1.4rem); font-weight: 800; font-variant-numeric: tabular-nums; margin-top: .15rem; }
.stat.highlight { background: var(--accent-soft); border-color: var(--accent); }
.stat.highlight .value { color: var(--accent); }

.chart-wrap {
  position: relative; width: 100%;
  aspect-ratio: 16 / 9; min-height: 240px; max-height: 420px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .5rem;
}
.chart-wrap canvas { width: 100%; height: 100%; }
.legend { display: flex; flex-wrap: wrap; gap: 1rem; font-size: .85rem; color: var(--text-muted); margin: .6rem 0 0; padding: 0; list-style: none; }
.legend li { display: inline-flex; align-items: center; gap: .4rem; }
.legend .swatch { width: 14px; height: 4px; border-radius: 2px; display: inline-block; }

.table-wrap {
  overflow-x: auto; margin-top: 1.25rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  max-height: 460px; overflow-y: auto;
}
table { width: 100%; border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
th, td { padding: .6rem .75rem; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th {
  position: sticky; top: 0; background: var(--surface-2); z-index: 1;
  font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted);
}
tbody tr:hover { background: var(--surface-2); }
tfoot td { font-weight: 800; background: var(--surface-2); }
.pos { color: var(--accent); }
.neg { color: var(--accent-2); }

.verdict {
  margin-top: 1.25rem; padding: 1rem 1.1rem; border-radius: var(--radius-sm);
  background: var(--accent-soft); border-left: 4px solid var(--accent);
  font-weight: 600;
}

.disclaimer { font-size: .82rem; color: var(--text-muted); margin-top: 1.25rem; }

/* ---------- Content / FAQ ---------- */
.prose { max-width: 75ch; }
.prose h2 { margin-top: 1.6em; }
.prose ul, .prose ol { padding-left: 1.25rem; }
.prose li { margin-bottom: .35rem; }

.faq details {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); margin-bottom: .6rem;
}
.faq summary {
  cursor: pointer; padding: .9rem 1rem; font-weight: 700; list-style: none;
  display: flex; justify-content: space-between; gap: 1rem; align-items: center;
}
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; font-size: 1.3rem; color: var(--accent); flex: none; line-height: 1; }
.faq details[open] summary::after { content: "−"; }
.faq details > div { padding: 0 1rem 1rem; color: var(--text); }
.faq details > div p:last-child { margin-bottom: 0; }

.tool-links { display: grid; gap: .75rem; }
.tool-link {
  display: block; padding: 1rem; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); text-decoration: none; color: var(--text);
}
.tool-link:hover { border-color: var(--accent); color: var(--text); }
.tool-link strong { display: block; color: var(--accent); }
.tool-link span { font-size: .88rem; color: var(--text-muted); }

/* ---------- Footer ---------- */
.site-footer {
  border-top: 1px solid var(--border); background: var(--surface);
  padding: 2rem 0; font-size: .88rem; color: var(--text-muted);
}
.footer-inner { display: flex; flex-wrap: wrap; gap: 1rem 2rem; justify-content: space-between; }
.footer-links { display: flex; gap: 1rem; flex-wrap: wrap; }
.footer-links a { color: var(--text-muted); }
.site-footer p { margin: 0 0 .4rem; max-width: 70ch; }

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; }
}

@media print {
  .site-header, .ad-slot, .sidebar, .theme-toggle, .site-footer { display: none !important; }
  .page-grid { grid-template-columns: 1fr; }
  .card { box-shadow: none; }
}

/* ---------- Additions: extra calculators ---------- */
:root { --chart-d: #7c3aed; --chart-e: #ca8a04; }
:root[data-theme="dark"] { --chart-d: #a78bfa; --chart-e: #facc15; }

.stackbar {
  display: flex; width: 100%; height: 22px; border-radius: 999px; overflow: hidden;
  background: var(--surface-2); border: 1px solid var(--border);
}
.stackbar span { display: block; height: 100%; }

tr.total-row td { font-weight: 800; background: var(--accent-soft); }

.segmented { display: flex; flex-wrap: wrap; gap: .5rem; border: 0; padding: 0; margin: 0; }
.segmented legend { font-weight: 600; font-size: .9rem; margin-bottom: .35rem; padding: 0; }
.segmented label {
  flex: 1 1 150px; display: flex; align-items: center; gap: .5rem; cursor: pointer;
  padding: .65rem .8rem; min-height: 44px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); font-weight: 600; font-size: .92rem;
}
.segmented input { accent-color: var(--accent); width: 18px; height: 18px; margin: 0; }
.segmented label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }

.check { display: inline-flex; align-items: center; gap: .55rem; font-weight: 600; font-size: .92rem; cursor: pointer; min-height: 44px; }
.check input { accent-color: var(--accent); width: 18px; height: 18px; }

/* Header nav: single scrollable row on small screens */
@media (max-width: 899px) {
  .header-inner { flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: .25rem; padding-top: .5rem; padding-bottom: .4rem; }
  .site-nav { min-width: 0; max-width: 100%; }
  .site-nav { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; padding-bottom: 2px; }
  .site-nav::-webkit-scrollbar { display: none; }
  .site-nav a, .theme-toggle { white-space: nowrap; flex: none; }
}
