/* Shared design system — pulled in by index/settings/compare/traces.
 * Sits alongside Tailwind CDN: CSS custom properties + component classes
 * Tailwind utility classes (`text-[var(--ink)]`, `bg-[var(--surface-2)]`) can
 * reach through.
 *
 * Design dials applied:
 *   DESIGN_VARIANCE=8   asymmetric layouts allowed
 *   MOTION_INTENSITY=6  fluid CSS transitions + cascade reveals
 *   VISUAL_DENSITY=4    daily-app spacing, anti-card-overuse
 *
 * Banned: Inter, pure black, AI purple/blue glow, neon shadows, emojis.
 */

/* ---------- design tokens ---------- */
:root {
  /* Warm-neutral surface stack — escapes the cold AI-default white */
  --bg: #fbfaf7;
  --surface: #ffffff;
  --surface-2: #f4f3ef;
  --surface-3: #edebe4;
  --border: #e6e4dd;
  --border-strong: #d6d3c8;

  /* Ink — zinc-950 family, never #000000 */
  --ink: #18181b;
  --ink-2: #52525b;
  --ink-3: #a1a1aa;
  --ink-on-accent: #ffffff;

  /* Single accent — blue-600 de-saturated to ~65%, retains "translate"
   * association without the AI-neon glow. */
  --accent: #1e6fc7;
  --accent-soft: #e2efff;
  --accent-ring: rgba(30, 111, 199, .14);

  /* Functional */
  --success: #047857;
  --success-soft: #d1fae5;
  --warning: #b45309;
  --warning-soft: #fef3c7;
  --danger:  #b91c1c;
  --danger-soft: #fee2e2;

  /* Tinted shadows — never neutral gray */
  --elev-1: 0 1px 2px -1px rgba(24,24,27,.06), 0 2px 4px -2px rgba(24,24,27,.04);
  --elev-2: 0 20px 40px -15px rgba(24,24,27,.07);

  /* Geometry */
  --r-card: 1.5rem;
  --r-input: .75rem;
  --r-pill: 9999px;

  /* Motion */
  --ease-out-quart: cubic-bezier(.16, 1, .3, 1);
  --ease-out-back: cubic-bezier(.34, 1.56, .64, 1);
}

/* ---------- base ---------- */
html, body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Geist", "ui-sans-serif", system-ui, sans-serif;
  font-feature-settings: "ss01", "cv11";
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

body { position: relative; }

/* grain overlay — fixed pseudo on body so it never repaints during scroll.
 * pointer-events:none so it's invisible to mouse; z-index 0 sits below
 * absolutely-anything-positioned content (everything else should be in a
 * normal flow stacking context). */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: .035;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160' viewBox='0 0 160 160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2' seed='4'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.9 0'/></filter><rect width='160' height='160' filter='url(%23n)'/></svg>");
  background-size: 160px 160px;
}

/* Make sure interactive layers always paint above the grain. */
nav, main, header, footer { position: relative; z-index: 1; }

/* Strip the iOS tap highlight — :active state already gives tactile feedback */
button, a { -webkit-tap-highlight-color: transparent; }

/* ---------- typography ---------- */
.display-lg { font-size: clamp(40px, 6vw, 64px); line-height: 1.04; letter-spacing: -0.035em; font-weight: 600; }
.display-md { font-size: clamp(32px, 4vw, 44px); line-height: 1.08; letter-spacing: -0.03em;  font-weight: 600; }
.title-lg   { font-size: 20px; line-height: 1.4;   letter-spacing: -0.005em; font-weight: 600; }
.body-md    { font-size: 15px; line-height: 1.6;   letter-spacing: 0;        font-weight: 400; color: var(--ink-2); }
.body-sm    { font-size: 13px; line-height: 1.5;   letter-spacing: 0;        font-weight: 400; color: var(--ink-2); }
.label-sm   { font-size: 11px; line-height: 1.4;   letter-spacing: 0.08em;   font-weight: 600; text-transform: uppercase; color: var(--ink-3); }

.mono { font-family: "Geist Mono", ui-monospace, "SF Mono", monospace; font-feature-settings: "ss01"; }
.tab-nums { font-variant-numeric: tabular-nums; }

/* ---------- common surfaces ---------- */
.surface-1 { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-card); }
.surface-2 { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-card); }

/* Use sparingly — anti-card-overuse: prefer divider over surface */
.elev-1 { box-shadow: var(--elev-1); }
.elev-2 { box-shadow: var(--elev-2); }

.divider { border-top: 1px solid var(--border); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 44px;
  padding: 0 18px;
  border-radius: var(--r-input);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: -0.005em;
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  color: inherit;
  transition:
    transform .15s var(--ease-out-quart),
    background-color .15s var(--ease-out-quart),
    border-color .15s var(--ease-out-quart),
    box-shadow .2s var(--ease-out-quart);
}
.btn:disabled { opacity: .45; cursor: not-allowed; pointer-events: none; }

/* Tactile feedback — always on, no neon glow. */
.btn:active:not(:disabled) { transform: translateY(1px) scale(.99); }

.btn-primary {
  background: var(--ink);
  color: var(--ink-on-accent);
  border-color: var(--ink);
}
.btn-primary:hover:not(:disabled) { background: #27272a; }

.btn-accent {
  background: var(--accent);
  color: var(--ink-on-accent);
  border-color: var(--accent);
  box-shadow: inset 0 1px 0 rgba(255,255,255,.12);
}
.btn-accent:hover:not(:disabled) { background: #1c63b3; }

.btn-ghost {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--border);
}
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); border-color: var(--border-strong); }

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: rgba(185, 28, 28, .25);
}
.btn-danger:hover:not(:disabled) { background: #fbcaca; }

.btn-sm { height: 34px; padding: 0 12px; font-size: 13px; }
.btn-lg { height: 52px; padding: 0 26px; font-size: 15px; border-radius: 14px; }

.btn .material-symbols-outlined { font-variation-settings: 'wght' 400, 'FILL' 0; font-size: 18px; }

/* Magnetic hover — JS writes --mx/--my (range roughly [-.5, .5]) and CSS
 * does the actual transform. Outside React's render cycle by construction. */
.magnetic { --mx: 0; --my: 0; transition: transform .25s var(--ease-out-quart); will-change: transform; }
.magnetic:hover { transform: translate(calc(var(--mx) * 6px), calc(var(--my) * 6px)); }

/* ---------- inputs ---------- */
.field {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  border-radius: var(--r-input);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  transition: border-color .15s, box-shadow .15s;
}
.field::placeholder { color: var(--ink-3); }
.field:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}
textarea.field { height: auto; padding: 12px 14px; line-height: 1.5; }

/* ---------- badges + breathing dot ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 10px;
  border-radius: var(--r-pill);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-2);
}
.badge-accent  { background: var(--accent-soft); color: var(--accent);  border-color: transparent; }
.badge-success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge-warning { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge-danger  { background: var(--danger-soft);  color: var(--danger);  border-color: transparent; }

.dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
  background: var(--ink-3);
}
.dot-running { background: var(--accent); animation: breath 1.6s ease-in-out infinite; }
.dot-success { background: var(--success); }
.dot-warning { background: var(--warning); animation: breath 1.6s ease-in-out infinite; }
.dot-danger  { background: var(--danger);  animation: breath 1.6s ease-in-out infinite; }

@keyframes breath {
  0%, 100% { opacity: .55; transform: scale(.85); }
  50%      { opacity: 1;   transform: scale(1.0);  }
}

/* ---------- skeleton shimmer ---------- */
.skeleton {
  position: relative;
  overflow: hidden;
  background: var(--surface-2);
  border-radius: var(--r-input);
}
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255,255,255,.6) 50%,
    transparent 100%
  );
  animation: shimmer 1.5s linear infinite;
}
@keyframes shimmer {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* ---------- staggered reveal — driven by IntersectionObserver in design.js ---------- */
.reveal {
  opacity: 0;
  transform: translateY(12px);
}
.reveal.is-in {
  animation: rise-in .7s var(--ease-out-quart) calc(var(--i, 0) * 70ms) both;
}
@keyframes rise-in {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---------- top nav (shared across all 4 pages) ---------- */
.nav {
  position: sticky;
  top: 0;
  z-index: 50;
  height: 56px;
  background: rgba(251, 250, 247, .82);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}
.nav-inner {
  height: 100%;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.nav-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  text-decoration: none;
}
.nav-brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.nav-brand-mark .material-symbols-outlined { font-size: 18px; font-variation-settings: 'wght' 500, 'FILL' 1; }
.nav-brand-wordmark { font-weight: 600; letter-spacing: -0.01em; font-size: 15px; }
.nav-links {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.nav-link {
  position: relative;
  height: 36px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
  text-decoration: none;
  transition:
    color .15s var(--ease-out-quart),
    background-color .15s var(--ease-out-quart),
    transform .25s var(--ease-out-quart);
  --mx: 0; --my: 0;
  will-change: transform;
}
.nav-link:hover { color: var(--ink); background: var(--surface-2); transform: translate(calc(var(--mx)*4px), calc(var(--my)*4px)); }
.nav-link[aria-current="page"] { color: var(--ink); }
.nav-link[aria-current="page"]::after {
  content: "";
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: -10px;
  height: 2px;
  background: var(--ink);
  border-radius: 1px;
}
.nav-link .material-symbols-outlined { font-size: 16px; }

/* ---------- nav user chip (logged-in identity + logout) ---------- */
.nav-user-chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 6px 0 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 13px; font-weight: 500;
  margin-right: 8px;
  white-space: nowrap;
}
.nav-user-chip .nav-user-name {
  max-width: 140px; overflow: hidden; text-overflow: ellipsis;
}
.nav-user-chip .nav-user-logout {
  display: inline-grid; place-items: center;
  width: 22px; height: 22px; border-radius: 999px;
  border: none; background: transparent; color: var(--ink-3); cursor: pointer;
  transition: background-color .12s var(--ease-out-quart), color .12s var(--ease-out-quart);
}
.nav-user-chip .nav-user-logout:hover { background: var(--danger-soft); color: var(--danger); }

/* ---------- focus ring (consistent across buttons + links) ---------- */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.btn:focus-visible, .field:focus-visible { outline-offset: 3px; }

/* ---------- utility helpers ---------- */
.divide-soft > * + * { border-top: 1px solid var(--border); }
.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { scrollbar-width: none; }

/* ---------- live health indicator ----------
 * Tiny pill in the right side of the nav. design.js polls /api/health every
 * 5s and toggles is-ok / is-down / is-checking. Replaces the old anchor
 * that punched out to the system browser. */
.health-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 10px;
  border-radius: 9999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background-color .15s var(--ease-out-quart),
              border-color .15s var(--ease-out-quart),
              color .15s var(--ease-out-quart);
}
.health-indicator:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
}
.health-indicator .health-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  background: var(--ink-3);
}
.health-indicator.is-ok {
  color: var(--success);
  border-color: rgba(4, 120, 87, .25);
  background: var(--success-soft);
}
.health-indicator.is-ok .health-dot { background: var(--success); }
.health-indicator.is-down {
  color: var(--danger);
  border-color: rgba(185, 28, 28, .35);
  background: var(--danger-soft);
}
.health-indicator.is-down .health-dot {
  background: var(--danger);
  animation: breath 1.6s ease-in-out infinite;
}
.health-indicator.is-checking { opacity: .7; }
.health-indicator.is-checking .health-dot {
  background: var(--ink-3);
  animation: breath 1.8s ease-in-out infinite;
}

/* Sticky banner that appears only when health is down. Sits inside .nav
 * (after .nav-inner) so it scrolls along with the sticky nav and is visible
 * on every page without per-page markup duplication beyond one <div>. */
.health-banner {
  background: var(--danger-soft);
  color: var(--danger);
  border-top: 1px solid rgba(185, 28, 28, .25);
  padding: 8px 24px;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
}
.health-banner.hidden { display: none; }
.health-banner .btn-ghost {
  background: var(--surface);
  border-color: rgba(185, 28, 28, .25);
  color: var(--danger);
}
.health-banner .btn-ghost:hover { background: #fff5f5; }
