/* Shared layout + components for every calculator site. Loaded before a site's own site.css
   (see shell.ts § stylesheets), so a site overrides by adding rules, never by editing this file —
   this file is mirrored verbatim from packages/counter-ui on every sync-ui run (see
   scripts/sync-ui.mjs) and any local edit under a site's public/ui/ is silently reverted.

   Colors and fontFamily come from each site's own site.config.ts theme, piped in as CSS custom
   properties by shell.ts's themeVars() (an inline <style> block, same pattern core's render.ts
   uses). This file only ever reads var(--bg) etc, never sets a literal color, so the same
   stylesheet reskins per site. The values below are the fallback for anything a site doesn't
   override. */

:root {
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #6b6b6b;
  --accent: #2f6feb;
  --accent-fg: #ffffff;
  /* button.primary's background, not --accent directly. --accent-fg is a fixed white, but a
     site's own --accent (site.config.ts theme.colors.accent) isn't guaranteed to be dark enough
     for white text at AA (4.5:1) — e.g. bpm's orange #e0562f is only 3.79:1. Darkening by a flat
     15% via color-mix() before it becomes a button background holds AA for every accent hue
     without needing a second color in each site's config; --accent itself (links, checkboxes,
     the FAQ/table accents) stays untouched since those aren't paired with fixed white text. */
  --accent-button: color-mix(in srgb, var(--accent), black 15%);
  --border: #e2e2e2;
  --danger: #b3261e;
  --danger-bg: #fbeceb;
  --success: #1a7f37;
  --success-bg: #e9f7ee;
  --radius: 10px;
  --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  /* Tells the browser this page genuinely supports both modes, so native chrome this stylesheet
     doesn't otherwise style — scrollbars, the native checkbox/radio ring in browsers that don't
     honor accent-color below, autofill overlays — follows the same light/dark switch as
     everything else instead of the browser guessing (or defaulting to light chrome dropped onto
     a dark page, which reads as broken in exactly the way accent-color alone can't fix). */
  color-scheme: light dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  /* var(), not a direct value: an explicit rule on the element always wins over an inherited
     :root declaration regardless of specificity, so a site's site.config.ts theme.fontFamily
     (piped in as --font-family by shell.ts) has to arrive through the custom property to have
     any effect here. */
  font-family: var(--font-family);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

main {
  max-width: 42rem;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 4rem;
}

h1,
h2,
h3 {
  line-height: 1.15;
}

a {
  /* --accent-link falls back to --accent in light mode; the dark-mode block below overrides it
     with a lightened copy — see that block for why --accent itself can't just be redefined
     there. */
  color: var(--accent-link, var(--accent));
}

.muted {
  color: var(--muted);
}

/* --- Header / nav --- */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  max-width: 42rem;
  margin: 0 auto;
  padding: 1.25rem 1.25rem 0.5rem;
}

.site-wordmark {
  font-weight: 700;
  font-size: 1.15rem;
  text-decoration: none;
  color: var(--fg);
}

.site-nav {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.site-nav a {
  text-decoration: none;
  color: var(--muted);
  font-size: 0.95rem;
}

.site-nav a:hover {
  color: var(--fg);
}

/* --- Footer / family cross-links --- */

.site-footer {
  max-width: 42rem;
  margin: 2rem auto 0;
  padding: 1.5rem 1.25rem 2.5rem;
  border-top: 1px solid var(--border);
}

.footer-about {
  color: var(--muted);
  font-size: 0.9rem;
}

.site-family {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  margin: 0.75rem 0;
}

.site-family a {
  text-decoration: none;
  font-size: 0.9rem;
}

.footer-copy {
  font-size: 0.8rem;
  margin: 1rem 0 0;
}

/* --- Cards, tables, FAQ --- generic content components a calculator page reaches for */

.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin: 1.5rem 0;
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0;
  font-size: 0.95rem;
}

table.data-table th,
table.data-table td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

details.faq-item {
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 0;
}

details.faq-item summary {
  cursor: pointer;
  font-weight: 600;
}

/* --- Form fields (comment form and any calculator inputs that reuse the same look) --- */

.field {
  margin: 0.9rem 0;
}

.field label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
}

.field input,
.field textarea {
  width: 100%;
  font: inherit;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--fg);
}

.field textarea {
  min-height: 6rem;
  resize: vertical;
}

.field input:focus-visible,
.field textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Checkboxes and radios (unit/mode toggles on the BMI and percentage calculators, say) — tinted
   to the site's accent color rather than left as the browser's unstyled default, which reads as
   an oversight next to everything else on the page being themed. accent-color is supported by
   every evergreen browser; a browser without it just falls back to its native control unstyled,
   never broken. */
input[type='radio'],
input[type='checkbox'] {
  accent-color: var(--accent);
  width: 1.05em;
  height: 1.05em;
}

/* Honeypot: off-screen rather than display:none or visibility:hidden. A field a screen reader
   also skips (via aria-hidden + tabindex="-1" on the input, set in comments.ts) is invisible to
   every real visitor and to most crawlers, while a display:none field is the one bots are most
   often coded to specifically ignore. */
.field.honeypot {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  left: -9999px;
}

button {
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.55rem 1rem;
  background: var(--bg);
  color: inherit;
  cursor: pointer;
}

button.primary {
  background: var(--accent-button);
  color: var(--accent-fg);
  border-color: var(--accent-button);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* --- Comments --- */

.comments {
  margin-top: 2.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border);
}

.comment-list {
  list-style: none;
  margin: 0 0 1.5rem;
  padding: 0;
}

.comment-item {
  padding: 0.9rem 0;
  border-bottom: 1px solid var(--border);
}

.comment-meta {
  margin: 0 0 0.25rem;
  font-size: 0.9rem;
}

.comment-meta time {
  color: var(--muted);
}

.comment-body {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.comment-notice {
  font-size: 0.85rem;
}

.comment-status {
  margin-top: 0.75rem;
  font-size: 0.9rem;
}

.comment-status.success {
  color: var(--success);
}

.comment-status.error {
  color: var(--danger);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e0e10;
    --fg: #f2f2f2;
    --muted: #9a9a9f;
    --border: #2a2a2e;
    --danger-bg: #3a1f1d;
    --success-bg: #14301f;
    /* Every site picks its own --accent for a light (#fff-ish) background, where it clears
       WCAG AA (~4.5:1) by design. Against this file's near-black dark-mode --bg, that same blue
       (e.g. the default #2f6feb) drops to ~4.2:1 — a real contrast failure Lighthouse flags on
       plain text links, not the near-miss the old comment in shell.ts's themeVars() assumed.
       Mixing in white lightens whatever accent a site picked without needing a second color in
       site.config.ts; can't redefine --accent itself here because a custom property can't
       reference its own name (cycle -> invalid -> falls back to initial value). Only fixes text
       set directly in --accent (the `a` rule) against the *page* background — button.primary has
       its own fix (--accent-button, in the main :root block above) since there the accent is the
       background and the contrast risk is mode-independent, not dark-mode-specific. The
       checkbox/radio/outline uses aren't text-on-a-background at all, so neither applies. */
    --accent-link: color-mix(in srgb, var(--accent), white 25%);
  }

  .field input,
  .field textarea,
  button {
    background: #16161a;
    /* Explicit, not left to inherit/var() resolution across two media blocks: this used to be
       exactly the gap that let a dark background pair with shell.ts's light-mode --fg (see the
       comment on themeVars() in shell.ts) and produce unreadable black-on-black text. --fg is
       correctly dark-mode-aware here regardless now that that bug is fixed at the source, but
       stating it explicitly means this block is self-contained and can't regress the same way if
       the cascade elsewhere changes again. */
    color: var(--fg);
  }
}
