/**
 * Frontend Error Handling Styles
 * 
 * Styles for:
 * - Toast notifications
 * - Form field errors
 * - Error modals
 * - Loading states
 */

/* ============================================================================
   TOAST NOTIFICATIONS
   ============================================================================ */

.error-toast {
  position: fixed;
  top: 20px;
  right: 20px;
  min-width: 300px;
  max-width: 500px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.05);
  z-index: 10000;
  opacity: 0;
  transform: translateX(400px);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  pointer-events: none;
}

.error-toast.error-toast-show {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}

.error-toast.error-toast-exit {
  opacity: 0;
  transform: translateX(400px);
}

.error-toast-content {
  display: flex;
  align-items: flex-start;
  padding: 16px;
  gap: 12px;
}

.error-toast-icon {
  font-size: 20px;
  flex-shrink: 0;
  line-height: 1;
}

.error-toast-message {
  flex: 1;
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.error-toast-close {
  background: none;
  border: none;
  font-size: 24px;
  line-height: 1;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0;
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  transition: color 0.2s;
}

.error-toast-close:hover {
  color: var(--text-primary);
}

/* Toast variants */
.error-toast-error {
  border-left: 4px solid #d32f2f;
}

.error-toast-success {
  border-left: 4px solid #388e3c;
}

.error-toast-warning {
  border-left: 4px solid #f57c00;
}

.error-toast-info {
  border-left: 4px solid #1976d2;
}

/* Mobile responsiveness */
@media (max-width: 768px) {
  .error-toast {
    left: 20px;
    right: 20px;
    min-width: auto;
    max-width: none;
    transform: translateY(-100px);
  }
  
  .error-toast.error-toast-show {
    transform: translateY(0);
  }
  
  .error-toast.error-toast-exit {
    transform: translateY(-100px);
  }
}

/* ============================================================================
   FORM FIELD ERRORS
   ============================================================================ */

/* Error input styling */
.field-error {
  border-color: #d32f2f !important;
  background-color: rgba(211, 47, 47, 0.05) !important;
}

.field-error:focus {
  border-color: #d32f2f !important;
  box-shadow: 0 0 0 3px rgba(211, 47, 47, 0.1) !important;
  outline: none;
}

/* Form group with error */
.form-group-error {
  position: relative;
}

/* Error message styling */
.field-error-message {
  display: block;
  color: #d32f2f;
  font-size: 13px;
  margin-top: 6px;
  padding-left: 12px;
  line-height: 1.4;
  animation: slideDown 0.2s ease-out;
}

.field-error-message::before {
  content: '⚠ ';
  margin-right: 4px;
}

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

/* Error icon in input */
input.field-error,
textarea.field-error,
select.field-error {
  padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%23d32f2f' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cline x1='12' y1='8' x2='12' y2='12'/%3E%3Cline x1='12' y1='16' x2='12.01' y2='16'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 20px;
}

/* Adjust for different input types */
textarea.field-error {
  background-position: right 12px top 12px;
}

/* ============================================================================
   ERROR MODAL
   ============================================================================ */

.error-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 10001;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  transition: opacity 0.3s;
}

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

.error-modal-overlay.error-modal-exit {
  opacity: 0;
}

.error-modal {
  background: white;
  border-radius: 12px;
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  transform: scale(0.9);
  transition: transform 0.3s;
}

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

.error-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.error-modal-header h3 {
  margin: 0;
  font-size: 20px;
  color: var(--text-primary);
}

.error-modal-close {
  background: none;
  border: none;
  font-size: 28px;
  line-height: 1;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  transition: color 0.2s;
}

.error-modal-close:hover {
  color: var(--text-primary);
}

.error-modal-body {
  padding: 24px;
}

.error-modal-body p {
  margin: 0 0 16px;
  color: var(--text-primary);
  line-height: 1.6;
}

.error-modal-reference {
  background: rgba(0, 0, 0, 0.05);
  padding: 16px;
  border-radius: 8px;
  margin: 16px 0;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.error-modal-reference strong {
  color: var(--text-primary);
  white-space: nowrap;
}

.error-modal-reference code {
  font-family: 'Courier New', monospace;
  font-size: 14px;
  color: var(--accent-color);
  background: white;
  padding: 4px 8px;
  border-radius: 4px;
  flex: 1;
  min-width: 200px;
}

.error-modal-copy {
  background: var(--accent-color);
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.2s;
}

.error-modal-copy:hover {
  background: var(--accent-hover);
}

.error-modal-help {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 12px !important;
}

.error-modal-footer {
  padding: 16px 24px;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

.error-modal-footer button {
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
}

.error-modal-reload {
  background: var(--accent-color);
  color: white;
}

.error-modal-reload:hover {
  background: var(--accent-hover);
}

.error-modal-dismiss {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid rgba(0, 0, 0, 0.2) !important;
}

.error-modal-dismiss:hover {
  background: rgba(0, 0, 0, 0.05);
}

/* ============================================================================
   LOADING STATES
   ============================================================================ */

.loading-state {
  position: relative;
  pointer-events: none;
  opacity: 0.6;
}

.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 20px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(0, 0, 0, 0.1);
  border-top-color: var(--accent-color);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.loading-spinner span {
  font-size: 14px;
  color: var(--text-secondary);
}

/* Button loading state */
button.loading-state::after {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  top: 50%;
  left: 50%;
  margin-left: -8px;
  margin-top: -8px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* ============================================================================
   INLINE ERROR ALERTS
   ============================================================================ */

.error-alert {
  background: rgba(211, 47, 47, 0.1);
  border: 1px solid rgba(211, 47, 47, 0.3);
  border-left: 4px solid #d32f2f;
  border-radius: 6px;
  padding: 12px 16px;
  margin: 16px 0;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  animation: slideDown 0.3s ease-out;
}

.error-alert-icon {
  font-size: 20px;
  flex-shrink: 0;
}

.error-alert-content {
  flex: 1;
}

.error-alert-title {
  font-weight: 600;
  color: #d32f2f;
  margin: 0 0 4px;
  font-size: 14px;
}

.error-alert-message {
  color: var(--text-primary);
  margin: 0;
  font-size: 13px;
  line-height: 1.5;
}

.error-alert-dismiss {
  background: none;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 0;
  font-size: 20px;
  line-height: 1;
  flex-shrink: 0;
}

.error-alert-dismiss:hover {
  color: var(--text-primary);
}

/* Success variant */
.success-alert {
  background: rgba(56, 142, 60, 0.1);
  border: 1px solid rgba(56, 142, 60, 0.3);
  border-left: 4px solid #388e3c;
}

.success-alert .error-alert-title {
  color: #388e3c;
}

/* Warning variant */
.warning-alert {
  background: rgba(245, 124, 0, 0.1);
  border: 1px solid rgba(245, 124, 0, 0.3);
  border-left: 4px solid #f57c00;
}

.warning-alert .error-alert-title {
  color: #f57c00;
}

/* Info variant */
.info-alert {
  background: rgba(25, 118, 210, 0.1);
  border: 1px solid rgba(25, 118, 210, 0.3);
  border-left: 4px solid #1976d2;
}

.info-alert .error-alert-title {
  color: #1976d2;
}

/* ============================================================================
   DARK MODE SUPPORT
   ============================================================================ */

@media (prefers-color-scheme: dark) {
  .error-toast {
    background: var(--surface-color, #1e1e1e);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4), 0 0 0 1px rgba(255, 255, 255, 0.1);
  }
  
  .error-modal {
    background: var(--surface-color, #1e1e1e);
  }
  
  .error-modal-header,
  .error-modal-footer {
    border-color: rgba(255, 255, 255, 0.1);
  }
  
  .error-modal-reference {
    background: rgba(255, 255, 255, 0.05);
  }
  
  .error-modal-reference code {
    background: rgba(255, 255, 255, 0.1);
  }
  
  .error-modal-dismiss {
    border-color: rgba(255, 255, 255, 0.2) !important;
  }
  
  .error-modal-dismiss:hover {
    background: rgba(255, 255, 255, 0.1);
  }
  
  input.field-error,
  textarea.field-error,
  select.field-error {
    background-color: rgba(211, 47, 47, 0.1) !important;
  }
}

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

/* Focus styles for keyboard navigation */
.error-toast-close:focus,
.error-modal-close:focus,
.error-modal-copy:focus,
.error-modal-reload:focus,
.error-modal-dismiss:focus,
.error-alert-dismiss:focus {
  outline: 2px solid var(--accent-color);
  outline-offset: 2px;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  .error-toast,
  .error-modal,
  .error-modal-overlay,
  .field-error-message,
  .spinner {
    animation: none !important;
    transition: none !important;
  }
}

/* ============================================================================
   UTILITY CLASSES
   ============================================================================ */

/* Hide element */
.error-hidden {
  display: none !important;
}

/* Disabled state */
.error-disabled {
  opacity: 0.5;
  pointer-events: none;
  cursor: not-allowed;
}

/* Screen reader only */
.error-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;
}
