/*
 * Government Website Accessibility Framework
 * Compliant with WCAG 2.1 AA Standards
 * Built for Educational Institutions
 */

/* ============================================
   ACCESSIBILITY FOUNDATION
   ============================================ */

:root {
    /* High Contrast Color Palette for Accessibility */
    --primary-blue: #1e3a8a;
    --primary-blue-light: #3b82f6;
    --primary-blue-dark: #1e40af;
    
    --secondary-green: #059669;
    --secondary-green-light: #10b981;
    --secondary-green-dark: #047857;
    
    --accent-orange: #ea580c;
    --accent-red: #dc2626;
    --accent-yellow: #d97706;
    
    /* Accessible Gray Scale */
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;
    
    /* Text Colors with 4.5:1+ Contrast Ratio */
    --text-primary: #0f172a;
    --text-secondary: #334155;
    --text-tertiary: #64748b;
    --text-light: #ffffff;
    --text-muted: #64748b;
    
    /* Background Colors */
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --bg-dark: #1e293b;
    --bg-overlay: rgba(15, 23, 42, 0.8);
    
    /* Status Colors */
    --success: #059669;
    --warning: #d97706;
    --error: #dc2626;
    --info: #0284c7;
    
    /* Typography Scale */
    --font-size-xs: 0.75rem;    /* 12px */
    --font-size-sm: 0.875rem;   /* 14px */
    --font-size-base: 1rem;     /* 16px */
    --font-size-lg: 1.125rem;   /* 18px */
    --font-size-xl: 1.25rem;    /* 20px */
    --font-size-2xl: 1.5rem;    /* 24px */
    --font-size-3xl: 1.875rem;  /* 30px */
    --font-size-4xl: 2.25rem;   /* 36px */
    --font-size-5xl: 3rem;      /* 48px */
    
    /* Line Heights for Better Readability */
    --line-height-tight: 1.25;
    --line-height-normal: 1.5;
    --line-height-relaxed: 1.75;
    --line-height-loose: 2;
    
    /* Spacing Scale */
    --space-1: 0.25rem;   /* 4px */
    --space-2: 0.5rem;    /* 8px */
    --space-3: 0.75rem;   /* 12px */
    --space-4: 1rem;      /* 16px */
    --space-5: 1.25rem;   /* 20px */
    --space-6: 1.5rem;    /* 24px */
    --space-8: 2rem;      /* 32px */
    --space-10: 2.5rem;   /* 40px */
    --space-12: 3rem;     /* 48px */
    --space-16: 4rem;     /* 64px */
    --space-20: 5rem;     /* 80px */
    
    /* Shadows with Better Visibility */
    --shadow-sm: 0 1px 2px 0 rgba(15, 23, 42, 0.05);
    --shadow: 0 1px 3px 0 rgba(15, 23, 42, 0.1), 0 1px 2px 0 rgba(15, 23, 42, 0.06);
    --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.1), 0 2px 4px -1px rgba(15, 23, 42, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.1), 0 4px 6px -2px rgba(15, 23, 42, 0.05);
    --shadow-xl: 0 20px 25px -5px rgba(15, 23, 42, 0.1), 0 10px 10px -5px rgba(15, 23, 42, 0.04);
    
    /* Border Radius */
    --radius-sm: 0.25rem;
    --radius: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-full: 9999px;
    
    /* Transitions */
    --transition-fast: 150ms ease-in-out;
    --transition-base: 250ms ease-in-out;
    --transition-slow: 400ms ease-in-out;
    
    /* Focus Ring */
    --focus-ring: 0 0 0 3px rgba(59, 130, 246, 0.5);
    --focus-ring-error: 0 0 0 3px rgba(220, 38, 38, 0.5);
}

/* ============================================
   RESET AND BASE STYLES
   ============================================ */

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    font-size: 16px;
    line-height: 1.5;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

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

body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', 'Roboto', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    font-size: var(--font-size-base);
    line-height: var(--line-height-normal);
    color: var(--text-primary);
    background-color: var(--bg-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ============================================
   FOCUS MANAGEMENT
   ============================================ */

*:focus {
    outline: none;
}

*:focus-visible {
    outline: 2px solid var(--primary-blue);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

.focus-trap {
    position: fixed;
    top: -1px;
    left: -1px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

/* Skip to content link */
.skip-link {
    position: absolute;
    top: -40px;
    left: 6px;
    background: var(--primary-blue);
    color: white;
    padding: var(--space-2) var(--space-4);
    text-decoration: none;
    border-radius: var(--radius);
    font-weight: 600;
    z-index: 10000;
    transition: var(--transition-fast);
}

.skip-link:focus {
    top: 6px;
}

/* ============================================
   TYPOGRAPHY
   ============================================ */

h1, h2, h3, h4, h5, h6 {
    font-family: 'Inter', 'Roboto', sans-serif;
    font-weight: 600;
    line-height: var(--line-height-tight);
    color: var(--text-primary);
    margin: 0 0 var(--space-4) 0;
}

h1 {
    font-size: var(--font-size-4xl);
    font-weight: 700;
}

h2 {
    font-size: var(--font-size-3xl);
    font-weight: 600;
}

h3 {
    font-size: var(--font-size-2xl);
}

h4 {
    font-size: var(--font-size-xl);
}

h5 {
    font-size: var(--font-size-lg);
}

h6 {
    font-size: var(--font-size-base);
}

p {
    margin: 0 0 var(--space-4) 0;
    line-height: var(--line-height-relaxed);
    color: var(--text-secondary);
}

/* Large text for better readability */
.text-large {
    font-size: var(--font-size-lg);
    line-height: var(--line-height-relaxed);
}

/* Small text with minimum readable size */
.text-small {
    font-size: var(--font-size-sm);
    line-height: var(--line-height-normal);
}

/* Text colors with proper contrast */
.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }
.text-muted { color: var(--text-muted); }
.text-light { color: var(--text-light); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-error { color: var(--error); }
.text-info { color: var(--info); }

/* ============================================
   INTERACTIVE ELEMENTS
   ============================================ */

a {
    color: var(--primary-blue);
    text-decoration: underline;
    transition: var(--transition-fast);
}

a:hover {
    color: var(--primary-blue-dark);
    text-decoration: none;
}

a:focus-visible {
    outline: 2px solid var(--primary-blue);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

button {
    font-family: inherit;
    font-size: inherit;
    cursor: pointer;
    border: none;
    border-radius: var(--radius);
    transition: var(--transition-base);
    min-height: 44px; /* Minimum touch target size */
    min-width: 44px;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.6;
}

/* ============================================
   FORM ELEMENTS
   ============================================ */

input, textarea, select {
    font-family: inherit;
    font-size: var(--font-size-base);
    line-height: var(--line-height-normal);
    border: 2px solid var(--gray-300);
    border-radius: var(--radius);
    padding: var(--space-3) var(--space-4);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    transition: var(--transition-fast);
    min-height: 44px; /* Minimum touch target size */
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--primary-blue);
    box-shadow: var(--focus-ring);
}

input:invalid,
textarea:invalid,
select:invalid {
    border-color: var(--error);
}

input:invalid:focus,
textarea:invalid:focus,
select:invalid:focus {
    box-shadow: var(--focus-ring-error);
}

label {
    display: block;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: var(--space-2);
    cursor: pointer;
}

.required {
    color: var(--error);
}

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

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

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

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --primary-blue: #000080;
        --text-primary: #000000;
        --text-secondary: #000000;
        --gray-300: #666666;
        --bg-primary: #ffffff;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --text-primary: #f8fafc;
        --text-secondary: #e2e8f0;
        --text-tertiary: #cbd5e1;
        --bg-primary: #0f172a;
        --bg-secondary: #1e293b;
        --bg-tertiary: #334155;
        --gray-300: #475569;
    }
}

/* ============================================
   ACCESSIBILITY CONTROLS
   ============================================ */

/* Font Size Controls */
.font-size-label {
    color: var(--text-light);
    font-size: var(--font-size-sm);
    margin-right: var(--space-2);
    font-weight: 500;
}

.font-btn {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: var(--text-light);
    padding: var(--space-1) var(--space-3);
    margin: 0 var(--space-1);
    border-radius: var(--radius);
    font-size: var(--font-size-sm);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    min-width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.font-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-1px);
}

.font-btn:focus {
    outline: 2px solid var(--accent-orange);
    outline-offset: 2px;
    box-shadow: 0 0 0 2px var(--bg-primary);
}

.font-btn.active {
    background: var(--accent-orange);
    border-color: var(--accent-orange);
    color: var(--text-light);
}

.font-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Language Selector */
.language-selector {
    margin-left: var(--space-3);
}

.language-selector .dropdown-toggle {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: var(--text-light);
    padding: var(--space-1) var(--space-3);
    border-radius: var(--radius);
    font-size: var(--font-size-sm);
    transition: all 0.2s ease-in-out;
    min-width: 60px;
    height: 32px;
}

.language-selector .dropdown-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.5);
}

.language-selector .dropdown-toggle:focus {
    outline: 2px solid var(--accent-orange);
    outline-offset: 2px;
    box-shadow: 0 0 0 2px var(--bg-primary);
}

.language-selector .dropdown-menu {
    background: var(--bg-primary);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: var(--space-2) 0;
    min-width: 180px;
}

.language-selector .dropdown-item {
    color: var(--text-primary);
    padding: var(--space-2) var(--space-4);
    font-size: var(--font-size-sm);
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    text-decoration: none;
}

.language-selector .dropdown-item i {
    margin-right: var(--space-2);
    color: var(--primary-blue);
}

.language-selector .dropdown-item:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
    text-decoration: none;
}

.language-selector .dropdown-item:focus {
    outline: 2px solid var(--primary-blue);
    outline-offset: -2px;
}

/* Accessibility Tools Container */
.accessibility-tools {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: var(--space-2);
}

@media (max-width: 768px) {
    .accessibility-tools {
        justify-content: center;
        margin-top: var(--space-2);
    }
    
    .font-size-label {
        display: none;
    }
    
    .language-selector {
        margin-left: 0;
    }
}

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

/* ============================================
   RESPONSIVE DESIGN
   ============================================ */

@media (max-width: 768px) {
    html {
        font-size: 14px;
    }
    
    h1 {
        font-size: var(--font-size-3xl);
    }
    
    h2 {
        font-size: var(--font-size-2xl);
    }
    
    h3 {
        font-size: var(--font-size-xl);
    }
    
    /* Larger touch targets on mobile */
    button,
    input,
    textarea,
    select {
        min-height: 48px;
        min-width: 48px;
    }
}

/* ============================================
   ANIMATION UTILITIES
   ============================================ */

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.fade-in {
    animation: fadeIn 0.6s ease-out;
}

.slide-in-up {
    animation: slideInUp 0.6s ease-out;
}

.pulse {
    animation: pulse 2s infinite;
}

/* Disable animations for users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
    .fade-in,
    .slide-in-up,
    .pulse {
        animation: none;
    }
}

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

/* Font Size Management System */
:root {
    /* Default font sizes */
    --base-font-size: 12px; /* Changed default to 12px as requested */
    --font-scale-factor: 1;
}

/* Default html element font size */
html {
    font-size: 12px; /* Default size when no font-size class is applied */
}

/* Font size scaling using root HTML element for better inheritance */
html.font-size-small {
    font-size: 10px; /* Small size */
}

html.font-size-normal {
    font-size: 12px; /* Default size */
}

html.font-size-large {
    font-size: 14px; /* Large size */
}

html.font-size-extra-large {
    font-size: 16px; /* Extra large size */
}

/* Ensure all text elements inherit and scale properly */
body {
    font-size: 1rem; /* Inherits from html element */
    line-height: 1.6;
    transition: font-size 0.3s ease;
}

/* Scale all text elements proportionally */
h1, h2, h3, h4, h5, h6,
p, span, div, a, li, td, th,
.card-title, .card-text, .btn,
.nav-link, .dropdown-item,
.form-control, .form-label,
.alert, .badge, .breadcrumb,
.pagination, .modal-body,
.tooltip, .popover {
    font-size: inherit !important;
}

/* Maintain proper heading hierarchy */
html.font-size-small h1 { font-size: 1.75rem !important; }
html.font-size-small h2 { font-size: 1.5rem !important; }
html.font-size-small h3 { font-size: 1.25rem !important; }
html.font-size-small h4 { font-size: 1.1rem !important; }
html.font-size-small h5 { font-size: 1rem !important; }
html.font-size-small h6 { font-size: 0.9rem !important; }

html.font-size-normal h1 { font-size: 2rem !important; }
html.font-size-normal h2 { font-size: 1.75rem !important; }
html.font-size-normal h3 { font-size: 1.5rem !important; }
html.font-size-normal h4 { font-size: 1.25rem !important; }
html.font-size-normal h5 { font-size: 1.1rem !important; }
html.font-size-normal h6 { font-size: 1rem !important; }

html.font-size-large h1 { font-size: 2.25rem !important; }
html.font-size-large h2 { font-size: 2rem !important; }
html.font-size-large h3 { font-size: 1.75rem !important; }
html.font-size-large h4 { font-size: 1.5rem !important; }
html.font-size-large h5 { font-size: 1.25rem !important; }
html.font-size-large h6 { font-size: 1.1rem !important; }

html.font-size-extra-large h1 { font-size: 2.5rem !important; }
html.font-size-extra-large h2 { font-size: 2.25rem !important; }
html.font-size-extra-large h3 { font-size: 2rem !important; }
html.font-size-extra-large h4 { font-size: 1.75rem !important; }
html.font-size-extra-large h5 { font-size: 1.5rem !important; }
html.font-size-extra-large h6 { font-size: 1.25rem !important; }

/* Ensure buttons and form elements are properly sized */
html.font-size-large .btn,
html.font-size-extra-large .btn {
    min-height: 44px;
    padding: 12px 20px;
}

html.font-size-large .form-control,
html.font-size-extra-large .form-control {
    min-height: 44px;
    padding: 12px 16px;
}

/* Small elements that should scale less */
.small, small,
.badge, .breadcrumb,
.text-muted {
    font-size: 0.875em !important;
}

/* Elements that should not scale */
.no-font-scale,
.font-size-ignore {
    font-size: 1rem !important;
}

/* Font size button styles */
.accessibility-tools .font-size-btn {
    position: relative;
    font-weight: 600;
    min-width: 36px;
    margin: 0 2px;
    transition: all 0.3s ease;
    font-size: 14px !important; /* Fixed size for buttons */
}

.accessibility-tools .font-size-btn:hover {
    background-color: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

.accessibility-tools .font-size-btn.active {
    background-color: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.8);
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.5);
}

.accessibility-tools .font-size-btn:focus {
    outline: 2px solid #ffffff;
    outline-offset: 2px;
}

.accessibility-tools .font-size-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Progressive enhancement for responsive design */
@media (min-width: 768px) {
    html.font-size-large .container,
    html.font-size-extra-large .container {
        max-width: 1200px;
        padding: 0 20px;
    }
    
    /* Adjust card spacing for larger fonts */
    html.font-size-large .card,
    html.font-size-extra-large .card {
        margin-bottom: 1.75rem;
    }
}

/* Ensure proper line spacing */
html.font-size-large,
html.font-size-extra-large {
    line-height: 1.7;
}

html.font-size-small {
    line-height: 1.5;
}

/* Screen reader only content for font size announcements */
.sr-only-font-announce {
    position: absolute;
    left: -10000px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}