/* ============================================================================
   QCF design system — implements docs/qcf-ui-ux.md §2
   Loaded by the public site, the partner portal, and the post-checkout pages.

   Design thesis: "Guardrails, not a cage." Calm, protective, supportive. The two
   moods this must actively avoid are PUNITIVE (alarm-red, shaming, prison-bars)
   and SURVEILLANCE-CREEPY (cold, clinical, spyware). That is why there is no pure
   red anywhere in here, why the alert colour is a measured coral, and why the
   warmth colours (Sand, Fraunces) are load-bearing rather than decorative.
   ============================================================================ */

/* ----------------------------------------------------------------- fonts
   Self-hosted latin subsets. A filter product should not phone a font CDN on
   every page load — the whole pitch is that QCF minimises what leaves the
   machine, and hotlinking Google Fonts would leak a request per visitor.
   IBM Plex Sans ships as one variable file covering 400-600.               */

@font-face {
  font-family: 'Fraunces';
  src: url('/fonts/fraunces-600.woff2') format('woff2');
  font-weight: 600;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
    U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215;
}
@font-face {
  font-family: 'IBM Plex Sans';
  src: url('/fonts/plex-sans-var.woff2') format('woff2');
  font-weight: 400 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Mono';
  src: url('/fonts/plex-mono-400.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'IBM Plex Mono';
  src: url('/fonts/plex-mono-500.woff2') format('woff2');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

/* ----------------------------------------------------------------- tokens */

:root {
  /* Palette (§2). Names match the doc so the two stay legible against each other. */
  --ink: #1b2a41;
  --signal: #2a9d8f;
  --mist: #f4f6f7;
  --card: #ffffff;
  --sand: #e9c46a;
  --coral: #e07a5f;
  --slate: #5c6b7a;
  --hairline: #e2e8ea;

  /* Accessible partners for the three accent hues.
     The doc flags "check Sand/coral on white" — they do fail. Measured against
     white: Signal 3.3:1, Coral 3.0:1, Sand 1.7:1. All are fine as FILLS and as
     large text, none are safe for body copy or for white text sitting on them.
     These deepened variants all clear 4.5:1, so the rule throughout is:
     bright token = fill, deep token = text.                                   */
  --signal-deep: #1f7a6f; /* 5.2:1 with white on top */
  --coral-deep: #b4523a;  /* 5.0:1 with white on top */
  --sand-deep: #8a6414;   /* 5.4:1 on white */

  --signal-wash: #e9f5f3;
  --coral-wash: #fbeee9;
  --sand-wash: #fdf6e6;

  /* Type (§2). 40/28/20 display & headings, 16 body, 14 secondary, 13 mono. */
  --font-display: 'Fraunces', Georgia, 'Times New Roman', serif;
  --font-ui: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'Cascadia Mono', Consolas, monospace;

  --text-display: 2.5rem;
  --text-h1: 1.75rem;
  --text-h2: 1.25rem;
  --text-body: 1rem;
  --text-small: 0.875rem;
  --text-mono: 0.8125rem;

  /* 8px spacing grid (§2). Generous whitespace — calm needs room. */
  --s1: 0.5rem;
  --s2: 1rem;
  --s3: 1.5rem;
  --s4: 2rem;
  --s5: 3rem;
  --s6: 4rem;

  --radius: 12px;      /* soft, not sharp/punitive; not pill-round/toy */
  --radius-sm: 8px;
  --radius-pill: 999px;

  --shadow-card: 0 1px 2px rgba(27, 42, 65, 0.04), 0 4px 16px rgba(27, 42, 65, 0.05);
  --shadow-lift: 0 2px 4px rgba(27, 42, 65, 0.06), 0 12px 32px rgba(27, 42, 65, 0.09);

  /* Semantic surface aliases — every rule below uses these, never raw palette
     names, which is what lets dark mode be a token swap instead of a rewrite. */
  --bg: var(--mist);
  --surface: var(--card);
  --surface-sunken: #eef1f3;
  --text: var(--ink);
  --text-muted: var(--slate);
  --border: var(--hairline);
  --accent: var(--signal);
  --accent-text: var(--signal-deep);
  --accent-wash: var(--signal-wash);
  --alert: var(--coral);
  --alert-text: var(--coral-deep);
  --alert-wash: var(--coral-wash);
  --warm: var(--sand);
  --warm-text: var(--sand-deep);
  --warm-wash: var(--sand-wash);
  --focus: #2f6feb;
}

/* Dark mode. The doc ships the portal light-first and the tray dark (§2), but a
   partner checking a 2am tamper alert on a phone is the single most likely
   reader of this UI — so honouring the OS preference is not a nicety here. */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121b28;
    --surface: #1b2a41;
    --surface-sunken: #16222f;
    --text: #eef2f5;
    --text-muted: #9fb0c0;
    --border: #2c3f57;
    --accent: #45b8a9;
    --accent-text: #6fd3c4;
    --accent-wash: #17322f;
    --alert: #e8907a;
    --alert-text: #f0a892;
    --alert-wash: #38241d;
    --warm: #edcf85;
    --warm-text: #edcf85;
    --warm-wash: #33291245;
    --focus: #7aa5f5;
    --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
    --shadow-lift: 0 2px 4px rgba(0, 0, 0, 0.35), 0 12px 32px rgba(0, 0, 0, 0.35);
  }
}

/* ------------------------------------------------------------------- base */

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

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

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

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.25;
  font-weight: 600;
  letter-spacing: -0.01em;
}

/* Fraunces is used sparingly — large headings only (§2). Anything smaller than
   an h2 stays in Plex, or the warmth turns into noise. */
h1 {
  font-family: var(--font-display);
  font-size: var(--text-h1);
}
h2 {
  font-size: var(--text-h2);
}
h3 {
  font-size: var(--text-body);
}

p {
  margin: 0;
}

a {
  color: var(--accent-text);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

code,
kbd,
.mono {
  font-family: var(--font-mono);
  font-size: var(--text-mono);
}

/* Visible keyboard focus everywhere (§12). :focus-visible so a mouse click on a
   card doesn't paint a ring, but tabbing always does. */
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

.hidden {
  display: none !important;
}

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

.eyebrow {
  font-size: var(--text-small);
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.lede {
  font-size: 1.0625rem;
  color: var(--text-muted);
  max-width: 60ch;
}

.muted {
  color: var(--text-muted);
  font-size: var(--text-small);
}

/* ====================================================================
   THE STATUS LIGHT — §1 signature element
   One calm, gently breathing indicator, everywhere the filter's live
   state appears. A lighthouse beam: steady = safe.

   It encodes real information (the heartbeat), so the states map onto
   what the API actually returns from liveStatus():
     protected            -> steady teal, slow breathing glow
     pending | offgrid    -> amber, slower pulse
     offline | tampered   -> coral, no glow (needs the friend)

   Colour alone never carries the meaning — every use is paired with a
   text label, and the accessible name is set on the element (§12).
   ==================================================================== */

.status-light {
  --light-size: 12px;
  --light: var(--signal);
  --light-glow: rgba(42, 157, 143, 0.45);
  display: inline-block;
  flex: none;
  width: var(--light-size);
  height: var(--light-size);
  border-radius: 50%;
  background: var(--light);
  box-shadow: 0 0 0 0 var(--light-glow), 0 0 10px 1px var(--light-glow);
  animation: qcf-breathe 4s ease-in-out infinite;
}

/* Attention — a request pending, or a soft warning. Slower pulse than
   protected, so "something wants you" reads as calmer than "all is well"
   is energetic. Amber, never red. */
.status-light[data-state='pending'],
.status-light[data-state='offgrid'],
.status-light[data-state='attention'] {
  --light: var(--sand);
  --light-glow: rgba(233, 196, 106, 0.5);
  animation-duration: 6s;
}

/* Offline / tampered — coral and STILL. The absence of the breath is the
   signal: the lighthouse stopped turning. Deliberately not a fast blink,
   which would read as an alarm and push the whole product punitive. */
.status-light[data-state='offline'],
.status-light[data-state='tampered'],
.status-light[data-state='removed'] {
  --light: var(--coral);
  --light-glow: rgba(224, 122, 95, 0);
  animation: none;
  box-shadow: none;
}

@keyframes qcf-breathe {
  0%,
  100% {
    box-shadow: 0 0 0 0 var(--light-glow), 0 0 8px 0 var(--light-glow);
  }
  50% {
    box-shadow: 0 0 0 5px transparent, 0 0 18px 3px var(--light-glow);
  }
}

/* §12: reduced motion freezes the breathing to a static glow — it does not
   remove the glow, because the glow is what distinguishes "up" from "down". */
@media (prefers-reduced-motion: reduce) {
  .status-light {
    animation: none !important;
    box-shadow: 0 0 0 3px var(--light-glow), 0 0 14px 2px var(--light-glow);
  }
  .status-light[data-state='offline'],
  .status-light[data-state='tampered'],
  .status-light[data-state='removed'] {
    box-shadow: none;
  }
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

.status-light.lg {
  --light-size: 20px;
}
.status-light.xl {
  --light-size: 56px;
}

/* The hero lamp on the marketing page — the same component, scaled up, with a
   second soft halo so it reads as a light source rather than a dot. */
.status-lamp {
  position: relative;
  display: grid;
  place-items: center;
  width: 180px;
  height: 180px;
}
.status-lamp::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent-wash) 0%, transparent 68%);
  animation: qcf-halo 4s ease-in-out infinite;
}
@keyframes qcf-halo {
  0%,
  100% {
    transform: scale(0.9);
    opacity: 0.75;
  }
  50% {
    transform: scale(1.06);
    opacity: 1;
  }
}

/* A status line: light + label, used in headers and cards. */
.status-line {
  display: flex;
  align-items: center;
  gap: var(--s1);
  font-weight: 500;
}

/* --------------------------------------------------------------- surfaces */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--s3);
  box-shadow: var(--shadow-card);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--s2);
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: var(--s2);
}

/* Stat tile (§2 components). Label above, figure below in Fraunces so the
   number carries the warmth rather than looking like a dashboard readout. */
.card.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--s2) var(--s3);
}
.card.stat span {
  font-size: var(--text-small);
  color: var(--text-muted);
}
.card.stat strong {
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

/* Empty states are an invitation, not a blank (§10). */
.card.empty,
.empty {
  color: var(--text-muted);
  text-align: center;
  padding: var(--s4) var(--s3);
}

/* --------------------------------------------------------------- controls */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s1);
  /* §12: hit targets >= 44px. */
  min-height: 44px;
  padding: 0 var(--s3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: var(--text-body);
  font-weight: 500;
  line-height: 1;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}
.button:hover:not(:disabled) {
  background: var(--surface-sunken);
}
.button:active:not(:disabled) {
  transform: translateY(1px);
}
.button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.button.primary,
.button.allow {
  background: var(--signal-deep);
  border-color: var(--signal-deep);
  color: #fff;
}
.button.primary:hover:not(:disabled),
.button.allow:hover:not(:disabled) {
  background: #196257;
  border-color: #196257;
}

/* "Block" and "Deny" are outlined, not filled. A wall of solid alert-coloured
   buttons would make the partner's job feel like punishing someone — the doc is
   explicit that we inform rather than scream (§2). The destructive weight is
   carried by the confirm dialog, not by the paint. */
.button.block {
  background: transparent;
  border-color: var(--alert);
  color: var(--alert-text);
}
.button.block:hover:not(:disabled) {
  background: var(--alert-wash);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--s1);
}

label {
  display: block;
  font-size: var(--text-small);
  font-weight: 500;
  color: var(--text);
}

input[type='text'],
input[type='email'],
input[type='number'],
select,
textarea {
  width: 100%;
  min-height: 44px;
  margin-top: 6px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: var(--text-body);
}
textarea {
  min-height: 120px;
  font-family: var(--font-mono);
  font-size: var(--text-mono);
  line-height: 1.7;
  resize: vertical;
}
input[type='checkbox'] {
  accent-color: var(--signal-deep);
  width: 18px;
  height: 18px;
  margin: 0;
}

fieldset {
  margin: 0;
  padding: var(--s3) 0 0;
  border: 0;
  border-top: 1px solid var(--border);
}
legend {
  padding: 0;
  font-size: var(--text-small);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--text-muted);
}

/* Rule chip (§2 components) — whitelist / blacklist / category / app. */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: var(--text-mono);
}
.chip.allow {
  background: var(--accent-wash);
  border-color: transparent;
  color: var(--accent-text);
}
.chip.block {
  background: var(--alert-wash);
  border-color: transparent;
  color: var(--alert-text);
}
.chip.warm {
  background: var(--warm-wash);
  border-color: transparent;
  color: var(--warm-text);
}

/* Alert banner + inline notice. Errors are plain and actionable, never an
   apology and never vague (§10). */
#notice,
.notice {
  min-height: 1.5rem;
  font-size: var(--text-small);
  color: var(--text-muted);
}
#notice:not(:empty),
.notice:not(:empty) {
  padding: 10px var(--s2);
  border-radius: var(--radius-sm);
  background: var(--accent-wash);
  color: var(--accent-text);
}
#notice.error,
.notice.error,
.error {
  background: var(--alert-wash);
  color: var(--alert-text);
}
p.error {
  padding: 10px var(--s2);
  border-radius: var(--radius-sm);
  font-size: var(--text-small);
}

/* Mono is content-driven (§2): logs, keys, timestamps, domains ARE data. */
.domain,
.mono-data {
  font-family: var(--font-mono);
  font-size: var(--text-mono);
}

/* --------------------------------------------------------------- tables */

.table-wrap {
  padding: 0;
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-small);
}
thead th {
  position: sticky;
  top: 0;
  padding: var(--s2) var(--s3);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: var(--text-small);
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}
tbody td {
  padding: 12px var(--s3);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tbody tr:last-child td {
  border-bottom: 0;
}
tbody tr:hover {
  background: var(--surface-sunken);
}

/* ------------------------------------------------------------------ motion
   Restrained (§2): minimal fades on reveal, alerts slide in from the top. */

@keyframes qcf-fade-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}
.panel:not(.hidden),
.reveal {
  animation: qcf-fade-in 0.24s ease-out;
}
