/* =============================================================================
   Kingsoft Panel — custom CSS overlay (Phase 8)

   Tailwind via CDN handles ~99% of styling. This file provides:
   - keyframe animations (shimmer, pulse-dot, fade-in, flash-highlight)
   - utility classes that need pseudo-elements / multi-rule definitions
   - cross-browser scrollbar styling
   - tabular-nums helper
   - reduced-motion fallback
   - focus-visible ring polish
   ========================================================================== */

/* ---- Theme tokens (CSS variables) -------------------------------------- */
:root {
  --panel-bg: #020617;
  --panel-surface: #0f172a;
  --panel-surface-2: #1e293b;
  --panel-border: #1e293b;
  --panel-border-2: #334155;
  --panel-accent: #10b981;
  --panel-accent-violet: #8b5cf6;
  --panel-warn: #f59e0b;
  --panel-error: #f43f5e;
  --panel-text: #e2e8f0;
}

html, body {
  background: var(--panel-bg);
  color-scheme: dark;
}

body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Tabular nums utility — reserve fixed cell width on numeric stats so
   live-update changes don't jitter the layout. */
.tabular-nums,
.font-mono,
[x-text] {
  font-variant-numeric: tabular-nums;
}

/* x-cloak — hide elements until Alpine has hydrated state.
   Tailwind already supports [x-cloak] but we want a safer rule. */
[x-cloak] { display: none !important; }

/* ---- Skeleton loader (preferred over spinners) --------------------------- */
@keyframes shimmer {
  0%   { background-position: -200% 0; }
  100% { background-position:  200% 0; }
}

.skeleton {
  background: linear-gradient(
    90deg,
    rgba(148, 163, 184, 0.06) 25%,
    rgba(148, 163, 184, 0.14) 50%,
    rgba(148, 163, 184, 0.06) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s linear infinite;
  border-radius: 6px;
  min-height: 0.75rem;
}

.skeleton.skeleton-text {
  height: 0.875rem;
}

.skeleton.skeleton-stat {
  height: 1.5rem;
  width: 4ch;
}

/* ---- Live-pulse indicator ----------------------------------------------- */
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%      { opacity: 0.45; transform: scale(0.85); }
}

.animate-pulse-dot {
  animation: pulse-dot 1.6s ease-in-out infinite;
}

/* ---- Flash highlight on value change (driven by alpine-stores helper) ---- */
@keyframes flash-highlight {
  0%   { background-color: rgba(245, 158, 11, 0.0); }
  10%  { background-color: rgba(245, 158, 11, 0.35); }
  100% { background-color: rgba(245, 158, 11, 0.0); }
}

.flash-highlight {
  animation: flash-highlight 0.7s ease-out 1;
  border-radius: 4px;
}

/* ---- Fade-in on data arrival ------------------------------------------- */
@keyframes fade-in {
  from { opacity: 0; transform: translateY(2px); }
  to   { opacity: 1; transform: translateY(0); }
}

.fade-in {
  animation: fade-in 0.25s ease-out 1;
}

/* ---- Card baseline (for places not using full Tailwind) ----------------- */
.card {
  border-radius: 0.875rem;
  border: 1px solid var(--panel-border);
  background: rgba(15, 23, 42, 0.6);
  box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.4), 0 1px 3px 0 rgb(0 0 0 / 0.3);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--panel-border);
}

.card-body {
  padding: 1.25rem;
}

/* ---- Status pills (re-usable utility classes) --------------------------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.125rem 0.625rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 500;
  border: 1px solid;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 9999px;
  background: currentColor;
  flex-shrink: 0;
}

.pill-success {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.3);
}

.pill-success.pill-active::before {
  animation: pulse-dot 1.6s ease-in-out infinite;
}

.pill-warn {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border-color: rgba(245, 158, 11, 0.3);
}

.pill-error {
  background: rgba(244, 63, 94, 0.15);
  color: #fb7185;
  border-color: rgba(244, 63, 94, 0.3);
}

.pill-info {
  background: rgba(59, 130, 246, 0.15);
  color: #60a5fa;
  border-color: rgba(59, 130, 246, 0.3);
}

.pill-idle {
  background: rgba(100, 116, 139, 0.15);
  color: #94a3b8;
  border-color: rgba(100, 116, 139, 0.3);
}

/* ---- Mobile-friendly tap targets (per accessibility WCAG 2.5.5) --------- */
@media (max-width: 768px) {
  .nav-item,
  button:not(.btn-inline),
  a.btn,
  a.nav-item {
    min-height: 44px;
  }
}

/* ---- Scrollbar polish (webkit) ----------------------------------------- */
.scrollbar-thin {
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 163, 184, 0.25) transparent;
}

.scrollbar-thin::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.scrollbar-thin::-webkit-scrollbar-track {
  background: transparent;
}

.scrollbar-thin::-webkit-scrollbar-thumb {
  background-color: rgba(148, 163, 184, 0.25);
  border-radius: 3px;
}

.scrollbar-thin::-webkit-scrollbar-thumb:hover {
  background-color: rgba(148, 163, 184, 0.4);
}

/* ---- Focus-visible polish (consistent emerald ring) --------------------- */
:focus-visible {
  outline: 2px solid rgba(16, 185, 129, 0.5);
  outline-offset: 2px;
  border-radius: 6px;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.5);
}

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

/* ---- Tooltip (data-tooltip attribute) ---------------------------------- */
[data-tooltip] {
  position: relative;
}

[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  padding: 0.25rem 0.5rem;
  background: var(--panel-surface);
  border: 1px solid var(--panel-border-2);
  border-radius: 6px;
  font-size: 0.75rem;
  white-space: nowrap;
  pointer-events: none;
  z-index: 60;
  box-shadow: 0 4px 12px -4px rgb(0 0 0 / 0.4);
}

/* ---- Print-friendly minimal reset (operator may want PDF reports) ------ */
@media print {
  aside, header, footer, #panel-toast { display: none !important; }
  body { background: white; color: black; }
  .card { border-color: #ccc; background: white; }
}
