/* ── Voice Input Plugin — Floating Panel ── */

#vi-panel {
    position: fixed;
    bottom: 100px;
    left: 28px;
    z-index: 99999;
    display: flex;
    flex-direction: column-reverse;
    align-items: flex-start;
    gap: 10px;
    pointer-events: none;
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

#vi-panel.vi-visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: all;
}

/* ── Mic button ── */
#vi-btn {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: none;
    background: #1e7e34;
    color: #fff;
    font-size: 26px;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.15s;
    outline-offset: 3px;
}

#vi-btn:hover  { background: #155724; transform: scale(1.08); }
#vi-btn:focus  { outline: 3px solid #ffc107; }

#vi-btn.vi-recording {
    background: #c82333;
    animation: vi-pulse 1.4s ease infinite;
}

@keyframes vi-pulse {
    0%   { box-shadow: 0 0 0 0   rgba(200, 35, 51, 0.65); }
    70%  { box-shadow: 0 0 0 18px rgba(200, 35, 51, 0);   }
    100% { box-shadow: 0 0 0 0   rgba(200, 35, 51, 0);    }
}

/* ── Status label ── */
#vi-status {
    background: rgba(30, 30, 30, 0.82);
    color: #fff;
    padding: 5px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-family: sans-serif;
    white-space: nowrap;
    display: none;
    pointer-events: none;
}

#vi-status.vi-visible { display: block; }

/* ── Interim transcript bubble ── */
#vi-interim {
    background: #fff;
    border: 2px solid #1e7e34;
    border-radius: 10px;
    padding: 8px 14px;
    max-width: 260px;
    font-size: 13px;
    font-family: sans-serif;
    color: #555;
    font-style: italic;
    line-height: 1.45;
    word-break: break-word;
    box-shadow: 0 2px 8px rgba(0,0,0,0.18);
    display: none;
    pointer-events: none;
}

#vi-interim.vi-visible { display: block; }

/* ── Tooltip on hover ── */
#vi-tooltip {
    background: rgba(30, 30, 30, 0.82);
    color: #fff;
    padding: 5px 12px;
    border-radius: 8px;
    font-size: 12px;
    font-family: sans-serif;
    white-space: nowrap;
    display: none;
    pointer-events: none;
    align-self: flex-start;
    margin-bottom: -4px;
}

#vi-panel.vi-visible:not(.vi-recording-active) #vi-tooltip { display: block; }

/* ── Accessibility: high-contrast support ── */
@media (forced-colors: active) {
    #vi-btn { border: 2px solid ButtonText; }
}

/* ── Navigation command button (always visible, bottom-left) ── */
#vi-nav-wrap {
    position: fixed;
    bottom: 28px;
    left: 28px;
    z-index: 99998;
    display: flex;
    flex-direction: column-reverse;
    align-items: flex-start;
    gap: 8px;
}

#vi-nav-btn {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: none;
    background: #0056b3;
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(0,0,0,0.30);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 1px;
    transition: background 0.2s, transform 0.15s;
    outline-offset: 3px;
}

#vi-nav-label {
    font-size: 8px;
    font-family: sans-serif;
    font-weight: bold;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    line-height: 1;
}

#vi-nav-btn:hover  { background: #003d82; transform: scale(1.08); }
#vi-nav-btn:focus  { outline: 3px solid #ffc107; }

#vi-nav-btn.vi-nav-on {
    background: #e67e00;
    animation: vi-pulse 1.4s ease infinite;
}

/* Visual cue when nav needs user interaction to reactivate (after page reload) */
#vi-nav-btn.vi-nav-pulse {
    animation: vi-pulse-need 1.2s ease infinite;
    border: 3px solid #ffc107;
}

@keyframes vi-pulse-need {
    0%   { box-shadow: 0 0 0 0   rgba(255, 193, 7, 0.75); }
    70%  { box-shadow: 0 0 0 18px rgba(255, 193, 7, 0);   }
    100% { box-shadow: 0 0 0 0   rgba(255, 193, 7, 0);    }
}

#vi-nav-feedback {
    background: rgba(30, 30, 30, 0.90);
    color: #fff;
    padding: 7px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-family: sans-serif;
    max-width: 260px;
    word-break: break-word;
    display: none;
    pointer-events: none;
    line-height: 1.4;
}

#vi-nav-feedback.vi-nav-ok  { border-left: 4px solid #28a745; }
#vi-nav-feedback.vi-nav-err { border-left: 4px solid #dc3545; }

/* ── Subtítulos automáticos (Whisper API transcription) ── */
#vi-captions {
    position: fixed;
    bottom: 95px;
    left: 50%;
    transform: translateX(-50%);
    max-width: 80%;
    min-width: 320px;
    background: rgba(0, 0, 0, 0.85);
    color: #fff;
    padding: 14px 22px;
    border-radius: 10px;
    font-family: sans-serif;
    font-size: 19px;
    font-weight: 500;
    line-height: 1.4;
    text-align: center;
    z-index: 99997;
    display: none;
    pointer-events: none;
    text-shadow: 0 2px 4px rgba(0,0,0,0.85);
    box-shadow: 0 4px 18px rgba(0,0,0,0.45);
    word-break: break-word;
}

#vi-captions.vi-captions-visible {
    display: block;
}

#vi-captions.vi-captions-loading::before {
    content: '⏳ ';
    opacity: 0.7;
}

/* ── Plugin's own modal (replaces window.prompt for API key entry) ── */
#vi-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 100000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: sans-serif;
}

#vi-modal {
    background: #fff;
    border-radius: 10px;
    padding: 24px;
    width: 460px;
    max-width: 90vw;
    box-shadow: 0 10px 40px rgba(0,0,0,0.4);
}

#vi-modal-title {
    font-size: 18px;
    font-weight: bold;
    margin-bottom: 10px;
    color: #222;
}

#vi-modal-text {
    font-size: 14px;
    color: #555;
    margin-bottom: 14px;
    line-height: 1.5;
}

#vi-modal-input {
    width: 100%;
    padding: 10px 12px;
    border: 2px solid #1e7e34;
    border-radius: 6px;
    font-size: 15px;
    font-family: monospace;
    box-sizing: border-box;
    outline: none;
}

#vi-modal-input:focus { border-color: #155724; }

#vi-modal-buttons {
    margin-top: 16px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

#vi-modal-buttons button {
    padding: 8px 18px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
}

#vi-modal-cancel {
    background: #e0e0e0;
    color: #333;
}

#vi-modal-ok {
    background: #1e7e34;
    color: #fff;
}

#vi-modal-ok:hover { background: #155724; }
#vi-modal-cancel:hover { background: #c8c8c8; }

/* ── Transcribe-videos toggle button (for deaf/mute students) ── */
#vi-transcribe-btn {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: 3px solid #fff;
    background: #555;
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(0,0,0,0.30);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 1px;
    transition: background 0.2s, transform 0.15s;
    outline-offset: 3px;
}

#vi-transcribe-btn:hover  { transform: scale(1.08); }
#vi-transcribe-btn:focus  { outline: 3px solid #ffc107; }

#vi-transcribe-btn .vi-tr-label {
    font-size: 7px;
    font-family: sans-serif;
    font-weight: bold;
    letter-spacing: 0.3px;
    text-transform: uppercase;
    line-height: 1;
}

/* When transcription is ON, button turns green and pulses */
#vi-transcribe-btn.vi-transcribe-on {
    background: #28a745;
    animation: vi-pulse-green 1.6s ease infinite;
}

@keyframes vi-pulse-green {
    0%   { box-shadow: 0 0 0 0   rgba(40, 167, 69, 0.6); }
    70%  { box-shadow: 0 0 0 14px rgba(40, 167, 69, 0);  }
    100% { box-shadow: 0 0 0 0   rgba(40, 167, 69, 0);   }
}

/* ── Unified Accessibility Panel — groups all a11y tools in one place ── */
#vi-a11y-panel {
    position: fixed;
    bottom: 18px;
    left: 18px;
    background: rgba(255, 255, 255, 0.97);
    border: 3px solid #1e7e34;
    border-radius: 14px;
    padding: 8px 10px 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.30);
    z-index: 99996;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 9px;
    font-family: sans-serif;
    max-width: 95px;
    transition: padding 0.2s ease, max-width 0.2s ease, background 0.2s ease;
}

/* ── COLLAPSED state — only the toggle icon shows, takes minimal space ── */
#vi-a11y-panel.vi-a11y-collapsed {
    padding: 0;
    max-width: 78px;
    min-width: auto;
    background: transparent;
    border-color: transparent;
    box-shadow: none;
    gap: 0;
}

#vi-a11y-panel.vi-a11y-collapsed > *:not(#vi-a11y-toggle) {
    display: none !important;
}

/* The expand/collapse toggle button (♿) — BIG and prominent for visibility */
#vi-a11y-toggle {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    border: 4px solid #1e7e34;
    background: #fff;
    color: #1e7e34;
    cursor: pointer;
    font-size: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.15s;
    box-shadow: 0 6px 20px rgba(0,0,0,0.30);
    outline-offset: 4px;
    line-height: 1;
}

#vi-a11y-toggle:hover { background: #e8f5e9; transform: scale(1.08); }
#vi-a11y-toggle:focus { outline: 4px solid #ffc107; }

/* Subtle pulse when collapsed to draw attention */
#vi-a11y-panel.vi-a11y-collapsed #vi-a11y-toggle {
    animation: vi-a11y-icon-pulse 3s ease infinite;
}

@keyframes vi-a11y-icon-pulse {
    0%, 100% { box-shadow: 0 6px 20px rgba(0,0,0,0.30), 0 0 0 0 rgba(30,126,52,0.5); }
    50%      { box-shadow: 0 6px 20px rgba(0,0,0,0.30), 0 0 0 12px rgba(30,126,52,0); }
}

/* When expanded, the toggle becomes a small X in the corner */
#vi-a11y-panel:not(.vi-a11y-collapsed) #vi-a11y-toggle {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 22px;
    height: 22px;
    font-size: 13px;
    background: #fff;
    border-color: #aaa;
    color: #555;
    box-shadow: none;
}

#vi-a11y-panel:not(.vi-a11y-collapsed) #vi-a11y-toggle:hover {
    background: #f0f0f0;
    border-color: #1e7e34;
}

#vi-a11y-title {
    font-size: 9px;
    font-weight: 800;
    color: #155724;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    text-align: center;
    width: 100%;
    padding-bottom: 5px;
    border-bottom: 2px solid #1e7e34;
    margin-bottom: 2px;
    line-height: 1.2;
}

/* Override absolute positioning for elements moved inside the panel */
#vi-a11y-panel #vi-nav-wrap {
    position: relative;
    bottom: auto;
    left: auto;
    gap: 9px;
}

/* Microphone shortcut button (for students who can speak — focuses text + dictates) */
#vi-mic-shortcut {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: 3px solid #fff;
    background: #1e7e34;
    color: #fff;
    cursor: pointer;
    font-size: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 1px;
    transition: background 0.2s, transform 0.15s;
    outline-offset: 3px;
    box-shadow: 0 4px 14px rgba(0,0,0,0.30);
}

#vi-mic-shortcut:hover { background: #155724; transform: scale(1.08); }
#vi-mic-shortcut:focus { outline: 3px solid #ffc107; }

#vi-mic-shortcut .vi-a11y-label,
#vi-read-shortcut .vi-a11y-label {
    font-size: 7px;
    font-weight: bold;
    letter-spacing: 0.3px;
    text-transform: uppercase;
    line-height: 1;
}

/* Read aloud shortcut button (TTS — for low vision / reading difficulties) */
#vi-read-shortcut {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: 3px solid #fff;
    background: #6f42c1;  /* purple — distinct from green (mic) and orange (nav) */
    color: #fff;
    cursor: pointer;
    font-size: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 1px;
    transition: background 0.2s, transform 0.15s;
    outline-offset: 3px;
    box-shadow: 0 4px 14px rgba(0,0,0,0.30);
}

#vi-read-shortcut:hover { background: #5a32a0; transform: scale(1.08); }
#vi-read-shortcut:focus { outline: 3px solid #ffc107; }

/* Help button */
#vi-a11y-help {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid #1e7e34;
    background: #fff;
    color: #1e7e34;
    font-weight: bold;
    font-size: 18px;
    cursor: pointer;
    transition: background 0.2s;
}

#vi-a11y-help:hover  { background: #e8f5e9; }
#vi-a11y-help:focus  { outline: 3px solid #ffc107; }

/* Welcome highlight pulse when student arrives */
#vi-a11y-panel.vi-a11y-welcome {
    animation: vi-a11y-welcome-pulse 1.5s ease 3;
}

@keyframes vi-a11y-welcome-pulse {
    0%, 100% { box-shadow: 0 8px 32px rgba(0,0,0,0.30), 0 0 0 0 rgba(30,126,52,0.6); }
    50%      { box-shadow: 0 8px 32px rgba(0,0,0,0.30), 0 0 0 18px rgba(30,126,52,0); }
}

/* Help modal */
#vi-a11y-help-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 100001;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: sans-serif;
}

.vi-help-content {
    background: #fff;
    padding: 26px 30px;
    border-radius: 14px;
    max-width: 540px;
    width: 92vw;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 12px 40px rgba(0,0,0,0.40);
}

.vi-help-content h2 {
    margin: 0 0 14px;
    color: #155724;
    font-size: 22px;
    text-align: center;
}

.vi-help-content p {
    line-height: 1.5;
    color: #333;
    margin: 8px 0;
}

.vi-help-content ul {
    list-style: none;
    padding: 0;
    margin: 14px 0;
}

.vi-help-content li {
    margin-bottom: 10px;
    line-height: 1.5;
    padding: 10px 12px;
    border-left: 4px solid #1e7e34;
    background: #f8f9fa;
    border-radius: 4px;
    color: #333;
}

.vi-help-content li strong { color: #155724; }
.vi-help-content li em     { color: #666; font-size: 0.92em; }

.vi-help-content kbd {
    background: #f0f0f0;
    border: 1px solid #aaa;
    border-radius: 3px;
    padding: 1px 6px;
    font-family: monospace;
    font-size: 0.9em;
}

#vi-help-close {
    margin-top: 16px;
    background: #1e7e34;
    color: #fff;
    border: none;
    padding: 11px 30px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 700;
    display: block;
    margin-left: auto;
    margin-right: auto;
}

#vi-help-close:hover { background: #155724; }

/* ── Mobile / Tablet responsive ── */
@media (max-width: 768px) {
    #vi-a11y-panel {
        bottom: 12px;
        left: 12px;
        padding: 6px 8px 10px;
        max-width: 76px;
        gap: 7px;
    }
    #vi-a11y-toggle {
        width: 60px;
        height: 60px;
        font-size: 34px;
        border-width: 3px;
    }
    #vi-a11y-panel:not(.vi-a11y-collapsed) #vi-a11y-toggle {
        width: 24px;
        height: 24px;
        font-size: 14px;
    }
    #vi-a11y-panel.vi-a11y-collapsed {
        max-width: 66px;
    }
    #vi-mic-shortcut, #vi-read-shortcut, #vi-btn, #vi-nav-btn, #vi-transcribe-btn {
        width: 50px;
        height: 50px;
        font-size: 18px;
    }
    #vi-nav-label, #vi-mic-shortcut .vi-a11y-label, #vi-read-shortcut .vi-a11y-label, #vi-transcribe-btn span:not([aria-hidden="true"]) {
        font-size: 6px !important;
    }
    #vi-a11y-help {
        width: 28px;
        height: 28px;
        font-size: 14px;
    }
    #vi-a11y-title {
        font-size: 8px;
        padding-bottom: 4px;
    }
    #vi-captions {
        font-size: 16px;
        padding: 10px 14px;
        bottom: 12px;
        max-width: calc(100vw - 100px);
    }
    .vi-help-content {
        padding: 20px 18px;
        max-height: 75vh;
    }
    .vi-help-content h2 { font-size: 18px; }
    .vi-help-content li { font-size: 14px; }
}

/* Touch-friendly: bigger tap targets on phones */
@media (max-width: 480px) {
    #vi-a11y-toggle {
        width: 64px;
        height: 64px;
    }
    #vi-captions {
        font-size: 15px;
        bottom: 100px; /* clear of phone nav bar */
    }
}
