/* NeoSpeech — speech UI primitives (mic & speaker buttons + wrappers) */

/* ── Input wrap ────────────────────────────────────────────────────────────── */
.neo-speech-input-wrap {
    position: relative;
    display: flex;
    align-items: stretch;
    flex: 1;
    min-width: 0;
}

.neo-speech-input-wrap input,
.neo-speech-input-wrap textarea {
    flex: 1;
    min-width: 0;
    padding-right: 40px !important; /* room for mic button */
}

/* ── Shared button base ────────────────────────────────────────────────────── */
.neo-speech-mic-btn,
.neo-speech-speaker-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    padding: 0;
    transition: background 0.15s, color 0.15s, opacity 0.15s, box-shadow 0.15s;
    line-height: 1;
    box-sizing: border-box;
}

/* ── Mic button (inside input) ───────────────────────────────────────────── */
.neo-speech-mic-btn {
    width: 32px;
    height: 32px;
    background: var(--accent, #2563eb);
    color: #fff;
    opacity: 0.75;
    border-radius: 50%;
}

.neo-speech-mic-btn:hover {
    opacity: 1;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.25);
}

.neo-speech-mic-btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* ── Mic positioned inside input wrap ─────────────────────────────────────── */
.neo-speech-input-wrap .neo-speech-mic-btn {
    position: absolute;
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
    z-index: 2;
}

/* ── Active / listening state ─────────────────────────────────────────────── */
.neo-speech-mic-btn--active {
    background: rgba(239, 68, 68, 0.12) !important;
    color: #ef4444 !important;
    opacity: 1 !important;
    box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.3) !important;
    animation: neo-speech-pulse 1.2s ease-in-out infinite;
}

@keyframes neo-speech-pulse {
    0%, 100% { transform: translateY(-50%) scale(1); }
    50%       { transform: translateY(-50%) scale(1.18); }
}

/* Reset pulse transform for mic buttons not inside a wrap */
.neo-speech-mic-btn.neo-speech-mic-btn--active:not(.neo-speech-input-wrap .neo-speech-mic-btn) {
    animation: neo-speech-pulse-plain 1.2s ease-in-out infinite;
}

@keyframes neo-speech-pulse-plain {
    0%, 100% { transform: scale(1); }
    50%       { transform: scale(1.18); }
}

/* ── State-specific coloring ───────────────────────────────────────────────── */
.neo-speech-mic-btn[data-speech-state="listening"] {
    background: rgba(239, 68, 68, 0.12) !important;
    color: #ef4444 !important;
    opacity: 1;
}

.neo-speech-mic-btn[data-speech-state="transcribing"],
.neo-speech-mic-btn[data-speech-state="stopping"] {
    background: rgba(37, 99, 235, 0.1);
    color: var(--accent, #2563eb);
    opacity: 0.9;
}

.neo-speech-mic-btn[data-speech-state="ready"] {
    background: rgba(34, 197, 94, 0.12);
    color: #16a34a;
    opacity: 1;
}

.neo-speech-mic-btn[data-speech-state="error"] {
    background: rgba(245, 158, 11, 0.12);
    color: #d97706;
    opacity: 1;
}

/* ── TTS Output bar ────────────────────────────────────────────────────────── */
/* The speaker toolbar sits above the output block */
.neo-speech-output-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 2px 0 6px;
}

/* ── Speaker button (in output bar) ──────────────────────────────────────── */
.neo-speech-speaker-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 28px;
    padding: 0 10px 0 8px;
    border-radius: 14px;
    background: var(--bg-elevated, rgba(0,0,0,0.05));
    color: var(--text-secondary, #6b7280);
    font-size: 12px;
    font-family: inherit;
    font-weight: 500;
    white-space: nowrap;
    border: 1px solid var(--border-color, rgba(0,0,0,0.08));
    opacity: 0.9;
}

.neo-speech-speaker-btn:hover {
    background: var(--bg-card, rgba(0,0,0,0.09));
    color: var(--text-primary, #111827);
    opacity: 1;
    box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.neo-speech-speaker-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.neo-speech-speaker-btn--active {
    background: rgba(37, 99, 235, 0.1) !important;
    color: var(--accent, #2563eb) !important;
    border-color: rgba(37, 99, 235, 0.25) !important;
    opacity: 1 !important;
    animation: neo-speech-speaker-pulse 1.4s ease-in-out infinite;
}

@keyframes neo-speech-speaker-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(37,99,235,0.2); }
    50%       { box-shadow: 0 0 0 4px rgba(37,99,235,0.12); }
}

.neo-speech-speaker-btn[data-speech-state="loading"] {
    color: var(--accent, #2563eb);
    opacity: 0.7;
    cursor: wait;
}

.neo-speech-speaker-btn[data-speech-state="playing"] {
    background: rgba(37, 99, 235, 0.1);
    color: var(--accent, #2563eb);
    border-color: rgba(37, 99, 235, 0.2);
}

.neo-speech-speaker-btn[data-speech-state="error"] {
    background: rgba(245, 158, 11, 0.1);
    color: #d97706;
    border-color: rgba(245, 158, 11, 0.2);
}

/* ── Inline error label ───────────────────────────────────────────────────── */
.neo-speech-error {
    display: none;
    font-size: 11px;
    color: #ef4444;
    margin-left: 4px;
    white-space: nowrap;
    vertical-align: middle;
}

/* ── Dark mode overrides ───────────────────────────────────────────────────── */
[data-theme="dark"] .neo-speech-mic-btn {
    background: rgba(255, 255, 255, 0.08);
    color: #9ca3af;
}

[data-theme="dark"] .neo-speech-mic-btn:hover {
    background: rgba(255, 255, 255, 0.14);
    color: #f3f4f6;
}

[data-theme="dark"] .neo-speech-speaker-btn {
    background: rgba(255, 255, 255, 0.06);
    color: #9ca3af;
    border-color: rgba(255,255,255,0.1);
}

[data-theme="dark"] .neo-speech-speaker-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    color: #f3f4f6;
}

/* ── NeoAgent panel specific ──────────────────────────────────────────────── */
.neo-agent-panel__input-area .neo-speech-input-wrap {
    flex: 1;
    min-width: 0;
}

.neo-agent-panel__input-area .neo-speech-mic-btn {
    position: absolute;
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
}

/* Active pulse inside wrapped input */
.neo-speech-input-wrap .neo-speech-mic-btn--active {
    animation: neo-speech-pulse 1.2s ease-in-out infinite;
}

/* ── Academy chat input ───────────────────────────────────────────────────── */
.chat-input-area .neo-speech-input-wrap {
    flex: 1;
    min-width: 0;
}

/* ── Catalog / home search wrap ───────────────────────────────────────────── */
.home-search-wrap .neo-speech-input-wrap,
.catalog-search-wrap .neo-speech-input-wrap {
    flex: 1;
    min-width: 0;
}

/* ── Tool chat composer ───────────────────────────────────────────────────── */
.chat-composer .neo-speech-input-wrap {
    flex: 1;
    min-width: 0;
    align-items: flex-end;
}

.chat-composer .neo-speech-input-wrap .neo-speech-mic-btn {
    top: auto;
    bottom: 8px;
    transform: none;
}

/* ── Pulsing mic recording ring (visible on all themes) ─────────────────── */
.neo-speech-mic-btn[data-speech-state="listening"]::before {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    border: 2px solid rgba(239, 68, 68, 0.5);
    animation: neo-speech-ring 1.2s ease-in-out infinite;
    pointer-events: none;
}

@keyframes neo-speech-ring {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: 0.4; transform: scale(1.3); }
}

/* ── Loading spinner for transcribing state ───────────────────────────────── */
.neo-speech-mic-btn[data-speech-state="transcribing"] svg,
.neo-speech-mic-btn[data-speech-state="stopping"] svg {
    animation: neo-speech-spin 1s linear infinite;
}

@keyframes neo-speech-spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}
