/* ==========================================================================
   BatterySec design system
   Swiss editorial structure + industrial control-system documentation.
   No framework. ~1 file. Tokens first, then primitives, then components.
   ========================================================================== */

/* ---------- Fonts (self-hosted, subset to latin) ---------- */
@font-face {
  font-family: 'Plex Sans';
  src: url('/assets/fonts/IBMPlexSans.woff2') format('woff2-variations');
  font-weight: 100 700;
  font-display: swap;
  font-style: normal;
}
@font-face {
  font-family: 'Plex Mono';
  src: url('/assets/fonts/IBMPlexMono400.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Plex Mono';
  src: url('/assets/fonts/IBMPlexMono.woff2') format('woff2');
  font-weight: 500;
  font-display: swap;
}

/* ---------- Tokens ---------- */
:root {
  /* Colour: graphite / warm off-white / metallic grey + ONE accent (high-voltage amber).
     Accent is reserved for live-path, focus and primary action. Never decorative. */
  --graphite-900: #0d0f11;
  --graphite-800: #16191c;
  --graphite-700: #1f2327;
  --graphite-600: #2c3238;
  --steel-500: #6b757e;
  --steel-400: #929ba3;
  --steel-300: #b9c0c6;
  --paper-100: #f4f2ee;
  --paper-000: #fbfaf8;
  --amber-500: #ff8a1f;
  --amber-400: #ffa04d;
  --amber-dim: rgba(255, 138, 31, 0.14);
  --signal-green: #4ba82e;
  --alert-red: #d1462f;

  --bg: var(--paper-000);
  --bg-alt: var(--paper-100);
  --ink: var(--graphite-900);
  --ink-soft: #4a5158;
  --rule: #d9d5ce;
  --rule-strong: #b6b1a8;

  /* Type scale — 1.25 minor third, clamped for fluid layout */
  --t-xs: 0.75rem;
  --t-sm: 0.8125rem;
  --t-base: clamp(1rem, 0.97rem + 0.15vw, 1.0625rem);
  --t-lg: clamp(1.125rem, 1.05rem + 0.35vw, 1.3125rem);
  --t-xl: clamp(1.375rem, 1.2rem + 0.75vw, 1.75rem);
  --t-2xl: clamp(1.75rem, 1.4rem + 1.5vw, 2.5rem);
  --t-3xl: clamp(2.25rem, 1.6rem + 2.9vw, 4rem);
  --t-4xl: clamp(2.35rem, 1.5rem + 3.4vw, 4.25rem);

  /* Spacing — 4px base */
  --s-1: 0.25rem;  --s-2: 0.5rem;   --s-3: 0.75rem;  --s-4: 1rem;
  --s-5: 1.5rem;   --s-6: 2rem;     --s-7: 3rem;     --s-8: 4rem;
  --s-9: 6rem;     --s-10: 8rem;

  --measure: 68ch;
  --gutter: clamp(1.25rem, 4vw, 4rem);
  --maxw: 1320px;

  --focus: 0 0 0 2px var(--bg), 0 0 0 4px var(--amber-500);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: var(--graphite-900);
    --bg-alt: var(--graphite-800);
    --ink: #eceae6;
    --ink-soft: #a7aeb5;
    --rule: #2a2f34;
    --rule-strong: #3d444b;
  }
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Plex Sans', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  font-size: var(--t-base);
  line-height: 1.6;
  font-feature-settings: 'kern' 1, 'liga' 1, 'cv05' 1;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img, svg { max-width: 100%; height: auto; display: block; }
h1, h2, h3, h4 { overflow-wrap: break-word; line-height: 1.1; letter-spacing: -0.022em; font-weight: 600; margin: 0; text-wrap: balance; }
p { margin: 0; text-wrap: pretty; }
a { color: inherit; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: 2px; }

/* ---------- Layout primitives ---------- */
.wrap { max-width: var(--maxw); margin-inline: auto; padding-inline: var(--gutter); }
.wrap-narrow { max-width: 860px; margin-inline: auto; padding-inline: var(--gutter); }
.section { padding-block: clamp(3.5rem, 8vw, 7rem); }
.section--alt { background: var(--bg-alt); }
.section--dark { background: var(--graphite-900); color: #eceae6; }
.section--dark { --ink: #eceae6; --ink-soft: #a7aeb5; --rule: #2a2f34; --rule-strong: #3d444b; --bg: var(--graphite-900); }
.rule { border: 0; border-top: 1px solid var(--rule); margin: 0; }
.stack > * + * { margin-top: var(--s-4); }
.measure { max-width: var(--measure); }

/* Editorial two-column: label rail + content. Collapses on small screens. */
.editorial { display: grid; gap: var(--s-5) var(--s-7); grid-template-columns: minmax(0,1fr); }
.editorial > * { min-width: 0; }
@media (min-width: 900px) { .editorial { grid-template-columns: 13rem minmax(0,1fr); } }

/* ---------- Typographic roles ---------- */
.eyebrow {
  overflow-wrap: anywhere;
  font-family: 'Plex Mono', ui-monospace, SFMono-Regular, monospace;
  font-size: var(--t-xs);
  font-weight: 500;
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0;
}
.eyebrow--accent { color: var(--amber-500); }
.display { font-size: var(--t-4xl); letter-spacing: -0.035em; font-weight: 600; }
.h1 { font-size: var(--t-3xl); letter-spacing: -0.03em; }
.h2 { font-size: var(--t-2xl); letter-spacing: -0.026em; }
.h3 { font-size: var(--t-xl); }
.h4 { font-size: var(--t-lg); }
.lede { font-size: var(--t-lg); color: var(--ink-soft); line-height: 1.5; }
.small { font-size: var(--t-sm); color: var(--ink-soft); }
.mono { font-family: 'Plex Mono', ui-monospace, SFMono-Regular, monospace; font-size: var(--t-sm); }
.num {
  font-family: 'Plex Mono', ui-monospace, monospace;
  font-size: var(--t-xs); font-weight: 500; color: var(--amber-500);
  letter-spacing: 0.06em;
}

/* ---------- Links ---------- */
.link {
  color: var(--ink); text-decoration: none;
  border-bottom: 1px solid var(--rule-strong);
  padding-bottom: 1px; transition: border-color .18s, color .18s;
}
.link:hover { border-color: var(--amber-500); color: var(--amber-500); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: var(--s-2);
  font-family: 'Plex Sans', sans-serif;
  font-size: var(--t-sm); font-weight: 500; letter-spacing: 0.01em;
  padding: 0.8125rem 1.375rem;
  border: 1px solid transparent; border-radius: 2px;
  text-decoration: none; cursor: pointer;
  transition: background .18s, border-color .18s, color .18s, transform .18s;
}
.btn:active { transform: translateY(1px); }
.btn--primary { background: var(--amber-500); color: #14100b; border-color: var(--amber-500); font-weight: 600; }
.btn--primary:hover { background: var(--amber-400); border-color: var(--amber-400); }
.btn--ghost { background: transparent; color: var(--ink); border-color: var(--rule-strong); }
.btn--ghost:hover { border-color: var(--ink); }
.btn__arrow { transition: transform .18s; }
.btn:hover .btn__arrow { transform: translateX(3px); }

/* ---------- Header ---------- */
.hdr {
  position: sticky; top: 0; z-index: 50;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--rule);
}
.hdr__in { display: flex; align-items: center; justify-content: space-between; gap: var(--s-5); min-height: 4rem; }
.hdr__brand { display: inline-flex; align-items: center; gap: 0.625rem; text-decoration: none; color: var(--ink); }
.hdr__nav { display: none; gap: var(--s-5); align-items: center; }
@media (min-width: 940px) { .hdr__nav { display: flex; } .hdr__toggle { display: none; } }
.hdr__nav a {
  font-size: var(--t-sm); text-decoration: none; color: var(--ink-soft);
  padding-block: 0.25rem; border-bottom: 1px solid transparent; transition: color .18s, border-color .18s;
}
.hdr__nav a:hover, .hdr__nav a[aria-current='page'] { color: var(--ink); border-color: var(--amber-500); }
.hdr__toggle {
  background: none; border: 1px solid var(--rule-strong); border-radius: 2px;
  padding: 0.5rem 0.75rem; cursor: pointer; color: var(--ink);
  font-family: 'Plex Mono', monospace; font-size: var(--t-xs);
}
.hdr__mobile { display: none; border-top: 1px solid var(--rule); padding-block: var(--s-4); }
.hdr__mobile[data-open='true'] { display: block; }
@media (min-width: 940px) { .hdr__mobile { display: none !important; } }
.hdr__mobile a { display: block; padding: 0.75rem 0; text-decoration: none; color: var(--ink); border-bottom: 1px solid var(--rule); }

/* ---------- Hero ---------- */
.hero { padding-block: clamp(3rem, 7vw, 6rem) clamp(2.5rem, 5vw, 4rem); }
.hero__grid { display: grid; gap: var(--s-7); grid-template-columns: minmax(0,1fr); align-items: start; }
.hero__grid > * { min-width: 0; }
@media (min-width: 1040px) { .hero__grid { grid-template-columns: minmax(0,1fr) minmax(0,1.05fr); gap: var(--s-8); align-items: center; } }
.hero__actions { display: flex; flex-wrap: wrap; gap: var(--s-3); margin-top: var(--s-6); }

/* ---------- Spec list (technical key/value rows) ---------- */
.spec { border-top: 1px solid var(--rule); }
.spec__row {
  display: grid; grid-template-columns: minmax(0,1fr); gap: var(--s-1);
  padding-block: var(--s-4); border-bottom: 1px solid var(--rule);
}
@media (min-width: 720px) { .spec__row { grid-template-columns: 15rem minmax(0,1fr); gap: var(--s-5); } }
.spec__row > * { min-width: 0; overflow-wrap: anywhere; }
.spec__k { font-family: 'Plex Mono', monospace; font-size: var(--t-sm); color: var(--ink-soft); }
.spec__v { color: var(--ink); }

/* ---------- Layer stack (physical → cloud) ---------- */
.layers { border: 1px solid var(--rule); border-radius: 3px; overflow: hidden; }
.layer {
  display: grid; grid-template-columns: 3.25rem minmax(0,1fr); align-items: start;
  gap: var(--s-4); padding: var(--s-5); border-bottom: 1px solid var(--rule);
  transition: background .2s;
}
.layer:last-child { border-bottom: 0; }
.layer:hover { background: var(--bg-alt); }
.layer__n {
  font-family: 'Plex Mono', monospace; font-size: var(--t-xs); font-weight: 500;
  color: var(--amber-500); padding-top: 0.3rem; letter-spacing: 0.06em;
}
.layer__t { font-size: var(--t-lg); font-weight: 600; margin-bottom: var(--s-2); letter-spacing: -0.02em; }
.layer__d { color: var(--ink-soft); font-size: var(--t-base); }
.layer__tags { display: flex; flex-wrap: wrap; gap: var(--s-2); margin-top: var(--s-3); }
.tag {
  font-family: 'Plex Mono', monospace; font-size: 0.6875rem; letter-spacing: 0.05em;
  padding: 0.2rem 0.5rem; border: 1px solid var(--rule-strong); border-radius: 2px;
  color: var(--ink-soft);
}

/* ---------- Capability grid ---------- */
.grid-2 { display: grid; gap: var(--s-6); grid-template-columns: minmax(0,1fr); }
.grid-2 > * { min-width: 0; }
@media (min-width: 760px) { .grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
.grid-3 { display: grid; gap: var(--s-6); grid-template-columns: minmax(0,1fr); }
.grid-3 > * { min-width: 0; }
@media (min-width: 700px) { .grid-3 { grid-template-columns: repeat(2, minmax(0,1fr)); } }
@media (min-width: 1060px) { .grid-3 { grid-template-columns: repeat(3, minmax(0,1fr)); } }

.cap { padding-top: var(--s-4); border-top: 2px solid var(--ink); }
.cap__t { font-size: var(--t-lg); font-weight: 600; margin-bottom: var(--s-2); letter-spacing: -0.02em; }
.cap__d { color: var(--ink-soft); }

/* ---------- Steps ---------- */
.steps { counter-reset: step; border-top: 1px solid var(--rule); }
.step {
  display: grid; grid-template-columns: minmax(0,1fr); gap: var(--s-2);
  padding-block: var(--s-5); border-bottom: 1px solid var(--rule);
}
@media (min-width: 820px) { .step { grid-template-columns: 4rem 16rem minmax(0,1fr); gap: var(--s-5); align-items: start; } }
.step > * { min-width: 0; }
.step__n { font-family: 'Plex Mono', monospace; font-size: var(--t-sm); color: var(--amber-500); font-weight: 500; }
.step__t { font-size: var(--t-lg); font-weight: 600; letter-spacing: -0.02em; }
.step__d { color: var(--ink-soft); }

/* ---------- Callout ---------- */
.callout {
  border-left: 2px solid var(--amber-500);
  background: var(--amber-dim);
  padding: var(--s-5);
  border-radius: 0 3px 3px 0;
}

/* ---------- Forms ---------- */
.form { display: grid; gap: var(--s-5); }
.field { display: grid; gap: var(--s-2); }
.field label { font-family: 'Plex Mono', monospace; font-size: var(--t-xs); letter-spacing: 0.09em; text-transform: uppercase; color: var(--ink-soft); }
.field .req { color: var(--amber-500); }
.field input, .field select, .field textarea {
  font-family: inherit; font-size: var(--t-base); color: var(--ink);
  background: var(--bg); border: 1px solid var(--rule-strong); border-radius: 2px;
  padding: 0.75rem 0.875rem; width: 100%;
  transition: border-color .18s, box-shadow .18s;
}
.field textarea { min-height: 8rem; resize: vertical; }
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible { border-color: var(--amber-500); }
.field input[aria-invalid='true'], .field textarea[aria-invalid='true'], .field select[aria-invalid='true'] { border-color: var(--alert-red); }
.field__err { font-size: var(--t-sm); color: var(--alert-red); min-height: 0; }
.field__hint { font-size: var(--t-sm); color: var(--ink-soft); }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

.form__status { padding: var(--s-4); border-radius: 2px; font-size: var(--t-base); }
.form__status--ok { background: rgba(75,168,46,.12); border-left: 2px solid var(--signal-green); }
.form__status--err { background: rgba(209,70,47,.1); border-left: 2px solid var(--alert-red); }

/* ---------- Footer ---------- */
.ftr { border-top: 1px solid var(--rule); padding-block: var(--s-7) var(--s-6); background: var(--bg-alt); }
.ftr__grid { display: grid; gap: var(--s-6); grid-template-columns: 1fr; }
@media (min-width: 780px) { .ftr__grid { grid-template-columns: 2fr 1fr 1fr; } }
.ftr__grid > * { min-width: 0; }
.ftr h3 { font-family: 'Plex Mono', monospace; font-size: var(--t-xs); letter-spacing: 0.1em; text-transform: uppercase; color: var(--ink-soft); font-weight: 500; margin-bottom: var(--s-3); }
.ftr a { display: block; text-decoration: none; color: var(--ink-soft); padding-block: 0.3rem; font-size: var(--t-sm); }
.ftr a:hover { color: var(--amber-500); }
.ftr__base { margin-top: var(--s-7); padding-top: var(--s-4); border-top: 1px solid var(--rule); display: flex; flex-wrap: wrap; gap: var(--s-4); justify-content: space-between; }

/* ---------- Diagram ---------- */
.diagram { width: 100%; }
.diagram text { font-family: 'Plex Mono', ui-monospace, monospace; }
.dg-node { fill: none; stroke: var(--rule-strong); stroke-width: 1; }
.dg-node--live { stroke: var(--amber-500); }
.dg-label { fill: var(--ink); font-size: 13px; font-weight: 500; letter-spacing: 0.03em; }
.dg-sub { fill: var(--ink-soft); font-size: 10.5px; letter-spacing: 0.03em; }
.dg-pow { stroke: var(--steel-500); stroke-width: 1.5; fill: none; }
.dg-ctl { stroke: var(--amber-500); stroke-width: 1.25; fill: none; stroke-dasharray: 4 3; }
.dg-bound { stroke: var(--rule-strong); stroke-width: 1; stroke-dasharray: 2 4; fill: none; }

/* Control-path dash flow — the ONLY looping animation on the site. */
@media (prefers-reduced-motion: no-preference) {
  .dg-ctl--flow { animation: dash 2.4s linear infinite; }
  @keyframes dash { to { stroke-dashoffset: -28; } }
}

/* ---------- Skip link ---------- */
.skip {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--amber-500); color: #14100b; padding: 0.75rem 1rem;
  font-size: var(--t-sm); font-weight: 600; text-decoration: none;
}
.skip:focus { left: 0; }

/* ---------- Utilities ----------
   NOTE: there are deliberately NO `style="..."` attributes anywhere in this site.
   The Content-Security-Policy sets `style-src 'self'` with no 'unsafe-inline', so an
   inline style attribute is silently dropped by the browser — it does not warn, the
   rule simply never applies. Anything that would have been an inline style has to be
   a class here instead. Adding 'unsafe-inline' to make inline styles work would be the
   wrong trade on a site whose subject is security.
   ------------------------------------------------------------------------------ */
/* The browser's own rule for [hidden] is `display: none`, but ANY component rule that
   sets its own display beats it on specificity. `.form { display: grid }` did exactly
   that: after a successful submit `form.hidden = true` had no visible effect, so the
   filled-in form stayed on screen next to the success message with its button stuck on
   "Sending…" — inviting a duplicate submission. This has to win over every component. */
[hidden] { display: none !important; }

.vh { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.mt-2 { margin-top: var(--s-2); } .mt-5 { margin-top: var(--s-5); }
.mt-6 { margin-top: var(--s-6); } .mt-7 { margin-top: var(--s-7); }
.mb-2 { margin-bottom: var(--s-2); } .mb-3 { margin-bottom: var(--s-3); }
.mb-5 { margin-bottom: var(--s-5); } .mb-6 { margin-bottom: var(--s-6); } .mb-7 { margin-bottom: var(--s-7); }
.m-0 { margin: 0; }
.mx-auto { margin-inline: auto; }
.pad-y-8 { padding-block: var(--s-8); }
.center { text-align: center; }
.text-left { text-align: left; }
.text-sm { font-size: var(--t-sm); }
.text-accent { color: var(--amber-500); }
.text-soft { color: var(--ink-soft); }

/* Constrained measures. Separate from .measure (68ch) where a tighter line is wanted. */
.mw-46 { max-width: 46ch; } .mw-50 { max-width: 50ch; }
.mw-52 { max-width: 52ch; } .mw-56 { max-width: 56ch; } .mw-64 { max-width: 64ch; }

/* Wordmark next to the logo glyph. */
.brand__word { font-weight: 600; letter-spacing: -0.02em; font-size: 1.0625rem; }
.brand__word--sm { font-weight: 600; letter-spacing: -0.02em; }

/* Centred call-to-action row. */
.hero__actions--center { justify-content: center; }

/* Contact page: the "what happens next" rail sticks alongside the form on wide screens. */
.rail { position: sticky; top: 6rem; }
@media (max-width: 899px) { .rail { position: static; } }

/* Numbered spec row — narrow first column for an ordinal instead of a label. */
.spec__row--num { grid-template-columns: 2rem minmax(0, 1fr); }
@media (min-width: 720px) { .spec__row--num { grid-template-columns: 2rem minmax(0, 1fr); } }

/* Long-form note on the Insights page. */
.note { border-top: 2px solid var(--ink); padding-top: var(--s-5); }
