/* ============================================================================
   Sasya design system - shadcn-inspired tokens in vanilla CSS.
   Note: shadcn/ui is a React + Tailwind component library. This project is
   served as static files by FastAPI (no build step), so we cannot import the
   React components. Instead we adopt shadcn's *design language*: the same HSL
   semantic-token model (--background / --foreground / --card / --primary /
   --muted / --border / --ring / --radius), a single accent, and one radius
   scale. Values are customised to Sasya's forest-tech brand (not default state).
   Themes: dark (default, matches the brand) + light, swapped via [data-theme].
   ============================================================================ */

:root {
  /* Radius scale (one system): chips/toggles = pill; inputs/buttons/cards = soft. */
  --radius: 14px;
  --radius-sm: 9px;
  --radius-lg: 20px;
  --radius-pill: 999px;

  /* Type */
  --font-display: "Sora", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-sans: "Instrument Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  /* Layout */
  --maxw: 1200px;
  --nav-h: 68px;
  --z-nav: 500;
  --z-toast: 800;
  --z-overlay: 700;
  --z-grain: 60;

  /* Semantic data colors (green->amber->red risk scale). These carry meaning in
     charts/gauges; they are NOT the brand accent, so they don't break the
     one-accent lock. Same values in both themes for consistent data reading. */
  --data-good: 152 62% 45%;
  --data-warn: 38 92% 55%;
  --data-bad: 4 78% 60%;
  --data-info: 199 89% 60%;
}

/* Registered so the gauge fill (conic-gradient stop driven by --p) can actually
   transition/animate instead of snapping. Falls back gracefully in browsers
   without @property: the value still applies, it just jumps. */
@property --p {
  syntax: "<number>";
  inherits: false;
  initial-value: 0;
}

/* -------------------------- DARK (default) -------------------------- */
:root,
:root[data-theme="dark"] {
  color-scheme: dark;
  /* Pitch-black neutral surfaces. No green in any background: green lives only
     in --primary (the single accent) and the data-* chart colours. */
  --background: 0 0% 0%;
  --surface: 0 0% 3.5%;
  --card: 0 0% 5.5%;
  --card-2: 0 0% 8.5%;
  --foreground: 0 0% 95%;
  --muted: 0 0% 15%;
  --muted-foreground: 0 0% 61%;
  --border: 0 0% 15%;
  --border-strong: 0 0% 24%;
  --input: 0 0% 11%;
  --primary: 152 60% 47%;
  --primary-strong: 152 66% 41%;
  --primary-foreground: 0 0% 4%;
  --ring: 152 60% 50%;
  --shadow-color: 0 0% 0%;
  --hero-glow: 152 60% 30%;
}

/* -------------------------- LIGHT -------------------------- */
:root[data-theme="light"] {
  color-scheme: light;
  --background: 140 30% 97%;
  --surface: 140 24% 99%;
  --card: 0 0% 100%;
  --card-2: 140 24% 98%;
  --foreground: 156 28% 12%;
  --muted: 145 22% 93%;
  --muted-foreground: 156 10% 38%;
  --border: 145 18% 87%;
  --border-strong: 145 16% 78%;
  --input: 145 20% 96%;
  --primary: 152 56% 36%;
  --primary-strong: 152 60% 30%;
  --primary-foreground: 0 0% 100%;
  --ring: 152 56% 40%;
  --shadow-color: 156 30% 40%;
  --hero-glow: 152 55% 65%;
}

/* -------------------------- base -------------------------- */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } }

body {
  margin: 0;
  font-family: var(--font-sans);
  background: hsl(var(--background));
  color: hsl(var(--foreground));
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  line-height: 1.55;
  overflow-x: hidden;
}

h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; line-height: 1.08; letter-spacing: -0.02em; margin: 0; }
p { margin: 0; }
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
.mono { font-family: var(--font-mono); font-feature-settings: "tnum" 1; }

::selection { background: hsl(var(--primary) / 0.28); }

:focus-visible {
  outline: 2px solid hsl(var(--ring));
  outline-offset: 2px;
  border-radius: 4px;
}

/* anchor jumps land below the fixed nav, not under it */
[id] { scroll-margin-top: calc(var(--nav-h) + 24px); }

.container { width: 100%; max-width: var(--maxw); margin: 0 auto; padding: 0 24px; }
@media (max-width: 640px) { .container { padding: 0 18px; } }

.eyebrow {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: var(--font-mono);
  font-size: 11.5px; letter-spacing: 0.16em; text-transform: uppercase;
  color: hsl(var(--primary));
  font-weight: 500;
}

/* -------------------------- buttons -------------------------- */
.btn {
  --btn-bg: transparent;
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  font-family: var(--font-sans); font-size: 15px; font-weight: 600;
  padding: 11px 20px; border-radius: var(--radius-sm);
  border: 1px solid transparent; cursor: pointer;
  transition: transform .16s cubic-bezier(.16,1,.3,1), background .2s ease, border-color .2s ease, box-shadow .2s ease, color .2s ease;
  white-space: nowrap; line-height: 1;
}
.btn svg { width: 18px; height: 18px; }
.btn:active { transform: translateY(1px) scale(.985); }

.btn-primary {
  background: hsl(var(--primary));
  color: hsl(var(--primary-foreground));
  box-shadow: 0 1px 0 hsl(var(--primary-strong)) inset, 0 8px 24px hsl(var(--primary) / 0.22);
}
.btn-primary:hover { background: hsl(var(--primary-strong)); transform: translateY(-1px); }

.btn-ghost {
  background: hsl(var(--card) / 0.6);
  color: hsl(var(--foreground));
  border-color: hsl(var(--border-strong));
  backdrop-filter: blur(6px);
}
.btn-ghost:hover { border-color: hsl(var(--primary) / 0.5); background: hsl(var(--card-2)); transform: translateY(-1px); }

.btn-sm { padding: 8px 14px; font-size: 13.5px; }
.btn-lg { padding: 14px 26px; font-size: 16px; }
.btn-block { width: 100%; }

/* -------------------------- chips / badges -------------------------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; font-weight: 500;
  padding: 5px 11px; border-radius: var(--radius-pill);
  background: hsl(var(--muted)); color: hsl(var(--muted-foreground));
  border: 1px solid hsl(var(--border));
}
.chip-primary { background: hsl(var(--primary) / 0.12); color: hsl(var(--primary)); border-color: hsl(var(--primary) / 0.28); }
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--font-mono); font-size: 10.5px; letter-spacing: .04em;
  text-transform: uppercase; padding: 3px 8px; border-radius: var(--radius-pill);
  border: 1px solid hsl(var(--border));
}
.badge-learned { background: hsl(var(--data-good) / 0.14); color: hsl(var(--data-good)); border-color: hsl(var(--data-good) / 0.3); }
.badge-prior { background: hsl(var(--muted)); color: hsl(var(--muted-foreground)); }

/* -------------------------- cards -------------------------- */
.card {
  background: hsl(var(--card));
  border: 1px solid hsl(var(--border));
  border-radius: var(--radius);
}

/* status dot only where it means live server state */
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: hsl(var(--data-warn)); flex: none; }
.is-online .live-dot { background: hsl(var(--data-good)); box-shadow: 0 0 0 3px hsl(var(--data-good) / 0.18); }
.is-offline .live-dot { background: hsl(var(--data-bad)); }

/* -------------------------- shared brand + icon button --------------------------
   Used by BOTH the landing (index.html) and the dashboard (app.html). Kept here
   in the shared design system so the dashboard, which does not load landing.css,
   still constrains the logo image and styles the theme toggle. Without the
   .brand img size cap the logo renders at its natural resolution. */
.brand { display: flex; align-items: center; gap: 11px; }
.brand img { width: 34px; height: 34px; border-radius: 9px; }
.brand-name { font-family: var(--font-display); font-weight: 600; font-size: 18px; letter-spacing: -0.01em; }
.brand-name span { color: hsl(var(--primary)); font-weight: 500; margin-left: 3px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: var(--radius-sm);
  background: hsl(var(--card) / 0.6); border: 1px solid hsl(var(--border));
  color: hsl(var(--foreground)); cursor: pointer; transition: border-color .2s, background .2s;
}
.icon-btn:hover { border-color: hsl(var(--primary) / 0.5); }
.icon-btn svg { width: 19px; height: 19px; }
.theme-icon-dark { display: none; }
:root[data-theme="light"] .theme-icon-dark { display: block; }
:root[data-theme="light"] .theme-icon-light { display: none; }

/* -------------------------- reveal gating --------------------------
   Elements with .reveal are hidden ONLY once <html> has .gsap-ready (added by
   JS after GSAP loads and only if motion is allowed). If JS/GSAP fails to load,
   or reduced-motion is set, .gsap-ready is never added and content stays visible.
   ------------------------------------------------------------------ */
/* Hidden state is CSS-class-based ONLY (no inline styles), so if the GSAP ticker
   never advances (throttled/offscreen tab) the watchdog can drop .gsap-ready and
   everything reappears in place. GSAP only ever animates toward the visible state
   with .to(), so it never writes an inline opacity:0 that a fallback can't undo. */
.gsap-ready .reveal { opacity: 0; will-change: transform, opacity; }
.gsap-ready .reveal[data-anim="rise"] { transform: translateY(28px); }
.gsap-ready .reveal[data-anim="fade"] { transform: translateY(14px); }
.gsap-ready .reveal[data-anim="lines"] { transform: translateY(26px); }
.gsap-ready .loop-panel > * { opacity: 0; transform: translateY(20px); }
@media (prefers-reduced-motion: reduce) {
  .gsap-ready .reveal,
  .gsap-ready .loop-panel > * { opacity: 1 !important; transform: none !important; }
}

/* film grain overlay (fixed, non-scrolling, pointer-none) */
.grain {
  position: fixed; inset: 0; z-index: var(--z-grain); pointer-events: none;
  opacity: .035; mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
@media (prefers-reduced-motion: reduce) { .grain { display: none; } }
