/* ============================================
   FGC TRAIN ARRIVALS - ACCESSIBILITY STYLES
   WCAG 2.1 Level AA Compliant
   ============================================ */

/* ============================================
   SKIP TO CONTENT
   ============================================ */

.skip-to-content {
    position: absolute;
    left: -9999px;
    z-index: 9999;
    padding: 12px 24px;
    background: var(--fgc-green);
    color: white;
    text-decoration: none;
    font-weight: 600;
    font-size: 16px;
    border-radius: 0 0 8px 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    transition: all 0.3s ease;
}

.skip-to-content:focus {
    left: 50%;
    top: 0;
    transform: translateX(-50%);
    outline: 3px solid white;
    outline-offset: 4px;
}

/* ============================================
   SCREEN READER ONLY
   ============================================ */

.sr-only {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
}

/* ============================================
   ENHANCED FOCUS INDICATORS
   ============================================ */

/* Visible focus for keyboard navigation */
body.keyboard-nav *:focus {
    outline: 3px solid var(--fgc-green) !important;
    outline-offset: 2px !important;
    box-shadow: 0 0 0 5px rgba(136, 187, 11, 0.2) !important;
}

/* High contrast focus indicators */
body.high-contrast *:focus,
body.high-contrast.keyboard-nav *:focus {
    outline: 4px solid #FFFF00 !important;
    outline-offset: 3px !important;
}

/* Interactive elements default focus */
button:focus,
a:focus,
input:focus,
select:focus,
textarea:focus,
[tabindex]:focus {
    outline: 2px solid var(--fgc-green);
    outline-offset: 2px;
}

/* ============================================
   HIGH CONTRAST MODE
   ============================================ */

body.high-contrast {
    /* Background colors */
    --color-bg-primary: #000000;
    --color-bg-secondary: #000000;
    --color-bg-card: #000000;
    
    /* Text colors - Maximum contrast */
    --color-text-primary: #FFFFFF;
    --color-text-secondary: #FFFF00;
    --color-text-light: #FFFFFF;
    
    /* Borders - High visibility */
    --color-border: #FFFFFF;
    --color-border-light: #FFFF00;
    
    /* FGC green remains for brand recognition */
    --fgc-green: #00FF00;
    --fgc-green-dark: #00CC00;
    --fgc-green-light: #66FF66;
}

body.high-contrast {
    background: #000000 !important;
    color: #FFFFFF !important;
}

body.high-contrast .station-header {
    background: #000000 !important;
    border-bottom: 4px solid #FFFF00 !important;
}

body.high-contrast .departures-table {
    background: #000000 !important;
    border: 3px solid #FFFFFF !important;
}

body.high-contrast .departures-table th {
    background: #000000 !important;
    color: #FFFF00 !important;
    border-bottom: 3px solid #FFFF00 !important;
}

body.high-contrast .departures-table td {
    border-bottom: 2px solid #FFFFFF !important;
    color: #FFFFFF !important;
}

body.high-contrast .line-badge-sm {
    border: 2px solid #FFFFFF !important;
    color: #000000 !important;
    background: #FFFF00 !important;
}

body.high-contrast .status-badge {
    border: 2px solid #FFFFFF !important;
    background: #000000 !important;
    color: #00FF00 !important;
}

body.high-contrast .status-badge.status-delayed {
    color: #FFFF00 !important;
}

body.high-contrast .status-badge.status-cancelled {
    color: #FF0000 !important;
}

body.high-contrast button {
    border: 2px solid #FFFFFF !important;
    background: #000000 !important;
    color: #FFFFFF !important;
}

body.high-contrast button:hover {
    background: #FFFFFF !important;
    color: #000000 !important;
}

/* ============================================
   FONT SIZE CONTROLS
   ============================================ */

/* Small font size */
body.font-small {
    font-size: 85%;
}

body.font-small .station-name {
    font-size: clamp(10px, 1.3vw, 20px) !important;
}

body.font-small .departures-table {
    font-size: 85%;
}

/* Large font size */
body.font-large {
    font-size: 115%;
}

body.font-large .station-name {
    font-size: clamp(13px, 1.8vw, 28px) !important;
}

body.font-large .departures-table {
    font-size: 115%;
}

body.font-large .departures-table th,
body.font-large .departures-table td {
    padding: clamp(20px, 2.5vmin, 48px) clamp(16px, 2vmin, 36px);
}

/* ============================================
   REDUCED MOTION
   ============================================ */

body.reduce-motion,
body.reduce-motion * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
}

body.reduce-motion .loading-spinner {
    animation: none !important;
    border-top-color: transparent !important;
}

body.reduce-motion .skeleton-card {
    animation: none !important;
}

body.reduce-motion .station-pulse {
    animation: none !important;
    opacity: 0 !important;
}

/* ============================================
   ACCESSIBILITY BUTTONS
   ============================================ */

.accessibility-btn {
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 6px;
    padding: 6px 10px;
    color: white;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.accessibility-btn:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: white;
    transform: translateY(-1px);
}

.accessibility-btn:active {
    transform: translateY(0);
}

.accessibility-btn:focus {
    outline: 3px solid white;
    outline-offset: 2px;
}

.font-size-controls {
    display: flex;
    gap: 6px;
    align-items: center;
}

/* ============================================
   KEYBOARD HINTS PANEL
   ============================================ */

.keyboard-hints-panel {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    backdrop-filter: blur(5px);
}

.hints-content {
    background: var(--color-bg-card);
    border-radius: 12px;
    padding: 32px;
    max-width: 600px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    position: relative;
}

.hints-content h2 {
    margin: 0 0 24px 0;
    font-size: 28px;
    font-weight: 700;
    color: var(--color-text-primary);
}

.hints-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: transparent;
    border: none;
    font-size: 32px;
    color: var(--color-text-secondary);
    cursor: pointer;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.hints-close:hover {
    background: var(--color-border-light);
    color: var(--color-text-primary);
}

.hints-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.hint-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px;
    background: var(--color-bg-primary);
    border-radius: 8px;
    border: 1px solid var(--color-border);
}

.hint-item kbd {
    background: var(--fgc-green);
    color: white;
    padding: 6px 12px;
    border-radius: 6px;
    font-family: 'Roboto Mono', monospace;
    font-size: 14px;
    font-weight: 600;
    min-width: 40px;
    text-align: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    border: 2px solid var(--fgc-green-dark);
}

.hint-item span {
    flex: 1;
    color: var(--color-text-primary);
    font-size: 16px;
}

/* High contrast adjustments */
body.high-contrast .keyboard-hints-panel {
    background: rgba(0, 0, 0, 0.95);
}

body.high-contrast .hints-content {
    background: #000000;
    border: 3px solid #FFFFFF;
}

body.high-contrast .hint-item {
    background: #000000;
    border: 2px solid #FFFFFF;
}

body.high-contrast .hint-item kbd {
    background: #FFFF00;
    color: #000000;
    border-color: #FFFFFF;
}

/* ============================================
   ARIA ENHANCEMENTS
   ============================================ */

/* Ensure ARIA labels are accessible */
[aria-label],
[aria-labelledby],
[aria-describedby] {
    /* Already handled by browsers, but ensure focus visibility */
}

/* Live regions should never be visible */
[aria-live] {
    position: absolute !important;
    left: -10000px !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
}

/* ============================================
   TABLE ACCESSIBILITY
   ============================================ */

.departures-table {
    /* Ensure proper table semantics */
}

.departures-table th {
    /* Column headers with scope */
}

.departures-table th[scope="col"] {
    font-weight: 700;
}

/* Zebra striping for better readability */
.departures-table tbody tr:nth-child(even) {
    background: rgba(0, 0, 0, 0.02);
}

body.dark-mode .departures-table tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
}

body.high-contrast .departures-table tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.05);
}

/* ============================================
   FORM ACCESSIBILITY
   ============================================ */

/* Ensure all inputs have visible labels */
label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--color-text-primary);
}

/* Required field indicator */
input:required,
select:required,
textarea:required {
    border-left: 4px solid var(--fgc-green);
}

/* Error states */
input:invalid,
select:invalid,
textarea:invalid {
    border-color: #D32F2F;
}

input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"] {
    border-color: #D32F2F;
    border-width: 2px;
}

/* ============================================
   TOUCH TARGET SIZES (Mobile Accessibility)
   ============================================ */

/* Minimum 44x44px touch targets */
button,
a,
input[type="button"],
input[type="submit"],
input[type="checkbox"],
input[type="radio"],
select {
    min-width: 44px;
    min-height: 44px;
    padding: 8px 12px;
}

/* Exception for inline text links */
p a,
span a {
    min-width: auto;
    min-height: auto;
}

/* ============================================
   COLOR CONTRAST
   ============================================ */

/* Ensure minimum 4.5:1 contrast ratio for normal text */
/* Ensure minimum 3:1 contrast ratio for large text (18pt+) */
/* Already handled in main styles, but verify critical elements */

.countdown-imminent {
    color: #D32F2F; /* High contrast red */
    font-weight: 700;
}

.countdown-soon {
    color: #FF6D00; /* High contrast orange */
    font-weight: 600;
}

/* ============================================
   RESPONSIVE ACCESSIBILITY
   ============================================ */

@media (max-width: 768px) {
    /* Larger touch targets on mobile */
    .accessibility-btn {
        min-width: 48px;
        min-height: 48px;
        padding: 10px 12px;
    }
    
    .hint-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    
    .hints-content {
        padding: 24px 16px;
    }
}

@media (max-width: 480px) {
    .skip-to-content {
        font-size: 14px;
        padding: 10px 20px;
    }
    
    .keyboard-hints-panel {
        padding: 10px;
    }
    
    .hints-content {
        max-height: 90vh;
        padding: 20px 12px;
    }
}

/* ============================================
   PRINT ACCESSIBILITY
   ============================================ */

@media print {
    .skip-to-content,
    .accessibility-btn,
    .keyboard-hints-panel,
    .font-size-controls {
        display: none !important;
    }
    
    /* Ensure good contrast for printing */
    * {
        background: white !important;
        color: black !important;
    }
    
    .departures-table th {
        background: #f0f0f0 !important;
        color: black !important;
    }
}

/* ============================================
   ANIMATION PREFERENCES
   ============================================ */

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

/* ============================================
   HIGH CONTRAST MEDIA QUERY
   ============================================ */

@media (prefers-contrast: high) {
    /* Additional high contrast styles for system preference */
    body {
        border: 1px solid currentColor;
    }
    
    button,
    a,
    input,
    select {
        border: 2px solid currentColor !important;
    }
}
