/* =============================================
   GREENPURE CBD — Accessibility & Performance Fixes
   Focus states, contrast, screen reader optimizations
   ============================================= */

/* ──────────────────────────────────────
   1. FOCUS STATES - WCAG 2.1 AA
   ────────────────────────────────────── */
a:focus,
button:focus,
input:focus,
select:focus,
textarea:focus,
[tabindex]:focus {
    outline: 3px solid var(--color-secondary);
    outline-offset: 2px;
}

a:focus:not(:focus-visible),
button:focus:not(:focus-visible),
input:focus:not(:focus-visible),
[tabindex]:focus:not(:focus-visible) {
    outline: none;
}

a:focus-visible,
button:focus-visible,
input:focus-visible {
    outline: 3px solid var(--color-secondary);
    outline-offset: 2px;
}

/* Skip link for accessibility */
.skip-link {
    position: absolute;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--color-primary);
    color: #fff;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    z-index: 999999;
    font-weight: 600;
    text-decoration: none;
    transition: top 0.3s;
}

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

/* ──────────────────────────────────────
   2. IMPROVED CONTRAST RATIOS
   ────────────────────────────────────── */
:root {
    --color-text-light: #4B5563;
    --color-text-muted: #6B7280;
}

/* Ensure minimum contrast for links */
a {
    color: var(--color-primary);
    text-decoration: underline;
    text-underline-offset: 2px;
}

a:hover {
    color: var(--color-primary-dark);
}

/* ──────────────────────────────────────
   3. SCREEN READER ONLY CLASS
   ────────────────────────────────────── */
.sr-only,
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

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

/* ──────────────────────────────────────
   4. REDUCE MOTION
   ────────────────────────────────────── */
@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;
    }
}

/* ──────────────────────────────────────
   5. IMPROVED FORM LABELS
   ────────────────────────────────────── */
label {
    display: block;
    font-weight: 500;
    margin-bottom: 6px;
    color: var(--color-text);
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="search"],
input[type="password"],
input[type="number"],
textarea,
select {
    width: 100%;
    padding: 12px 16px;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: #fff;
    font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(45, 106, 79, 0.15);
}

/* Required field indicator */
.required::after {
    content: " *";
    color: #DC2626;
}

/* Error states */
input.has-error,
textarea.has-error,
select.has-error {
    border-color: #DC2626;
}

.error-message {
    color: #DC2626;
    font-size: 0.875rem;
    margin-top: 4px;
}

/* Success states */
input.has-success,
textarea.has-success,
select.has-success {
    border-color: #059669;
}

/* ──────────────────────────────────────
   6. IMPROVED BUTTON ACCESSIBILITY
   ────────────────────────────────────── */
.btn {
    position: relative;
    text-decoration: none !important;
}

.btn:disabled,
.btn.disabled {
    opacity: 0.6;
    cursor: not-allowed;
    pointer-events: none;
}

.btn--loading::after {
    content: "";
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.75s linear infinite;
    margin-left: 8px;
}

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

/* ──────────────────────────────────────
   7. IMPROVED MODAL / DIALOG
   ────────────────────────────────────── */
[role="dialog"] {
    z-index: 10000;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 9999;
}

/* ──────────────────────────────────────
   8. ARIA IMPROVEMENTS
   ────────────────────────────────────── */
[aria-live] {
    contain: layout style property;
}

[aria-hidden="true"] {
    display: none !important;
}

/* Make sure error messages are announced */
[aria-invalid="true"] {
    border-color: #DC2626;
}

[aria-describedby] {
    display: block;
}

/* ──────────────────────────────────────
   9. TABLE ACCESSIBILITY
   ────────────────────────────────────── */
table {
    border-collapse: collapse;
    width: 100%;
    margin-bottom: 1rem;
}

th {
    text-align: left;
    padding: 12px;
    background: var(--color-bg-soft);
    border-bottom: 2px solid var(--color-border);
    font-weight: 600;
}

td {
    padding: 12px;
    border-bottom: 1px solid var(--color-border);
}

caption {
    padding: 8px;
    text-align: left;
    font-weight: 600;
    caption-side: bottom;
    color: var(--color-text-muted);
}

/* ──────────────────────────────────────
   10. NAVIGATION IMPROVEMENTS
   ────────────────────────────────────── */
.site-nav__list a {
    text-decoration: none;
}

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

.current-menu-item > a {
    font-weight: 600;
    text-decoration: underline;
}

/* Mobile menu improvements */
.mobile-menu {
    touch-action: manipulation;
}

/* ──────────────────────────────────────
   11. AGE GATE ACCESSIBILITY
   ────────────────────────────────────── */
.age-gate {
    position: fixed;
    inset: 0;
    z-index: 99999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.age-gate[hidden] {
    display: none;
}

/* ──────────────────────────────────────
   12. LOADING STATES
   ────────────────────────────────────── */
.loading {
    position: relative;
    pointer-events: none;
}

.loading::after {
    content: "";
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
}

.skeleton {
    background: linear-gradient(90deg, var(--color-bg-soft) 25%, var(--color-bg) 50%, var(--color-bg-soft) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: var(--radius-sm);
}

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

/* ──────────────────────────────────────
   13. RESPONSIVE TABLE WRAPPER
   ────────────────────────────────────── */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table-responsive table {
    min-width: 600px;
}

/* ──────────────────────────────────────
   14. PREFERS COLOR SCHEME (DARK)
   ────────────────────────────────────── */
@media (prefers-color-scheme: dark) {
    :root {
        --color-bg: #0F1F17;
        --color-bg-soft: #1A2F24;
        --color-bg-green: #1B4332;
        --color-text: #F0F7F4;
        --color-text-muted: #9CA3AF;
        --color-border: #2D3F34;
    }
}
