/* =========================================================
   SFY UniFi Monitor — Always-on TV dashboard animations
   Consumes CustomEvents (site:statechange, summary:update) from app.js.
   Isolated from core UI; safe to remove by not loading the file.
   ========================================================= */

/* =========================================================
   #5 — Ambient dot-field background
   ========================================================= */

.dot-field {
  position: fixed;
  inset: 0;
  z-index: -10;
  pointer-events: none;
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.08) 1px, transparent 1.5px)
    0 0 / 24px 24px;
  overflow: hidden;
}

.dot-field::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.16) 1px, transparent 1.5px)
    0 0 / 24px 24px;
  -webkit-mask-image: radial-gradient(
    circle 400px at var(--mx, 50%) var(--my, 50%),
    black 0%,
    transparent 60%
  );
  mask-image: radial-gradient(
    circle 400px at var(--mx, 50%) var(--my, 50%),
    black 0%,
    transparent 60%
  );
  pointer-events: none;
}

.dot-field-ripple {
  position: fixed;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border-radius: 50%;
  border: 1px solid var(--text-display);
  pointer-events: none;
  animation: ripple 1.5s ease-out forwards;
  z-index: -9;
}

@keyframes ripple {
  from {
    transform: scale(0);
    opacity: 0.6;
  }
  to {
    transform: scale(20);
    opacity: 0;
  }
}

/* =========================================================
   #1 — Ambient status pulse behind hero number
   ========================================================= */

.hero {
  --status-color: var(--success);
}

.hero[data-health="degraded"] {
  --status-color: var(--accent);
}

.hero-main {
  position: relative;
  z-index: 0;
}

.hero-main::after {
  content: "";
  position: absolute;
  width: 200px;
  height: 200px;
  top: 50%;
  left: 50%;
  margin: -100px 0 0 -100px;
  border-radius: 50%;
  border: 2px solid var(--status-color);
  pointer-events: none;
  z-index: -1;
  transform-origin: center;
  animation: hero-pulse 4s linear infinite;
}

.hero[data-health="degraded"] .hero-main::after {
  animation-duration: 1.6s;
}

@keyframes hero-pulse {
  0% {
    transform: scale(1);
    opacity: 0.8;
  }
  100% {
    transform: scale(2.2);
    opacity: 0;
  }
}

/* =========================================================
   #2 — Dotted marquee ticker
   ========================================================= */

.ticker {
  height: 28px;
  overflow: hidden;
  font-family: var(--font-display);
  font-size: 14px;
  letter-spacing: 0.06em;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--black);
  color: var(--text-secondary);
  white-space: nowrap;
  position: relative;
}

.ticker-track {
  display: inline-flex;
  gap: 2rem;
  white-space: nowrap;
  line-height: 28px;
  animation: ticker-scroll 120s linear infinite;
  will-change: transform;
}

@keyframes ticker-scroll {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(-50%);
  }
}

.ticker-alert {
  color: var(--accent);
  animation: ticker-flash 0.8s ease-in-out infinite;
}

@keyframes ticker-flash {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.3;
  }
}

/* =========================================================
   #6 — "Since poll" sweep bar
   ========================================================= */

.sweep-bar {
  height: 2px;
  background: var(--border);
  margin: 0 var(--space-xl) var(--space-sm);
  position: relative;
  overflow: hidden;
}

.sweep-fill {
  height: 100%;
  width: 0%;
  background: var(--text-display);
  transition: width 200ms linear, background 200ms linear,
    box-shadow 200ms linear;
}

.sweep-bar.sweep-flash .sweep-fill {
  background: var(--success);
  box-shadow: 0 0 12px var(--success);
}

/* =========================================================
   #3 — Orbital device indicators per card
   ========================================================= */

.card-data .orbit-container {
  grid-column: 2;
  justify-self: end;
  width: 48px;
  height: 48px;
  padding: 0;
  position: relative;
  margin-top: var(--space-xs);
  animation: orbit-spin 12s linear infinite;
}

.orbit-dot {
  position: absolute;
  width: 4px;
  height: 4px;
  left: 50%;
  top: 50%;
  margin: -2px 0 0 -2px;
  border-radius: 50%;
  background: var(--success);
}

.orbit-dot.offline {
  background: var(--accent);
}

@keyframes orbit-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* =========================================================
   #7 — Status-dot heartbeat / flatline
   ========================================================= */

.card.status-OK .status-dot {
  animation: heartbeat 1.8s ease-in-out infinite;
  transform-origin: center;
}

@keyframes heartbeat {
  0%,
  60%,
  100% {
    transform: scale(1);
  }
  15% {
    transform: scale(1.4);
  }
  30% {
    transform: scale(1);
  }
  45% {
    transform: scale(1.3);
  }
}

.card.status-DOWN_PENDING .status-dot {
  animation: flatline 2s steps(2) infinite;
}

@keyframes flatline {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.2;
  }
}

/* =========================================================
   #8 — Glitch transition on state change
   ========================================================= */

.card.state-changed {
  animation: card-glitch 220ms steps(4, end);
  position: relative;
  z-index: 1;
}

.card.state-changed::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: rgba(255, 255, 255, 0.12);
  clip-path: polygon(0 40%, 100% 40%, 100% 55%, 0 55%);
  animation: glitch-tear 220ms steps(4, end);
  pointer-events: none;
  mix-blend-mode: difference;
}

@keyframes card-glitch {
  0% {
    transform: translate(0, 0);
    filter: none;
  }
  20% {
    transform: translate(-2px, 1px);
    filter: hue-rotate(90deg);
  }
  40% {
    transform: translate(2px, -1px);
    filter: hue-rotate(-90deg);
  }
  60% {
    transform: translate(-1px, 0);
    filter: none;
  }
  100% {
    transform: translate(0, 0);
    filter: none;
  }
}

@keyframes glitch-tear {
  0%,
  100% {
    transform: translateX(0);
  }
  25% {
    transform: translateX(3px);
  }
  50% {
    transform: translateX(-3px);
  }
  75% {
    transform: translateX(2px);
  }
}

/* =========================================================
   #9 — Dot-matrix digit counter (hero summary)
   ========================================================= */

/* Use inline-grid with one named cell so d-old + d-new stack in the
   same slot. display:block without grid/abs caused the "half digit"
   render during load — spans sitting in document flow instead of
   overlapping, so the overflow-hidden wasn't clipping d-new. */
#summary-number .digit {
  display: inline-grid;
  grid-template-areas: "slot";
  height: 1em;
  line-height: 1;
  overflow: hidden;
  vertical-align: top;
}

#summary-number .digit > span {
  grid-area: slot;
  line-height: 1;
  transition: transform 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

#summary-number .digit .d-new {
  transform: translateY(100%);
}

#summary-number .digit.rolling .d-old {
  transform: translateY(-100%);
}

#summary-number .digit.rolling .d-new {
  transform: translateY(0);
}

/* =========================================================
   #4 — CRT scanline + phosphor glow overlay
   ========================================================= */

.crt-overlay {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  mix-blend-mode: overlay;
  opacity: 0.25;
  background: repeating-linear-gradient(
    0deg,
    rgba(255, 255, 255, 0.06) 0 1px,
    transparent 1px 3px
  );
  animation: crt-flicker 4s ease-in-out infinite,
    crt-drift 0.15s linear infinite;
}

.crt-overlay::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(
    ellipse at center,
    transparent 40%,
    rgba(0, 0, 0, 0.4) 100%
  );
}

@keyframes crt-drift {
  0% {
    background-position-y: 0;
  }
  100% {
    background-position-y: 3px;
  }
}

@keyframes crt-flicker {
  0%,
  100% {
    opacity: 0.25;
  }
  50% {
    opacity: 0.22;
  }
  97% {
    opacity: 0.3;
  }
}

/* Manual screensaver trigger — styled to match .meta-val rows so it
   reads as inert monospace tertiary text until hover. */
.meta-action {
  background: transparent;
  border: none;
  padding: 0;
  margin: 0;
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--text-secondary);
  text-transform: uppercase;
  cursor: pointer;
  transition: color var(--dur, 200ms) var(--ease-out, ease);
}

.meta-action:hover,
.meta-action:focus-visible {
  color: var(--text-display);
  outline: none;
}

/* =========================================================
   #10 — Idle screensaver: cyberpunk monitoring panel
   Full-screen glanceable status. Shows live site count, banner,
   and incident roster. Auto-updates while idle.
   ========================================================= */

.idle-overlay {
  position: fixed;
  inset: 0;
  background: #f4f4f4;
  z-index: 10000;
  overflow: hidden;
  /* Locally flip the theme tokens so every .idle-* rule below reads
     correctly on a bright backdrop without having to duplicate them. */
  --text-primary: #1a1a1a;
  --text-display: #000000;
  --text-secondary: #555555;
  --text-disabled: #b0b0b0;
  --border-visible: #cccccc;
}

.idle-overlay[hidden] {
  display: none;
}

/* Scan-line veneer — dark lines on the bright backdrop so they stay visible. */
.idle-overlay::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  background: repeating-linear-gradient(
    0deg,
    rgba(0, 0, 0, 0.05) 0 1px,
    rgba(0, 0, 0, 0) 1px 3px
  );
  animation: crt-drift 0.15s linear infinite;
}

/* Soft vignette — light falloff with a gentle center haze so text
   reads cleanly over the ripple grid. */
.idle-overlay::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 1;
  background: radial-gradient(
    ellipse at center,
    rgba(244, 244, 244, 0.45) 0%,
    rgba(244, 244, 244, 0) 35%,
    rgba(255, 255, 255, 0.75) 100%
  );
}

/* Decorative rippling dot grid behind .idle-screen. A base dot grid
   fills the full overlay; a vertical mask fades dots out near the top
   so hero content has clear air. .idle-ripple elements are spawned
   from JS at random (x, y) and expand outward, brightening dots they
   pass through via `mix-blend-mode: screen`. */
.idle-ripples {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  overflow: hidden;
  background:
    radial-gradient(circle, rgba(0, 0, 0, 0.22) 1px, transparent 1.6px)
    0 0 / 14px 14px;
  -webkit-mask-image: linear-gradient(
    to bottom,
    transparent 0%,
    rgba(0, 0, 0, 0.35) 35%,
    black 60%,
    black 100%
  );
  mask-image: linear-gradient(
    to bottom,
    transparent 0%,
    rgba(0, 0, 0, 0.35) 35%,
    black 60%,
    black 100%
  );
}

.idle-ripple {
  position: absolute;
  left: var(--x, 50%);
  top: var(--y, 75%);
  width: 0;
  height: 0;
  border: 1.5px solid rgba(0, 0, 0, 0.7);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  mix-blend-mode: multiply;
  animation: idle-ripple-expand var(--dur, 3.2s) cubic-bezier(0.15, 0.7, 0.3, 1) forwards;
}

@keyframes idle-ripple-expand {
  0%   { width: 0;      height: 0;      opacity: 0; border-width: 2.5px; }
  10%  {                                opacity: 1;                       }
  100% { width: 75vmax; height: 75vmax; opacity: 0; border-width: 1px;   }
}

.idle-screen {
  position: relative;
  z-index: 3;
  width: 100%;
  height: 100%;
  max-width: 1600px;
  margin: 0 auto;
  padding: clamp(var(--space-xl), 3vw, var(--space-3xl));
  display: flex;
  flex-direction: column;
  color: var(--text-primary);
  font-family: var(--font-mono);
  --idle-accent: var(--success);
}

.idle-screen[data-state="degraded"] {
  --idle-accent: var(--accent);
}

/* Header row — brand on the left, wall-clock on the right */
.idle-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  letter-spacing: 0.12em;
  color: var(--text-secondary);
  text-transform: uppercase;
  padding-bottom: var(--space-md);
  border-bottom: 1px solid var(--border-visible);
}

.idle-brand {
  color: var(--idle-accent);
  letter-spacing: 0.15em;
}

.idle-timestamp {
  color: var(--text-display);
  font-variant-numeric: tabular-nums;
}

.idle-timestamp #idle-time {
  margin-left: var(--space-xs);
}

/* Core — hero number + banner + incident list, vertically centered */
.idle-core {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2xl);
  padding: var(--space-2xl) 0;
  min-height: 0;
}

.idle-hero {
  text-align: center;
  animation: idle-breath 4s ease-in-out infinite;
}

@keyframes idle-breath {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.02); }
}

.idle-number {
  font-family: var(--font-display);
  font-size: clamp(96px, 18vw, 280px);
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--idle-accent);
  transition: color 400ms;
  font-variant-numeric: tabular-nums;
}

.idle-screen[data-state="degraded"] .idle-number {
  animation: idle-number-alarm 1.2s ease-in-out infinite;
}

@keyframes idle-number-alarm {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.75; }
}

.idle-label {
  font-family: var(--font-mono);
  font-size: 18px;
  letter-spacing: 0.35em;
  color: var(--text-secondary);
  margin-top: var(--space-md);
}

/* Banner — status headline */
.idle-banner {
  display: flex;
  gap: var(--space-md);
  align-items: center;
  font-family: var(--font-mono);
  font-size: clamp(16px, 1.6vw, 24px);
  letter-spacing: 0.15em;
  color: var(--idle-accent);
  text-transform: uppercase;
}

.idle-screen[data-state="degraded"] .idle-banner {
  animation: idle-banner-flash 1.6s steps(2) infinite;
}

@keyframes idle-banner-flash {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.idle-banner-rule {
  color: var(--text-disabled);
  text-shadow: none;
}

/* Incident roster — one row per down site */
.idle-incidents {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  width: 100%;
  max-width: 900px;
  font-family: var(--font-mono);
  font-size: clamp(16px, 1.5vw, 22px);
}

.idle-incidents:empty {
  display: none;
}

.idle-incident {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-lg);
  padding: var(--space-sm) var(--space-md);
  border-left: 3px solid var(--accent);
  background: rgba(215, 25, 33, 0.08);
  color: var(--text-display);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  animation: idle-incident-pulse 2.4s ease-in-out infinite;
}

.idle-incident[data-status="PENDING"] {
  border-left-color: var(--warning);
  background: rgba(212, 168, 67, 0.08);
  animation: none;
}

@keyframes idle-incident-pulse {
  0%, 100% { background: rgba(215, 25, 33, 0.08); }
  50% { background: rgba(215, 25, 33, 0.2); }
}

.idle-incident-name {
  color: var(--text-display);
  font-weight: 500;
  letter-spacing: 0.08em;
}

.idle-incident-status {
  color: var(--accent);
  font-weight: 700;
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}

.idle-incident[data-status="PENDING"] .idle-incident-status {
  color: var(--warning);
}

.idle-incident-since {
  color: var(--text-secondary);
  font-size: 0.8em;
  letter-spacing: 0.08em;
}

/* Footer — last poll, since timer, activity cursor */
.idle-footer {
  display: flex;
  gap: var(--space-md);
  align-items: center;
  flex-wrap: wrap;
  font-size: 13px;
  letter-spacing: 0.1em;
  color: var(--text-secondary);
  text-transform: uppercase;
  padding-top: var(--space-md);
  border-top: 1px solid var(--border-visible);
  font-variant-numeric: tabular-nums;
}

.idle-footer span span {
  color: var(--text-display);
  margin-left: var(--space-xs);
}

.idle-footer-sep {
  color: var(--text-disabled);
}

.idle-activity {
  margin-left: auto;
  color: var(--idle-accent);
}

.idle-cursor {
  animation: idle-cursor 0.9s steps(2) infinite;
  margin-left: 2px;
}

@keyframes idle-cursor {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

/* Dim the underlying dashboard so the idle screen owns the frame */
body.idle .grid,
body.idle .archived,
body.idle .ticker,
body.idle .sweep-bar,
body.idle .hero {
  opacity: 0;
  transition: opacity 1s ease-out;
}

/* =========================================================
   TV scaling for new elements
   ========================================================= */

@media (min-width: 1920px) {
  .hero-main::after {
    width: 300px;
    height: 300px;
    margin: -150px 0 0 -150px;
  }
  .ticker {
    height: 36px;
    font-size: 18px;
  }
  .ticker-track {
    line-height: 36px;
  }
  .card-data .orbit-container {
    width: 64px;
    height: 64px;
  }
  .orbit-dot {
    width: 6px;
    height: 6px;
    margin: -3px 0 0 -3px;
  }
}
