/* ============================================
   PHASE 5: ACCESSIBILITY & UX IMPROVEMENTS
   ============================================ */

/* Focus Visible States - Better keyboard navigation */
:focus-visible {
    outline: 2px solid #c5a059 !important;
    outline-offset: 2px !important;
}

/* Remove default outline for mouse users, keep for keyboard */
:focus:not(:focus-visible) {
    outline: none;
}

/* Skip Link for keyboard users */
.skip-link {
    position: absolute;
    top: -100%;
    left: 50%;
    transform: translateX(-50%);
    background: #0a2f25;
    color: #c5a059;
    padding: 0.75rem 1.5rem;
    border-radius: 0.5rem;
    font-weight: 700;
    z-index: 1000;
    transition: top 0.2s ease;
}

.skip-link:focus {
    top: 0.5rem;
}

/* Mobile Menu Styles */
#public-nav {
    transition: all 0.3s ease;
}

/* Mobile: collapsible dropdown under the sticky header */
@media (max-width: 767.98px) {
    #public-nav {
        display: none;
        position: absolute;
        top: 100%;
        right: 0;
        left: 0;
        flex-direction: column;
        align-items: stretch;
        background: #0a2f25;
        padding: 0.75rem;
        border-bottom: 1px solid rgba(197, 160, 89, 0.25);
        box-shadow: 0 12px 20px -8px rgba(0, 0, 0, 0.45);
        z-index: 45;
    }

    #public-nav.mobile-open {
        display: flex;
    }

    #public-nav button {
        width: 100%;
        text-align: right;
        padding: 0.875rem 1rem;
        border-radius: 0.5rem;
        font-size: 0.9375rem;
    }

    #mobile-menu-toggle {
        display: flex !important;
    }
}

/* Desktop: the toggle is redundant because the nav is always visible */
@media (min-width: 768px) {
    #public-nav {
        display: flex !important;
    }

    #mobile-menu-toggle {
        display: none !important;
    }
}

/* Modal Focus Trapping - Ensure focus stays within modal */
.modal-open {
    overflow: hidden;
}

/*
 * Do NOT add `display` rules for [role="dialog"] here.
 *
 * Every dialog ships with BOTH `hidden` and `flex` in its class list and is
 * toggled by swapping them in JS. An earlier version of this file had:
 *     .fixed[role="dialog"]        { display: none; }
 *     .fixed[role="dialog"].flex   { display: flex;  }
 * Because this stylesheet loads after the compiled Tailwind, the second rule
 * (specificity 0-3-0) beat `.hidden` (0-1-0) and every modal rendered on page
 * load. Visibility is owned solely by the `hidden` class.
 */

/* Better focus styles for form elements */
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
button:focus-visible,
a:focus-visible {
    outline: 2px solid #c5a059 !important;
    outline-offset: 2px !important;
    box-shadow: 0 0 0 2px rgba(197, 160, 89, 0.2) !important;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --tw-border-opacity: 1;
    }
    
    .border-brand-gold\/20,
    .border-brand-gold\/30 {
        border-color: #c5a059 !important;
    }
    
    .bg-brand-sand\/70 {
        background-color: #f7f4ee !important;
    }
}

/* Reduced motion support */
@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;
    }
    
    .fade-in {
        animation: none !important;
        opacity: 1 !important;
        transform: none !important;
    }
    
    .hover-lift:hover {
        transform: none !important;
    }
}

/* Screen reader only text */
.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;
}

/* Better touch targets for mobile */
@media (max-width: 767.98px) {
    button,
    [role="button"],
    a,
    input[type="checkbox"],
    input[type="radio"],
    select {
        min-height: 44px;
        min-width: 44px;
    }
    
    /* Ensure form elements have adequate touch targets */
    input,
    select,
    textarea {
        min-height: 48px;
    }
}

/* RTL-specific focus styles */
[dir="rtl"] :focus-visible {
    outline-offset: 2px;
}

/* Modal backdrop click to close hint */
[role="dialog"]::backdrop {
    background: rgba(10, 47, 37, 0.8);
}

/* Print styles */
@media print {
    header,
    footer,
    .fixed,
    button,
    nav {
        display: none !important;
    }
    
    main {
        padding: 0 !important;
    }
    
    .no-print {
        display: none !important;
    }
}

/* Better visible focus for interactive elements in cards */
.student-reg-card:focus-within {
    box-shadow: 0 0 0 3px rgba(197, 160, 89, 0.3);
}

/* Active nav state improvements */
.public-active-tab {
    position: relative;
}

.public-active-tab::after {
    content: '';
    position: absolute;
    bottom: -2px;
    right: 0;
    left: 0;
    height: 3px;
    background: #c5a059;
    border-radius: 0 0 0.5rem 0.5rem;
}

/* Toast accessibility */
#toast-notification[role="alert"] {
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Loading state for buttons */
button:disabled,
button[aria-busy="true"] {
    opacity: 0.6;
    cursor: not-allowed;
}

button[aria-busy="true"]::after {
    content: '';
    display: inline-block;
    width: 1em;
    height: 1em;
    margin-right: 0.5rem;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
}

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

/* Ensure proper contrast for disabled states */
:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Selection styles */
::selection {
    background-color: #c5a059;
    color: #0a2f25;
}

/* Improve readability of placeholder text */
::placeholder {
    color: #9ca3af;
    opacity: 1;
}

/* Form validation styles */
input:invalid:not(:placeholder-shown),
select:invalid:not(:placeholder-shown) {
    border-color: #e11d48;
}

input:valid:not(:placeholder-shown),
select:valid:not(:placeholder-shown) {
    border-color: #16a34a;
}

/* Better table accessibility on mobile */
@media (max-width: 767.98px) {
    table[role="grid"] {
        display: block;
        overflow-x: auto;
    }
    
    table[role="grid"] thead {
        position: sticky;
        left: 0;
    }
}