/**
 * Responsive & Accessibility Enhancements
 *
 * Mobile-first responsive design with WCAG AA compliance
 *
 * @package Cricket_Availability
 * @since 1.0.0
 */

/* ============================================================================
   RESPONSIVE BREAKPOINTS
   ============================================================================ */

:root {
    /* Breakpoints */
    --breakpoint-xs: 375px;
    --breakpoint-sm: 576px;
    --breakpoint-md: 768px;
    --breakpoint-lg: 1024px;
    --breakpoint-xl: 1280px;

    /* Touch targets (WCAG 2.5.5) */
    --touch-target-min: 44px;

    /* Font sizes - fluid typography */
    --font-size-base: clamp(0.875rem, 2vw, 1rem);
    --font-size-sm: clamp(0.75rem, 1.5vw, 0.875rem);
    --font-size-lg: clamp(1rem, 2.5vw, 1.125rem);
    --font-size-xl: clamp(1.125rem, 3vw, 1.5rem);
    --font-size-2xl: clamp(1.5rem, 4vw, 2rem);

    /* Spacing - responsive */
    --spacing-xs: clamp(4px, 1vw, 8px);
    --spacing-sm: clamp(8px, 2vw, 12px);
    --spacing-md: clamp(12px, 3vw, 16px);
    --spacing-lg: clamp(16px, 4vw, 24px);
    --spacing-xl: clamp(24px, 5vw, 32px);
}

/* ============================================================================
   MOBILE-FIRST BASE STYLES
   ============================================================================ */

/* Ensure all interactive elements meet minimum touch target size */
button,
a,
input,
select,
textarea,
.btn-cricket,
.tab-btn,
.filter-btn {
    min-height: var(--touch-target-min);
    min-width: var(--touch-target-min);
    padding: 12px 16px;
}

/* Responsive images */
img {
    max-width: 100%;
    height: auto;
}

/* Prevent horizontal scroll */
body {
    overflow-x: hidden;
}

/* ============================================================================
   MOBILE OPTIMIZATIONS (< 768px)
   ============================================================================ */

@media (max-width: 767px) {
    /* Typography */
    h1, .cricket-heading-xl {
        font-size: 1.75rem !important;
        line-height: 1.2;
    }

    h2, .cricket-heading-lg {
        font-size: 1.5rem !important;
    }

    h3 {
        font-size: 1.25rem !important;
    }

    /* Containers */
    .cricket-container,
    .cricket-admin-dashboard,
    .cricket-reports,
    .cricket-leaderboard,
    .cricket-achievements,
    .cricket-profile {
        padding: 12px !important;
    }

    /* Cards */
    .card-cricket {
        margin-bottom: 16px;
    }

    .card-cricket-body {
        padding: 16px !important;
    }

    /* Grids - stack on mobile */
    .dashboard-grid,
    .reports-grid,
    .profile-grid,
    .team-cards-grid,
    .achievements-grid {
        grid-template-columns: 1fr !important;
        gap: 16px !important;
    }

    .stats-grid,
    .metrics-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 12px !important;
    }

    .filter-grid {
        grid-template-columns: 1fr !important;
    }

    /* Tables - responsive scroll */
    .table-cricket-wrapper {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin: 0 -16px;
        padding: 0 16px;
    }

    .table-cricket {
        min-width: 600px;
        font-size: 0.875rem;
    }

    .table-cricket th,
    .table-cricket td {
        padding: 8px !important;
    }

    /* Buttons - full width on mobile */
    .btn-cricket-mobile-full {
        width: 100%;
        justify-content: center;
    }

    /* Flexbox - wrap on mobile */
    .cricket-flex {
        flex-wrap: wrap !important;
    }

    .cricket-flex-between {
        gap: 12px;
    }

    /* Forms */
    .form-cricket-input,
    .form-cricket-select,
    .form-cricket-textarea {
        font-size: 16px !important; /* Prevents zoom on iOS */
    }

    /* Modals - full screen on mobile */
    .modal-cricket {
        max-width: calc(100vw - 24px) !important;
        max-height: calc(100vh - 24px) !important;
        margin: 12px !important;
    }

    /* Leaderboard tabs - 2 columns */
    .leaderboard-tabs {
        display: grid !important;
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px;
    }

    .tab-btn {
        font-size: 0.75rem;
        padding: 8px 12px;
    }

    /* Achievement cards - single column */
    .achievements-grid {
        grid-template-columns: 1fr !important;
    }

    /* Profile header - stack vertically */
    .profile-header-content {
        flex-direction: column !important;
        align-items: center !important;
        text-align: center;
    }

    .profile-badges {
        justify-content: center;
    }

    /* Player cards - smaller on mobile */
    .player-card {
        padding: 12px !important;
    }

    .player-avatar {
        width: 40px !important;
        height: 40px !important;
        font-size: 0.875rem !important;
    }

    /* Drag and drop - larger touch areas */
    .player-list .player-card {
        min-height: 60px;
        margin-bottom: 12px;
    }

    /* Quick actions */
    .quick-actions .btn-cricket {
        width: 100%;
    }

    /* Sticky elements - mobile safe zones */
    .sticky-submit-bar {
        bottom: 0;
        left: 0;
        right: 0;
        padding: 12px;
        padding-bottom: calc(12px + env(safe-area-inset-bottom));
    }

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

    /* Spacing adjustments */
    .cricket-mb-4 {
        margin-bottom: 16px !important;
    }

    .cricket-mt-4 {
        margin-top: 16px !important;
    }

    .cricket-gap-3 {
        gap: 12px !important;
    }
}

/* ============================================================================
   TABLET OPTIMIZATIONS (768px - 1023px)
   ============================================================================ */

@media (min-width: 768px) and (max-width: 1023px) {
    /* Grids - 2 columns on tablet */
    .achievements-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .stats-grid {
        grid-template-columns: repeat(3, 1fr) !important;
    }

    .team-cards-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* Dashboard */
    .dashboard-grid,
    .reports-grid {
        grid-template-columns: 1fr !important;
    }
}

/* ============================================================================
   LANDSCAPE MOBILE (height < 500px)
   ============================================================================ */

@media (max-height: 500px) and (orientation: landscape) {
    /* Reduce vertical spacing */
    .card-cricket-body {
        padding: 12px !important;
    }

    .cricket-mb-4 {
        margin-bottom: 12px !important;
    }

    /* Smaller avatars */
    .profile-avatar-large .avatar-inner {
        width: 80px !important;
        height: 80px !important;
        font-size: 1.5rem !important;
    }

    /* Compact headers */
    .dashboard-header,
    .leaderboard-header,
    .achievements-header {
        padding: 12px !important;
    }
}

/* ============================================================================
   ACCESSIBILITY - WCAG AA COMPLIANCE
   ============================================================================ */

/* Focus indicators (WCAG 2.4.7) */
*:focus {
    outline: 3px solid var(--cricket-primary);
    outline-offset: 2px;
}

*:focus:not(:focus-visible) {
    outline: none;
}

*:focus-visible {
    outline: 3px solid var(--cricket-primary);
    outline-offset: 2px;
}

/* Skip to main content link */
.skip-to-main {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--cricket-primary);
    color: white;
    padding: 8px 16px;
    text-decoration: none;
    z-index: 10000;
}

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

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --cricket-primary: #1a4d1b;
        --cricket-gray-600: #000000;
    }

    .btn-cricket,
    .badge-cricket {
        border: 2px solid currentColor;
    }
}

/* Reduced motion (WCAG 2.3.3) */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .spinner-cricket {
        animation: none;
        border-top-color: transparent;
    }
}

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

.sr-only-focusable:focus {
    position: static;
    width: auto;
    height: auto;
    padding: inherit;
    margin: inherit;
    overflow: visible;
    clip: auto;
    white-space: normal;
}

/* Color contrast improvements */
.cricket-text-muted {
    color: #5f6368; /* WCAG AA compliant on white */
}

.badge-cricket {
    font-weight: 600; /* Improve readability */
}

/* Link styles - clear and distinguishable */
a {
    text-decoration: underline;
    text-decoration-skip-ink: auto;
}

a:hover,
a:focus {
    text-decoration-thickness: 2px;
}

.btn-cricket {
    text-decoration: none; /* Buttons don't need underlines */
}

/* Form labels - always visible */
label {
    display: block;
    margin-bottom: 4px;
    font-weight: 600;
}

/* Required field indicator */
.required::after {
    content: " *";
    color: var(--cricket-danger);
    font-weight: 700;
}

/* Error messages - clear and prominent */
.form-error {
    color: var(--cricket-danger);
    font-size: 0.875rem;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.form-error::before {
    content: "⚠";
    font-size: 1rem;
}

/* Success messages */
.form-success {
    color: var(--cricket-success);
    font-size: 0.875rem;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.form-success::before {
    content: "✓";
    font-size: 1rem;
}

/* Disabled state - clearly indicated */
button:disabled,
input:disabled,
select:disabled,
textarea:disabled,
.btn-cricket:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background-color: var(--cricket-gray-200) !important;
    color: var(--cricket-gray-600) !important;
}

/* ============================================================================
   TOUCH IMPROVEMENTS
   ============================================================================ */

/* Larger touch targets for small elements */
.table-cricket button,
.table-cricket a {
    min-height: 36px;
    min-width: 36px;
    padding: 8px 12px;
}

/* Prevent double-tap zoom */
button,
a,
input[type="submit"],
input[type="button"] {
    touch-action: manipulation;
}

/* Smooth scrolling (except for reduced motion) */
html {
    scroll-behavior: smooth;
}

/* Safe area insets for notched devices */
body {
    padding-top: env(safe-area-inset-top);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
}

/* ============================================================================
   PRINT STYLES
   ============================================================================ */

@media print {
    /* Hide interactive elements */
    .btn-cricket,
    .filter-btn,
    .tab-btn,
    .modal-cricket-overlay,
    .cricket-help-button,
    .quick-actions {
        display: none !important;
    }

    /* Expand collapsed content */
    details {
        display: block;
    }

    summary {
        display: none;
    }

    /* Page breaks */
    .card-cricket,
    .leaderboard-item,
    .achievement-card {
        page-break-inside: avoid;
    }

    /* Black and white */
    * {
        color: #000 !important;
        background: #fff !important;
    }

    /* Show URLs */
    a[href]::after {
        content: " (" attr(href) ")";
    }
}

/* ============================================================================
   DARK MODE SUPPORT (Optional)
   ============================================================================ */

@media (prefers-color-scheme: dark) {
    :root {
        --cricket-bg: #1a1a1a;
        --cricket-surface: #2a2a2a;
        --cricket-text: #e0e0e0;
    }

    body {
        background: var(--cricket-bg);
        color: var(--cricket-text);
    }

    .card-cricket {
        background: var(--cricket-surface);
        border-color: #404040;
    }

    .table-cricket {
        background: var(--cricket-surface);
    }

    .table-cricket tr:nth-child(even) {
        background: #333;
    }

    input,
    select,
    textarea {
        background: var(--cricket-surface);
        color: var(--cricket-text);
        border-color: #404040;
    }
}

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

/* Responsive visibility */
.show-mobile {
    display: none;
}

@media (max-width: 767px) {
    .show-mobile {
        display: block;
    }

    .hide-mobile {
        display: none;
    }
}

.show-tablet {
    display: none;
}

@media (min-width: 768px) and (max-width: 1023px) {
    .show-tablet {
        display: block;
    }

    .hide-tablet {
        display: none;
    }
}

.show-desktop {
    display: none;
}

@media (min-width: 1024px) {
    .show-desktop {
        display: block;
    }

    .hide-desktop {
        display: none;
    }
}

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

.text-truncate-2 {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Aspect ratio (for images/videos) */
.aspect-ratio-16-9 {
    aspect-ratio: 16 / 9;
}

.aspect-ratio-1-1 {
    aspect-ratio: 1 / 1;
}

/* Loading skeleton */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: loading 1.5s ease-in-out infinite;
}

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

/* ============================================================================
   PERFORMANCE OPTIMIZATIONS
   ============================================================================ */

/* GPU acceleration for animations */
.animate-gpu {
    will-change: transform;
    transform: translateZ(0);
}

/* Lazy loading */
img[loading="lazy"] {
    background: var(--cricket-gray-100);
}

/* Reduce paint area */
.contain-paint {
    contain: paint;
}

.contain-layout {
    contain: layout;
}

/* ============================================================================
   FIXES FOR COMMON ISSUES
   ============================================================================ */

/* Fix iOS Safari button appearance */
input[type="submit"],
input[type="button"],
button {
    -webkit-appearance: none;
    appearance: none;
}

/* Fix iOS Safari input zoom */
@supports (-webkit-touch-callout: none) {
    input,
    select,
    textarea {
        font-size: 16px;
    }
}

/* Fix Android Chrome autocomplete background */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0 1000px white inset;
}

/* Fix flexbox min-height in Safari */
.flex-safari-fix {
    min-height: 0;
}

/* Fix z-index stacking */
.modal-cricket-overlay {
    isolation: isolate;
}

/* Prevent text selection on buttons */
button,
.btn-cricket {
    user-select: none;
    -webkit-user-select: none;
}
