/* ═══════════════════════════════════════════════════════════════════════════
   VetERP Loading states — skeleton, refresh bar, inline loading.
   Shared by the tenant app, the backoffice and the tutor portal (the portal does not load
   components.css, so this lives in its own file). Components: VetSkeleton* in SharedAssets.
   ═══════════════════════════════════════════════════════════════════════════ */

/* ────────────────────────────────────────────────────────────────────────────
   SKELETON & LOADERS
   Skeleton = first load of content with a known shape. Refresh = reload keeping the current
   content dimmed (pagination/filter). Pure CSS shared by every app (tenant, backoffice,
   portal); each app only overrides the --skeleton-* tokens when it needs to.
   ─────────────────────────────────────────────────────────────────────────── */

:root {
  --skeleton-base: var(--color-gray-100);
  --skeleton-highlight: var(--color-gray-200);
  --skeleton-radius: 8px;
  --skeleton-delay: 150ms; /* anti-flicker: fast responses never show the skeleton */
  --refresh-bar-color: var(--color-primary-600);
}

.vet-skeleton-region {
  position: relative;
  width: 100%;
  animation: vetSkeletonFadeIn 0.2s ease var(--skeleton-delay) both;
}
.vet-skeleton {
  display: block;
  background: linear-gradient(90deg,
    var(--skeleton-base) 25%,
    var(--skeleton-highlight) 50%,
    var(--skeleton-base) 75%);
  background-size: 200% 100%;
  animation: vetSkeletonShimmer 1.4s ease-in-out infinite;
  border-radius: var(--skeleton-radius);
  max-width: 100%;
}
.vet-skeleton--text   { height: 12px; }
.vet-skeleton--title  { height: 20px; }
.vet-skeleton--circle { border-radius: 50%; flex-shrink: 0; }
.vet-skeleton--pill   { height: 22px; border-radius: 999px; }
.vet-skeleton--rect   { height: 40px; }
.vet-skeleton-lines   { display: flex; flex-direction: column; gap: 8px; width: 100%; }

.vet-skeleton-row   { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.vet-skeleton-stack { display: flex; flex-direction: column; gap: var(--space-2); flex: 1; min-width: 0; }

/* Table rows (VetDataTable) */
.vet-skeleton-table-row { animation: vetSkeletonFadeIn 0.2s ease var(--skeleton-delay) both; }
.vet-skeleton-table-row td { padding-top: 14px !important; padding-bottom: 14px !important; }
.vet-skeleton--muted { opacity: 0.7; }
.vet-skeleton-actions { display: flex; gap: 6px; justify-content: flex-end; }
.vet-skeleton-table-row:hover { background: transparent !important; }

/* Form body */
.vet-skeleton-form { display: flex; flex-direction: column; gap: var(--space-5); }
.vet-skeleton-form__tabs { display: flex; gap: var(--space-3); padding-bottom: var(--space-2); border-bottom: 1px solid var(--color-border); }
.vet-skeleton-form__section,
.vet-skeleton-card,
.vet-skeleton-detail__header {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-xl, 16px);
  padding: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
}
.vet-skeleton-form__grid { display: grid; gap: var(--space-4); grid-template-columns: repeat(var(--vet-skeleton-cols, 2), minmax(0, 1fr)); }
.vet-skeleton-form__field { display: flex; flex-direction: column; gap: 8px; }
.vet-skeleton-form__actions { display: flex; gap: var(--space-3); justify-content: flex-end; }

/* Cards (dashboards, tiles) */
.vet-skeleton-cards {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(auto-fill, minmax(var(--vet-skeleton-card-min, 220px), 1fr));
}
.vet-skeleton-card { padding: var(--space-4) var(--space-5); gap: var(--space-3); }

/* Queue / card lists */
.vet-skeleton-list { display: flex; flex-direction: column; gap: var(--space-3); }
.vet-skeleton-list__item {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg, 12px);
  padding: var(--space-3) var(--space-4);
}

/* Detail page (header + tabs + sections) */
.vet-skeleton-detail { display: flex; flex-direction: column; gap: var(--space-5); }

/* Skeleton rendered inside an existing card: flatten its own sections (no card-in-card) */
:is(.card-body, .admin-card) :is(.vet-skeleton-form__section, .vet-skeleton-detail__header, .vet-skeleton-card, .vet-skeleton-list__item) {
  border: 0;
  padding: 0;
  background: transparent;
}

/* Timeline */
.vet-skeleton-timeline { display: flex; flex-direction: column; gap: var(--space-4); padding: var(--space-2) 0; }

/* Refresh: keep the current content, dim it and show a thin indeterminate bar on top */
.vet-refresh-host { position: relative; }
.vet-refreshing {
  opacity: 0.55;
  pointer-events: none;
  transition: opacity 0.15s ease;
}
.vet-refresh-bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  overflow: hidden;
  z-index: 3;
  border-radius: 2px;
  animation: vetSkeletonFadeIn 0.2s ease var(--skeleton-delay) both;
}
.vet-refresh-bar::after {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  width: 35%;
  background: var(--refresh-bar-color);
  animation: vetRefreshBar 1.1s ease-in-out infinite;
}

/* Inline "loading options" hint used by lookup selects and small sub-blocks */
.vet-inline-loading {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--font-size-xs);
  color: var(--color-text-muted);
}

/* Search-as-you-type input (VetSearchIndicator): magnifier → thin ring + 2px line on the bottom edge.
   The ring/line appear only after 150ms (transition-delay), so quick answers never flash. */
.vet-search-field {
  position: relative;
}
.vet-search-field > .form-control {
  padding-right: 2.6rem;
}
.vet-search-indicator {
  position: absolute;
  top: 50%;
  right: 14px;
  width: 16px;
  height: 16px;
  transform: translateY(-50%);
  pointer-events: none;
  color: var(--color-text-muted);
}
.vet-search-indicator__glass,
.vet-search-indicator__ring {
  position: absolute;
  inset: 0;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
.vet-search-indicator__ring {
  box-sizing: border-box;
  border-radius: 50%;
  border: 2px solid var(--color-primary-100, rgba(20, 184, 166, 0.18));
  border-top-color: var(--color-primary-600);
  opacity: 0;
  transform: scale(0.6);
  animation: vetSearchSpin 0.7s linear infinite;
}
.vet-search-indicator--pending { color: var(--color-primary-600); }
.vet-search-indicator--loading .vet-search-indicator__glass {
  opacity: 0;
  transform: scale(0.6);
  transition-delay: 0.15s;
}
.vet-search-indicator--loading .vet-search-indicator__ring {
  opacity: 1;
  transform: scale(1);
  transition-delay: 0.15s;
}
.vet-search-indicator__bar {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 1px;
  height: 2px;
  border-radius: 2px;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.vet-search-indicator__bar::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -35%;
  width: 35%;
  border-radius: inherit;
  background: linear-gradient(90deg, transparent, var(--color-primary-500), transparent);
  animation: vetRefreshBar 1.1s ease-in-out infinite;
}
.vet-search-indicator__bar--loading {
  opacity: 1;
  transition-delay: 0.15s;
}

/* Results that no longer match what is typed (debounce or request running): kept, dimmed, not clickable. */
.vet-search-results-stale {
  opacity: 0.55;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

@keyframes vetSearchSpin {
  to { rotate: 360deg; }
}

.vet-sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes vetSkeletonShimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
@keyframes vetSkeletonFadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes vetRefreshBar {
  0%   { left: -35%; }
  100% { left: 100%; }
}

@media (max-width: 720px) {
  .vet-skeleton-form__grid { grid-template-columns: minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  .vet-skeleton { animation: none; background: var(--skeleton-highlight); }
  .vet-refresh-bar::after { animation: none; left: 0; width: 100%; opacity: 0.6; }
  .btn-loading::before { animation-duration: 1.6s; }
  .vet-search-indicator__ring { animation-duration: 1.6s; }
  .vet-search-indicator__bar::after { animation: none; left: 0; width: 100%; opacity: 0.6; }
}
