/* ==========================================================================
   REHUMANIZE DESIGN SYSTEM — shared by the dashboard and the public website
   --------------------------------------------------------------------------
   Documented in DESIGN-SYSTEM.md (project root). Rules that matter:
   - Amber #F5A623 is the brand/verdict color. It appears in the logo and
     wherever data means "AI-detected" — nowhere else. Never use it for
     buttons, links, or decoration.
   - Both themes ship: light is default, [data-theme="dark"] on <html>
     switches; prefers-color-scheme is honored until the user picks.
   - All motion respects prefers-reduced-motion.
   ========================================================================== */

/* ── Fonts (load via Google Fonts link in each page <head>):
   Sora:600,700 · IBM Plex Sans:400,500,600 · IBM Plex Mono:400,500 */

:root {
  /* ── Ink & surfaces (light) ─────────────────────────────────────────── */
  --rh-bg:            #F2F5F7;  /* cool mist page background */
  --rh-surface:       #FFFFFF;  /* cards, panels */
  --rh-surface-2:     #E9EEF1;  /* inset wells, table stripes, code blocks */
  --rh-ink:           #16232E;  /* primary text — deep harbor blue-black */
  --rh-ink-2:         #4C5D6B;  /* secondary text */
  --rh-ink-3:         #5F7280;  /* captions, axis labels — AA on bg/surface */
  --rh-line:          #D5DDE3;  /* borders */
  --rh-line-faint:    #E4EAEE;  /* hairline data rules */

  /* ── Interactive accent — "instrument cyan" ─────────────────────────── */
  --rh-accent:        #0F6E84;  /* links, primary buttons, active states */
  --rh-accent-hover:  #0B5A6C;
  --rh-accent-soft:   #E0EEF1;  /* selected-row wash, active nav item */
  --rh-on-accent:     #FFFFFF;

  /* ── Brand amber — logo + AI-verdict data ONLY ──────────────────────── */
  --rh-brand:         #F5A623;  /* the logo and the "AI-detected" mark */
  --rh-brand-ink:     #9A6A00;  /* AA text-safe amber for light surfaces */
  --rh-brand-soft:    #FBEED3;  /* AI-verdict chip/row background */

  /* ── Semantic ───────────────────────────────────────────────────────── */
  --rh-success:       #1A7F4B;
  --rh-success-soft:  #DDF0E5;
  --rh-warning:       #8A5A00;
  --rh-warning-soft:  #F6ECD4;
  --rh-error:         #B3261E;
  --rh-error-soft:    #F8E2E0;
  --rh-on-error:      #FFFFFF;
  --rh-info:          #1D62C4;
  --rh-info-soft:     #E0EAF9;

  /* ── Data visualization ─────────────────────────────────────────────── */
  /* Verdict encodings — fixed meanings, never reassigned */
  --rh-viz-ai:        #F5A623;  /* AI-detected — matches the product mark */
  --rh-viz-human:     #4477AA;
  --rh-viz-uncertain: #98A6B0;
  /* Categorical series (Paul Tol bright — colorblind-safe), in order */
  --rh-viz-1: #4477AA;
  --rh-viz-2: #66CCEE;
  --rh-viz-3: #228833;
  --rh-viz-4: #CCBB44;
  --rh-viz-5: #EE6677;
  --rh-viz-6: #AA3377;
  --rh-viz-7: #BBBBBB;
  --rh-viz-grid:      #E4EAEE;  /* chart gridlines = hairline token */
  --rh-viz-axis:      #5F7280;  /* axis text = ink-3 */

  /* ── Typography ─────────────────────────────────────────────────────── */
  --rh-font-display: 'Sora', system-ui, sans-serif;
  --rh-font-body: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
  --rh-font-mono: 'IBM Plex Mono', ui-monospace, monospace;
  /* Scale — 1.250 major third from 16px base */
  --rh-text-xs:   0.75rem;   /* 12 — captions, axis labels */
  --rh-text-sm:   0.875rem;  /* 14 — secondary UI, table body */
  --rh-text-base: 1rem;      /* 16 — body */
  --rh-text-lg:   1.25rem;   /* 20 — card titles, h4 */
  --rh-text-xl:   1.5625rem; /* 25 — h3 */
  --rh-text-2xl:  1.9375rem; /* 31 — h2 */
  --rh-text-3xl:  2.4375rem; /* 39 — h1 */
  --rh-text-4xl:  3rem;      /* 48 — hero display */
  --rh-leading-tight: 1.2;
  --rh-leading-body:  1.55;

  /* ── Spacing (4px base) ─────────────────────────────────────────────── */
  --rh-space-1: 4px;  --rh-space-2: 8px;   --rh-space-3: 12px;
  --rh-space-4: 16px; --rh-space-5: 24px;  --rh-space-6: 32px;
  --rh-space-7: 48px; --rh-space-8: 64px;  --rh-space-9: 96px;

  /* ── Radius ─────────────────────────────────────────────────────────── */
  --rh-radius-sm:   4px;   /* chips, code spans */
  --rh-radius-md:   8px;   /* buttons, inputs, cards */
  --rh-radius-lg:   14px;  /* modals, feature panels */
  --rh-radius-full: 999px; /* pills, toggles */

  /* ── Elevation — shadows tinted with the ink hue, never flat gray ───── */
  --rh-shadow-1: 0 1px 2px rgba(22, 35, 46, 0.06);
  --rh-shadow-2: 0 2px 8px rgba(22, 35, 46, 0.08), 0 1px 2px rgba(22, 35, 46, 0.05);
  --rh-shadow-3: 0 8px 28px rgba(22, 35, 46, 0.12), 0 2px 6px rgba(22, 35, 46, 0.06);

  /* ── Motion ─────────────────────────────────────────────────────────── */
  --rh-dur-fast:   120ms;  /* hover/press feedback */
  --rh-dur-base:   200ms;  /* toggles, fades, chips */
  --rh-dur-slow:   320ms;  /* panels, modals, theme switch */
  --rh-dur-page:   560ms;  /* route/section transitions, chart draw-in */
  --rh-ease:       cubic-bezier(0.2, 0, 0, 1);      /* standard decelerate */
  --rh-ease-in:    cubic-bezier(0.3, 0, 0.8, 0.15); /* exits */
  --rh-ease-swing: cubic-bezier(0.34, 1.3, 0.64, 1); /* toggle knobs, chips */

  color-scheme: light;
}

/* ── Dark theme ──────────────────────────────────────────────────────── */
[data-theme="dark"] {
  --rh-bg:            #10181F;
  --rh-surface:       #182430;
  --rh-surface-2:     #1F2E3C;
  --rh-ink:           #E8EDF1;
  --rh-ink-2:         #A9B7C2;
  --rh-ink-3:         #8A9BA8;
  --rh-line:          #2C3D4C;
  --rh-line-faint:    #22323F;

  --rh-accent:        #4FB3C9;
  --rh-accent-hover:  #6FC4D6;
  --rh-accent-soft:   #143441;
  --rh-on-accent:     #0C1519;

  --rh-brand-ink:     #F5C46B; /* amber lightened for dark-surface text */
  --rh-brand-soft:    #3A2E13;

  --rh-success:       #55C489;
  --rh-success-soft:  #14352A;
  --rh-warning:       #E0B25C;
  --rh-warning-soft:  #38301A;
  --rh-error:         #F2938C;
  --rh-error-soft:    #43201E;
  --rh-on-error:      #2A100D;
  --rh-info:          #7FAEE8;
  --rh-info-soft:     #1A2C45;

  --rh-viz-human:     #6E9FD1;
  --rh-viz-uncertain: #5F707C;
  --rh-viz-1: #6E9FD1; --rh-viz-2: #66CCEE; --rh-viz-3: #4FBB6B;
  --rh-viz-4: #D9C75C; --rh-viz-5: #EE7788; --rh-viz-6: #C065A0;
  --rh-viz-7: #8A9AA6;
  --rh-viz-grid:      #22323F;
  --rh-viz-axis:      #6E7E8B;

  --rh-shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --rh-shadow-2: 0 2px 8px rgba(0, 0, 0, 0.45), 0 1px 2px rgba(0, 0, 0, 0.3);
  --rh-shadow-3: 0 8px 28px rgba(0, 0, 0, 0.55), 0 2px 6px rgba(0, 0, 0, 0.35);

  color-scheme: dark;
}

/* System preference applies until the user chooses (data-theme unset) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --rh-bg: #10181F; --rh-surface: #182430; --rh-surface-2: #1F2E3C;
    --rh-ink: #E8EDF1; --rh-ink-2: #A9B7C2; --rh-ink-3: #8A9BA8;
    --rh-line: #2C3D4C; --rh-line-faint: #22323F;
    --rh-accent: #4FB3C9; --rh-accent-hover: #6FC4D6;
    --rh-accent-soft: #143441; --rh-on-accent: #0C1519;
    --rh-brand-ink: #F5C46B; --rh-brand-soft: #3A2E13;
    --rh-success: #55C489; --rh-success-soft: #14352A;
    --rh-warning: #E0B25C; --rh-warning-soft: #38301A;
    --rh-error: #F2938C; --rh-error-soft: #43201E; --rh-on-error: #2A100D;
    --rh-info: #7FAEE8; --rh-info-soft: #1A2C45;
    --rh-viz-human: #6E9FD1; --rh-viz-uncertain: #5F707C;
    --rh-viz-1: #6E9FD1; --rh-viz-2: #66CCEE; --rh-viz-3: #4FBB6B;
    --rh-viz-4: #D9C75C; --rh-viz-5: #EE7788; --rh-viz-6: #C065A0;
    --rh-viz-7: #8A9AA6;
    --rh-viz-grid: #22323F; --rh-viz-axis: #6E7E8B;
    --rh-shadow-1: 0 1px 2px rgba(0,0,0,0.4);
    --rh-shadow-2: 0 2px 8px rgba(0,0,0,0.45), 0 1px 2px rgba(0,0,0,0.3);
    --rh-shadow-3: 0 8px 28px rgba(0,0,0,0.55), 0 2px 6px rgba(0,0,0,0.35);
    color-scheme: dark;
  }
}

/* ==========================================================================
   BASE
   ========================================================================== */

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--rh-bg);
  color: var(--rh-ink);
  font-family: var(--rh-font-body);
  font-size: var(--rh-text-base);
  line-height: var(--rh-leading-body);
  -webkit-font-smoothing: antialiased;
  transition: background-color var(--rh-dur-slow) var(--rh-ease),
              color var(--rh-dur-slow) var(--rh-ease);
}

h1, h2, h3, h4 {
  font-family: var(--rh-font-display);
  font-weight: 600;
  line-height: var(--rh-leading-tight);
  color: var(--rh-ink);
  margin: 0 0 var(--rh-space-4);
  letter-spacing: -0.01em;
}
h1 { font-size: var(--rh-text-3xl); }
h2 { font-size: var(--rh-text-2xl); }
h3 { font-size: var(--rh-text-xl); }
h4 { font-size: var(--rh-text-lg); }

p { margin: 0 0 var(--rh-space-4); max-width: 70ch; }

a {
  color: var(--rh-accent);
  text-decoration: none;
  transition: color var(--rh-dur-fast) var(--rh-ease);
}
a:hover { color: var(--rh-accent-hover); text-decoration: underline; }

code, .rh-mono {
  font-family: var(--rh-font-mono);
  font-size: 0.9em;
}
code {
  background: var(--rh-surface-2);
  border-radius: var(--rh-radius-sm);
  padding: 1px 5px;
}

/* Data values line up in columns */
.rh-num { font-family: var(--rh-font-mono); font-variant-numeric: tabular-nums; }

/* Visible keyboard focus, everywhere */
:focus-visible {
  outline: 2px solid var(--rh-accent);
  outline-offset: 2px;
  border-radius: var(--rh-radius-sm);
}

/* ==========================================================================
   COMPONENTS
   ========================================================================== */

/* ── Buttons ─────────────────────────────────────────────────────────── */
.rh-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--rh-space-2);
  font-family: var(--rh-font-body);
  font-size: var(--rh-text-sm);
  font-weight: 600;
  padding: 9px 18px;
  border-radius: var(--rh-radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color var(--rh-dur-fast) var(--rh-ease),
              border-color var(--rh-dur-fast) var(--rh-ease),
              color var(--rh-dur-fast) var(--rh-ease),
              transform var(--rh-dur-fast) var(--rh-ease),
              box-shadow var(--rh-dur-fast) var(--rh-ease);
}
.rh-btn:active { transform: scale(0.97); }
.rh-btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.rh-btn-primary { background: var(--rh-accent); color: var(--rh-on-accent); }
.rh-btn-primary:hover:not(:disabled) { background: var(--rh-accent-hover); box-shadow: var(--rh-shadow-1); }

.rh-btn-secondary {
  background: var(--rh-surface);
  color: var(--rh-ink);
  border-color: var(--rh-line);
}
.rh-btn-secondary:hover:not(:disabled) { border-color: var(--rh-ink-3); background: var(--rh-surface-2); }

.rh-btn-ghost { background: transparent; color: var(--rh-accent); }
.rh-btn-ghost:hover:not(:disabled) { background: var(--rh-accent-soft); }

.rh-btn-danger { background: var(--rh-error); color: var(--rh-on-error); }

/* ── Cards ───────────────────────────────────────────────────────────── */
.rh-card {
  background: var(--rh-surface);
  border: 1px solid var(--rh-line-faint);
  border-radius: var(--rh-radius-md);
  padding: var(--rh-space-5);
  box-shadow: var(--rh-shadow-1);
  transition: box-shadow var(--rh-dur-base) var(--rh-ease),
              transform var(--rh-dur-base) var(--rh-ease);
}
.rh-card-interactive:hover {
  box-shadow: var(--rh-shadow-2);
  transform: translateY(-2px);
}

/* ── Inputs ──────────────────────────────────────────────────────────── */
.rh-input, .rh-select {
  font-family: var(--rh-font-body);
  font-size: var(--rh-text-sm);
  color: var(--rh-ink);
  background: var(--rh-surface);
  border: 1px solid var(--rh-line);
  border-radius: var(--rh-radius-md);
  padding: 9px 12px;
  width: 100%;
  transition: border-color var(--rh-dur-fast) var(--rh-ease);
}
.rh-input::placeholder { color: var(--rh-ink-3); }
.rh-input:focus, .rh-select:focus {
  outline: none;
  border-color: var(--rh-accent);
  box-shadow: 0 0 0 3px var(--rh-accent-soft);
}
.rh-label {
  display: block;
  font-size: var(--rh-text-sm);
  font-weight: 500;
  color: var(--rh-ink-2);
  margin-bottom: var(--rh-space-1);
}

/* ── Toggle switch (dashboard pipeline controls, theme, site mode) ───── */
.rh-toggle {
  position: relative;
  display: inline-block;
  width: 40px; height: 22px;
  flex: none;
}
.rh-toggle input { opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.rh-toggle-track {
  position: absolute; inset: 0;
  background: var(--rh-line);
  border-radius: var(--rh-radius-full);
  pointer-events: none;
  transition: background-color var(--rh-dur-base) var(--rh-ease);
}
.rh-toggle-track::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  background: var(--rh-surface);
  border-radius: 50%;
  box-shadow: var(--rh-shadow-1);
  transition: transform var(--rh-dur-base) var(--rh-ease-swing);
}
.rh-toggle input:checked + .rh-toggle-track { background: var(--rh-accent); }
.rh-toggle input:checked + .rh-toggle-track::after { transform: translateX(18px); }
.rh-toggle input:focus-visible + .rh-toggle-track {
  outline: 2px solid var(--rh-accent);
  outline-offset: 2px;
}

/* ── Badges & chips ──────────────────────────────────────────────────── */
.rh-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: var(--rh-text-xs);
  font-weight: 600;
  padding: 3px 10px;
  border-radius: var(--rh-radius-full);
  background: var(--rh-surface-2);
  color: var(--rh-ink-2);
}
/* Verdict badges — the one place brand amber appears in the UI */
.rh-badge-ai        { background: var(--rh-brand-soft);   color: var(--rh-brand-ink); }
.rh-badge-human     { background: var(--rh-info-soft);    color: var(--rh-info); }
.rh-badge-uncertain { background: var(--rh-surface-2);    color: var(--rh-ink-2); }
.rh-badge-success   { background: var(--rh-success-soft); color: var(--rh-success); }
.rh-badge-warning   { background: var(--rh-warning-soft); color: var(--rh-warning); }
.rh-badge-error     { background: var(--rh-error-soft);   color: var(--rh-error); }
.rh-badge-info      { background: var(--rh-info-soft);    color: var(--rh-info); }

/* ── Tables — instrument style: hairline rules, tabular numerals ─────── */
.rh-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--rh-text-sm);
}
.rh-table th {
  text-align: left;
  font-weight: 600;
  color: var(--rh-ink-2);
  padding: var(--rh-space-2) var(--rh-space-3);
  border-bottom: 1px solid var(--rh-line);
}
.rh-table td {
  padding: var(--rh-space-2) var(--rh-space-3);
  border-bottom: 1px solid var(--rh-line-faint);
}
.rh-table td.rh-num, .rh-table th.rh-num { text-align: right; }
.rh-table tbody tr {
  transition: background-color var(--rh-dur-fast) var(--rh-ease);
}
.rh-table tbody tr:hover { background: var(--rh-surface-2); }

/* ── Tooltip ─────────────────────────────────────────────────────────── */
.rh-tooltip {
  position: relative;
}
.rh-tooltip .rh-tooltip-body {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: var(--rh-ink);
  color: var(--rh-bg);
  font-size: var(--rh-text-xs);
  padding: 6px 10px;
  border-radius: var(--rh-radius-sm);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--rh-dur-base) var(--rh-ease),
              transform var(--rh-dur-base) var(--rh-ease);
  z-index: 30;
}
.rh-tooltip:hover .rh-tooltip-body,
.rh-tooltip:focus-visible .rh-tooltip-body {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Modal ───────────────────────────────────────────────────────────── */
.rh-modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(10, 16, 22, 0.55);
  display: grid;
  place-items: center;
  z-index: 100;
  animation: rh-fade-in var(--rh-dur-base) var(--rh-ease);
}
.rh-modal {
  background: var(--rh-surface);
  border-radius: var(--rh-radius-lg);
  box-shadow: var(--rh-shadow-3);
  padding: var(--rh-space-6);
  max-width: 480px;
  width: calc(100% - var(--rh-space-6));
  animation: rh-rise-in var(--rh-dur-slow) var(--rh-ease);
}

/* ── Skeleton loading ────────────────────────────────────────────────── */
.rh-skeleton {
  background: linear-gradient(90deg,
    var(--rh-surface-2) 25%, var(--rh-line-faint) 50%, var(--rh-surface-2) 75%);
  background-size: 200% 100%;
  border-radius: var(--rh-radius-sm);
  animation: rh-shimmer 1.4s ease-in-out infinite;
  color: transparent;
  user-select: none;
}

/* ── Logo loading spinner — dimensional rotation, not a flat spin ────── */
.rh-spinner {
  width: 48px; height: 48px;
  animation: rh-logo-turn 1.6s var(--rh-ease) infinite;
  transform-style: preserve-3d;
}

/* ==========================================================================
   KEYFRAMES
   ========================================================================== */
@keyframes rh-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes rh-rise-in {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes rh-shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}
@keyframes rh-logo-turn {
  0%   { transform: perspective(300px) rotateY(0deg); }
  50%  { transform: perspective(300px) rotateY(180deg); }
  100% { transform: perspective(300px) rotateY(360deg); }
}
/* Number counting and chart draw-ins are done in JS/SVG per page,
   using --rh-dur-page and --rh-ease. */

/* ==========================================================================
   REDUCED MOTION — static alternatives, not broken layouts
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .rh-skeleton { animation: none; background: var(--rh-surface-2); }
  .rh-spinner  { animation: none; }
}
