/* =====================================================
   UI/UX Enhancements - Priority High Improvements
   ===================================================== */

/* === 1. SKELETON LOADING STATES === */

/* Base skeleton animation */
@keyframes skeleton-shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

.skeleton {
  background: linear-gradient(
    90deg,
    #f0f0f0 0%,
    #e0e0e0 20%,
    #f0f0f0 40%,
    #f0f0f0 100%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius);
  display: block;
}

/* Skeleton variants */
.skeleton-text {
  height: 1rem;
  margin-bottom: 0.5rem;
  border-radius: 4px;
}

.skeleton-text:last-child {
  margin-bottom: 0;
  width: 80%;
}

.skeleton-heading {
  height: 1.5rem;
  width: 60%;
  margin-bottom: 1rem;
  border-radius: var(--radius);
}

.skeleton-avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
}

.skeleton-button {
  height: 2.5rem;
  width: 120px;
  border-radius: var(--radius);
}

.skeleton-card {
  height: 200px;
  border-radius: calc(var(--radius) + 2px);
}

/* Skeleton table row */
.skeleton-table-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 1rem;
  padding: 1rem;
  border-bottom: 1px solid var(--light);
}

.skeleton-table-row .skeleton {
  height: 1rem;
}

/* Calendar skeleton */
.skeleton-calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 0.5rem;
  padding: 1rem;
}

.skeleton-calendar-day {
  aspect-ratio: 1;
  border-radius: var(--radius);
}

/* Dashboard skeleton */
.skeleton-dashboard {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
}

/* === 2. LOADING STATE BUTTONS === */

.btn.is-loading {
  position: relative;
  color: transparent !important;
  pointer-events: none;
  cursor: not-allowed;
}

.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  top: 50%;
  left: 50%;
  margin-left: -8px;
  margin-top: -8px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: white;
  animation: btn-spinner 0.6s linear infinite;
}

@keyframes btn-spinner {
  to {
    transform: rotate(360deg);
  }
}

/* Spinner variants for different button types */
.btn-primary.is-loading::after,
.btn-secondary.is-loading::after,
.btn-danger.is-loading::after {
  border-color: rgba(255, 255, 255, 0.3);
  border-top-color: white;
}

.btn-outline.is-loading::after {
  border-color: rgba(44, 62, 80, 0.2);
  border-top-color: var(--primary);
}

/* === 3. ENHANCED FORM FEEDBACK === */

/* Form group with validation state */
.form-group.has-success .form-input,
.form-group.has-success input,
.form-group.has-success select,
.form-group.has-success textarea {
  border-color: var(--secondary);
  box-shadow: 0 0 0 3px rgba(24, 188, 156, 0.12);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2318BC9C' viewBox='0 0 16 16'%3E%3Cpath d='M13.854 3.646a.5.5 0 0 1 0 .708l-7 7a.5.5 0 0 1-.708 0l-3.5-3.5a.5.5 0 1 1 .708-.708L6.5 10.293l6.646-6.647a.5.5 0 0 1 .708 0z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 16px 16px;
  padding-right: 2.5rem;
}

.form-group.has-error .form-input,
.form-group.has-error input,
.form-group.has-error select,
.form-group.has-error textarea {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px rgba(231, 76, 60, 0.12);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%23E74C3C' viewBox='0 0 16 16'%3E%3Cpath d='M8 15A7 7 0 1 1 8 1a7 7 0 0 1 0 14zm0 1A8 8 0 1 0 8 0a8 8 0 0 0 0 16z'/%3E%3Cpath d='M7.002 11a1 1 0 1 1 2 0 1 1 0 0 1-2 0zM7.1 4.995a.905.905 0 1 1 1.8 0l-.35 3.507a.552.552 0 0 1-1.1 0L7.1 4.995z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 16px 16px;
  padding-right: 2.5rem;
}

/* Success feedback message */
.form-feedback-success {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--secondary);
  font-size: 0.85rem;
  margin-top: 0.35rem;
  font-weight: 500;
}

.form-feedback-success::before {
  content: "\f058";
  font-family: "Font Awesome 6 Free";
  font-weight: 900;
}

/* Error feedback message (enhanced existing .field-error) */
.field-error,
.form-feedback-error {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--danger);
  font-size: 0.85rem;
  margin-top: 0.35rem;
  font-weight: 500;
}

.field-error::before,
.form-feedback-error::before {
  content: "\f06a";
  font-family: "Font Awesome 6 Free";
  font-weight: 900;
  flex-shrink: 0;
}

/* Input focus improvements */
.form-input:focus-visible,
.form-group input:focus-visible,
.form-group select:focus-visible,
.form-group textarea:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.15);
  transform: translateY(-1px);
  transition: all 0.2s ease;
}

/* === 4. ENHANCED MODALS WITH BACKDROP BLUR === */

/* Modal overlays with enhanced backdrop */
#modal-conferma,
#modal-conferma-disponibilita,
#modal-aggiungi-slot,
#modalExportRiepilogo,
#modalCalendario {
  background-color: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* Modal content with improved shadow */
#modal-conferma .contenuto-modal,
#modal-conferma-disponibilita .contenuto-modal,
#modal-aggiungi-slot .contenuto-modal,
#modalExportRiepilogo .contenuto-modal,
#modalCalendario .contenuto-modal {
  box-shadow:
    0 24px 48px rgba(15, 23, 42, 0.15),
    0 12px 24px rgba(15, 23, 42, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.8);
}

/* #modal-classi overlay fade (uses .modal:not(.hidden) to show) */
#modal-classi:not(.hidden) {
  animation: overlayFadeIn 0.22s ease both;
}

/* Modal header improvements */
.modal-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid rgba(44, 62, 80, 0.08);
}

.modal-header i {
  font-size: 1.5rem;
  color: var(--accent);
}

.modal-header h3 {
  margin: 0;
  color: var(--primary);
  font-size: 1.25rem;
}

/* === 5. ENHANCED LOADING STATES FOR CONTENT === */

/* Loading overlay for cards */
.card-loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  border-radius: calc(var(--radius) + 2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.card-loading-overlay.is-visible {
  opacity: 1;
  pointer-events: auto;
}

.card-loading-spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(52, 152, 219, 0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: card-spinner 0.8s linear infinite;
}

@keyframes card-spinner {
  to {
    transform: rotate(360deg);
  }
}

/* Empty state for calendar/tables */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.5rem;
  text-align: center;
  color: var(--text-light);
}

.empty-state-icon {
  font-size: 3rem;
  color: rgba(52, 152, 219, 0.3);
  margin-bottom: 1rem;
}

.empty-state-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 0.5rem;
}

.empty-state-description {
  font-size: 0.95rem;
  color: var(--text-light);
  margin: 0 0 1.5rem;
  max-width: 400px;
}

.empty-state-action {
  margin-top: 0.5rem;
}

/* === 6. MICRO-INTERACTIONS === */

/* Smooth hover elevations */
.page-card,
.card-toolbar button,
.btn {
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

@media (hover: hover) {
  .page-card:hover {
    box-shadow: 0 24px 40px rgba(44, 62, 80, 0.12);
    transform: translateY(-2px);
  }

  /* Button hover improvements */
  .btn:not(:disabled):not(.is-loading):hover {
    transform: translateY(-1px);
  }
}

.btn:not(:disabled):not(.is-loading):active {
  transform: scale(0.98) translateY(0);
}

/* Badge pulse animation */
.badge-soft.badge-pulse {
  animation: badge-pulse 2s ease-in-out infinite;
}

@keyframes badge-pulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(24, 188, 156, 0.4);
  }
  50% {
    box-shadow: 0 0 0 8px rgba(24, 188, 156, 0);
  }
}

/* Input focus pulse */
.form-input:focus,
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  animation: input-focus-pulse 0.4s ease-out;
}

@keyframes input-focus-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(52, 152, 219, 0.3);
  }
  100% {
    box-shadow: 0 0 0 3px rgba(52, 152, 219, 0.15);
  }
}

/* === 7. TOAST === */
/* Toast gestito da #toast-container (notifiche.js) e .toast (stile-base.css) */

/* === 8. TABLE LOADING STATE === */

.table-container {
  position: relative;
  min-height: 200px;
}

.table-container.is-loading {
  opacity: 0.6;
  pointer-events: none;
}

.table-skeleton {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem;
}

.table-skeleton-header {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--light);
}

.table-skeleton-header .skeleton {
  height: 1.25rem;
}

.table-skeleton-body {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* === 9. PROGRESS INDICATORS === */

.progress-bar {
  width: 100%;
  height: 8px;
  background-color: rgba(52, 152, 219, 0.12);
  border-radius: 999px;
  overflow: hidden;
  position: relative;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--secondary));
  border-radius: 999px;
  transition: width 0.3s ease;
  position: relative;
  overflow: hidden;
}

.progress-bar-fill::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent,
    rgba(255, 255, 255, 0.3),
    transparent
  );
  animation: progress-shimmer 1.5s infinite;
}

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

/* === 10. UTILITY CLASSES === */

/* Fade in animation */
.fade-in {
  animation: fade-in 0.3s ease-out;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Slide in from right */
.slide-in-right {
  animation: slide-in-right 0.3s ease-out;
}

@keyframes slide-in-right {
  from {
    opacity: 0;
    transform: translateX(20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Pulsing dot indicator (for live updates) */
.status-indicator {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--secondary);
  animation: status-pulse 2s ease-in-out infinite;
}

.status-indicator.status-warning {
  background-color: var(--warning);
}

.status-indicator.status-danger {
  background-color: var(--danger);
}

@keyframes status-pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

/* Disabled state improvements */
button:disabled,
.btn:disabled,
input:disabled,
select:disabled,
textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  filter: grayscale(0.3);
}

/* Focus visible improvements for keyboard navigation */
*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

button:focus-visible,
.btn:focus-visible {
  outline-offset: 3px;
}

/* === 11. RESPONSIVE REFINEMENTS === */

@media (max-width: 768px) {
  .skeleton-dashboard {
    grid-template-columns: 1fr;
  }

  .empty-state {
    padding: 2rem 1rem;
  }

  .empty-state-icon {
    font-size: 2.5rem;
  }
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* === 12. ACCESSIBILITY IMPROVEMENTS === */

/* Skip to main content link */
.skip-to-main {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--primary);
  color: white;
  padding: 0.5rem 1rem;
  text-decoration: none;
  border-radius: 0 0 var(--radius) 0;
  z-index: 10000;
  transition: top 0.2s ease;
}

.skip-to-main:focus {
  top: 0;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
  .skeleton {
    background: #d0d0d0;
    animation: none;
  }

  .btn {
    border: 2px solid currentColor;
  }

  .form-input:focus,
  .form-group input:focus,
  .form-group select:focus,
  .form-group textarea:focus {
    outline: 3px solid currentColor;
  }
}

/* Badge Classi Utente */
.badge-class {
    display: inline-block;
    padding: 2px 6px;
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1;
    color: #fff;
    text-align: center;
    white-space: nowrap;
    vertical-align: baseline;
    border-radius: 4px;
    background-color: var(--primary); /* Fallback to primary if not specific */
    margin-right: 4px;
    margin-bottom: 2px;
    opacity: 0.9;
}

.user-classes-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
