/**
 * WKBL Analytics - CSS Transitions & Animations
 *
 * Design Principles:
 * - GPU-accelerated transforms (will-change, transform3d)
 * - Smooth 300ms transitions
 * - Dark theme optimized
 */

/* ===========================================
   0. Global Scrollbar Styling
   =========================================== */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(100, 116, 139, 0.2);
  border-radius: 10px;
  border: 2px solid transparent;
  background-clip: content-box;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(249, 115, 22, 0.4);
  border: 2px solid transparent;
  background-clip: content-box;
}

.dark ::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.15);
}

.dark ::-webkit-scrollbar-thumb:hover {
  background: rgba(249, 115, 22, 0.3);
}

/* Enhanced Sticky Table Header with Blur */
.table-scroll-container thead,
thead.sticky {
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

/* Subtle row lift effect */
tbody tr {
  transition: all 200ms cubic-bezier(0.4, 0, 0.2, 1);
}

tbody tr:hover {
  transform: scale(1.002);
  z-index: 10;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.dark tbody tr:hover {
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

/* ===========================================
   0. Theme Transitions (Dark Mode)
   =========================================== */

/* Smooth theme transition when toggling */
.theme-transitioning,
.theme-transitioning *,
.theme-transitioning *::before,
.theme-transitioning *::after {
  transition:
    background-color 350ms cubic-bezier(0.4, 0, 0.2, 1),
    border-color 350ms cubic-bezier(0.4, 0, 0.2, 1),
    color 250ms cubic-bezier(0.4, 0, 0.2, 1),
    fill 250ms cubic-bezier(0.4, 0, 0.2, 1),
    stroke 250ms cubic-bezier(0.4, 0, 0.2, 1),
    box-shadow 350ms cubic-bezier(0.4, 0, 0.2, 1),
    backdrop-filter 350ms cubic-bezier(0.4, 0, 0.2, 1),
    opacity 250ms cubic-bezier(0.4, 0, 0.2, 1) !important;
}

/* Staggered transitions for visual hierarchy */
.theme-transitioning header { transition-delay: 0ms !important; }
.theme-transitioning main { transition-delay: 50ms !important; }
.theme-transitioning footer { transition-delay: 100ms !important; }
.theme-transitioning .card,
.theme-transitioning [class*="bg-white"],
.theme-transitioning [class*="bg-slate"] { transition-delay: 25ms !important; }

/* Smooth backdrop blur transition for glassmorphism */
.theme-transitioning [class*="backdrop-blur"] {
  transition: background-color 350ms cubic-bezier(0.4, 0, 0.2, 1) !important;
}

/* Enhanced Glassmorphism for Header */
header {
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.1);
  border-bottom: 1px solid rgba(249, 115, 22, 0.1);
}

.dark header {
  background-color: rgba(11, 14, 20, 0.8) !important;
  border-bottom: 1px solid rgba(249, 115, 22, 0.2);
  box-shadow: 0 4px 30px rgba(0, 0, 0, 0.5);
}

/* Section Heading Accent */
h2 {
  position: relative;
  padding-left: 1rem;
}

h2::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.25rem;
  bottom: 0.25rem;
  width: 4px;
  background: #f97316;
  border-radius: 2px;
  box-shadow: 0 0 10px rgba(249, 115, 22, 0.4);
}

/* Prevent flash of unstyled content */
html:not(.dark) body,
html.dark body {
  transition: background-color 0ms;
}

/* ===========================================
   1. HTMX Page Transitions
   =========================================== */

/* Fade out during request */
.htmx-request {
  opacity: 0.5;
  transition: opacity 200ms ease-out;
}

/* Element is being swapped in - start state */
.htmx-settling {
  opacity: 0;
  transform: translateY(8px);
}

/* Element has settled - end state */
.htmx-settling,
.htmx-added {
  animation: fadeSlideIn 300ms ease-out forwards;
}

@keyframes fadeSlideIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Swap transition class for HTMX */
.htmx-swapping {
  opacity: 0;
  transform: scale(0.98);
  transition: opacity 150ms ease-out, transform 150ms ease-out;
}

/* Table row hover enhancement with left accent bar */
tbody tr {
  transition: background-color 150ms ease, box-shadow 150ms ease;
  position: relative;
}

tbody tr::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: transparent;
  transition: background-color 150ms ease;
}

tbody tr:hover::before {
  background: #f97316;
}

/* Enhanced row hover for data tables */
.data-table tbody tr:hover {
  background-color: rgba(249, 115, 22, 0.08);
  box-shadow: inset 0 0 0 1px rgba(249, 115, 22, 0.1);
}

.dark .data-table tbody tr:hover {
  background-color: rgba(249, 115, 22, 0.12);
  box-shadow: inset 0 0 0 1px rgba(249, 115, 22, 0.15);
}

/* Zebra stripes for better readability */
tbody tr:nth-child(even) {
  background-color: rgba(100, 116, 139, 0.03);
}

.dark tbody tr:nth-child(even) {
  background-color: rgba(100, 116, 139, 0.05);
}

/* Zebra + hover combined */
tbody tr:nth-child(even):hover {
  background-color: rgba(249, 115, 22, 0.1);
}

.dark tbody tr:nth-child(even):hover {
  background-color: rgba(249, 115, 22, 0.14);
}

/* Roster table: keep layout stable even if Tailwind is delayed/blocked */
.roster-table {
  min-width: 980px;
  table-layout: fixed;
}

.roster-table th,
.roster-table td {
  white-space: nowrap;
}

/* Prevent CJK per-character wrapping for player names */
.player-name {
  display: block;
  white-space: nowrap;
  word-break: keep-all;
  overflow-wrap: normal;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Prevent CJK per-character wrapping for team names in tables */
.team-name {
  white-space: nowrap !important;
  word-break: keep-all !important;
  overflow-wrap: normal !important;
  display: inline-block;
}

/* HTMX loading indicator */
.page-loader {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 3px;
  z-index: 60;
  pointer-events: none;
  opacity: 0;
  transition: opacity 200ms ease-out;
}

.page-loader-bar {
  height: 100%;
  width: 40%;
  background: linear-gradient(90deg, rgba(249, 115, 22, 0), #f97316, rgba(249, 115, 22, 0));
  transform: translateX(-120%);
  animation: pageLoader 1.2s ease-in-out infinite;
}

body.is-loading .page-loader {
  opacity: 1;
}

@keyframes pageLoader {
  0% {
    transform: translateX(-120%);
  }
  50% {
    transform: translateX(10%);
  }
  100% {
    transform: translateX(120%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .page-loader-bar {
    animation: none;
    width: 100%;
    transform: none;
    background: #f97316;
  }
}

.htmx-indicator {
  display: none;
  opacity: 0;
  transition: opacity 200ms ease-out;
}

.htmx-request .htmx-indicator,
.htmx-request.htmx-indicator {
  display: inline-block;
  opacity: 1;
}

/* Spinner */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(249, 115, 22, 0.3);
  border-top-color: #f97316;
  border-radius: 50%;
  animation: spin 600ms linear infinite;
}

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

/* ===========================================
   6. UI Element Transitions
   =========================================== */

/* Button hover effects */
button,
.btn {
  transition: background-color 200ms ease,
              transform 150ms ease,
              box-shadow 200ms ease;
}

button:hover:not(:disabled),
.btn:hover:not(:disabled) {
  transform: translateY(-1px);
}

button:active:not(:disabled),
.btn:active:not(:disabled) {
  transform: translateY(0);
}

/* Tab switching */
.tab {
  position: relative;
  transition: color 200ms ease, background-color 200ms ease;
}

.tab::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 50%;
  width: 0;
  height: 2px;
  background: #f97316;
  transition: width 200ms ease, left 200ms ease;
}

.tab.active::after,
.tab:hover::after {
  width: 100%;
  left: 0;
}

/* ===========================================
   7. Mobile Utilities
   =========================================== */

/* Hide scrollbars for horizontal menus/tables while keeping scroll enabled */
.no-scrollbar::-webkit-scrollbar {
  display: none;
}

.no-scrollbar {
  -ms-overflow-style: none; /* IE/Edge */
  scrollbar-width: none; /* Firefox */
}

/* ===========================================
   7.05 Scroll Shadow Indicators
   =========================================== */

/* Scroll shadow wrapper - shows gradient edges when content overflows */
.scroll-shadow {
  position: relative;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Left/right gradient shadows using pseudo-elements */
.scroll-shadow::before,
.scroll-shadow::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  width: 24px;
  pointer-events: none;
  z-index: 5;
  opacity: 0;
  transition: opacity 200ms ease-out;
}

.scroll-shadow::before {
  left: 0;
  background: linear-gradient(90deg, rgba(255,255,255,0.95) 0%, transparent 100%);
}

.scroll-shadow::after {
  right: 0;
  background: linear-gradient(270deg, rgba(255,255,255,0.95) 0%, transparent 100%);
}

/* Dark mode gradients */
.dark .scroll-shadow::before {
  background: linear-gradient(90deg, rgba(15,23,42,0.95) 0%, transparent 100%);
}

.dark .scroll-shadow::after {
  background: linear-gradient(270deg, rgba(15,23,42,0.95) 0%, transparent 100%);
}

/* JS toggles these classes based on scroll position */
.scroll-shadow.can-scroll-left::before {
  opacity: 1;
}

.scroll-shadow.can-scroll-right::after {
  opacity: 1;
}

/* Alternative: always-visible subtle shadow (no JS needed) */
.scroll-shadow-always::before,
.scroll-shadow-always::after {
  opacity: 0.6;
}

/* ===========================================
   7.1 Mobile Responsive Tables
   =========================================== */

/* Mobile breakpoint: 768px and below */
@media (max-width: 768px) {
  /* Allow roster table to shrink on mobile */
  .roster-table {
    min-width: unset;
    width: 100%;
    font-size: 0.75rem;
  }

  .roster-table th,
  .roster-table td {
    padding: 0.375rem 0.25rem;
  }

  /* Sticky first column for horizontal scroll */
  .roster-table th:first-child,
  .roster-table td:first-child {
    position: sticky;
    left: 0;
    z-index: 10;
    background: inherit;
  }

  /* Player name column - allow truncation */
  .player-name {
    max-width: 80px;
  }

  /* Hide less important columns on mobile */
  .hide-mobile {
    display: none !important;
  }

  /* Compact stat cells */
  .roster-table th:nth-child(n+3),
  .roster-table td:nth-child(n+3) {
    min-width: 32px;
    text-align: center;
  }

  /* Season stats table responsive */
  .season-stats-table {
    font-size: 0.75rem;
  }

  .season-stats-table th,
  .season-stats-table td {
    padding: 0.375rem 0.25rem;
  }

  .season-stats-table th:nth-child(2),
  .season-stats-table td:nth-child(2) {
    width: 48px;
  }

  .season-stats-table th:nth-child(n+3),
  .season-stats-table td:nth-child(n+3) {
    width: 56px;
  }

  /* Stats container - reduce min height on mobile */
  .stats-container {
    min-height: 200px;
  }
}

/* Small mobile (phones in portrait) */
@media (max-width: 480px) {
  .roster-table {
    /* Minimum 12px for WCAG accessibility (was 0.675rem = 10.8px) */
    font-size: 0.75rem;
  }

  .roster-table th,
  .roster-table td {
    padding: 0.25rem 0.25rem;
  }

  .player-name {
    /* Slightly wider to show more characters */
    max-width: 72px;
  }

  /* Extra compact for very small screens */
  .season-stats-table {
    /* Minimum 12px for WCAG accessibility (was 0.675rem = 10.8px) */
    font-size: 0.75rem;
  }

  .season-stats-table th:nth-child(n+3),
  .season-stats-table td:nth-child(n+3) {
    width: 44px;
  }
}

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

/* ===========================================
   8. Focus States (Accessibility)
   =========================================== */

a:focus-visible,
button:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 2px solid #f97316;
  outline-offset: 2px;
  transition: outline-offset 100ms ease;
}

/* ===========================================
   9. Player Season Stats UI Stability
   =========================================== */

/* Generic fade-in utility for server-rendered sections */
.animate-fade-in {
  animation: fadeSlideIn 220ms ease-out forwards;
}

/* Staggered card entry animation */
.card-enter {
  animation: cardEnter 300ms ease-out forwards;
}

.card-enter:nth-child(1) { animation-delay: 0ms; }
.card-enter:nth-child(2) { animation-delay: 50ms; }
.card-enter:nth-child(3) { animation-delay: 100ms; }
.card-enter:nth-child(4) { animation-delay: 150ms; }
.card-enter:nth-child(5) { animation-delay: 200ms; }
.card-enter:nth-child(6) { animation-delay: 250ms; }

@keyframes cardEnter {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Prevent layout jump during HTMX tab swaps */
.stats-container {
  min-height: 300px;
  will-change: opacity, transform;
}

/* Stabilize season stats table column widths across scopes */
.season-stats-table {
  table-layout: fixed;
  width: 100%;
}

.season-stats-table th,
.season-stats-table td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

.season-stats-table th:nth-child(2),
.season-stats-table td:nth-child(2) {
  width: 60px;
}

.season-stats-table th:nth-child(n+3),
.season-stats-table td:nth-child(n+3) {
  width: 80px;
}

/* Season stats tabs: disable spam-click + align indicator */
.season-stats-tab:disabled {
  opacity: 0.6;
  cursor: wait;
}

.season-stats-indicator.htmx-request {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}

/* ===========================================
   10. Mobile Navigation
   =========================================== */

/* iOS Safe Area support for bottom navigation */
.safe-area-bottom {
  padding-bottom: env(safe-area-inset-bottom, 0);
}

/* Mobile menu slide animation enhancement */
#mobile-menu-overlay {
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
}

#mobile-menu-panel {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

/* Bottom nav active state - JS adds these classes */
[data-bottom-nav] a.active {
  color: #f97316;
}

.dark [data-bottom-nav] a.active {
  color: #fb923c;
}

/* Prevent body scroll when menu open */
body.menu-open {
  overflow: hidden;
  position: fixed;
  width: 100%;
}

/* Smooth menu transition on Safari */
@supports (-webkit-touch-callout: none) {
  #mobile-menu-panel {
    -webkit-transform: translateX(100%);
    transform: translateX(100%);
  }

  #mobile-menu-panel:not(.translate-x-full) {
    -webkit-transform: translateX(0);
    transform: translateX(0);
  }
}

/* ===========================================
   11. Skeleton Loading Components
   =========================================== */

/* Base skeleton box with shimmer effect */
.skeleton-box {
  background: linear-gradient(
    90deg,
    rgba(229, 231, 235, 0.8) 0%,
    rgba(249, 115, 22, 0.1) 50%,
    rgba(229, 231, 235, 0.8) 100%
  );
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s ease-in-out infinite;
  border-radius: 4px;
}

.dark .skeleton-box {
  background: linear-gradient(
    90deg,
    rgba(51, 65, 85, 0.8) 0%,
    rgba(249, 115, 22, 0.15) 50%,
    rgba(51, 65, 85, 0.8) 100%
  );
  background-size: 200% 100%;
}

@keyframes skeleton-shimmer {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

/* Skeleton container fade out */
.skeleton-container {
  transition: opacity 200ms ease-out;
}

.is-loading .skeleton-container {
  opacity: 1;
}

/* Content fade in after skeleton */
.skeleton-fade-in {
  animation: skeletonFadeIn 300ms ease-out forwards;
}

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

/* Skeleton row for tables */
.skeleton-row td {
  background: transparent !important;
}

.skeleton-row .skeleton-box {
  min-height: 16px;
}

/* Reduce motion preference */
@media (prefers-reduced-motion: reduce) {
  .skeleton-box {
    animation: none;
    background: rgba(229, 231, 235, 0.8);
  }

  .dark .skeleton-box {
    background: rgba(51, 65, 85, 0.8);
  }

  .skeleton-fade-in {
    animation: none;
    opacity: 1;
    transform: none;
  }
}

/* ===========================================
   12. Screen Reader Only (Accessibility)
   =========================================== */

.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;
}

/* Focus-visible state for sr-only skip links */
.sr-only.focus\:not-sr-only:focus,
.focus\:not-sr-only:focus {
  position: fixed;
  width: auto;
  height: auto;
  padding: 0.5rem 1rem;
  margin: 0;
  overflow: visible;
  clip: auto;
  white-space: normal;
  z-index: 9999;
}

/* Forced colors mode (Windows High Contrast) */
@media (forced-colors: active) {
  .skeleton-box {
    forced-color-adjust: none;
    background: GrayText !important;
  }

  button:focus,
  a:focus,
  [tabindex]:focus {
    outline: 3px solid Highlight !important;
    outline-offset: 2px !important;
  }
}

/* ===========================================
   13. Empty State Component
   =========================================== */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.5rem;
  text-align: center;
  min-height: 200px;
}

.empty-state-icon {
  width: 64px;
  height: 64px;
  margin-bottom: 1rem;
  color: #94a3b8;
  opacity: 0.6;
}

.dark .empty-state-icon {
  color: #475569;
}

.empty-state-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: #475569;
  margin-bottom: 0.5rem;
}

.dark .empty-state-title {
  color: #94a3b8;
}

.empty-state-description {
  font-size: 0.875rem;
  color: #64748b;
  max-width: 320px;
  line-height: 1.5;
}

.dark .empty-state-description {
  color: #64748b;
}

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

/* ===========================================
   14. Data Formatting Utilities
   =========================================== */

/* Tabular numbers for consistent stat alignment */
.stat-value {
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1;
}

/* Positive/negative value indicators */
.stat-positive {
  color: #16a34a;
}

.dark .stat-positive {
  color: #4ade80;
}

.stat-negative {
  color: #dc2626;
}

.dark .stat-negative {
  color: #f87171;
}

/* ===========================================
   15. Performance Optimization Classes
   =========================================== */

/* GPU acceleration hint for animated elements */
.will-animate {
  will-change: transform, opacity;
}

/* Content visibility optimization for off-screen content */
.content-auto {
  content-visibility: auto;
  contain-intrinsic-size: 0 500px;
}

/* Image optimization */
.img-optimized {
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
}

/* Prevent text rendering jank */
.text-optimized {
  text-rendering: optimizeSpeed;
}

/* ===========================================
   16. Sortable Tables
   =========================================== */

/* Sticky table header for long tables */
.table-sticky thead {
  position: sticky;
  top: 3.5rem; /* Header height: h-14 = 3.5rem (56px) */
  z-index: 20;
  background: inherit;
}

.table-sticky thead th {
  background: inherit;
}

/* Dark mode sticky header */
.dark .table-sticky thead {
  background-color: #0f172a; /* slate-900 */
}

/* Scrollable table container with sticky header support
 * Use this wrapper for long tables that need:
 * 1. Horizontal scroll on mobile (overflow-x-auto)
 * 2. Sticky headers that work within the container
 * The max-height creates a scrolling context where sticky works */
.table-scroll-container {
  max-height: clamp(400px, 70vh, 900px);
  overflow-y: auto;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-scroll-container thead {
  position: sticky;
  top: 0;
  z-index: 10;
}

/* Home EFF table readability: align 2-line stat cells with single-line cells */
#players-table-inner th {
  vertical-align: bottom;
}

#players-table-inner td {
  vertical-align: top;
}

/* Sortable column header */
th[data-sortable] {
  cursor: pointer;
  user-select: none;
  transition: background-color 150ms ease;
}

th[data-sortable]:hover {
  background-color: rgba(249, 115, 22, 0.05);
}

.dark th[data-sortable]:hover {
  background-color: rgba(249, 115, 22, 0.1);
}

/* Sort indicator */
.sort-indicator {
  vertical-align: middle;
  transition: opacity 150ms ease;
}

th[data-sortable]:hover .sort-indicator {
  opacity: 1 !important;
}

/* Active sort column */
th[data-sortable][aria-sort] {
  background-color: rgba(249, 115, 22, 0.03);
}

.dark th[data-sortable][aria-sort] {
  background-color: rgba(249, 115, 22, 0.05);
}

/* ===========================================
   16.5 Live Indicator Animation
   =========================================== */

/* Live dot with ping animation */
.live-dot {
  position: relative;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #ef4444;
  display: inline-block;
  margin-right: 6px;
}

.live-dot::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background-color: #ef4444;
  animation: live-ping 1.5s cubic-bezier(0, 0, 0.2, 1) infinite;
}

@keyframes live-ping {
  75%, 100% {
    transform: scale(2.5);
    opacity: 0;
  }
}

/* Live badge with glow effect */
.live-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 9999px;
  background-color: #ef4444;
  color: white;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5);
  animation: live-glow 2s ease-in-out infinite;
}

@keyframes live-glow {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(239, 68, 68, 0);
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .live-dot::before {
    animation: none;
  }
  .live-badge {
    animation: none;
  }
}

/* ===========================================
   17. Accessibility Enhancements (WCAG AA)
   =========================================== */

/* Enhanced focus ring for keyboard users */
*:focus-visible {
  outline: 2px solid #f97316;
  outline-offset: 2px;
}

/* High contrast orange for WCAG AA (4.5:1 on white) */
.text-orange-wcag {
  color: #c2410c; /* orange-700, 5.11:1 contrast on white */
}

.dark .text-orange-wcag {
  color: #fb923c; /* orange-400, 5.74:1 contrast on #0b0e14 */
}

/* Link underline for better visibility */
.link-underline {
  text-decoration-line: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

/* Skip to content link — hidden by default, visible on keyboard focus */
.skip-link {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link:focus {
  position: fixed;
  top: 1rem;
  left: 1rem;
  z-index: 9999;
  width: auto;
  height: auto;
  padding: 1rem 1.5rem;
  margin: 0;
  overflow: visible;
  clip: auto;
  white-space: normal;
  background: #f97316;
  color: white;
  font-weight: 600;
  border-radius: 0.5rem;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

/* Screen reader announcements */
.sr-announce {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Reduced motion - minimize distractions */
@media (prefers-reduced-motion: reduce) {
  .animate-fade-in,
  .htmx-settling,
  .htmx-added {
    animation: none !important;
    opacity: 1;
    transform: none;
  }

  .page-loader-bar {
    animation: none;
  }
}

/* High contrast mode support */
@media (prefers-contrast: more) {
  a:hover,
  button:hover {
    text-decoration: underline;
    text-decoration-thickness: 2px;
  }

  th[data-sortable]:hover {
    outline: 2px solid currentColor;
    outline-offset: -2px;
  }

  tbody tr:hover {
    outline: 2px solid #f97316;
    outline-offset: -2px;
  }
}

/* Ensure minimum touch target size (44x44px) */
@media (pointer: coarse) {
  button,
  a,
  [role="button"] {
    min-height: 44px;
    min-width: 44px;
  }

  /* Except for inline links in text */
  p a,
  li a,
  td a {
    min-height: auto;
    min-width: auto;
    padding: 0.25rem 0;
  }
}
