/* ═══════════════════════════════════════════════════════════
   ACCESSIBILITY — Unified Settings Panel + TTS
   Mental health web accessibility (WCAG 2.1 compliant)
   ═══════════════════════════════════════════════════════════ */

/* ── Settings FAB (Removed - Integrated into Navbar) ── */
.settings-fab {
    display: none !important;
}

/* ── Settings Panel (Modern Popout) ─────────────────────── */
.settings-panel {
    position: fixed;
    top: 65px; /* Navbar height approximate */
    left: 20px;
    z-index: 99997;
    width: 320px;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(12px) saturate(180%);
    -webkit-backdrop-filter: blur(12px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 24px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0,0,0,0.02);
    padding: 0;
    opacity: 0;
    transform: translateY(-10px) scale(0.98);
    pointer-events: none;
    transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    overflow: hidden;
    font-family: 'Cairo', sans-serif;
}

/* Dark mode panel adjustment */
[data-theme="dark"] .settings-panel {
    background: rgba(26, 31, 26, 0.85);
    border-color: rgba(255, 255, 255, 0.1);
}

.settings-panel.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Dashboard override: when dashboard is active, panel should still be top-left */
.dashboard-active .settings-panel {
    top: 70px;
    left: 20px;
    bottom: auto;
}

@media (max-width: 768px) {
    .settings-panel {
        top: auto;
        bottom: 80px; /* Above bottom nav */
        left: 50%;
        transform: translate(-50%, 10px) scale(0.95);
        width: calc(100% - 40px);
        max-width: 350px;
    }
    .settings-panel.open {
        transform: translate(-50%, 0) scale(1);
    }
}

/* Panel header */
.settings-panel-header {
    padding: 20px 24px 16px;
    border-bottom: 1px solid rgba(0,0,0,0.06);
    display: flex;
    align-items: center;
    gap: 12px;
}

[data-theme="dark"] .settings-panel-header {
    border-color: rgba(255,255,255,0.08);
}

.settings-panel-header .header-icon {
    font-size: 1.4rem;
    filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1));
}

.settings-panel-header .header-title {
    font-size: 1.15rem;
    font-weight: 950;
    color: var(--lana-blue, #27ae60);
    letter-spacing: -0.01em;
}

/* Panel body */
.settings-panel-body {
    padding: 8px 12px 16px;
}

/* Setting Row */
.setting-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 14px;
    border-radius: 18px;
    transition: all 0.25s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    cursor: pointer;
    user-select: none;
    margin-bottom: 6px;
}

.setting-row:hover {
    background: rgba(39, 174, 96, 0.08);
    transform: translateX(6px);
}

[data-theme="dark"] .setting-row:hover {
    background: rgba(46, 204, 113, 0.1);
}

.setting-row-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.setting-row-icon {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    flex-shrink: 0;
}

.setting-row-icon.theme-icon {
    background: linear-gradient(135deg, #2ecc71, #27ae60);
    color: #fff;
    box-shadow: 0 4px 10px rgba(39, 174, 96, 0.3);
}

.setting-row-icon.tts-icon {
    background: linear-gradient(135deg, #3498db, #2980b9);
    color: #fff;
    box-shadow: 0 4px 10px rgba(52, 152, 219, 0.3);
}

.setting-row-icon.font-icon {
    background: linear-gradient(135deg, #f39c12, #d35400);
    color: #fff;
    box-shadow: 0 4px 10px rgba(243, 156, 18, 0.3);
}

.setting-row-text {
    display: flex;
    flex-direction: column;
}

.setting-row-label {
    font-size: 0.95rem;
    font-weight: 800;
    color: var(--text-body, #222);
    line-height: 1.2;
}

[data-theme="dark"] .setting-row-label {
    color: #eee;
}

.setting-row-desc {
    font-size: 0.75rem;
    color: var(--text-muted, #666);
    line-height: 1.3;
    margin-top: 3px;
}

[data-theme="dark"] .setting-row-desc {
    color: #aaa;
}

/* ── Select Dropdown (Popout Style) ─────────────────────── */
.settings-select-popout {
    background: rgba(255, 255, 255, 0.5);
    border: 1.5px solid rgba(0,0,0,0.1);
    border-radius: 10px;
    padding: 4px 8px;
    font-family: 'Cairo', sans-serif;
    font-weight: 700;
    font-size: 0.8rem;
    color: var(--text-body);
    cursor: pointer;
    outline: none;
    transition: all 0.3s ease;
    width: 80px;
    height: 32px;
    margin: 0 !important;
}

[data-theme="dark"] .settings-select-popout {
    background: rgba(0, 0, 0, 0.2);
    border-color: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.settings-select-popout:focus {
    border-color: var(--lana-blue);
    background: #fff;
}

[data-theme="dark"] .settings-select-popout:focus {
    background: #222;
}

/* ── Toggle Switch ──────────────────────────────────────── */
.toggle-switch {
    position: relative;
    width: 48px;
    height: 26px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0 !important;
    width: 0 !important;
    height: 0 !important;
    position: absolute !important;
    margin: 0 !important;
    padding: 0 !important;
    border: none !important;
    min-height: 0 !important;
    pointer-events: none;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: var(--border, #ccc);
    border-radius: 26px;
    transition: all 0.3s ease;
    border: none !important;
    height: 26px !important;
    width: 48px !important;
    padding: 0 !important;
    margin: 0 !important;
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #fff;
    bottom: 3px;
    left: 3px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--lana-blue, #27ae60);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(22px);
}

/* ── TTS Hover Highlight ── */
body.tts-active p:hover,
body.tts-active span:hover,
body.tts-active a:hover,
body.tts-active li:hover,
body.tts-active input:hover,
body.tts-active .settings-form-title:hover,
body.tts-active .settings-row-title:hover,
body.tts-active .setting-row-label:hover,
body.tts-active h1:hover, body.tts-active h2:hover, body.tts-active h3:hover,
body.tts-active h4:hover, body.tts-active h5:hover, body.tts-active h6:hover {
    outline: 2px dashed rgba(52, 152, 219, 0.45) !important;
    outline-offset: 3px;
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%233498db'%3E%3Cpath d='M11.53,2.53C11.82,2.24 12,1.83 12,1.41C12,0.59 11.38,0 10.59,0C10.17,0 9.76,0.18 9.47,0.47L2.47,7.47C2.18,7.76 2,8.17 2,8.59V14.59C2,15.38 2.62,16 3.41,16C3.83,16 4.24,15.82 4.53,15.53L11.53,8.53C11.82,8.24 12,7.83 12,7.41V2.53H11.53Z'/%3E%3C/svg%3E"), auto;
}

.tts-speaking-el {
    outline: 2.5px solid var(--lana-blue, #27ae60) !important;
    outline-offset: 4px;
    background: rgba(46, 204, 113, 0.08) !important;
    transition: all 0.3s ease;
    border-radius: 8px;
}

/* ── TTS Speaking Indicator ─────────────────────────────── */
.tts-indicator {
    position: fixed;
    bottom: 86px;
    left: 86px;
    z-index: 99996;
    background: linear-gradient(135deg, #2980b9, #3498db);
    color: #fff;
    padding: 8px 18px;
    border-radius: 30px;
    font-size: 0.82rem;
    font-family: 'Cairo', sans-serif;
    font-weight: 700;
    box-shadow: 0 4px 16px rgba(41, 128, 185, 0.4);
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.3s ease;
    pointer-events: none;
    display: flex;
    align-items: center;
    gap: 8px;
}

.tts-indicator.visible {
    opacity: 1;
    transform: translateY(0);
}

.tts-indicator .tts-wave {
    display: flex;
    gap: 2px;
    align-items: flex-end;
    height: 14px;
}

.tts-indicator .tts-wave span {
    width: 3px;
    background: #fff;
    border-radius: 2px;
    animation: ttsWave 0.8s ease-in-out infinite;
}

.tts-indicator .tts-wave span:nth-child(1) { height: 4px; animation-delay: 0s; }
.tts-indicator .tts-wave span:nth-child(2) { height: 8px; animation-delay: 0.15s; }
.tts-indicator .tts-wave span:nth-child(3) { height: 12px; animation-delay: 0.3s; }
.tts-indicator .tts-wave span:nth-child(4) { height: 6px; animation-delay: 0.45s; }

@keyframes ttsWave {
    0%, 100% { transform: scaleY(0.4); }
    50% { transform: scaleY(1); }
}

/* ── Skip to Main Content (keyboard nav) ────────────────── */
.skip-to-main {
    position: absolute;
    top: -100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--lana-blue, #27ae60);
    color: #fff;
    padding: 10px 24px;
    border-radius: 0 0 12px 12px;
    font-size: 1rem;
    z-index: 100000;
    transition: top 0.3s ease;
    text-decoration: none;
    font-family: 'Cairo', sans-serif;
}

.skip-to-main:focus {
    top: 0;
}

/* ── Focus styles for keyboard navigation ───────────────── */
*:focus-visible {
    outline: 3px solid var(--lana-blue, #27ae60) !important;
    outline-offset: 3px;
}

/* ── Hide old theme toggle when settings panel exists ───── */
.theme-toggle {
    display: none !important;
}

/* ── Reduced motion support ─────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .settings-fab,
    .settings-panel,
    .tts-indicator,
    .toggle-slider,
    .toggle-slider::before {
        transition: none !important;
    }

    .settings-fab:hover {
        transform: none;
    }

    .tts-indicator .tts-wave span {
        animation: none;
    }
}

/* ── Mobile adjustments ─────────────────────────────────── */
@media (max-width: 400px) {
    .settings-panel {
        left: 12px;
        right: 12px;
        width: auto;
    }

    .settings-fab {
        bottom: 16px;
        left: 16px;
        width: 46px;
        height: 46px;
        font-size: 1.3rem;
    }
}

/* ── Global keyboard focus visibility ───────────────────── */
a:focus-visible,
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
    outline: 3px solid #0f62fe;
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(15, 98, 254, 0.2);
    border-radius: 8px;
}

/* Improve muted text contrast for WCAG AA */
:root {
    --text-muted: #4f5d6b;
}

/* Onboarding role hint cards */
.onboarding-hints {
    margin: 1rem auto 1.5rem;
    max-width: 900px;
    text-align: right;
}

.onboarding-title {
    color: var(--lana-dark);
    font-weight: 800;
    margin-bottom: 0.75rem;
}

.onboarding-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 0.75rem;
}

.onboarding-card {
    border: 1px solid #d6e3ef;
    background: #fff;
    color: #1f2d3d;
    padding: 0.9rem;
    border-radius: 12px;
    opacity: 0.65;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.onboarding-card.active {
    opacity: 1;
    transform: translateY(-2px);
    border-color: #2f80ed;
}

/* Respect reduced-motion preference */
@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;
    }

    .helpyy-animate,
    .scroll-reveal,
    .hero-typewriter,
    .helpyy-badge-ping {
        animation: none !important;
        transition: none !important;
        transform: none !important;
    }
}
