/**
 * Psyn.app - UI Components
 * Enhanced component library with micro-interactions
 * Developer: Aaliyah
 */

/* ============================================
   1. BUTTONS
   ============================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: 600;
  line-height: 1.5;
  text-decoration: none;
  border: none;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
  position: relative;
  overflow: hidden;
  min-height: 44px; /* Touch target */
  white-space: nowrap;
}

.btn:focus-visible {
  outline: 2px solid var(--syntax-gold);
  outline-offset: 4px;
}

.btn:active {
  transform: scale(0.98);
}

/* Primary Button */
.btn-primary {
  background: linear-gradient(135deg, var(--syntax-gold) 0%, #2565a8 100%);
  color: var(--frost-white);
  box-shadow: var(--shadow-subtle);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #4D9FE6 0%, var(--syntax-gold) 100%);
  box-shadow: 0 0 0 1px var(--syntax-gold),
              0 4px 16px rgba(49, 120, 198, 0.4);
  transform: translateY(-2px);
}

.btn-primary:active {
  transform: translateY(0) scale(0.98);
}

/* Secondary Button */
.btn-secondary {
  background: var(--midnight-elevated);
  color: var(--frost-white);
  border: 2px solid rgba(230, 232, 235, 0.2);
}

.btn-secondary:hover {
  background: var(--midnight-popover);
  border-color: var(--function-blue);
  box-shadow: 0 0 0 1px rgba(134, 192, 255, 0.3),
              0 4px 16px rgba(134, 192, 255, 0.15);
  transform: translateY(-2px);
}

/* Ghost Button */
.btn-ghost {
  background: transparent;
  color: var(--frost-secondary);
  border: 1px solid rgba(230, 232, 235, 0.15);
}

.btn-ghost:hover {
  background: rgba(230, 232, 235, 0.05);
  border-color: var(--frost-tertiary);
  color: var(--frost-white);
}

/* Danger Button */
.btn-danger {
  background: var(--error-coral);
  color: var(--frost-white);
}

.btn-danger:hover {
  background: #f07178;
  box-shadow: 0 0 0 1px var(--error-coral),
              0 4px 16px rgba(236, 95, 103, 0.3);
}

/* Button Sizes */
.btn-sm {
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-sm);
  min-height: 36px;
}

.btn-lg {
  padding: var(--space-3) var(--space-6);
  font-size: var(--text-lg);
  min-height: 52px;
}

/* Button with icon */
.btn-icon {
  padding: var(--space-2);
  min-width: 44px;
  min-height: 44px;
}

/* Disabled state */
.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* ============================================
   2. BADGES
   ============================================ */

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0.25rem 0.75rem;
  font-size: var(--text-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

/* Status Badges */
.badge-active {
  background: rgba(95, 179, 179, 0.15);
  color: var(--variable-teal);
  border: 1px solid rgba(95, 179, 179, 0.3);
}

.badge-beta {
  background: rgba(134, 192, 255, 0.15);
  color: var(--function-blue);
  border: 1px solid rgba(134, 192, 255, 0.3);
}

.badge-archived {
  background: rgba(101, 115, 126, 0.15);
  color: var(--comment-gray);
  border: 1px solid rgba(101, 115, 126, 0.3);
}

.badge-maintenance {
  background: rgba(240, 198, 116, 0.15);
  color: var(--syntax-gold);
  border: 1px solid rgba(240, 198, 116, 0.3);
}

/* Tech Badges */
.badge-tech {
  background: rgba(230, 232, 235, 0.05);
  color: var(--frost-tertiary);
  border: 1px solid rgba(230, 232, 235, 0.1);
  font-family: var(--font-code);
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  transition: all var(--duration-fast) var(--ease-out);
}

.badge-tech:hover {
  background: rgba(230, 232, 235, 0.1);
  border-color: var(--function-blue);
  color: var(--function-blue);
}

/* Category Badge */
.badge-category {
  background: var(--midnight-elevated);
  color: var(--syntax-gold);
  border: 1px solid rgba(240, 198, 116, 0.2);
  font-family: var(--font-code);
}

/* Badge with dot indicator */
.badge-dot::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  margin-right: 4px;
}

/* ============================================
   3. CARDS
   ============================================ */

.card {
  background: var(--midnight-card);
  border: 1px solid rgba(230, 232, 235, 0.1);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  transition: all var(--duration-base) var(--ease-out);
}

.card:hover {
  border-color: rgba(230, 232, 235, 0.2);
  box-shadow: var(--shadow-medium);
}

.card-interactive {
  cursor: pointer;
}

.card-interactive:hover {
  transform: translateY(-4px);
  box-shadow: 0 0 0 1px rgba(134, 192, 255, 0.3),
              0 8px 24px rgba(134, 192, 255, 0.15);
}

.card-header {
  margin-bottom: var(--space-4);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid rgba(230, 232, 235, 0.1);
}

.card-title {
  font-size: var(--text-xl);
  font-weight: 600;
  color: var(--frost-white);
  margin: 0;
}

.card-subtitle {
  font-size: var(--text-sm);
  color: var(--frost-tertiary);
  margin-top: var(--space-1);
}

.card-body {
  color: var(--frost-secondary);
}

.card-footer {
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid rgba(230, 232, 235, 0.1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
}

/* Elevated Card */
.card-elevated {
  background: var(--midnight-elevated);
  box-shadow: var(--shadow-medium);
}

/* Highlighted Card */
.card-highlight {
  border: 2px solid var(--syntax-gold);
  background: linear-gradient(135deg, var(--midnight-elevated) 0%, var(--midnight-card) 100%);
}

/* ============================================
   4. FORM INPUTS
   ============================================ */

.form-group {
  margin-bottom: var(--space-4);
}

.form-label {
  display: block;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--frost-white);
  margin-bottom: var(--space-2);
}

.form-label-required::after {
  content: '*';
  color: var(--error-coral);
  margin-left: 4px;
}

.form-input,
.form-textarea,
.form-select {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-body);
  font-size: var(--text-base);
  color: var(--frost-white);
  background: var(--midnight-elevated);
  border: 2px solid rgba(230, 232, 235, 0.1);
  border-radius: var(--radius-md);
  transition: all var(--duration-fast) var(--ease-out);
  min-height: 44px;
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
  outline: none;
  border-color: var(--function-blue);
  box-shadow: 0 0 0 3px rgba(134, 192, 255, 0.1);
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--frost-disabled);
}

.form-textarea {
  min-height: 120px;
  resize: vertical;
}

.form-input:disabled,
.form-textarea:disabled,
.form-select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.form-input-error {
  border-color: var(--error-coral);
}

.form-input-error:focus {
  box-shadow: 0 0 0 3px rgba(236, 95, 103, 0.1);
}

.form-help {
  display: block;
  font-size: var(--text-sm);
  color: var(--frost-tertiary);
  margin-top: var(--space-1);
}

.form-error {
  display: block;
  font-size: var(--text-sm);
  color: var(--error-coral);
  margin-top: var(--space-1);
}

/* ============================================
   5. LOADING STATES
   ============================================ */

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-8);
  color: var(--frost-tertiary);
  font-family: var(--font-code);
  font-size: var(--text-sm);
}

.loading::after {
  content: '...';
  display: inline-block;
  width: 1.5em;
  animation: loading-dots 1.5s steps(4, end) infinite;
}

@keyframes loading-dots {
  0%, 20% { content: ''; }
  40% { content: '.'; }
  60% { content: '..'; }
  80%, 100% { content: '...'; }
}

/* Spinner */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(230, 232, 235, 0.2);
  border-top-color: var(--function-blue);
  border-radius: 50%;
  animation: spinner-rotate 0.8s linear infinite;
}

@keyframes spinner-rotate {
  to { transform: rotate(360deg); }
}

.spinner-lg {
  width: 40px;
  height: 40px;
  border-width: 3px;
}

/* Skeleton Loading */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--midnight-card) 0%,
    var(--midnight-elevated) 50%,
    var(--midnight-card) 100%
  );
  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;
  margin-bottom: 0.5em;
}

.skeleton-title {
  height: 2em;
  width: 60%;
}

.skeleton-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
}

/* ============================================
   6. TOAST NOTIFICATIONS
   ============================================ */

.toast-container {
  position: fixed;
  top: var(--space-4);
  right: var(--space-4);
  z-index: 9999;
  pointer-events: none;
}

.toast {
  background: var(--midnight-elevated);
  border: 1px solid rgba(230, 232, 235, 0.2);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-2);
  box-shadow: var(--shadow-high);
  pointer-events: auto;
  min-width: 320px;
  max-width: 480px;
  animation: toast-slide-in var(--duration-base) var(--ease-out);
}

@keyframes toast-slide-in {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.toast-success {
  border-left: 4px solid var(--variable-teal);
}

.toast-error {
  border-left: 4px solid var(--error-coral);
}

.toast-warning {
  border-left: 4px solid var(--syntax-gold);
}

.toast-info {
  border-left: 4px solid var(--function-blue);
}

.toast-title {
  font-weight: 600;
  color: var(--frost-white);
  margin-bottom: var(--space-1);
}

.toast-message {
  font-size: var(--text-sm);
  color: var(--frost-secondary);
}

/* ============================================
   7. MODALS
   ============================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 14, 20, 0.8);
  backdrop-filter: blur(4px);
  z-index: 9998;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  animation: modal-fade-in var(--duration-base) var(--ease-out);
}

@keyframes modal-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  background: var(--midnight-elevated);
  border: 1px solid rgba(230, 232, 235, 0.2);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-dramatic);
  max-width: 600px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  animation: modal-scale-in var(--duration-base) var(--ease-out);
}

@keyframes modal-scale-in {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.modal-header {
  padding: var(--space-6);
  border-bottom: 1px solid rgba(230, 232, 235, 0.1);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: var(--text-2xl);
  font-weight: 600;
  color: var(--frost-white);
  margin: 0;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--frost-tertiary);
  font-size: var(--text-2xl);
  cursor: pointer;
  padding: var(--space-2);
  line-height: 1;
  transition: color var(--duration-fast) var(--ease-out);
}

.modal-close:hover {
  color: var(--frost-white);
}

.modal-body {
  padding: var(--space-6);
  color: var(--frost-secondary);
}

.modal-footer {
  padding: var(--space-6);
  border-top: 1px solid rgba(230, 232, 235, 0.1);
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
}

/* ============================================
   8. TOOLTIPS
   ============================================ */

.tooltip-wrapper {
  position: relative;
  display: inline-block;
}

.tooltip {
  position: absolute;
  bottom: 100%;
  left: 50%;
  transform: translateX(-50%) translateY(-8px);
  background: var(--midnight-popover);
  color: var(--frost-white);
  padding: var(--space-1) var(--space-2);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity var(--duration-fast) var(--ease-out);
  box-shadow: var(--shadow-medium);
  z-index: 9997;
}

.tooltip::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 4px solid transparent;
  border-top-color: var(--midnight-popover);
}

.tooltip-wrapper:hover .tooltip,
.tooltip-wrapper:focus-within .tooltip {
  opacity: 1;
}

/* ============================================
   9. PROGRESS INDICATORS
   ============================================ */

.progress-bar {
  width: 100%;
  height: 8px;
  background: var(--midnight-elevated);
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: relative;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--function-blue), var(--variable-teal));
  border-radius: var(--radius-lg);
  transition: width var(--duration-base) var(--ease-out);
  position: relative;
  overflow: hidden;
}

.progress-bar-fill::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.3) 50%,
    transparent 100%
  );
  animation: progress-shimmer 2s ease-in-out infinite;
}

@keyframes progress-shimmer {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* Indeterminate Progress */
.progress-bar-indeterminate .progress-bar-fill {
  width: 30% !important;
  animation: progress-indeterminate 1.5s ease-in-out infinite;
}

@keyframes progress-indeterminate {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(400%); }
}

/* Circular Progress */
.progress-circle {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 4px solid var(--midnight-elevated);
  border-top-color: var(--function-blue);
  animation: spinner-rotate 1s linear infinite;
}

/* ============================================
   ACCESSIBILITY UTILITIES
   ============================================ */

/* Skip to main content link */
.skip-to-main {
  position: absolute;
  top: -100px;
  left: 0;
  background: var(--syntax-gold);
  color: var(--midnight-canvas);
  padding: var(--space-2) var(--space-3);
  text-decoration: none;
  font-weight: 600;
  z-index: 10000;
  border-radius: 0 0 var(--radius-md) 0;
}

.skip-to-main:focus {
  top: 0;
}

/* Screen reader only */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Focus visible utility */
.focus-ring:focus-visible {
  outline: 2px solid var(--syntax-gold);
  outline-offset: 4px;
}

/* ============================================
   RESPONSIVE ADJUSTMENTS
   ============================================ */

@media (max-width: 768px) {
  .toast-container {
    left: var(--space-2);
    right: var(--space-2);
  }
  
  .toast {
    min-width: auto;
    max-width: none;
  }
  
  .modal {
    margin: var(--space-2);
  }
  
  .btn-lg {
    padding: var(--space-2) var(--space-4);
    font-size: var(--text-base);
  }
}

/* ============================================
   REDUCED MOTION
   ============================================ */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  .skeleton,
  .spinner,
  .progress-bar-fill::after {
    animation: none !important;
  }
}
