/* ============================================================
   MOTION — animation layer for kube-hat.
   Loaded after components.css so it wins on the cascade.
   Additive only: no layout changes, no markup dependencies.
   All animations respect prefers-reduced-motion.
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ---------- keyframes ---------- */
@keyframes kh-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes kh-slide-up {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0)    scale(1); }
}

@keyframes kh-scan-drift {
  from { background-position: 0 0, 0 0, 0 0; }
  to   { background-position: 400px 400px, 0 0, 0 0; }
}

@keyframes kh-pulse-ring {
  0%   { box-shadow: 0 0 0 0 var(--accent);   opacity: 1; }
  70%  { box-shadow: 0 0 0 8px transparent;   opacity: 0; }
  100% { box-shadow: 0 0 0 0 transparent;     opacity: 0; }
}

@keyframes kh-bar-in {
  from { transform: scaleY(0.15); opacity: 0; }
  to   { transform: scaleY(1);    opacity: 1; }
}

@keyframes kh-sep-drift {
  0%, 100% { opacity: 0.4; }
  50%      { opacity: 0.9; }
}

/* ---------- 1. Ambient background drift ----------
   The existing diagonal-tick pattern on body::before now slowly slides.
   Multi-layered background-position values in the same order as the
   original declaration in components.css. ~120s per cycle: barely
   perceptible, feels like the system is running. */
body::before {
  animation: kh-scan-drift 120s linear infinite;
}

/* ---------- 2. Buttons: glow-hover + press ---------- */
.btn--primary:not(:disabled) {
  position: relative;
  overflow: hidden;
  isolation: isolate;
}
.btn--primary:not(:disabled)::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(
    120deg,
    transparent 30%,
    rgba(255, 255, 255, 0.18) 50%,
    transparent 70%
  );
  transform: translateX(-120%);
  transition: transform 700ms var(--ease-out);
  pointer-events: none;
}
.btn--primary:not(:disabled):hover::after {
  transform: translateX(120%);
}
.btn--primary:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow:
    0 0 0 1px var(--accent-bright),
    0 0 18px -2px var(--accent),
    0 6px 22px -8px var(--accent);
}
.btn--primary:not(:disabled):active {
  transform: translateY(1px);
  transition-duration: 40ms;
  box-shadow: 0 0 0 1px var(--accent);
}

.btn--secondary:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow:
    0 0 0 1px var(--accent),
    0 0 14px -4px var(--accent);
}
.btn--secondary:not(:disabled):active {
  transform: translateY(1px);
  transition-duration: 40ms;
}

.btn--danger:not(:disabled):hover {
  transform: translateY(-1px);
  box-shadow:
    0 0 14px -2px var(--danger),
    0 6px 18px -8px var(--danger);
}
.btn--danger:not(:disabled):active {
  transform: translateY(1px);
  transition-duration: 40ms;
}

.btn--ghost:not(:disabled):hover {
  transform: translateY(-1px);
}

/* ---------- 3. Modal reveal ----------
   .kh-modal is the shared modal skeleton used by release notes,
   user-edit, user-create. Backdrop fades; card slides + fades.
   Animations run whenever display flips from none → flex/block. */
.kh-modal {
  animation: kh-fade-in 160ms var(--ease-out);
}
.kh-modal__backdrop {
  animation: kh-fade-in 200ms var(--ease-out);
}
.kh-modal__card {
  animation: kh-slide-up 260ms var(--ease-out);
  transform-origin: center top;
}

/* ---------- 4. Sidebar: enhanced active state ----------
   Active nav-item glows the icon, animates the accent bar in,
   and gets a subtle inset ring. Hover triggers a soft label lift. */
.nav-item {
  transition:
    background var(--dur-fast) var(--ease-out),
    color var(--dur-fast) var(--ease-out),
    box-shadow var(--dur-med) var(--ease-out),
    transform var(--dur-fast) var(--ease-out);
}
.nav-item:hover {
  transform: translateX(2px);
}
.nav-item[aria-current="page"],
.nav-item.is-active {
  box-shadow:
    inset 0 0 0 1px var(--border-accent),
    inset 0 0 12px -4px var(--accent-soft);
}
.nav-item[aria-current="page"]::before,
.nav-item.is-active::before {
  animation: kh-bar-in 280ms var(--ease-out) both;
  transform-origin: center;
}
.nav-item[aria-current="page"] .nav-item__icon,
.nav-item.is-active .nav-item__icon {
  filter: drop-shadow(0 0 6px var(--accent));
  transition: filter var(--dur-med) var(--ease-out);
}

/* ---------- 5. Topbar zones + animated separator ----------
   Groups action chips into telemetry / identity zones.
   The separator is a thin vertical hairline that gently breathes. */
.topbar__zone {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
}
.topbar__sep {
  width: 1px;
  align-self: stretch;
  margin: 10px 4px;
  background: linear-gradient(
    180deg,
    transparent,
    var(--border-strong) 30%,
    var(--border-strong) 70%,
    transparent
  );
  animation: kh-sep-drift 3.6s var(--ease-in-out) infinite;
}

/* ---------- 6. Framed cards (corner-brackets, animated) ----------
   Signature style: extract the login card's chrome corners into a
   reusable variant.

   Auto-applied to:
     - .card--framed (explicit opt-in)
     - .content-section > .card (every settings-tab primary card, so
       the whole Settings surface gets consistent HUD chrome without
       editing 20 template blocks).

   Skips .card--ticks so we don't double up with the existing
   thinner corners on login / cluster cards. */
.card--framed,
.content-section > .card:not(.card--ticks) {
  position: relative;
}
.card--framed::before,
.card--framed::after,
.content-section > .card:not(.card--ticks)::before,
.content-section > .card:not(.card--ticks)::after {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  border-color: var(--accent);
  border-style: solid;
  opacity: 0.5;
  pointer-events: none;
  transition:
    opacity 220ms var(--ease-out),
    width 220ms var(--ease-out),
    height 220ms var(--ease-out);
}
.card--framed::before,
.content-section > .card:not(.card--ticks)::before {
  top: 6px;
  left: 6px;
  border-width: 1px 0 0 1px;
}
.card--framed::after,
.content-section > .card:not(.card--ticks)::after {
  bottom: 6px;
  right: 6px;
  border-width: 0 1px 1px 0;
}
.card--framed:hover::before,
.card--framed:hover::after,
.content-section > .card:not(.card--ticks):hover::before,
.content-section > .card:not(.card--ticks):hover::after {
  opacity: 0.95;
  width: 18px;
  height: 18px;
}

/* Chip pulse ring (used on the "live"/status chip dot) */
.chip__dot {
  position: relative;
}
.chip__dot::after {
  content: "";
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  animation: kh-pulse-ring 2.4s var(--ease-out) infinite;
  pointer-events: none;
}

/* Small: stat-tile press feedback */
.stat-tile:active {
  transform: translateY(0);
  transition-duration: 40ms;
}

/* ---------- 7. Ambient status LED (topbar) ----------
   Small green dot + label, pulses gently. When the status chip is a
   button (clickable → opens command palette), lift on hover. */
.kh-status {
  display: inline-flex;
  align-items: center;
  gap: var(--s-2);
  background: var(--bg-panel-raised);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  padding: 4px 10px;
  color: var(--ink-dim);
  font-size: var(--fs-xs);
  letter-spacing: 0.08em;
  transition: border-color var(--dur-fast) var(--ease-out),
              transform var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}
.kh-status:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 0 12px -4px var(--accent);
}
.kh-status__led {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
  position: relative;
  flex-shrink: 0;
}
.kh-status__led::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 1px solid var(--success);
  opacity: 0.7;
  animation: kh-pulse-ring 2s var(--ease-out) infinite;
}
.kh-status__label {
  font-family: var(--font-mono);
  font-weight: var(--fw-semibold);
  color: var(--ink-dim);
}
.kh-status__kbd {
  font-family: var(--font-mono);
  color: var(--muted-2);
  border-left: 1px solid var(--border);
  padding-left: 8px;
}
/* Degraded / update-available state — set via JS by adding
   .kh-status--warn or .kh-status--err. */
.kh-status--warn .kh-status__led,
.kh-status--warn .kh-status__led::after {
  background: var(--warning, #f5a524);
  box-shadow: 0 0 8px var(--warning, #f5a524);
  border-color: var(--warning, #f5a524);
}
.kh-status--err .kh-status__led,
.kh-status--err .kh-status__led::after {
  background: var(--danger);
  box-shadow: 0 0 8px var(--danger);
  border-color: var(--danger);
}

/* ---------- 8. Table row activation ----------
   Rows already have :hover background from components.css. We add a
   persistent accent left-rule on the hovered row + a background
   feathering into transparent so the row lights up left-to-right.
   Pseudo-elements on <tr> are unreliable across browsers, so we do
   this on the first cell instead. */
tbody tr {
  transition: background var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-med) var(--ease-out);
}
tbody tr:hover {
  box-shadow: inset 3px 0 0 var(--accent);
}
tbody tr:hover td:first-child {
  background: linear-gradient(90deg, var(--accent-soft), transparent 80%);
}

/* ---------- 9. Number-ticker entrance ----------
   The ticker JS toggles .is-ticking during the count-up so a mono font
   + accent color highlights the running digits, then settles. */
[data-kh-ticker] {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  transition: color var(--dur-med) var(--ease-out);
}
[data-kh-ticker].is-ticking {
  color: var(--accent);
  text-shadow: 0 0 8px var(--accent-soft);
}

/* ---------- 10. Empty-state hero (clusters page) ---------- */
.kh-empty {
  display: grid;
  place-items: center;
  gap: var(--s-4);
  padding: var(--s-8, 48px) var(--s-5);
  text-align: center;
  min-height: 60vh;
  animation: kh-fade-in 400ms var(--ease-out);
}
.kh-empty__radar {
  position: relative;
  width: 220px; height: 220px;
  border-radius: 50%;
  border: 1px solid var(--border-accent);
  background:
    radial-gradient(circle at center, transparent 68%, var(--accent-soft) 100%),
    repeating-radial-gradient(circle at center, transparent 0 22px, var(--border) 22px 23px);
}
.kh-empty__radar::before {
  content: "";
  position: absolute; inset: 0;
  border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 0deg 320deg, var(--accent) 355deg, transparent 360deg);
  animation: kh-radar-sweep 3.6s linear infinite;
  filter: blur(0.4px);
  mix-blend-mode: screen;
}
.kh-empty__radar::after {
  content: "";
  position: absolute;
  top: 50%; left: 50%;
  width: 10px; height: 10px;
  margin: -5px 0 0 -5px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
  animation: kh-pulse-ring 2s var(--ease-out) infinite;
}
@keyframes kh-radar-sweep {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
.kh-empty__eyebrow {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  letter-spacing: 0.28em;
  color: var(--accent);
  text-transform: uppercase;
}
.kh-empty__title {
  font-size: var(--fs-xl, 22px);
  font-weight: var(--fw-semibold);
  color: var(--ink);
  letter-spacing: 0.04em;
}
.kh-empty__body {
  max-width: 460px;
  color: var(--muted);
  font-size: var(--fs-sm);
  line-height: 1.6;
}
.kh-empty__cta {
  display: inline-flex; align-items: center; gap: var(--s-2);
  margin-top: var(--s-2);
}

/* ============================================================
   TIER 3 — cinematic FX (boot overlay, pulse, telemetry rail).
   All controlled by kh-fx.js.
   ============================================================ */

/* ---------- Boot overlay ----------
   Full-viewport chrome that animates in, holds for a beat, and
   fades out on `.is-done`. Fires once per session on login page. */
.kh-boot {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: radial-gradient(circle at center,
    rgba(0, 0, 0, 0.85) 0%,
    rgba(0, 0, 0, 0.6) 60%,
    rgba(0, 0, 0, 0.98) 100%);
  pointer-events: none;
  overflow: hidden;
  opacity: 1;
  transition: opacity 380ms var(--ease-out);
}
.kh-boot.is-done { opacity: 0; }

.kh-boot__cross {
  position: absolute;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent), 0 0 32px var(--accent-soft);
  transform-origin: center;
}
.kh-boot__cross--h {
  left: 50%; top: 50%; height: 1px; width: 0;
  transform: translate(-50%, -50%);
}
.kh-boot__cross--v {
  left: 50%; top: 50%; width: 1px; height: 0;
  transform: translate(-50%, -50%);
}
.kh-boot.is-running .kh-boot__cross--h {
  animation: kh-boot-cross-h 720ms var(--ease-out) forwards;
}
.kh-boot.is-running .kh-boot__cross--v {
  animation: kh-boot-cross-v 720ms var(--ease-out) 100ms forwards;
}
@keyframes kh-boot-cross-h {
  0%   { width: 0; opacity: 0; }
  15%  { opacity: 1; }
  60%  { width: 100vw; opacity: 1; }
  100% { width: 100vw; opacity: 0.35; }
}
@keyframes kh-boot-cross-v {
  0%   { height: 0; opacity: 0; }
  15%  { opacity: 1; }
  60%  { height: 100vh; opacity: 1; }
  100% { height: 100vh; opacity: 0.35; }
}

.kh-boot__ring {
  position: absolute;
  left: 50%; top: 50%;
  width: 12px; height: 12px;
  margin-left: -6px; margin-top: -6px;
  border: 1px solid var(--accent);
  border-radius: 50%;
  opacity: 0;
  box-shadow: 0 0 20px var(--accent);
}
.kh-boot.is-running .kh-boot__ring {
  animation: kh-boot-ring 900ms var(--ease-out) 240ms forwards;
}
.kh-boot.is-running .kh-boot__ring--2 {
  animation-delay: 420ms;
  animation-duration: 1100ms;
}
@keyframes kh-boot-ring {
  0%   { transform: scale(0.4); opacity: 1; border-width: 2px; }
  60%  { transform: scale(24);  opacity: 0.35; border-width: 1px; }
  100% { transform: scale(38);  opacity: 0;    border-width: 1px; }
}

.kh-boot__label {
  position: absolute;
  left: 50%; top: 62%;
  transform: translate(-50%, -50%);
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  letter-spacing: 0.35em;
  color: var(--accent);
  text-transform: uppercase;
  opacity: 0;
  text-shadow: 0 0 8px var(--accent);
}
.kh-boot.is-running .kh-boot__label {
  animation: kh-fade-in 300ms var(--ease-out) 620ms forwards;
}

/* ---------- Pulse (topbar success/error/info flash) ----------
   Adds a colored top hairline + soft glow that runs across then fades.
   Triggered by window.khPulse("ok"|"err"|"info"). Uses ::after on the
   already-sticky-positioned topbar (sticky is a positioning context). */
.topbar::after {
  content: "";
  position: absolute;
  left: 0; right: 0; top: -1px;
  height: 2px;
  background: linear-gradient(90deg, transparent, currentColor, transparent);
  opacity: 0;
  pointer-events: none;
}
.kh-pulse--ok    { --pulse-c: var(--success); }
.kh-pulse--err   { --pulse-c: var(--danger); }
.kh-pulse--info  { --pulse-c: var(--accent); }
.topbar.kh-pulse--ok::after,
.topbar.kh-pulse--err::after,
.topbar.kh-pulse--info::after {
  color: var(--pulse-c);
  animation: kh-pulse-sweep 900ms var(--ease-out);
}
.topbar.kh-pulse--ok,
.topbar.kh-pulse--err,
.topbar.kh-pulse--info {
  box-shadow: inset 0 3px 24px -6px var(--pulse-c);
  animation: kh-pulse-glow 900ms var(--ease-out);
}
@keyframes kh-pulse-sweep {
  0%   { opacity: 0; transform: translateX(-40%); }
  30%  { opacity: 1; }
  100% { opacity: 0; transform: translateX(40%); }
}
@keyframes kh-pulse-glow {
  0%   { box-shadow: inset 0 3px 0 -3px var(--pulse-c); }
  30%  { box-shadow: inset 0 6px 32px -4px var(--pulse-c); }
  100% { box-shadow: inset 0 0 0 -3px transparent; }
}

/* ---------- Ambient telemetry rail (hover-to-reveal) ----------
   Idle: a tiny accent handle flush against the right viewport edge.
   On hover: badges slide in leftward from the edge.
   On mouseleave: badges slide back rightward and vanish into the edge.
   JS (kh-fx.js) only runs the 1s timer while .is-open — no work while
   idle. The body is position:absolute so it doesn't reserve layout
   width, keeping the handle pinned to the viewport edge. */
[data-kh-telemetry] {
  position: fixed;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  z-index: var(--z-topbar, 40);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  /* Left padding is the hover hotspot — makes the handle easier to
     find without needing pixel-perfect aim. Zero right padding keeps
     the handle flush to the viewport edge. */
  padding: var(--s-4) 0 var(--s-4) 40px;
}
@media (max-width: 1439px) {
  [data-kh-telemetry] { display: none; }
}
.kh-rail__handle {
  width: 3px;
  height: 64px;
  border-radius: 2px 0 0 2px;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
  opacity: 0.55;
  flex-shrink: 0;
  transition: opacity var(--dur-med) var(--ease-out),
              height var(--dur-med) var(--ease-out);
}
[data-kh-telemetry]:hover .kh-rail__handle,
[data-kh-telemetry].is-open .kh-rail__handle {
  opacity: 1;
  height: 96px;
}
.kh-rail__body {
  /* Absolute so it doesn't reserve width — handle stays at the edge. */
  position: absolute;
  right: 12px;
  top: 50%;
  display: flex;
  flex-direction: column;
  gap: var(--s-3);
  transform: translate(120%, -50%);
  opacity: 0;
  pointer-events: none;
  transition: transform 280ms var(--ease-out),
              opacity 220ms var(--ease-out);
}
[data-kh-telemetry].is-open .kh-rail__body {
  transform: translate(0, -50%);
  opacity: 1;
  pointer-events: auto;
}
.kh-rail__badge {
  min-width: 96px;
  padding: 8px 12px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  box-shadow: var(--elev-1);
  text-align: right;
  position: relative;
  overflow: hidden;
  transition: border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}
.kh-rail__badge::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 2px;
  background: var(--accent);
  opacity: 0.7;
}
.kh-rail__badge:hover {
  border-color: var(--accent);
  box-shadow: var(--elev-2), 0 0 16px -6px var(--accent);
}
.kh-rail__k {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--muted-2);
  text-transform: uppercase;
}
.kh-rail__v {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-md);
  color: var(--accent);
  text-shadow: 0 0 8px var(--accent-soft);
  line-height: 1.1;
  margin-top: 2px;
}
.kh-rail__v--sm { font-size: var(--fs-sm); }
.kh-rail__s {
  font-family: var(--font-mono);
  font-size: 9px;
  letter-spacing: 0.12em;
  color: var(--muted-2);
  text-transform: uppercase;
  margin-top: 2px;
}

/* ============================================================
   CLUSTER PAGE — filter toolbar, sort carets, pulsing pills.
   Injected/toggled by static/js/kh-cluster.js.
   ============================================================ */

.kh-tbl-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-3);
  margin: var(--s-3) 0 var(--s-3);
  padding: 0;
}
.kh-tbl-toolbar__filter {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1;
  max-width: 420px;
  border: 1px solid var(--border-strong);
  background: var(--bg-input);
  border-radius: var(--r-pill);
  padding: 4px 12px 4px 34px;
  transition: border-color var(--dur-fast) var(--ease-out),
              box-shadow var(--dur-fast) var(--ease-out);
}
.kh-tbl-toolbar__filter:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.kh-tbl-toolbar__icon {
  position: absolute;
  left: 12px;
  color: var(--muted);
  pointer-events: none;
  display: grid;
  place-items: center;
}
.kh-tbl-toolbar__input {
  flex: 1;
  background: transparent;
  border: 0;
  outline: 0;
  padding: 6px 0;
  color: var(--ink);
  font-family: inherit;
  font-size: var(--fs-sm);
}
.kh-tbl-toolbar__input::placeholder { color: var(--muted-2); }
.kh-tbl-toolbar__clear {
  background: transparent;
  border: 0;
  color: var(--muted);
  font-size: var(--fs-md);
  cursor: pointer;
  padding: 0 4px;
  transition: color var(--dur-fast) var(--ease-out);
}
.kh-tbl-toolbar__clear:hover { color: var(--danger); }
.kh-tbl-toolbar__count {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  color: var(--muted);
  min-width: 90px;
  text-align: right;
  transition: color var(--dur-fast) var(--ease-out);
}
.kh-tbl-toolbar__count.is-active {
  color: var(--accent);
  text-shadow: 0 0 6px var(--accent-soft);
}

/* Sortable header cells */
.kh-th-sortable {
  cursor: pointer;
  user-select: none;
  position: relative;
  padding-right: 22px !important;
  transition: color var(--dur-fast) var(--ease-out);
}
.kh-th-sortable:hover { color: var(--accent); }
.kh-th-caret {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 10px;
  height: 10px;
  opacity: 0.35;
  background:
    linear-gradient(45deg, transparent 46%, currentColor 46% 54%, transparent 54%) 0 3px / 8px 3px no-repeat,
    linear-gradient(-45deg, transparent 46%, currentColor 46% 54%, transparent 54%) 8px 3px / 8px 3px no-repeat;
  transition: opacity var(--dur-fast) var(--ease-out);
}
.kh-th-sortable.is-sorted-asc .kh-th-caret,
.kh-th-sortable.is-sorted-desc .kh-th-caret {
  opacity: 1;
  color: var(--accent);
}
.kh-th-sortable.is-sorted-asc .kh-th-caret {
  background:
    linear-gradient(45deg, transparent 46%, currentColor 46% 54%, transparent 54%) 0 3px / 10px 4px no-repeat,
    linear-gradient(-45deg, transparent 46%, currentColor 46% 54%, transparent 54%) 5px 3px / 10px 4px no-repeat;
}
.kh-th-sortable.is-sorted-desc .kh-th-caret {
  transform: translateY(-50%) rotate(180deg);
}

/* Hidden rows (filter miss) */
.kh-row-hidden { display: none !important; }

/* Pulsing problem pills — CrashLoop / ImagePull / etc.
   Uses the existing .pod-state-pill.problem class from cluster.js. */
.pod-state-pill.problem {
  position: relative;
  overflow: visible;
  box-shadow: 0 0 0 0 var(--danger);
  animation: kh-pill-pulse 2s var(--ease-out) infinite;
}
@keyframes kh-pill-pulse {
  0%   { box-shadow: 0 0 0 0    rgba(255, 68, 68, 0.55); }
  70%  { box-shadow: 0 0 0 8px  rgba(255, 68, 68, 0);    }
  100% { box-shadow: 0 0 0 0    rgba(255, 68, 68, 0);    }
}

/* ============================================================
   TOASTS (window.khToast + kh-toasts.js auto-hook)
   ============================================================ */
.kh-toaster {
  position: fixed;
  top: calc(var(--layout-topbar-h, 56px) + 12px);
  right: 16px;
  z-index: 9500;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: min(420px, calc(100vw - 32px));
}
.kh-toast {
  pointer-events: auto;
  position: relative;
  display: grid;
  grid-template-columns: 24px 1fr auto auto;
  align-items: start;
  gap: var(--s-3);
  padding: 12px 14px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-md);
  box-shadow: var(--elev-3), 0 0 20px -8px var(--accent);
  color: var(--ink);
  opacity: 0;
  transform: translateX(24px);
  transition: opacity 220ms var(--ease-out),
              transform 260ms var(--ease-out),
              border-color var(--dur-fast) var(--ease-out);
  overflow: hidden;
}
.kh-toast.is-in  { opacity: 1; transform: translateX(0); }
.kh-toast.is-out { opacity: 0; transform: translateX(24px); }

/* Countdown hairline that shrinks left-to-right = time to auto-dismiss.
   Uses `animation` so `mouseenter` pausing kills it visually too. */
.kh-toast::after {
  content: "";
  position: absolute;
  left: 0; bottom: 0; height: 2px; width: 100%;
  background: var(--accent);
  opacity: 0.55;
  transform-origin: left center;
  animation: kh-toast-life var(--ttl, 5000ms) linear forwards;
}
.kh-toast:hover::after { animation-play-state: paused; }

@keyframes kh-toast-life {
  from { transform: scaleX(1); }
  to   { transform: scaleX(0); }
}

.kh-toast--ok  { border-left-color: var(--success); box-shadow: var(--elev-3), 0 0 22px -8px var(--success); }
.kh-toast--ok::after,
.kh-toast--ok  .kh-toast__icon { color: var(--success); }
.kh-toast--err { border-left-color: var(--danger);  box-shadow: var(--elev-3), 0 0 22px -8px var(--danger); }
.kh-toast--err::after,
.kh-toast--err .kh-toast__icon { color: var(--danger); }
.kh-toast--info .kh-toast__icon { color: var(--accent); }

.kh-toast__icon {
  width: 22px; height: 22px; display: grid; place-items: center;
  filter: drop-shadow(0 0 6px currentColor);
}
.kh-toast__icon svg { width: 18px; height: 18px; }
.kh-toast__title {
  font-weight: var(--fw-semibold);
  font-size: var(--fs-sm);
  color: var(--ink);
  letter-spacing: 0.02em;
}
.kh-toast__text {
  margin-top: 2px;
  font-size: var(--fs-sm);
  color: var(--muted);
  line-height: 1.45;
  word-wrap: break-word;
}
.kh-toast__action {
  font-family: inherit; font-size: var(--fs-xs);
  padding: 4px 10px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--border-accent);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease-out);
}
.kh-toast__action:hover { background: var(--accent); color: var(--accent-contrast); }
.kh-toast__close {
  background: transparent; border: 0; color: var(--muted);
  font-size: 18px; cursor: pointer; padding: 0 4px; line-height: 1;
  transition: color var(--dur-fast) var(--ease-out);
}
.kh-toast__close:hover { color: var(--danger); }

/* ============================================================
   SKELETONS — shimmering placeholders for loading states.
   Any element with `.kh-skel` shows a moving accent shimmer.
   ============================================================ */
.kh-skel,
.kh-skel-line,
.kh-skel-block {
  position: relative;
  overflow: hidden;
  background: var(--bg-panel-raised);
  border-radius: var(--r-sm);
  color: transparent !important;
  user-select: none;
}
.kh-skel::after,
.kh-skel-line::after,
.kh-skel-block::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    var(--accent-soft) 45%,
    var(--accent-softer) 55%,
    transparent 100%
  );
  transform: translateX(-100%);
  animation: kh-skel-sweep 1400ms linear infinite;
}
@keyframes kh-skel-sweep {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(100%);  }
}
.kh-skel-line   { display: inline-block; height: 12px; width: 80px; vertical-align: middle; }
.kh-skel-block  { display: block; height: 44px; width: 100%; }

/* Auto-apply skeleton to the existing `.stat-value.loading` class used
   by the clusters-index cards while pod/node counts are being fetched. */
.stat-value.loading {
  position: relative;
  overflow: hidden;
  background: var(--bg-panel-raised);
  border-radius: var(--r-sm);
  color: transparent !important;
  min-width: 40px;
  display: inline-block;
  user-select: none;
}
.stat-value.loading::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    var(--accent-soft) 45%,
    var(--accent-softer) 55%,
    transparent 100%
  );
  transform: translateX(-100%);
  animation: kh-skel-sweep 1400ms linear infinite;
}
/* Pie-total is bigger — reserve enough width for the shimmer to matter. */
.pie-total.stat-value.loading { min-width: 60px; height: 22px; }

/* ============================================================
   AUDIT LOG — color-coded action chips + user avatar chip.
   Applied by kh-audit.js at DOMContentLoaded.
   ============================================================ */

.audit-act {
  font-family: var(--font-mono);
  font-size: var(--fs-xs);
  letter-spacing: 0.06em;
  text-transform: lowercase;
  padding: 2px 10px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border);
  background: var(--bg-panel-raised);
  color: var(--muted);
  transition: box-shadow var(--dur-fast) var(--ease-out);
}
.audit-act--ok    { color: var(--success); border-color: var(--success); background: var(--success-soft, rgba(58, 195, 128, 0.10)); }
.audit-act--err   { color: var(--danger);  border-color: var(--danger);  background: var(--danger-soft,  rgba(255, 90, 90, 0.10)); }
.audit-act--warn  { color: var(--warning); border-color: var(--warning); background: var(--warning-soft, rgba(245, 165, 36, 0.10)); }
.audit-act--info  { color: var(--accent);  border-color: var(--border-accent); background: var(--accent-soft); }
.audit-act--exec  { color: var(--accent);  border-color: var(--accent);        background: var(--accent-soft);
                    box-shadow: 0 0 10px -4px var(--accent); }
.audit-act--ai    { color: #b178ff;        border-color: rgba(177,120,255,0.6); background: rgba(177,120,255,0.10); }
.audit-act--muted { color: var(--muted-2); border-color: var(--border);        background: transparent; }
tbody tr:hover .audit-act--exec { box-shadow: 0 0 14px -2px var(--accent); }

/* User cell → avatar chip + name. */
.audit-user {
  display: flex;
  align-items: center;
  gap: 8px;
}
.audit-user__avatar {
  display: inline-grid; place-items: center;
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: var(--fw-bold);
  letter-spacing: 0.02em;
  border: 1px solid var(--border-accent);
  flex-shrink: 0;
}
.audit-user__avatar--sys {
  background: var(--bg-panel-raised);
  color: var(--muted);
  border-color: var(--border);
}
.audit-user__avatar--sys svg { width: 14px; height: 14px; }
.audit-user__name {
  font-size: var(--fs-sm);
  color: var(--ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Time cell — monospaced, muted, with a subtle accent left rule to
   line up as a HUD readout column. */
.audit-table td.audit-time {
  color: var(--muted);
  font-size: var(--fs-xs);
  border-left: 2px solid transparent;
  transition: border-color var(--dur-fast) var(--ease-out);
}
tbody tr:hover .audit-table td.audit-time,
.audit-table tbody tr:hover td.audit-time {
  border-left-color: var(--accent);
  color: var(--ink);
}

/* Small: brand-mark subtle idle breathing on login/topbar */
.brand-mark {
  transition: box-shadow var(--dur-med) var(--ease-out),
              transform var(--dur-med) var(--ease-out);
}
.brand:hover .brand-mark {
  transform: rotate(-4deg) scale(1.05);
  box-shadow: var(--glow);
}
