/* ============================================================
   frontend/css/ui-improvements.css
   ✅ PHASE 4: UI Improvements Styles
   Loading states, skeletons, accessibility
   ============================================================ */

/* ============================================================
   Loading Overlay
   ============================================================ */

.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(4px);
}

.loading-spinner {
  text-align: center;
  color: white;
}

.loading-spinner .spinner-border {
  width: 3rem;
  height: 3rem;
  border-width: 0.3em;
}

.loading-message {
  margin-top: 1rem;
  font-size: 1.1rem;
  font-weight: 500;
}

/* ============================================================
   Skeleton Loader
   ============================================================ */

.skeleton-loader {
  padding: 1rem;
  animation: pulse 1.5s ease-in-out infinite;
}

.skeleton-line {
  height: 1rem;
  background: linear-gradient(
    90deg,
    #f0f0f0 25%,
    #e0e0e0 50%,
    #f0f0f0 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 4px;
  margin-bottom: 0.75rem;
}

.skeleton-line.short {
  width: 60%;
}

@keyframes shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

/* ============================================================
   Button Loading State
   ============================================================ */

button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

button .spinner-border-sm {
  width: 1rem;
  height: 1rem;
  border-width: 0.15em;
}

/* ============================================================
   Alert Styles
   ============================================================ */

.alert {
  position: relative;
  animation: slideIn 0.3s ease-out;
  margin-bottom: 1rem;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.alert.fade:not(.show) {
  opacity: 0;
  transition: opacity 0.15s linear;
}

.error-alert {
  border-left: 4px solid #dc3545;
}

.success-alert {
  border-left: 4px solid #28a745;
}

@keyframes slideIn {
  from {
    transform: translateY(-20px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.alert i {
  font-size: 1.25rem;
}

.alert .retry-button {
  font-size: 0.875rem;
}

/* ============================================================
   Form Validation States
   ============================================================ */

.is-invalid {
  border-color: #dc3545 !important;
  padding-right: calc(1.5em + 0.75rem);
  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='%23dc3545'%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='%23dc3545' stroke='none'/%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right calc(0.375em + 0.1875rem) center;
  background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

.is-valid {
  border-color: #28a745 !important;
  padding-right: calc(1.5em + 0.75rem);
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3e%3cpath fill='%2328a745' d='M2.3 6.73L.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.1875rem) center;
  background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

.invalid-feedback {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.875rem;
  color: #dc3545;
}

.valid-feedback {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.875rem;
  color: #28a745;
}

/* ============================================================
   Accessibility - Screen Reader Only
   ============================================================ */

.visually-hidden,
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* ============================================================
   Focus Visible (Keyboard Navigation)
   ============================================================ */

*:focus-visible {
  outline: 2px solid #1a5490;
  outline-offset: 2px;
  border-radius: 4px;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid #1a5490;
  outline-offset: 2px;
  box-shadow: 0 0 0 4px rgba(26, 84, 144, 0.1);
}

/* Remove default focus outline */
*:focus:not(:focus-visible) {
  outline: none;
}

/* ============================================================
   Skip to Main Content Link
   ============================================================ */

.skip-to-main {
  position: absolute;
  top: -40px;
  left: 0;
  background: #1a5490;
  color: white;
  padding: 8px 16px;
  text-decoration: none;
  z-index: 10000;
  border-radius: 0 0 4px 0;
}

.skip-to-main:focus {
  top: 0;
}

/* ============================================================
   Keyboard Navigation Indicators
   ============================================================ */

[role="button"]:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid #1a5490;
  outline-offset: 2px;
}

/* ============================================================
   Disabled State Improvements
   ============================================================ */

button:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  opacity: 0.6;
  pointer-events: none;
}

button:disabled:hover {
  transform: none;
  box-shadow: none;
}

/* ============================================================
   Loading States for Specific Components
   ============================================================ */

.btn-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
}

.btn-loading::after {
  content: "";
  position: absolute;
  width: 1rem;
  height: 1rem;
  top: 50%;
  left: 50%;
  margin-left: -0.5rem;
  margin-top: -0.5rem;
  border: 2px solid currentColor;
  border-radius: 50%;
  border-right-color: transparent;
  animation: spinner-border 0.75s linear infinite;
}

@keyframes spinner-border {
  to {
    transform: rotate(360deg);
  }
}

/* ============================================================
   Card Loading State
   ============================================================ */

.card.loading {
  position: relative;
  pointer-events: none;
}

.card.loading::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.8);
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============================================================
   Toast Notifications
   ============================================================ */

.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  min-width: 300px;
  max-width: 400px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  padding: 1rem;
  animation: slideInRight 0.3s ease-out;
}

@keyframes slideInRight {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.toast.toast-success {
  border-left: 4px solid #28a745;
}

.toast.toast-error {
  border-left: 4px solid #dc3545;
}

.toast.toast-warning {
  border-left: 4px solid #ffc107;
}

.toast.toast-info {
  border-left: 4px solid #17a2b8;
}

/* ============================================================
   Progress Indicators
   ============================================================ */

.progress-bar-animated {
  animation: progress-bar-stripes 1s linear infinite;
}

@keyframes progress-bar-stripes {
  0% {
    background-position: 1rem 0;
  }
  100% {
    background-position: 0 0;
  }
}

/* ============================================================
   Empty States
   ============================================================ */

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: #6c757d;
}

.empty-state-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.empty-state-title {
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: #495057;
}

.empty-state-message {
  margin-bottom: 1.5rem;
}

/* ============================================================
   Responsive Improvements
   ============================================================ */

@media (max-width: 768px) {
  .loading-overlay .spinner-border {
    width: 2rem;
    height: 2rem;
  }
  
  .loading-message {
    font-size: 1rem;
  }
  
  .alert {
    margin-left: 0.5rem;
    margin-right: 0.5rem;
  }
  
  .toast {
    min-width: auto;
    max-width: calc(100vw - 40px);
  }
  
  .toast-container {
    left: 20px;
    right: 20px;
  }
}

/* ============================================================
   Print Styles
   ============================================================ */

@media print {
  .loading-overlay,
  .alert,
  .toast,
  button,
  .btn {
    display: none !important;
  }
}

/* ============================================================
   High Contrast Mode Support
   ============================================================ */

@media (prefers-contrast: high) {
  .skeleton-line {
    background: #000;
  }
  
  button:focus-visible,
  a:focus-visible,
  input:focus-visible {
    outline-width: 3px;
  }
}

/* ============================================================
   Reduced Motion Support
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  
  .loading-overlay,
  .alert,
  .toast {
    animation: none;
  }
}