/**
 * PROJECT OUTLIER — Immersive Operating System
 * Design System (Milestone 1)
 *
 * Extends the existing Operation Phoenix tokens (phoenix-tokens.css) with an
 * immersive, cinematic layer: deeper surfaces, restrained agency-accent glow,
 * a larger display type scale, responsive device scaling (phone/iPad/desktop/wall),
 * and first-class accessibility modes (reduced motion, high contrast, large touch).
 *
 * This is additive. It never overrides brand tokens applied at runtime by
 * ConfigAPI.applyBrandTheme() / DashboardProfilesAPI.applyTheme(); it consumes them.
 */

:root {
  /* Agency accent is inherited from --phx-accent / --phx-brand-primary (runtime themed). */
  --im-accent: var(--phx-accent);
  --im-accent-dim: var(--phx-accent-dim);
  --im-brand: var(--phx-brand-primary);
  --im-highlight: var(--phx-highlight, var(--phx-success));

  /* ── Immersive surfaces (deeper than base for cinematic depth) ── */
  --im-void: #04060a;
  --im-abyss: #020407;
  --im-base: var(--phx-bg-base);
  --im-raised: rgba(18, 24, 34, 0.72);
  --im-elevated: rgba(24, 32, 45, 0.85);
  --im-glass: rgba(10, 14, 22, 0.66);
  --im-glass-strong: rgba(7, 10, 17, 0.88);
  --im-hairline: rgba(255, 255, 255, 0.08);
  --im-hairline-strong: rgba(255, 255, 255, 0.14);
  --im-blur: 22px;
  --im-blur-strong: 40px;

  /* ── Restrained glow (agency-accent driven) ── */
  --im-glow-accent: 0 0 40px -8px color-mix(in srgb, var(--im-accent) 45%, transparent);
  --im-glow-soft: 0 0 24px -10px color-mix(in srgb, var(--im-accent) 30%, transparent);
  --im-ring-accent: 0 0 0 1px color-mix(in srgb, var(--im-accent) 42%, transparent);

  /* ── Elevation (cinematic, layered) ── */
  --im-shadow-1: 0 1px 2px rgba(0, 0, 0, 0.5);
  --im-shadow-2: 0 8px 30px -12px rgba(0, 0, 0, 0.7);
  --im-shadow-3: 0 24px 70px -24px rgba(0, 0, 0, 0.8);
  --im-shadow-float: 0 30px 90px -30px rgba(0, 0, 0, 0.85), 0 2px 0 rgba(255, 255, 255, 0.03) inset;

  /* ── Display type scale (fluid; scales up on Wall) ── */
  --im-scale: 1;
  --im-text-micro: calc(0.6875rem * var(--im-scale));
  --im-text-xs: calc(0.75rem * var(--im-scale));
  --im-text-sm: calc(0.875rem * var(--im-scale));
  --im-text-md: calc(1rem * var(--im-scale));
  --im-text-lg: calc(1.25rem * var(--im-scale));
  --im-text-xl: calc(1.625rem * var(--im-scale));
  --im-text-2xl: calc(2.25rem * var(--im-scale));
  --im-text-3xl: calc(3.25rem * var(--im-scale));
  --im-text-display: clamp(2.75rem, 6vw, calc(5.5rem * var(--im-scale)));
  --im-text-hero: clamp(3.5rem, 9vw, calc(8rem * var(--im-scale)));

  --im-font-display: var(--phx-font-display);
  --im-font-ui: var(--phx-font-ui);
  --im-font-data: var(--phx-font-data);

  --im-track-tight: -0.03em;
  --im-track-normal: 0;
  --im-track-wide: 0.08em;
  --im-track-widest: 0.22em;

  /* ── Spacing rhythm ── */
  --im-gap-1: 0.375rem;
  --im-gap-2: 0.75rem;
  --im-gap-3: 1.125rem;
  --im-gap-4: 1.75rem;
  --im-gap-5: 2.5rem;
  --im-gap-6: 3.5rem;
  --im-radius-sm: 10px;
  --im-radius-md: 16px;
  --im-radius-lg: 22px;
  --im-radius-xl: 30px;
  --im-radius-pill: 999px;

  /* ── Touch ── */
  --im-touch: 48px;
  --im-touch-lg: 60px;

  /* ── Motion ── */
  --im-motion-fast: 160ms;
  --im-motion-base: 280ms;
  --im-motion-slow: 480ms;
  --im-motion-cinematic: 720ms;
  --im-ease: cubic-bezier(0.22, 1, 0.36, 1);
  --im-ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
}

/* ── Severity: color + text label token pairing (color-independent) ── */
:root {
  --im-sev-routine: var(--phx-threat-green);
  --im-sev-guarded: var(--phx-threat-blue);
  --im-sev-elevated: var(--phx-threat-yellow);
  --im-sev-high: var(--phx-threat-orange);
  --im-sev-severe: var(--phx-threat-red);
}

/* ─────────────────────────────────────────────────────────────
   Responsive device classes — set --im-scale + layout affordances
   Phone  <  600
   iPad   600 – 1180
   Desktop 1180 – 2200
   Wall   > 2200 (also honored via [data-immersive-device="wall"])
   ───────────────────────────────────────────────────────────── */
@media (max-width: 599px) {
  :root { --im-scale: 0.82; }
}
@media (min-width: 600px) and (max-width: 1179px) {
  :root { --im-scale: 0.94; }
}
@media (min-width: 1180px) and (max-width: 2199px) {
  :root { --im-scale: 1; }
}
@media (min-width: 2200px) {
  :root { --im-scale: 1.5; }
}
:root[data-immersive-device="wall"] { --im-scale: 1.6; }
:root[data-immersive-device="desktop"] { --im-scale: 1; }
:root[data-immersive-device="ipad"] { --im-scale: 0.94; }
:root[data-immersive-device="phone"] { --im-scale: 0.82; }

/* ─────────────────────────────────────────────────────────────
   Accessibility modes (persisted on <html> by immersive-shell.js)
   ───────────────────────────────────────────────────────────── */

/* Reduced motion: honor OS preference + explicit toggle */
:root[data-immersive-motion="reduced"] {
  --im-motion-fast: 0ms;
  --im-motion-base: 0ms;
  --im-motion-slow: 0ms;
  --im-motion-cinematic: 0ms;
}
:root[data-immersive-motion="reduced"] *,
@media (prefers-reduced-motion: reduce) {
}
:root[data-immersive-motion="reduced"] *,
:root[data-immersive-motion="reduced"] *::before,
:root[data-immersive-motion="reduced"] *::after {
  animation-duration: 0.001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.001ms !important;
  scroll-behavior: auto !important;
}
@media (prefers-reduced-motion: reduce) {
  .im-anim,
  .im-anim * {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* High contrast: stronger surfaces, hairlines, and text */
:root[data-immersive-contrast="high"] {
  --im-void: #000000;
  --im-abyss: #000000;
  --im-glass: rgba(0, 0, 0, 0.92);
  --im-glass-strong: rgba(0, 0, 0, 0.97);
  --im-raised: rgba(0, 0, 0, 0.92);
  --im-elevated: rgba(0, 0, 0, 0.95);
  --im-hairline: rgba(255, 255, 255, 0.55);
  --im-hairline-strong: rgba(255, 255, 255, 0.85);
  --phx-text-primary: #ffffff;
  --phx-text-secondary: #eef3f9;
  --phx-text-muted: #cfd8e4;
  --im-glow-accent: none;
  --im-glow-soft: none;
}
:root[data-immersive-contrast="high"] .im-glass,
:root[data-immersive-contrast="high"] .im-card {
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

/* Large touch: enlarge interactive targets */
:root[data-immersive-touch="large"] {
  --im-touch: 60px;
  --im-touch-lg: 76px;
  --im-scale: calc(1.08 * 1);
}

/* ─────────────────────────────────────────────────────────────
   Base primitives (immersive surfaces)
   ───────────────────────────────────────────────────────────── */

.im-scope {
  font-family: var(--im-font-ui);
  color: var(--phx-text-primary);
}

.im-glass {
  background: var(--im-glass);
  backdrop-filter: blur(var(--im-blur)) saturate(140%);
  -webkit-backdrop-filter: blur(var(--im-blur)) saturate(140%);
  border: 1px solid var(--im-hairline);
}

.im-card {
  position: relative;
  background: var(--im-raised);
  backdrop-filter: blur(var(--im-blur)) saturate(135%);
  -webkit-backdrop-filter: blur(var(--im-blur)) saturate(135%);
  border: 1px solid var(--im-hairline);
  border-radius: var(--im-radius-lg);
  box-shadow: var(--im-shadow-2);
  overflow: hidden;
}

/* Focus visibility — keyboard navigation */
.im-scope :focus-visible,
.im-focusable:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--im-abyss), 0 0 0 5px var(--im-accent);
  border-radius: var(--im-radius-sm);
}

/* Buttons */
.im-btn {
  --_bg: var(--im-glass);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--im-gap-2);
  min-height: var(--im-touch);
  padding: 0 1.25rem;
  border-radius: var(--im-radius-pill);
  border: 1px solid var(--im-hairline-strong);
  background: var(--_bg);
  color: var(--phx-text-primary);
  font-family: var(--im-font-ui);
  font-size: var(--im-text-sm);
  font-weight: 600;
  letter-spacing: var(--im-track-wide);
  text-transform: uppercase;
  text-decoration: none;
  cursor: pointer;
  transition: transform var(--im-motion-fast) var(--im-ease),
    box-shadow var(--im-motion-base) var(--im-ease),
    border-color var(--im-motion-base) var(--im-ease),
    background var(--im-motion-base) var(--im-ease);
}
.im-btn:hover { transform: translateY(-1px); border-color: color-mix(in srgb, var(--im-accent) 55%, transparent); box-shadow: var(--im-glow-soft); }
.im-btn:active { transform: translateY(0); }
.im-btn--primary {
  --_bg: linear-gradient(135deg, color-mix(in srgb, var(--im-accent) 92%, #fff 0%), var(--im-accent-dim));
  color: #04060a;
  border-color: transparent;
  box-shadow: var(--im-glow-soft);
}
.im-btn--primary:hover { box-shadow: var(--im-glow-accent); }
.im-btn--ghost { --_bg: transparent; }
.im-btn--icon { padding: 0; width: var(--im-touch); }

/* Severity chips — always pair a color with a text label (color-independent) */
.im-sev {
  display: inline-flex;
  align-items: center;
  gap: 0.5em;
  padding: 0.28em 0.8em;
  border-radius: var(--im-radius-pill);
  font-size: var(--im-text-xs);
  font-weight: 700;
  letter-spacing: var(--im-track-wide);
  text-transform: uppercase;
  border: 1px solid currentColor;
}
.im-sev::before {
  content: "";
  width: 0.6em; height: 0.6em; border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 8px currentColor;
}
.im-sev--routine { color: var(--im-sev-routine); }
.im-sev--guarded { color: var(--im-sev-guarded); }
.im-sev--elevated { color: var(--im-sev-elevated); }
.im-sev--high { color: var(--im-sev-high); }
.im-sev--severe { color: var(--im-sev-severe); }

/* Utility */
.im-visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0);
  white-space: nowrap; border: 0;
}
.im-eyebrow {
  font-size: var(--im-text-micro);
  letter-spacing: var(--im-track-widest);
  text-transform: uppercase;
  color: var(--phx-text-muted);
  font-weight: 700;
}
.im-muted { color: var(--phx-text-muted); }
.im-unavailable {
  color: var(--phx-text-muted);
  font-style: italic;
}
