/**
 * Social Authentication Buttons Styles
 * 
 * Provides visual styling for social auth buttons with state management,
 * animations, and accessibility features.
 * 
 * Requirements: 4.1, 4.2, 4.3, 4.4, 4.5
 */

/* Base Button Styles */
.social-auth-btn {
  background: #ffffff;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  padding: 14px 24px;
  font-size: 16px;
  font-weight: 600;
  color: #333333;
  cursor: pointer;
  transition: all 0.2s ease-out;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 12px;
  width: 100%;
  margin-bottom: 12px;
  position: relative;
  overflow: hidden;
  font-family: inherit;
  text-align: left;
  min-height: 44px; /* WCAG 2.1 Level AAA minimum touch target */
  box-sizing: border-box;
}

.social-auth-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
  border-width: 2.5px;
}

.social-auth-btn:focus {
  outline: 3px solid #4285f4;
  outline-offset: 2px;
}

.social-auth-btn:active:not(:disabled) {
  transform: translateY(0);
}

/* Provider-Specific Hover Colors */
.social-auth-btn[data-provider="google"]:hover:not(:disabled) {
  background: linear-gradient(135deg, #f8f9ff 0%, #e8f0ff 100%);
  border-color: #4285f4;
  color: #1a73e8;
}

.social-auth-btn[data-provider="google"]:hover:not(:disabled) i {
  color: #4285f4;
  transform: scale(1.1);
}

.social-auth-btn[data-provider="facebook"]:hover:not(:disabled) {
  background: linear-gradient(135deg, #f0f5ff 0%, #e6f0ff 100%);
  border-color: #1877f2;
  color: #0a4fa8;
}

.social-auth-btn[data-provider="facebook"]:hover:not(:disabled) i {
  color: #1877f2;
  transform: scale(1.1);
}

.social-auth-btn[data-provider="microsoft"]:hover:not(:disabled) {
  background: linear-gradient(135deg, #f8fcff 0%, #e6f7ff 100%);
  border-color: #00a4ef;
  color: #0078d4;
}

.social-auth-btn[data-provider="microsoft"]:hover:not(:disabled) i {
  color: #00a4ef;
  transform: scale(1.1);
}

.social-auth-btn[data-provider="linkedin"]:hover:not(:disabled) {
  background: linear-gradient(135deg, #f8fbff 0%, #e6f4ff 100%);
  border-color: #0077b5;
  color: #004471;
}

.social-auth-btn[data-provider="linkedin"]:hover:not(:disabled) i {
  color: #0077b5;
  transform: scale(1.1);
}

.social-auth-btn[data-provider="apple"]:hover:not(:disabled) {
  background: linear-gradient(135deg, #f5f5f5 0%, #e8e8e8 100%);
  border-color: #000000;
  color: #000000;
}

.social-auth-btn[data-provider="apple"]:hover:not(:disabled) i {
  color: #000000;
  transform: scale(1.1);
}

.social-auth-btn[data-provider="github"]:hover:not(:disabled) {
  background: linear-gradient(135deg, #f6f8fa 0%, #e1e4e8 100%);
  border-color: #24292e;
  color: #24292e;
}

.social-auth-btn[data-provider="github"]:hover:not(:disabled) i {
  color: #24292e;
  transform: scale(1.1);
}

/* Icon Styles */
.social-auth-btn i {
  font-size: 24px;
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease-out;
}

.social-auth-btn .button-text {
  flex: 1;
  text-align: left;
}

/* Connected State */
.social-auth-btn.connected {
  background: linear-gradient(135deg, #e8f5e9 0%, #f1f8f4 100%);
  border: 2px solid #28a745;
  color: #155724;
  cursor: not-allowed;
  position: relative;
  overflow: hidden;
  padding: 12px 24px;
}

.social-auth-btn.connected::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
  animation: shimmer 2s ease-in-out infinite;
}

@keyframes shimmer {
  0% { left: -100%; }
  100% { left: 100%; }
}

.social-auth-btn.connected .icon,
.social-auth-btn.connected i {
  color: #28a745;
}

.social-auth-btn.connected .checkmark {
  display: inline-block;
  animation: checkPulse 2s ease-in-out infinite;
}

@keyframes checkPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* Two-line text layout for connected state */
.social-auth-btn.connected .button-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  line-height: 1.3;
}

.social-auth-btn.connected .button-text .fw-semibold {
  font-weight: 600;
  font-size: 16px;
}

.social-auth-btn.connected .button-text .small {
  font-size: 13px;
  font-weight: 400;
}

.social-auth-btn.connected .button-text .opacity-75 {
  opacity: 0.75;
}

/* Loading State */
.social-auth-btn.loading {
  opacity: 0.6;
  cursor: wait;
  pointer-events: none;
  position: relative;
}

.social-auth-btn.loading i {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Loading spinner */
.social-auth-btn.loading .fa-spinner,
.social-auth-btn.loading .fas.fa-spinner {
  animation: spin 1s linear infinite;
}

/* Loading text */
.social-auth-btn.loading .button-text {
  opacity: 0.7;
}

/* Error State */
.social-auth-btn.error {
  background: #fff5f5;
  border-color: #dc3545;
  color: #721c24;
}

.social-auth-btn.error i {
  color: #dc3545;
}

/* Rate Limited State */
.social-auth-btn.rate-limited {
  background: linear-gradient(135deg, #fff8e1 0%, #ffecb3 100%);
  border: 2px solid #ffc107;
  color: #856404;
  cursor: not-allowed;
  opacity: 0.8;
}

.social-auth-btn.rate-limited i {
  color: #ffc107;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Rate Limit Error Message Styles */
.social-auth-error {
  animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.social-auth-error .badge {
  font-family: 'Courier New', monospace;
  letter-spacing: 0.5px;
  animation: countdownPulse 1s ease-in-out infinite;
}

@keyframes countdownPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.05); }
}

/* Disabled State */
.social-auth-btn:disabled:not(.connected):not(.loading):not(.unavailable) {
  background: #f8f9fa;
  border-color: #dee2e6;
  color: #6c757d;
  cursor: not-allowed;
  opacity: 0.65;
}

/* Unavailable State */
.social-auth-btn.unavailable {
  background: linear-gradient(135deg, #fff3cd 0%, #ffeaa7 100%);
  border: 2px solid #ffc107;
  color: #856404;
  cursor: not-allowed;
  position: relative;
  overflow: hidden;
  padding: 12px 24px;
}

.social-auth-btn.unavailable i {
  color: #ffc107;
}

.social-auth-btn.unavailable .button-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  line-height: 1.3;
}

.social-auth-btn.unavailable .button-text .fw-semibold {
  font-weight: 600;
  font-size: 16px;
}

.social-auth-btn.unavailable .button-text .small {
  font-size: 13px;
  font-weight: 400;
}

.social-auth-btn.unavailable .button-text .opacity-75 {
  opacity: 0.75;
}

/* Responsive Design */

/* Mobile (< 576px) - Single column, full width */
@media (max-width: 575px) {
  .social-auth-btn {
    padding: 16px 20px;
    font-size: 16px; /* Prevents iOS zoom */
    min-height: 48px; /* Enhanced touch target for mobile - WCAG 2.1 Level AAA */
  }
  
  .social-auth-btn i {
    font-size: 22px;
  }
  
  .social-auth-divider {
    font-size: 13px;
    margin: 20px 0;
  }

  /* Mobile-optimized provider prioritization */
  .mobile-optimized .social-auth-btn[data-provider="google"],
  .mobile-optimized .social-auth-btn[data-provider="microsoft"] {
    border-width: 2.5px;
    font-weight: 700;
  }

  /* Optimize OAuth redirect flow - prevent zoom on focus */
  .social-auth-btn:focus {
    font-size: 16px;
  }

  /* Ensure proper spacing for mobile touch - minimum 8px between interactive elements */
  .social-auth-btn + .social-auth-btn {
    margin-top: 12px;
  }
  
  /* Ensure all form inputs have minimum 48px height on mobile */
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="password"],
  select,
  textarea {
    min-height: 48px;
    font-size: 16px; /* Prevent iOS zoom */
    padding: 12px 16px;
  }
  
  /* Ensure all buttons have minimum 44px touch target */
  button,
  .btn,
  [role="button"] {
    min-height: 44px;
    min-width: 44px;
    padding: 12px 20px;
    font-size: 16px; /* Prevent iOS zoom */
  }
  
  /* Adequate spacing between form elements */
  .form-group,
  .mb-3 {
    margin-bottom: 16px;
  }
  
  /* Ensure labels are adequately spaced from inputs */
  label {
    margin-bottom: 8px;
    display: block;
  }
  
  /* Prevent iOS zoom on input focus */
  input:focus,
  select:focus,
  textarea:focus {
    font-size: 16px;
  }
}

/* Tablet (576px - 768px) - 2-column grid, smaller buttons */
@media (min-width: 576px) and (max-width: 767px) {
  .social-auth-buttons-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }
  
  .social-auth-btn {
    margin-bottom: 0;
    padding: 12px 16px;
    font-size: 15px;
  }
  
  .social-auth-btn i {
    font-size: 20px;
  }
}

/* Desktop (> 768px) - 2-column grid */
@media (min-width: 768px) {
  .social-auth-buttons-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
  }
  
  .social-auth-btn {
    margin-bottom: 0;
  }
}

/* Touch Targets (WCAG 2.1 Level AAA) - for touch devices */
@media (pointer: coarse) {
  .social-auth-btn {
    min-height: 48px;
    padding: 16px 24px;
  }
  
  /* Ensure all interactive elements have adequate touch targets */
  button,
  .btn,
  [role="button"],
  a.btn {
    min-height: 44px;
    min-width: 44px;
  }
  
  /* Form inputs should be easy to tap */
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="password"],
  select,
  textarea {
    min-height: 48px;
    font-size: 16px; /* Prevent zoom on iOS */
  }
  
  /* Adequate spacing between interactive elements - minimum 8px */
  .social-auth-btn + .social-auth-btn {
    margin-top: 12px;
  }
}

/* Reduced Motion Support */
@media (prefers-reduced-motion: reduce) {
  .social-auth-btn,
  .social-auth-btn::before,
  .social-auth-btn i,
  .social-auth-btn .checkmark {
    animation: none !important;
    transition: none !important;
  }
  
  .social-auth-btn:hover:not(:disabled) {
    transform: none;
  }
}

/* High Contrast Mode Support */
@media (prefers-contrast: high) {
  .social-auth-btn {
    border-width: 3px;
    font-weight: 700;
  }
  
  .social-auth-btn:focus-visible {
    outline-width: 4px;
    outline-offset: 3px;
  }
  
  .social-auth-btn.connected {
    border-width: 3px;
  }
  
  /* Ensure sufficient contrast in high contrast mode */
  .social-auth-btn {
    color: #000000;
  }
  
  .social-auth-btn.connected {
    background: #d4edda;
    color: #000000;
  }
}

/* Dark Mode Support */
@media (prefers-color-scheme: dark) {
  .social-auth-btn {
    background: #2d2d2d;
    border-color: #444444;
    color: #e0e0e0;
  }
  
  .social-auth-btn:hover:not(:disabled) {
    background: #3d3d3d;
  }
  
  .social-auth-btn.connected {
    background: linear-gradient(135deg, #1a3a1a 0%, #2a4a2a 100%);
    border-color: #4caf50;
    color: #a5d6a7;
  }
  
  .social-auth-btn.error {
    background: #3a1a1a;
    border-color: #f44336;
    color: #ffcdd2;
  }
  
  .social-auth-btn:disabled:not(.connected):not(.loading) {
    background: #1a1a1a;
    border-color: #333333;
    color: #666666;
  }
}

/* Container Styles */
.social-auth-buttons-container {
  margin: 20px 0;
}

/* Ensure minimum spacing between buttons (WCAG 2.1 Level AAA) */
.social-auth-btn + .social-auth-btn {
  margin-top: 8px;
}

@media (min-width: 576px) {
  .social-auth-btn + .social-auth-btn {
    margin-top: 0;
  }
}

/* Divider */
.social-auth-divider {
  display: flex;
  align-items: center;
  text-align: center;
  margin: 24px 0;
  color: #6c757d;
  font-size: 14px;
}

.social-auth-divider::before,
.social-auth-divider::after {
  content: '';
  flex: 1;
  border-bottom: 1px solid #dee2e6;
}

.social-auth-divider::before {
  margin-right: 16px;
}

.social-auth-divider::after {
  margin-left: 16px;
}

/* Screen Reader Only Text */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
}

/* Skip to content link for keyboard users */
.skip-to-email {
  position: absolute;
  left: -9999px;
  z-index: 999;
  padding: 10px 20px;
  background: #4285f4;
  color: white;
  text-decoration: none;
  border-radius: 4px;
}

.skip-to-email:focus {
  left: 50%;
  transform: translateX(-50%);
  top: 10px;
}

/* Validation announcements for screen readers */
#validation-announcements {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* Ensure proper color contrast ratios (WCAG 2.1 Level AA - 4.5:1) */
/* Default text color #333333 on white background = 12.63:1 ratio ✓ */
/* Connected state: Text color #155724 on #e8f5e9 background = 7.2:1 ratio ✓ */
/* Error state: Text color #721c24 on #fff5f5 background = 8.9:1 ratio ✓ */

/* Focus Visible (for keyboard navigation) - WCAG 2.1 Level AA */
.social-auth-btn:focus-visible {
  outline: 3px solid #4285f4;
  outline-offset: 2px;
  box-shadow: 0 0 0 3px rgba(66, 133, 244, 0.2);
}

.social-auth-btn:focus:not(:focus-visible) {
  outline: none;
}

/* Provider-specific focus colors for better visibility */
.social-auth-btn[data-provider="google"]:focus-visible {
  outline-color: #4285f4;
  box-shadow: 0 0 0 3px rgba(66, 133, 244, 0.2);
}

.social-auth-btn[data-provider="facebook"]:focus-visible {
  outline-color: #1877f2;
  box-shadow: 0 0 0 3px rgba(24, 119, 242, 0.2);
}

.social-auth-btn[data-provider="microsoft"]:focus-visible {
  outline-color: #00a4ef;
  box-shadow: 0 0 0 3px rgba(0, 164, 239, 0.2);
}

.social-auth-btn[data-provider="linkedin"]:focus-visible {
  outline-color: #0077b5;
  box-shadow: 0 0 0 3px rgba(0, 119, 181, 0.2);
}

.social-auth-btn[data-provider="apple"]:focus-visible {
  outline-color: #000000;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.2);
}

.social-auth-btn[data-provider="github"]:focus-visible {
  outline-color: #333333;
  box-shadow: 0 0 0 3px rgba(51, 51, 51, 0.2);
}

/* Print Styles */
@media print {
  .social-auth-buttons-container {
    display: none;
  }
}
