/**
 * CONSYS Component Library
 * Reusable components with micro-interactions for PWA
 * 
 * This file contains all reusable UI components following the design system
 * with enhanced micro-interactions for better mobile UX.
 */

/* ==========================================================================
   BUTTON COMPONENTS
   ========================================================================== */

/* Enhanced Button Base */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  font-size: var(--font-size-sm);
  font-weight: var(--font-weight-medium);
  line-height: var(--line-height-tight);
  border-radius: var(--radius-lg);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
  text-decoration: none;
  min-height: var(--touch-target-min);
  min-width: var(--touch-target-min);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  overflow: hidden;
}

/* Ripple Effect */
.btn::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.3);
  transform: translate(-50%, -50%);
  transition: width var(--duration-normal) ease, height var(--duration-normal) ease;
}

.btn:active::before {
  width: 300px;
  height: 300px;
}

/* Touch Feedback */
.btn.touch-active {
  transform: scale(0.98);
  transition: transform var(--duration-fast) var(--ease-out);
}

/* Button Variants */
.btn-primary {
  background: linear-gradient(135deg, var(--color-primary-500) 0%, var(--color-primary-600) 100%);
  color: var(--color-neutral-0);
  border-color: var(--color-primary-500);
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  background: linear-gradient(135deg, var(--color-primary-600) 0%, var(--color-primary-700) 100%);
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
}

.btn-primary:focus {
  outline: none;
  box-shadow: var(--shadow-lg), 0 0 0 3px var(--color-primary-200);
}

.btn-secondary {
  background-color: var(--color-neutral-0);
  color: var(--color-primary-500);
  border-color: var(--color-primary-500);
  box-shadow: var(--shadow-sm);
}

.btn-secondary:hover {
  background-color: var(--color-primary-50);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.btn-ghost {
  background-color: transparent;
  color: var(--color-primary-500);
  border-color: transparent;
}

.btn-ghost:hover {
  background-color: var(--color-primary-50);
  transform: translateY(-1px);
}

/* Floating Action Button */
.btn-fab {
  position: fixed;
  bottom: calc(var(--space-6) + var(--safe-area-inset-bottom));
  right: var(--space-6);
  width: 56px;
  height: 56px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--color-primary-500) 0%, var(--color-primary-600) 100%);
  color: var(--color-neutral-0);
  border: none;
  box-shadow: var(--shadow-lg);
  z-index: 40;
  transition: all var(--duration-normal) var(--ease-out);
}

.btn-fab:hover {
  transform: scale(1.1) translateY(-2px);
  box-shadow: var(--shadow-2xl);
}

.btn-fab:active {
  transform: scale(0.95);
}

/* ==========================================================================
   CARD COMPONENTS
   ========================================================================== */

/* Enhanced Card Base */
.card {
  background-color: var(--color-neutral-0);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--color-neutral-200);
  overflow: hidden;
  transition: all var(--duration-normal) var(--ease-out);
  position: relative;
}

.card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--color-primary-500) 0%, var(--color-primary-400) 100%);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform var(--duration-normal) var(--ease-out);
}

.card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-4px);
}

.card:hover::before {
  transform: scaleX(1);
}

/* Interactive Card */
.card-interactive {
  cursor: pointer;
  transition: all var(--duration-normal) var(--ease-out);
}

.card-interactive:hover {
  transform: translateY(-6px) scale(1.02);
  box-shadow: var(--shadow-xl);
}

.card-interactive:active {
  transform: translateY(-2px) scale(0.98);
  transition: all var(--duration-fast) var(--ease-out);
}

/* Card Variants */
.card-elevated {
  box-shadow: var(--shadow-lg);
}

.card-outlined {
  border: 2px solid var(--color-primary-200);
  box-shadow: none;
}

.card-gradient {
  background: linear-gradient(135deg, var(--color-primary-50) 0%, var(--color-neutral-0) 100%);
}

/* Card Components */
.card-header {
  padding: var(--space-6);
  border-bottom: 1px solid var(--color-neutral-200);
  position: relative;
}

.card-header-actions {
  position: absolute;
  top: var(--space-4);
  right: var(--space-4);
  display: flex;
  gap: var(--space-2);
}

.card-body {
  padding: var(--space-6);
}

.card-footer {
  padding: var(--space-6);
  border-top: 1px solid var(--color-neutral-200);
  background-color: var(--color-neutral-50);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Stats Card */
.stats-card {
  background: linear-gradient(135deg, var(--color-primary-500) 0%, var(--color-primary-600) 100%);
  color: var(--color-neutral-0);
  border: none;
  position: relative;
  overflow: hidden;
}

.stats-card::after {
  content: '';
  position: absolute;
  top: -50%;
  right: -50%;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.1) 0%, transparent 70%);
  transform: rotate(45deg);
}

.stats-value {
  font-size: var(--font-size-3xl);
  font-weight: var(--font-weight-bold);
  line-height: var(--line-height-tight);
  margin-bottom: var(--space-2);
}

.stats-label {
  font-size: var(--font-size-sm);
  opacity: 0.9;
  font-weight: var(--font-weight-medium);
}

/* ==========================================================================
   FORM COMPONENTS
   ========================================================================== */

/* Enhanced Form Group */
.form-group {
  margin-bottom: var(--space-6);
  position: relative;
}

/* Floating Label Input */
.form-floating {
  position: relative;
}

.form-floating .form-input {
  padding: var(--space-4) var(--space-4) var(--space-3) var(--space-4);
  border: 2px solid var(--color-neutral-300);
  transition: all var(--duration-normal) var(--ease-out);
}

.form-floating .form-label {
  position: absolute;
  top: var(--space-4);
  left: var(--space-4);
  font-size: var(--font-size-base);
  color: var(--color-neutral-500);
  pointer-events: none;
  transition: all var(--duration-normal) var(--ease-out);
  transform-origin: left top;
}

.form-floating .form-input:focus,
.form-floating .form-input:not(:placeholder-shown) {
  border-color: var(--color-primary-500);
}

.form-floating .form-input:focus + .form-label,
.form-floating .form-input:not(:placeholder-shown) + .form-label {
  transform: translateY(-1.5rem) scale(0.875);
  color: var(--color-primary-500);
  font-weight: var(--font-weight-medium);
}

/* Input with Icon */
.form-input-icon {
  position: relative;
}

.form-input-icon .form-input {
  padding-left: calc(var(--space-4) + 24px + var(--space-2));
}

.form-input-icon .input-icon {
  position: absolute;
  left: var(--space-4);
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  color: var(--color-neutral-400);
  transition: color var(--duration-fast) var(--ease-out);
}

.form-input-icon .form-input:focus + .input-icon {
  color: var(--color-primary-500);
}

/* Enhanced Checkbox */
.form-checkbox {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
  min-height: var(--touch-target-min);
}

.form-checkbox input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.form-checkbox .checkbox-custom {
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-neutral-300);
  border-radius: var(--radius-base);
  background-color: var(--color-neutral-0);
  transition: all var(--duration-fast) var(--ease-out);
  display: flex;
  align-items: center;
  justify-content: center;
}

.form-checkbox input[type="checkbox"]:checked + .checkbox-custom {
  background-color: var(--color-primary-500);
  border-color: var(--color-primary-500);
  transform: scale(1.1);
}

.form-checkbox input[type="checkbox"]:checked + .checkbox-custom::after {
  content: '✓';
  color: var(--color-neutral-0);
  font-size: var(--font-size-xs);
  font-weight: var(--font-weight-bold);
  animation: checkmark var(--duration-normal) var(--ease-bounce);
}

@keyframes checkmark {
  0% {
    transform: scale(0) rotate(45deg);
    opacity: 0;
  }
  50% {
    transform: scale(1.2) rotate(45deg);
    opacity: 1;
  }
  100% {
    transform: scale(1) rotate(45deg);
    opacity: 1;
  }
}

/* ==========================================================================
   NAVIGATION COMPONENTS
   ========================================================================== */

/* Navigation Item */
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  color: var(--color-neutral-600);
  text-decoration: none;
  border-radius: var(--radius-lg);
  transition: all var(--duration-fast) var(--ease-out);
  min-height: var(--touch-target-min);
  position: relative;
  overflow: hidden;
}

.nav-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background-color: var(--color-primary-500);
  transform: scaleY(0);
  transition: transform var(--duration-normal) var(--ease-out);
}

.nav-item:hover {
  background-color: var(--color-primary-50);
  color: var(--color-primary-600);
  transform: translateX(4px);
}

.nav-item-active {
  background-color: var(--color-primary-100);
  color: var(--color-primary-700);
  font-weight: var(--font-weight-medium);
}

.nav-item-active::before {
  transform: scaleY(1);
}

/* Bottom Navigation - Migrated to Tailwind CSS */
/* Legacy styles removed - now using pure Tailwind classes in templates */

/* ==========================================================================
   ALERT COMPONENTS
   ========================================================================== */

/* Toast Notifications */
.toast {
  position: fixed;
  top: calc(var(--app-bar-height) + var(--space-4));
  right: var(--space-4);
  left: var(--space-4);
  background-color: var(--color-neutral-0);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  border: 1px solid var(--color-neutral-200);
  padding: var(--space-4);
  z-index: 60;
  transform: translateY(-100px);
  opacity: 0;
  transition: all var(--duration-normal) var(--ease-out);
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast-success {
  border-left: 4px solid var(--color-success-500);
  background-color: var(--color-success-50);
}

.toast-warning {
  border-left: 4px solid var(--color-warning-500);
  background-color: var(--color-warning-50);
}

.toast-error {
  border-left: 4px solid var(--color-error-500);
  background-color: var(--color-error-50);
}

.toast-info {
  border-left: 4px solid var(--color-info-500);
  background-color: var(--color-info-50);
}

/* Alert Banners */
.alert {
  padding: var(--space-4);
  border-radius: var(--radius-lg);
  border: 1px solid transparent;
  margin-bottom: var(--space-4);
  position: relative;
  animation: slideDown var(--duration-normal) var(--ease-out);
}

.alert-success {
  background-color: var(--color-success-50);
  border-color: var(--color-success-200);
  color: var(--color-success-800);
}

.alert-warning {
  background-color: var(--color-warning-50);
  border-color: var(--color-warning-200);
  color: var(--color-warning-800);
}

.alert-error {
  background-color: var(--color-error-50);
  border-color: var(--color-error-200);
  color: var(--color-error-800);
}

.alert-info {
  background-color: var(--color-info-50);
  border-color: var(--color-info-200);
  color: var(--color-info-800);
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ==========================================================================
   LOADING COMPONENTS
   ========================================================================== */

/* Spinner */
.spinner {
  width: 24px;
  height: 24px;
  border: 2px solid var(--color-neutral-200);
  border-top: 2px solid var(--color-primary-500);
  border-radius: var(--radius-full);
  animation: spin 1s linear infinite;
}

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

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Skeleton Loader */
.skeleton {
  background: linear-gradient(90deg, var(--color-neutral-200) 25%, var(--color-neutral-100) 50%, var(--color-neutral-200) 75%);
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: var(--radius-base);
}

.skeleton-text {
  height: 1rem;
  margin-bottom: var(--space-2);
}

.skeleton-title {
  height: 1.5rem;
  width: 60%;
  margin-bottom: var(--space-3);
}

.skeleton-avatar {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
}

@keyframes skeleton-loading {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* ==========================================================================
   MODAL COMPONENTS
   ========================================================================== */

/* Modal Overlay */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 70;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  opacity: 0;
  transition: opacity var(--duration-normal) var(--ease-out);
}

.modal-overlay.show {
  opacity: 1;
}

/* Modal Content */
.modal {
  background-color: var(--color-neutral-0);
  border-radius: var(--radius-2xl);
  box-shadow: var(--shadow-2xl);
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  overflow: hidden;
  transform: scale(0.9) translateY(20px);
  transition: transform var(--duration-normal) var(--ease-out);
}

.modal-overlay.show .modal {
  transform: scale(1) translateY(0);
}

.modal-header {
  padding: var(--space-6);
  border-bottom: 1px solid var(--color-neutral-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: var(--font-size-xl);
  font-weight: var(--font-weight-semibold);
  color: var(--color-neutral-900);
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  border: none;
  background-color: var(--color-neutral-100);
  color: var(--color-neutral-600);
  cursor: pointer;
  transition: all var(--duration-fast) var(--ease-out);
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover {
  background-color: var(--color-neutral-200);
  transform: scale(1.1);
}

.modal-body {
  padding: var(--space-6);
  overflow-y: auto;
}

.modal-footer {
  padding: var(--space-6);
  border-top: 1px solid var(--color-neutral-200);
  display: flex;
  gap: var(--space-3);
  justify-content: flex-end;
}

/* ==========================================================================
   RESPONSIVE UTILITIES
   ========================================================================== */

/* Mobile-first responsive utilities */
@media (max-width: 639px) {
  .mobile-hidden {
    display: none !important;
  }
  
  .mobile-full-width {
    width: 100% !important;
  }
  
  .mobile-stack {
    flex-direction: column !important;
  }
}

@media (min-width: 640px) {
  .sm-hidden {
    display: none !important;
  }
}

@media (min-width: 768px) {
  .md-hidden {
    display: none !important;
  }
}

@media (min-width: 1024px) {
  .lg-hidden {
    display: none !important;
  }
}

/* ==========================================================================
   MICRO-INTERACTIONS
   ========================================================================== */

/* Hover Effects */
.hover-lift {
  transition: transform var(--duration-fast) var(--ease-out);
}

.hover-lift:hover {
  transform: translateY(-2px);
}

.hover-scale {
  transition: transform var(--duration-fast) var(--ease-out);
}

.hover-scale:hover {
  transform: scale(1.05);
}

/* Focus Indicators */
.focus-ring:focus {
  outline: none;
  box-shadow: 0 0 0 3px var(--color-primary-200);
}

/* Loading States */
.loading {
  position: relative;
  pointer-events: none;
  opacity: 0.7;
}

.loading::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 20px;
  height: 20px;
  margin: -10px 0 0 -10px;
  border: 2px solid var(--color-neutral-300);
  border-top: 2px solid var(--color-primary-500);
  border-radius: var(--radius-full);
  animation: spin 1s linear infinite;
}

/* Success Animation */
.success-pulse {
  animation: successPulse var(--duration-slow) var(--ease-out);
}

@keyframes successPulse {
  0% {
    transform: scale(1);
    box-shadow: 0 0 0 0 var(--color-success-500);
  }
  50% {
    transform: scale(1.05);
    box-shadow: 0 0 0 10px rgba(34, 197, 94, 0);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
  }
}