/**
 * Integration Platform — Shared Loading States
 * Skeleton loaders, button spinners, and content placeholders.
 */

/* Tokens (optional overrides) */
:root {
  --ip-skeleton-radius: 8px;
  --ip-spinner-size: 16px;
  --ip-spinner-border: 2px;
}

/* ── Button spinner ── */
.is-loading {
  position: relative;
  pointer-events: none;
}
.is-loading > * {
  visibility: hidden;
}
.is-loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: var(--ip-spinner-size);
  height: var(--ip-spinner-size);
  margin: calc(var(--ip-spinner-size) / -2) 0 0 calc(var(--ip-spinner-size) / -2);
  border: var(--ip-spinner-border) solid rgba(255, 255, 255, .3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: ip-spin .6s linear infinite;
}

.btn.is-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}
.btn.is-loading::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  width: 16px; height: 16px;
  margin: -8px 0 0 -8px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: ip-spin .6s linear infinite;
}
.btn-outline.is-loading::after,
.btn-ghost.is-loading::after {
  border-color: rgba(123,250,76,.25);
  border-top-color: var(--accent, #7BFA4C);
}

/* ── Skeleton loader ── */
.skeleton {
  background: linear-gradient(90deg,
    var(--surface, #1D2D46) 25%,
    var(--hover, #253368) 50%,
    var(--surface, #1D2D46) 75%);
  background-size: 200% 100%;
  animation: ip-shimmer 1.5s ease-in-out infinite;
  border-radius: var(--ip-skeleton-radius);
  color: transparent !important;
  pointer-events: none;
  user-select: none;
}
.skeleton * { visibility: hidden; }

.skeleton-text {
  height: 14px;
  margin-bottom: 8px;
  border-radius: 4px;
}
.skeleton-text.w-75 { width: 75%; }
.skeleton-text.w-50 { width: 50%; }
.skeleton-text.w-25 { width: 25%; }

.skeleton-line { height: 12px; border-radius: 6px; }
.skeleton-line.lg { height: 16px; }
.skeleton-line.sm { height: 10px; }
.skeleton-gap-6 { margin-bottom: 6px; }
.skeleton-gap-10 { margin-bottom: 10px; }

.skeleton-card {
  height: 120px;
  border-radius: var(--r-lg, 12px);
}

.skeleton-circle {
  width: 40px; height: 40px;
  border-radius: 50%;
}

/* Lists / tables */
.skeleton-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.skeleton-row .skeleton {
  flex: 1;
}
.skeleton-table {
  display: grid;
  gap: 10px;
}
.skeleton-table .skeleton {
  height: 14px;
  border-radius: 6px;
}

/* ── Page-level loading overlay ── */
.page-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  gap: 12px;
  color: var(--text3, #5A6499);
  font-size: 13px;
}
.page-loading::before {
  content: '';
  width: 20px; height: 20px;
  border: 2px solid var(--border, #253368);
  border-top-color: var(--accent, #7BFA4C);
  border-radius: 50%;
  animation: ip-spin .7s linear infinite;
}

/* ── Inline spinner (for text areas) ── */
.spinner-inline {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--border, #253368);
  border-top-color: var(--accent, #7BFA4C);
  border-radius: 50%;
  animation: ip-spin .6s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

/* ── Overlay (for cards/modals) ── */
.loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(0, 0, 0, .35);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  border-radius: inherit;
  color: var(--text2, #9BA8D8);
  font-size: 12px;
}
.loading-overlay::before {
  content: '';
  width: 18px;
  height: 18px;
  border: 2px solid rgba(123, 250, 76, .25);
  border-top-color: var(--accent, #7BFA4C);
  border-radius: 50%;
  animation: ip-spin .7s linear infinite;
}

/* ── Animations ── */
@keyframes ip-spin {
  to { transform: rotate(360deg); }
}
@keyframes ip-shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* ── Light mode adjustments ── */
html.light .skeleton {
  background: linear-gradient(90deg,
    var(--ink2, #EEF0F6) 25%,
    var(--ink3, #E2E5EF) 50%,
    var(--ink2, #EEF0F6) 75%);
  background-size: 200% 100%;
  animation: ip-shimmer 1.5s ease-in-out infinite;
}
html.light .btn.is-loading::after {
  border-color: rgba(0,0,0,.15);
  border-top-color: #fff;
}

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  .skeleton,
  .btn.is-loading::after,
  .spinner-inline,
  .page-loading::before,
  .loading-overlay::before,
  .is-loading::after {
    animation: none !important;
  }
  .skeleton {
    background-position: 50% 0 !important;
  }
}
