/**
 * UI Component Library Custom Styles
 * These styles extend Tailwind CSS with animations and custom component styles
 */

/* ============================================
   ANIMATIONS - Keyframes
   ============================================ */

/* Spinner rotation animation */
@keyframes spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* Fade in animation */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* Fade out animation */
@keyframes fadeOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

/* Slide in from bottom (for modals) */
@keyframes slideInUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Slide out to bottom */
@keyframes slideOutDown {
  from {
    opacity: 1;
    transform: translateY(0);
  }
  to {
    opacity: 0;
    transform: translateY(16px);
  }
}

/* Scale in (for modals and tooltips) */
@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.95);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* Scale out */
@keyframes scaleOut {
  from {
    opacity: 1;
    transform: scale(1);
  }
  to {
    opacity: 0;
    transform: scale(0.95);
  }
}

/* Slide in from right (for select dropdown) */
@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(-8px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* Pulse animation for loading states */
@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.5;
  }
}

/* Shimmer effect for skeleton loading */
@keyframes shimmer {
  0% {
    background-position: -200% 0;
  }
  100% {
    background-position: 200% 0;
  }
}

/* ============================================
   ANIMATION CLASSES
   ============================================ */

.animate-spin {
  animation: spin 1s linear infinite;
}

.animate-fade-in {
  animation: fadeIn 150ms ease-out forwards;
}

.animate-fade-out {
  animation: fadeOut 150ms ease-in forwards;
}

.animate-slide-in-up {
  animation: slideInUp 200ms ease-out forwards;
}

.animate-slide-out-down {
  animation: slideOutDown 150ms ease-in forwards;
}

.animate-scale-in {
  animation: scaleIn 150ms ease-out forwards;
}

.animate-scale-out {
  animation: scaleOut 150ms ease-in forwards;
}

.animate-slide-in-right {
  animation: slideInRight 150ms ease-out forwards;
}

.animate-pulse-subtle {
  animation: pulse 2s ease-in-out infinite;
}

.animate-shimmer {
  background: linear-gradient(90deg, #f3f4f6 0%, #e5e7eb 50%, #f3f4f6 100%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
}

/* ============================================
   FOCUS STYLES - Accessibility
   ============================================ */

.focus-ring {
  outline: none;
}

.focus-ring:focus-visible {
  outline: 2px solid transparent;
  outline-offset: 2px;
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px #0284c7;
}

/* Focus visible for dark backgrounds */
.focus-ring-light:focus-visible {
  box-shadow: 0 0 0 2px #1f2937, 0 0 0 4px #0ea5e9;
}

/* ============================================
   MODAL STYLES
   ============================================ */

/* Modal backdrop */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
  z-index: 50;
}

.modal-backdrop.entering {
  animation: fadeIn 150ms ease-out forwards;
}

.modal-backdrop.exiting {
  animation: fadeOut 150ms ease-in forwards;
}

/* Modal container */
.modal-container {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  overflow-y: auto;
}

/* Modal content */
.modal-content {
  position: relative;
  width: 100%;
  background-color: white;
  border-radius: 0.75rem;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

.modal-content.entering {
  animation: scaleIn 200ms ease-out forwards;
}

.modal-content.exiting {
  animation: scaleOut 150ms ease-in forwards;
}

/* Modal sizes */
.modal-sm { max-width: 24rem; }   /* 384px */
.modal-md { max-width: 32rem; }   /* 512px */
.modal-lg { max-width: 48rem; }   /* 768px */
.modal-xl { max-width: 64rem; }   /* 1024px */
.modal-full { max-width: calc(100% - 2rem); max-height: calc(100% - 2rem); }

/* ============================================
   TOOLTIP STYLES
   ============================================ */

.tooltip {
  position: absolute;
  z-index: 60;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  line-height: 1.25rem;
  background-color: #1f2937;
  color: white;
  border-radius: 0.375rem;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  pointer-events: none;
  white-space: nowrap;
}

.tooltip.entering {
  animation: fadeIn 100ms ease-out forwards;
}

.tooltip.exiting {
  animation: fadeOut 75ms ease-in forwards;
}

/* Tooltip arrow */
.tooltip-arrow {
  position: absolute;
  width: 0;
  height: 0;
  border: 6px solid transparent;
}

.tooltip-arrow-top {
  bottom: -12px;
  left: 50%;
  transform: translateX(-50%);
  border-top-color: #1f2937;
}

.tooltip-arrow-bottom {
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  border-bottom-color: #1f2937;
}

.tooltip-arrow-left {
  right: -12px;
  top: 50%;
  transform: translateY(-50%);
  border-left-color: #1f2937;
}

.tooltip-arrow-right {
  left: -12px;
  top: 50%;
  transform: translateY(-50%);
  border-right-color: #1f2937;
}

/* ============================================
   TOGGLE/SWITCH STYLES
   ============================================ */

.toggle-track {
  position: relative;
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  border-radius: 9999px;
  transition: background-color 200ms ease;
}

.toggle-track-sm { width: 2rem; height: 1.25rem; }     /* 32x20 */
.toggle-track-md { width: 2.75rem; height: 1.5rem; }   /* 44x24 */
.toggle-track-lg { width: 3.5rem; height: 2rem; }      /* 56x32 */

.toggle-thumb {
  position: absolute;
  background-color: white;
  border-radius: 9999px;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  transition: transform 200ms ease;
}

.toggle-thumb-sm { width: 0.875rem; height: 0.875rem; }   /* 14x14 */
.toggle-thumb-md { width: 1.125rem; height: 1.125rem; }   /* 18x18 */
.toggle-thumb-lg { width: 1.5rem; height: 1.5rem; }       /* 24x24 */

/* ============================================
   SLIDER STYLES
   ============================================ */

.slider-track {
  position: relative;
  width: 100%;
  height: 0.375rem;
  background-color: #e5e7eb;
  border-radius: 9999px;
}

.slider-fill {
  position: absolute;
  height: 100%;
  background-color: #0284c7;
  border-radius: 9999px;
}

.slider-thumb {
  position: absolute;
  width: 1.25rem;
  height: 1.25rem;
  background-color: white;
  border: 2px solid #0284c7;
  border-radius: 9999px;
  cursor: pointer;
  transform: translateX(-50%) translateY(-50%);
  top: 50%;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
  transition: box-shadow 150ms ease, border-color 150ms ease;
}

.slider-thumb:hover {
  box-shadow: 0 0 0 4px rgba(2, 132, 199, 0.2);
}

.slider-thumb:active {
  box-shadow: 0 0 0 6px rgba(2, 132, 199, 0.3);
}

.slider-thumb:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px #fff, 0 0 0 4px #0284c7;
}

.slider-disabled .slider-track {
  background-color: #f3f4f6;
}

.slider-disabled .slider-fill {
  background-color: #9ca3af;
}

.slider-disabled .slider-thumb {
  border-color: #9ca3af;
  cursor: not-allowed;
}

/* ============================================
   SELECT DROPDOWN STYLES
   ============================================ */

.select-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 0.25rem;
  background-color: white;
  border: 1px solid #e5e7eb;
  border-radius: 0.5rem;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  z-index: 40;
  max-height: 15rem;
  overflow-y: auto;
}

.select-dropdown.entering {
  animation: slideInUp 150ms ease-out forwards;
}

.select-dropdown.exiting {
  animation: fadeOut 100ms ease-in forwards;
}

.select-option {
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  transition: background-color 100ms ease;
}

.select-option:hover {
  background-color: #f3f4f6;
}

.select-option.selected {
  background-color: #e0f2fe;
  color: #0284c7;
}

.select-option.highlighted {
  background-color: #f3f4f6;
}

.select-group-label {
  padding: 0.5rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ============================================
   SEARCH INPUT STYLES
   ============================================ */

.search-suggestions {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 0.25rem;
  background-color: white;
  border: 1px solid #e5e7eb;
  border-radius: 0.5rem;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
  z-index: 40;
  max-height: 15rem;
  overflow-y: auto;
}

.search-suggestions.entering {
  animation: fadeIn 100ms ease-out forwards;
}

.search-suggestion-item {
  padding: 0.625rem 0.75rem;
  cursor: pointer;
  transition: background-color 100ms ease;
}

.search-suggestion-item:hover,
.search-suggestion-item.highlighted {
  background-color: #f3f4f6;
}

/* ============================================
   PORTAL CONTAINER
   ============================================ */

#ui-portal-root {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 100;
  pointer-events: none;
}

#ui-portal-root > * {
  pointer-events: auto;
}

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

/* Hide visually but keep accessible to screen readers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Reset button styles */
.btn-reset {
  appearance: none;
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
}

/* Truncate text with ellipsis */
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Line clamp for multi-line truncation */
.line-clamp-2 {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.line-clamp-3 {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
