/* ==========================================================================
   LexicoWeb - WCAG 2.1 AA Compliant Stylesheet with Dark Mode
   ========================================================================== */

/* CSS Custom Properties for theming */
:root {
    /* Light mode colors - WCAG AA compliant (4.5:1 contrast ratio) */
    --color-bg-primary: #ffffff;
    --color-bg-secondary: #f8fafc;
    --color-bg-tertiary: #f1f5f9;
    --color-text-primary: #1e293b;
    --color-text-secondary: #475569;
    --color-text-muted: #64748b;
    --color-border: #cbd5e1;
    --color-accent: #1e40af;
    --color-accent-hover: #1e3a8a;
    --color-accent-light: #dbeafe;
    --color-success: #166534;
    --color-error: #b91c1c;
    --color-warning: #a16207;
    --color-header-bg: #1e3a8a;
    --color-header-text: #ffffff;
    --color-footer-bg: #1e293b;
    --color-footer-text: #f1f5f9;
    --color-focus: #2563eb;
    --color-link: #1d4ed8;
    --color-link-visited: #6d28d9;
}

/* Dark mode colors */
[data-theme="dark"] {
    --color-bg-primary: #0f172a;
    --color-bg-secondary: #1e293b;
    --color-bg-tertiary: #334155;
    --color-text-primary: #f1f5f9;
    --color-text-secondary: #cbd5e1;
    --color-text-muted: #94a3b8;
    --color-border: #475569;
    --color-accent: #60a5fa;
    --color-accent-hover: #93c5fd;
    --color-accent-light: #1e3a5f;
    --color-success: #4ade80;
    --color-error: #f87171;
    --color-warning: #fbbf24;
    --color-header-bg: #1e293b;
    --color-header-text: #f1f5f9;
    --color-footer-bg: #0f172a;
    --color-footer-text: #cbd5e1;
    --color-focus: #60a5fa;
    --color-link: #93c5fd;
    --color-link-visited: #c4b5fd;
}

/* System preference detection */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --color-bg-primary: #0f172a;
        --color-bg-secondary: #1e293b;
        --color-bg-tertiary: #334155;
        --color-text-primary: #f1f5f9;
        --color-text-secondary: #cbd5e1;
        --color-text-muted: #94a3b8;
        --color-border: #475569;
        --color-accent: #60a5fa;
        --color-accent-hover: #93c5fd;
        --color-accent-light: #1e3a5f;
        --color-success: #4ade80;
        --color-error: #f87171;
        --color-warning: #fbbf24;
        --color-header-bg: #1e293b;
        --color-header-text: #f1f5f9;
        --color-footer-bg: #0f172a;
        --color-footer-text: #cbd5e1;
        --color-focus: #60a5fa;
        --color-link: #93c5fd;
        --color-link-visited: #c4b5fd;
    }
}

/* ==========================================================================
   Base Styles - WCAG compliant
   ========================================================================== */

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

html {
    line-height: 1.5;
    font-size: 100%; /* Respect user font size preferences */
    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;
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--color-bg-secondary);
    color: var(--color-text-primary);
    transition: background-color 0.2s ease, color 0.2s ease;
}

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

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

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

/* Skip link - WCAG 2.4.1 */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    background: var(--color-accent);
    color: #fff;
    padding: 0.5rem 1rem;
    z-index: 100;
    text-decoration: none;
    font-weight: 600;
}

.skip-link:focus {
    top: 0;
}

/* Links - WCAG 1.4.1 */
a {
    color: var(--color-link);
    text-decoration: underline;
}

a:visited {
    color: var(--color-link-visited);
}

a:hover, a:focus {
    text-decoration: none;
}

/* ==========================================================================
   Layout utilities
   ========================================================================== */

.min-h-screen { min-height: 100vh; }
.container { width: 100%; max-width: 1280px; margin: 0 auto; }
.mx-auto { margin-left: auto; margin-right: auto; }
.max-w-md { max-width: 28rem; }
.max-w-4xl { max-width: 56rem; }
.max-w-6xl { max-width: 72rem; }

/* Spacing */
.px-3 { padding-left: 0.75rem; padding-right: 0.75rem; }
.px-4 { padding-left: 1rem; padding-right: 1rem; }
.px-6 { padding-left: 1.5rem; padding-right: 1.5rem; }
.px-8 { padding-left: 2rem; padding-right: 2rem; }
.py-2 { padding-top: 0.5rem; padding-bottom: 0.5rem; }
.py-3 { padding-top: 0.75rem; padding-bottom: 0.75rem; }
.py-4 { padding-top: 1rem; padding-bottom: 1rem; }
.py-8 { padding-top: 2rem; padding-bottom: 2rem; }
.py-16 { padding-top: 4rem; padding-bottom: 4rem; }
.p-4 { padding: 1rem; }
.p-6 { padding: 1.5rem; }
.p-8 { padding: 2rem; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.mb-8 { margin-bottom: 2rem; }
.mt-4 { margin-top: 1rem; }
.mt-6 { margin-top: 1.5rem; }
.mt-8 { margin-top: 2rem; }
.mt-16 { margin-top: 4rem; }
.mt-auto { margin-top: auto; }
.mr-2 { margin-right: 0.5rem; }
.mr-4 { margin-right: 1rem; }
.my-4 { margin-top: 1rem; margin-bottom: 1rem; }
.space-x-4 > * + * { margin-left: 1rem; }
.space-y-2 > * + * { margin-top: 0.5rem; }
.space-y-4 > * + * { margin-top: 1rem; }
.gap-6 { gap: 1.5rem; }
.gap-8 { gap: 2rem; }

/* Flexbox */
.flex { display: flex; }
.flex-1 { flex: 1 1 0%; }
.inline { display: inline; }
.inline-block { display: inline-block; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.items-center { align-items: center; }
.flex-col { flex-direction: column; }

/* Grid */
.grid { display: grid; }
.grid-cols-1 { grid-template-columns: repeat(1, 1fr); }

@media (min-width: 768px) {
    .md\:grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
    .md\:grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
    .md\:grid-cols-4 { grid-template-columns: repeat(4, 1fr); }
}

/* ==========================================================================
   Typography - WCAG 1.4.3, 1.4.4, 1.4.12
   ========================================================================== */

.text-sm { font-size: 0.875rem; line-height: 1.5; }
.text-base { font-size: 1rem; line-height: 1.5; }
.text-lg { font-size: 1.125rem; line-height: 1.5; }
.text-xl { font-size: 1.25rem; line-height: 1.4; }
.text-2xl { font-size: 1.5rem; line-height: 1.3; }
.text-3xl { font-size: 1.875rem; line-height: 1.2; }
.text-4xl { font-size: 2.25rem; line-height: 1.2; }
.text-5xl { font-size: 3rem; line-height: 1.1; }
.font-medium { font-weight: 500; }
.font-semibold { font-weight: 600; }
.font-bold { font-weight: 700; }
.text-center { text-align: center; }
.leading-relaxed { line-height: 1.625; }

/* ==========================================================================
   Colors - Using CSS variables for theme support
   ========================================================================== */

.bg-white { background-color: var(--color-bg-primary); }
.bg-gray-50 { background-color: var(--color-bg-secondary); }
.bg-gray-100 { background-color: var(--color-bg-tertiary); }
.bg-gray-800 { background-color: var(--color-footer-bg); }
.bg-blue-600 { background-color: var(--color-accent); }
.bg-blue-900 { background-color: var(--color-header-bg); }
.bg-green-600 { background-color: #16a34a; }
.bg-green-800 { background-color: #166534; }

.text-white { color: #ffffff; }
.text-gray-300 { color: var(--color-text-muted); }
.text-gray-500 { color: var(--color-text-muted); }
.text-gray-600 { color: var(--color-text-secondary); }
.text-gray-700 { color: var(--color-text-primary); }
.text-gray-900 { color: var(--color-text-primary); }
.text-blue-600 { color: var(--color-accent); }
.text-blue-900 { color: var(--color-accent); }
.text-green-600 { color: var(--color-success); }
.text-purple-600 { color: #9333ea; }
.text-orange-600 { color: var(--color-warning); }
.text-red-600 { color: var(--color-error); }

/* ==========================================================================
   Components
   ========================================================================== */

.rounded { border-radius: 0.25rem; }
.rounded-lg { border-radius: 0.5rem; }
.shadow { box-shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06); }
.shadow-lg { box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05); }
.border { border: 1px solid var(--color-border); }
.border-gray-300 { border-color: var(--color-border); }
.border-blue-700 { border-color: var(--color-accent); }
.border-green-600 { border-color: #16a34a; }
.border-green-700 { border-color: #15803d; }

/* Interactive states */
.hover\:underline:hover { text-decoration: underline; }
.hover\:bg-gray-100:hover { background-color: var(--color-bg-tertiary); }
.hover\:bg-blue-700:hover { background-color: var(--color-accent-hover); }
.hover\:bg-blue-800:hover { background-color: #1e40af; }
.hover\:bg-green-700:hover { background-color: #15803d; }
.hover\:shadow-lg:hover { box-shadow: 0 10px 15px -3px rgba(0,0,0,0.1); }
.transition { transition: all 0.2s ease; }

/* Buttons - WCAG compliant */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    font-weight: 500;
    border-radius: 0.375rem;
    text-decoration: none;
    cursor: pointer;
    border: none;
    transition: background-color 0.2s, box-shadow 0.2s;
}

.btn:focus {
    outline: 3px solid var(--color-focus);
    outline-offset: 2px;
}

.btn-primary {
    background-color: var(--color-accent);
    color: #ffffff;
}

.btn-primary:hover {
    background-color: var(--color-accent-hover);
}

/* Forms - WCAG 1.3.1, 1.4.3, 3.3.2 */
.form-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text-primary);
    margin-bottom: 0.25rem;
}

.form-input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--color-border);
    border-radius: 0.375rem;
    background-color: var(--color-bg-primary);
    color: var(--color-text-primary);
    font-size: 1rem;
    line-height: 1.5;
}

.form-input:focus {
    outline: none;
    border-color: var(--color-focus);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.form-input::placeholder {
    color: var(--color-text-muted);
}

/* Cards */
.card {
    background-color: var(--color-bg-primary);
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    padding: 1.5rem;
}

/* ==========================================================================
   Dark mode toggle button
   ========================================================================== */

.theme-toggle {
    background: transparent;
    border: none;
    padding: 0.5rem;
    cursor: pointer;
    color: inherit;
    border-radius: 0.375rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.theme-toggle:hover {
    background-color: rgba(255,255,255,0.1);
}

.theme-toggle svg {
    width: 1.25rem;
    height: 1.25rem;
}

.theme-toggle .sun-icon { display: none; }
.theme-toggle .moon-icon { display: block; }

[data-theme="dark"] .theme-toggle .sun-icon { display: block; }
[data-theme="dark"] .theme-toggle .moon-icon { display: none; }

/* ==========================================================================
   Header & Navigation
   ========================================================================== */

.site-header {
    background-color: var(--color-header-bg);
    color: var(--color-header-text);
}

.site-header a {
    color: var(--color-header-text);
    text-decoration: none;
}

.site-header a:hover {
    text-decoration: underline;
}

.nav-link {
    padding: 0.5rem 0.75rem;
    border-radius: 0.375rem;
}

.nav-link:focus {
    outline: 2px solid #ffffff;
    outline-offset: 2px;
}

/* ==========================================================================
   Footer
   ========================================================================== */

.site-footer {
    background-color: var(--color-footer-bg);
    color: var(--color-footer-text);
}

/* ==========================================================================
   Sidebar (Admin/Dashboard layouts)
   ========================================================================== */

.sidebar {
    background-color: var(--color-header-bg);
    color: var(--color-header-text);
    min-height: 100vh;
    width: 16rem;
    padding: 1rem;
}

.sidebar a {
    display: block;
    padding: 0.5rem 1rem;
    border-radius: 0.375rem;
    color: var(--color-header-text);
    text-decoration: none;
    margin-bottom: 0.25rem;
}

.sidebar a:hover {
    background-color: rgba(255,255,255,0.1);
}

.sidebar a:focus {
    outline: 2px solid #ffffff;
    outline-offset: -2px;
}

.sidebar hr {
    border: none;
    border-top: 1px solid rgba(255,255,255,0.2);
    margin: 1rem 0;
}

/* ==========================================================================
   Accessibility utilities
   ========================================================================== */

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

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --color-border: #000000;
    }

    .btn, .form-input, .card {
        border: 2px solid currentColor;
    }
}

/* Ensure text resizes properly */
@media (min-width: 640px) {
    html {
        font-size: 100%;
    }
}

/* Print styles */
@media print {
    .site-header, .site-footer, .sidebar, .theme-toggle, .skip-link {
        display: none !important;
    }

    body {
        background: white;
        color: black;
    }

    a {
        text-decoration: underline;
        color: black;
    }
}

/* Width utilities */
.w-full { width: 100%; }
.w-64 { width: 16rem; }
