/**
 * Interaction States - Botify ModBot Mini-App
 * ==============================================
 *
 * Standardized interaction state styles for consistent UX.
 * Requires: unified-theme.css
 *
 * STATES:
 * 1. Loading - Page/component loading with spinner
 * 2. Saving - Button/form saving state
 * 3. Empty - No data/empty state
 * 4. Error - Error state with message
 * 5. Success - Success feedback
 * 6. Disabled - Disabled with reason tooltip
 * 7. Partial Success - Mixed results state
 * 8. Skeleton - Loading placeholders
 */

/* ============================================
 * 1. LOADING STATE
 * Page/component loading with spinner
 * ============================================ */

.is-loading {
  position: relative;
  pointer-events: none;
}

.is-loading::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg-overlay-light);
  z-index: 10;
}

/* Loading container (centered spinner + text) */
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-8);
  min-height: 200px;
  gap: var(--space-4);
}

.loading-container--inline {
  flex-direction: row;
  min-height: auto;
  padding: var(--space-4);
}

.loading-container--fullpage {
  min-height: 60vh;
}

/* Spinner */
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border-subtle);
  border-top-color: var(--color-primary-500);
  border-radius: var(--radius-full);
  animation: spin 1s linear infinite;
}

.spinner--sm {
  width: 16px;
  height: 16px;
  border-width: 2px;
}

.spinner--lg {
  width: 48px;
  height: 48px;
  border-width: 4px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.loading-text {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
}

/* Hidden utility for loading toggling */
.hidden {
  display: none !important;
}

/* ============================================
 * 2. SAVING STATE
 * Button/form saving state
 * ============================================ */

.btn--loading,
.btn.is-saving {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

.btn--loading::after,
.btn.is-saving::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: var(--radius-full);
  animation: spin 0.8s linear infinite;
  color: var(--text-primary);
}

/* Saving overlay for forms/sections */
.is-saving-overlay {
  position: relative;
}

.is-saving-overlay::before {
  content: 'Saving...';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-overlay-light);
  color: var(--text-primary);
  font-weight: var(--font-weight-medium);
  z-index: 10;
  border-radius: inherit;
}

/* ============================================
 * 3. EMPTY STATE
 * No data/empty state display
 * ============================================ */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-8);
  text-align: center;
  min-height: 200px;
}

.empty-state--compact {
  padding: var(--space-6);
  min-height: 150px;
}

.empty-state__icon {
  font-size: 3rem;
  margin-bottom: var(--space-4);
  opacity: 0.5;
}

.empty-state__title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}

.empty-state__message {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  max-width: 300px;
  line-height: var(--line-height-relaxed);
  margin-bottom: var(--space-4);
}

.empty-state__action {
  margin-top: var(--space-2);
}

/* ============================================
 * 4. ERROR STATE
 * Error state with message
 * ============================================ */

.error-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-8);
  text-align: center;
  min-height: 200px;
}

.error-container__icon {
  font-size: 3rem;
  color: var(--color-danger-500);
  margin-bottom: var(--space-4);
}

.error-container__title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--color-danger-500);
  margin-bottom: var(--space-2);
}

.error-container__message {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  max-width: 300px;
  line-height: var(--line-height-relaxed);
  margin-bottom: var(--space-4);
}

.error-container__action {
  margin-top: var(--space-2);
}

/* Inline error state for form fields */
.is-error,
.has-error {
  border-color: var(--color-danger-500) !important;
}

.is-error:focus,
.has-error:focus {
  box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2) !important;
}

/* Error banner (top of page) */
.error-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: var(--space-3) var(--space-4);
  background: var(--color-danger-500);
  color: var(--text-primary);
  text-align: center;
  font-size: var(--font-size-sm);
  z-index: var(--z-notification);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
}

.error-banner__close {
  background: transparent;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: var(--space-1);
  opacity: 0.8;
}

.error-banner__close:hover {
  opacity: 1;
}

/* ============================================
 * 5. SUCCESS STATE
 * Success feedback
 * ============================================ */

.is-success {
  border-color: var(--color-success-500) !important;
}

.is-success:focus {
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2) !important;
}

/* Success flash animation */
.success-flash {
  animation: success-flash 0.5s ease-out;
}

@keyframes success-flash {
  0% {
    background-color: rgba(34, 197, 94, 0.3);
  }
  100% {
    background-color: transparent;
  }
}

/* Success container */
.success-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-8);
  text-align: center;
}

.success-container__icon {
  font-size: 3rem;
  color: var(--color-success-500);
  margin-bottom: var(--space-4);
}

.success-container__title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--color-success-500);
  margin-bottom: var(--space-2);
}

.success-container__message {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  line-height: var(--line-height-relaxed);
}

/* Checkmark animation */
.checkmark {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
  display: block;
  stroke-width: 2;
  stroke: var(--color-success-500);
  stroke-miterlimit: 10;
  box-shadow: inset 0 0 0 var(--color-success-500);
  animation: checkmark-fill 0.4s ease-in-out 0.4s forwards, checkmark-scale 0.3s ease-in-out 0.9s both;
}

.checkmark__circle {
  stroke-dasharray: 166;
  stroke-dashoffset: 166;
  stroke-width: 2;
  stroke-miterlimit: 10;
  stroke: var(--color-success-500);
  fill: none;
  animation: checkmark-stroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}

.checkmark__check {
  transform-origin: 50% 50%;
  stroke-dasharray: 48;
  stroke-dashoffset: 48;
  animation: checkmark-stroke 0.3s cubic-bezier(0.65, 0, 0.45, 1) 0.8s forwards;
}

@keyframes checkmark-stroke {
  100% {
    stroke-dashoffset: 0;
  }
}

@keyframes checkmark-scale {
  0%, 100% {
    transform: none;
  }
  50% {
    transform: scale3d(1.1, 1.1, 1);
  }
}

@keyframes checkmark-fill {
  100% {
    box-shadow: inset 0 0 0 30px rgba(34, 197, 94, 0.1);
  }
}

/* ============================================
 * 6. DISABLED STATE
 * Disabled with reason tooltip
 * ============================================ */

.is-disabled,
[disabled] {
  opacity: 0.5;
  cursor: not-allowed !important;
  pointer-events: none;
}

/* Disabled with tooltip showing reason */
.disabled-with-reason {
  position: relative;
  opacity: 0.5;
  cursor: help !important;
  pointer-events: auto;
}

.disabled-with-reason::before {
  content: attr(data-reason);
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  padding: var(--space-2) var(--space-3);
  background: var(--bg-surface-solid);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: var(--transition-fast);
  z-index: var(--z-tooltip);
  box-shadow: var(--shadow-lg);
}

.disabled-with-reason::after {
  content: '';
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--bg-surface-solid);
  opacity: 0;
  visibility: hidden;
  transition: var(--transition-fast);
  z-index: var(--z-tooltip);
}

.disabled-with-reason:hover::before,
.disabled-with-reason:hover::after {
  opacity: 1;
  visibility: visible;
}

/* ============================================
 * 7. PARTIAL SUCCESS STATE
 * Mixed results (some success, some failure)
 * ============================================ */

.partial-success {
  background: rgba(245, 158, 11, 0.1);
  border: 1px solid var(--color-warning-500);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}

.partial-success__header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-warning-500);
  font-weight: var(--font-weight-semibold);
  margin-bottom: var(--space-3);
}

.partial-success__icon {
  font-size: 1.25rem;
}

.partial-success__summary {
  font-size: var(--font-size-sm);
  color: var(--text-secondary);
  margin-bottom: var(--space-3);
}

.partial-success__list {
  list-style: none;
  padding: 0;
  margin: 0;
  font-size: var(--font-size-sm);
}

.partial-success__item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border-subtle);
}

.partial-success__item:last-child {
  border-bottom: none;
}

.partial-success__item--success {
  color: var(--color-success-500);
}

.partial-success__item--failure {
  color: var(--color-danger-500);
}

/* ============================================
 * 8. SKELETON LOADING
 * Loading placeholders
 * ============================================ */

.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-elevated) 25%,
    var(--bg-active) 50%,
    var(--bg-elevated) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-md);
}

@keyframes skeleton-shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.skeleton--text {
  height: 1em;
  border-radius: var(--radius-sm);
}

.skeleton--title {
  height: 1.5em;
  width: 60%;
}

.skeleton--avatar {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-full);
}

.skeleton--button {
  height: 40px;
  width: 100px;
}

.skeleton--card {
  height: 120px;
}

/* Skeleton row for lists */
.skeleton-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) 0;
}

.skeleton-row__avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}

.skeleton-row__content {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.skeleton-row__line {
  height: 12px;
  border-radius: var(--radius-sm);
}

.skeleton-row__line--short {
  width: 40%;
}

.skeleton-row__line--medium {
  width: 70%;
}

/* ============================================
 * PROGRESS INDICATOR
 * ============================================ */

.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--bg-elevated);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-bar__fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-primary-500), var(--color-secondary-500));
  border-radius: var(--radius-full);
  transition: width var(--transition-base);
}

.progress-bar--success .progress-bar__fill {
  background: var(--color-success-500);
}

.progress-bar--warning .progress-bar__fill {
  background: var(--color-warning-500);
}

.progress-bar--danger .progress-bar__fill {
  background: var(--color-danger-500);
}

/* Animated progress (indeterminate) */
.progress-bar--indeterminate .progress-bar__fill {
  width: 30%;
  animation: progress-indeterminate 1.5s ease-in-out infinite;
}

@keyframes progress-indeterminate {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(400%);
  }
}
