/**
 * BWay UI Components
 * Modern styling for form validation, toasts, and loading states
 */

/* ========================================
   CSS Custom Properties
   ======================================== */
:root {
  --bway-success: #10b981;
  --bway-success-light: #d1fae5;
  --bway-error: #ef4444;
  --bway-error-light: #fee2e2;
  --bway-warning: #f59e0b;
  --bway-warning-light: #fef3c7;
  --bway-info: #3b82f6;
  --bway-info-light: #dbeafe;
  --bway-text: #1f2937;
  --bway-text-light: #6b7280;
  --bway-border: #d1d5db;
  --bway-white: #ffffff;
  --bway-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --bway-shadow-lg: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  --bway-radius: 8px;
  --bway-transition: 0.2s ease;
}

/* ========================================
   Form Validation Styles
   ======================================== */

/* Valid state */
input.is-valid,
textarea.is-valid,
select.is-valid {
  border-color: var(--bway-success) !important;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3e%3cpath fill='%2310b981' d='M2.3 6.73.6 4.53c-.4-1.04.46-1.4 1.1-.8l1.1 1.4 3.4-3.8c.6-.63 1.6-.27 1.2.7l-4 4.6c-.43.5-.8.4-1.1.1z'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right calc(0.375em + 0.25rem) center;
  background-size: calc(0.75em + 0.5rem) calc(0.75em + 0.5rem);
  padding-right: calc(1.5em + 1rem) !important;
}

/* Invalid state */
input.is-invalid,
textarea.is-invalid,
select.is-invalid {
  border-color: var(--bway-error) !important;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' width='12' height='12' fill='none' stroke='%23ef4444'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23ef4444' stroke='none'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right calc(0.375em + 0.25rem) center;
  background-size: calc(0.75em + 0.5rem) calc(0.75em + 0.5rem);
  padding-right: calc(1.5em + 1rem) !important;
}

input.is-invalid:focus,
textarea.is-invalid:focus,
select.is-invalid:focus {
  box-shadow: 0 0 0 3px var(--bway-error-light) !important;
  outline: none;
}

input.is-valid:focus,
textarea.is-valid:focus,
select.is-valid:focus {
  box-shadow: 0 0 0 3px var(--bway-success-light) !important;
  outline: none;
}

/* Error message */
.bway-field-error {
  color: var(--bway-error);
  font-size: 0.875rem;
  margin-top: 0.375rem;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  animation: bway-shake 0.4s ease;
}

.bway-field-error::before {
  content: '';
  display: inline-block;
  width: 14px;
  height: 14px;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23ef4444' 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-size: contain;
  flex-shrink: 0;
}

@keyframes bway-shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-5px); }
  40%, 80% { transform: translateX(5px); }
}

/* ========================================
   Toast Notification Styles
   ======================================== */

/* Toast container positions */
.bway-toast-container {
  position: fixed;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem;
  pointer-events: none;
  max-width: 100%;
}

.bway-toast-top-right {
  top: 0;
  right: 0;
}

.bway-toast-top-left {
  top: 0;
  left: 0;
}

.bway-toast-top-center {
  top: 0;
  left: 50%;
  transform: translateX(-50%);
}

.bway-toast-bottom-right {
  bottom: 0;
  right: 0;
}

.bway-toast-bottom-left {
  bottom: 0;
  left: 0;
}

.bway-toast-bottom-center {
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
}

/* Toast element */
.bway-toast {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 1rem;
  background: var(--bway-white);
  border-radius: var(--bway-radius);
  box-shadow: var(--bway-shadow-lg);
  min-width: 300px;
  max-width: 420px;
  pointer-events: auto;
  position: relative;
  overflow: hidden;
  opacity: 0;
  transform: translateX(100%);
  transition: all 0.3s ease;
}

.bway-toast-top-left .bway-toast,
.bway-toast-bottom-left .bway-toast {
  transform: translateX(-100%);
}

.bway-toast-top-center .bway-toast,
.bway-toast-bottom-center .bway-toast {
  transform: translateY(-20px);
}

.bway-toast-bottom-right .bway-toast,
.bway-toast-bottom-left .bway-toast,
.bway-toast-bottom-center .bway-toast {
  transform: translateY(20px);
}

.bway-toast-show {
  opacity: 1;
  transform: translateX(0) translateY(0) !important;
}

.bway-toast-hide {
  opacity: 0;
  transform: scale(0.9);
}

/* Toast icon */
.bway-toast-icon {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Toast content */
.bway-toast-content {
  flex: 1;
  min-width: 0;
}

.bway-toast-title {
  font-weight: 600;
  color: var(--bway-text);
  margin-bottom: 0.25rem;
}

.bway-toast-message {
  color: var(--bway-text-light);
  font-size: 0.9rem;
  line-height: 1.4;
}

/* Toast close button */
.bway-toast-close {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  background: none;
  border: none;
  padding: 0.25rem;
  cursor: pointer;
  color: var(--bway-text-light);
  opacity: 0.5;
  transition: opacity var(--bway-transition);
  line-height: 0;
}

.bway-toast-close:hover {
  opacity: 1;
}

/* Toast progress bar */
.bway-toast-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: rgba(0, 0, 0, 0.1);
}

.bway-toast-progress-bar {
  height: 100%;
  width: 100%;
  transform-origin: left;
}

/* Toast type variations */
.bway-toast-success {
  border-left: 4px solid var(--bway-success);
}

.bway-toast-success .bway-toast-icon {
  color: var(--bway-success);
}

.bway-toast-success .bway-toast-progress-bar {
  background: var(--bway-success);
}

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

.bway-toast-error .bway-toast-icon {
  color: var(--bway-error);
}

.bway-toast-error .bway-toast-progress-bar {
  background: var(--bway-error);
}

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

.bway-toast-warning .bway-toast-icon {
  color: var(--bway-warning);
}

.bway-toast-warning .bway-toast-progress-bar {
  background: var(--bway-warning);
}

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

.bway-toast-info .bway-toast-icon {
  color: var(--bway-info);
}

.bway-toast-info .bway-toast-progress-bar {
  background: var(--bway-info);
}

/* ========================================
   Loading States
   ======================================== */

/* Spinner animation */
@keyframes bway-spin {
  to { transform: rotate(360deg); }
}

/* Base spinner */
.bway-spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: bway-spin 0.75s linear infinite;
  vertical-align: middle;
}

.bway-spinner-sm {
  width: 14px;
  height: 14px;
  border-width: 2px;
}

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

/* Button loading state */
.bway-btn-loading {
  position: relative;
  pointer-events: none;
  opacity: 0.8;
}

.bway-btn-loading .bway-spinner {
  margin-right: 0.5rem;
}

.bway-btn-text {
  vertical-align: middle;
}

/* Loading overlay */
.bway-loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.3s ease;
  border-radius: inherit;
}

.bway-loading-overlay.bway-loading-visible {
  opacity: 1;
}

.bway-loading-content {
  text-align: center;
}

.bway-loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--bway-border);
  border-top-color: var(--theme-color, #ff161f);
  border-radius: 50%;
  animation: bway-spin 0.8s linear infinite;
  margin: 0 auto 1rem;
}

.bway-loading-spinner-lg {
  width: 56px;
  height: 56px;
  border-width: 4px;
}

.bway-loading-message {
  color: var(--bway-text);
  font-size: 0.95rem;
}

/* Fullscreen loading */
.bway-fullscreen-loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.95);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.bway-fullscreen-loading.bway-loading-visible {
  opacity: 1;
}

/* Skeleton loading */
.bway-skeleton-loading {
  position: relative;
  overflow: hidden;
}

.bway-skeleton-loading::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.4),
    transparent
  );
  animation: bway-skeleton-shimmer 1.5s infinite;
}

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

/* Inline loader */
.bway-inline-loader {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* ========================================
   Enhanced Form Styling
   ======================================== */

/* Input focus enhancement */
.default-form input:focus,
.default-form textarea:focus,
.default-form select:focus {
  border-color: var(--theme-color, #ff161f);
  box-shadow: 0 0 0 3px rgba(255, 22, 31, 0.1);
  outline: none;
}

/* Form submit button enhancements */
.theme-btn {
  position: relative;
  overflow: hidden;
  transition: all 0.3s ease;
}

.theme-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
}

/* Smooth input transitions */
.default-form input,
.default-form textarea,
.default-form select {
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

/* ========================================
   Responsive Adjustments
   ======================================== */

@media (max-width: 768px) {
  .bway-toast-container {
    padding: 0.75rem;
  }

  .bway-toast {
    min-width: 280px;
    max-width: calc(100vw - 1.5rem);
  }
}

@media (max-width: 576px) {
  .bway-toast-container {
    padding: 0.5rem;
  }

  .bway-toast {
    min-width: auto;
    max-width: calc(100vw - 1rem);
  }

  .bway-toast-top-right,
  .bway-toast-top-left {
    left: 0;
    right: 0;
    top: 0;
  }

  .bway-toast-bottom-right,
  .bway-toast-bottom-left {
    left: 0;
    right: 0;
    bottom: 0;
  }

  .bway-toast-top-center,
  .bway-toast-bottom-center {
    left: 0;
    right: 0;
    transform: none;
  }
}
