/* Voice UI Styles */

/* Global MRT Tap Highlight Reset */
[class^="mrt-"],
[class*=" mrt-"] {
    -webkit-tap-highlight-color: transparent;
}
:root {
    --mrt-fab-size: 60px;
    --mrt-fab-bottom: 30px;
    --mrt-fab-right: 30px;
    --mrt-fab-left: auto;
    --mrt-fab-top: auto;
}

/* Floating Action Button - Glassmorphism Effect */
.mrt-voice-fab {
    position: fixed;
    bottom: var(--mrt-fab-bottom);
    right: var(--mrt-fab-right);
    left: var(--mrt-fab-left);
    top: var(--mrt-fab-top);
    width: var(--mrt-fab-size);
    height: var(--mrt-fab-size);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    cursor: pointer;
    z-index: 9999;

    /* Glassmorphism - Light Mode */
    background: linear-gradient(
        135deg,
        rgba(37, 99, 235, 0.85) 0%,
        rgba(59, 130, 246, 0.75) 50%,
        rgba(96, 165, 250, 0.85) 100%
    );
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.35);
    box-shadow:
        0 8px 32px rgba(37, 99, 235, 0.35),
        0 4px 16px rgba(0, 0, 0, 0.15),
        inset 0 1px 2px rgba(255, 255, 255, 0.4),
        inset 0 -1px 2px rgba(0, 0, 0, 0.1);

    transition:
        transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
        background 0.3s ease,
        box-shadow 0.3s ease,
        border-color 0.3s ease;

    /* Prevent mobile tap highlight (ghost square on Chrome) */
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    touch-action: manipulation;

    /* Entrance animation with delay */
    opacity: 0;
    transform: scale(0);
    animation: fab-entrance 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) 0.8s forwards;
}

/* State label */
.mrt-voice-state-label {
    position: absolute;
    bottom: -20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: 10px;
    font-weight: 500;
    color: #6b7280;
    white-space: nowrap;
    opacity: 0.2;
    transition: opacity 0.25s;
    pointer-events: none;
}

.mrt-voice-fab:hover .mrt-voice-state-label {
    opacity: 0.35;
}

.mrt-voice-fab.is-listening .mrt-voice-state-label,
.mrt-voice-fab.is-thinking .mrt-voice-state-label,
.mrt-voice-fab.is-speaking .mrt-voice-state-label {
    opacity: 0.55;
}

.mrt-is-loading .mrt-voice-state-label,
.is-loading .mrt-voice-state-label,
.mrt-load-error .mrt-voice-state-label {
    display: none;
}

/* Subtle shimmer overlay for extra depth */
.mrt-voice-fab::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 50%;
    z-index: 0;
    background: linear-gradient(
        145deg,
        rgba(255, 255, 255, 0.25) 0%,
        rgba(255, 255, 255, 0.05) 40%,
        transparent 60%
    );
    pointer-events: none;
    transition: opacity 0.3s ease;
}

/* Entrance animation keyframes */
@keyframes fab-entrance {
    0% {
        opacity: 0;
        transform: scale(0);
    }
    100% {
        opacity: 1;
        transform: scale(1);
    }
}

.mrt-voice-fab:hover {
    background: linear-gradient(
        135deg,
        rgba(29, 78, 216, 0.9) 0%,
        rgba(37, 99, 235, 0.85) 50%,
        rgba(59, 130, 246, 0.9) 100%
    );
    transform: scale(1.08);
    box-shadow:
        0 12px 40px rgba(37, 99, 235, 0.45),
        0 6px 20px rgba(0, 0, 0, 0.2),
        inset 0 1px 3px rgba(255, 255, 255, 0.5),
        inset 0 -1px 2px rgba(0, 0, 0, 0.1);
    border-color: rgba(255, 255, 255, 0.45);
}

.mrt-voice-fab:active {
    transform: scale(0.95);
    box-shadow:
        0 4px 20px rgba(37, 99, 235, 0.3),
        0 2px 10px rgba(0, 0, 0, 0.15),
        inset 0 2px 4px rgba(0, 0, 0, 0.15);
}

/* Icon - Radical Reset to Fix Background Issues */
.mrt-voice-icon {
    all: unset; /* Strip all inherited styles */
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: 5;
    background: transparent;
    background-color: transparent;
    box-shadow: none;
    border: none;
    outline: none;
    padding: 0;
    margin: 0;
    /* Isolate from parent backdrop-filter effects */
    isolation: isolate;
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
    pointer-events: none; /* Click through to FAB if needed */
}

.mrt-voice-icon svg {
    all: unset;
    display: block;
    width: 24px;
    height: 24px;
    background: transparent;
    background-color: transparent;
    box-shadow: none;
    fill: none;
    stroke: currentColor;
}

/* Force transparency for any nested elements or global overrides */
.mrt-voice-fab .mrt-voice-icon,
.mrt-voice-fab .mrt-voice-icon svg,
.mrt-voice-fab .mrt-voice-icon *,
.mrt-voice-fab .mrt-voice-icon svg * {
    background: transparent;
    background-color: transparent;
    box-shadow: none;
}

/* Respect reduced motion preference for entrance animation */
@media (prefers-reduced-motion: reduce) {
    .mrt-voice-fab {
        opacity: 1;
        transform: scale(1);
        animation: none;
    }
}

/* Listening State (Pulse Animation) - Light Mode Glassmorphism */
.mrt-voice-fab.is-listening {
    background: linear-gradient(
        135deg,
        rgba(220, 38, 38, 0.9) 0%,
        rgba(239, 68, 68, 0.8) 50%,
        rgba(248, 113, 113, 0.85) 100%
    );
    border-color: rgba(255, 255, 255, 0.4);
    box-shadow:
        0 8px 32px rgba(220, 38, 38, 0.4),
        0 4px 16px rgba(0, 0, 0, 0.15),
        inset 0 1px 2px rgba(255, 255, 255, 0.3),
        inset 0 -1px 2px rgba(0, 0, 0, 0.1);
}

.mrt-voice-waves {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid rgba(220, 38, 38, 0.7);
    opacity: 0;
    z-index: -1;
}

.mrt-voice-fab.is-listening .mrt-voice-waves {
    animation: voice-pulse 1.5s infinite;
}

@keyframes voice-pulse {
    0% {
        transform: scale(1);
        opacity: 0.8;
    }
    100% {
        transform: scale(2);
        opacity: 0;
    }
}

/* Thinking State (Processing Animation) - Light Mode Glassmorphism */
.mrt-voice-fab.is-thinking {
    background: linear-gradient(
        135deg,
        rgba(124, 58, 237, 0.9) 0%,
        rgba(139, 92, 246, 0.8) 50%,
        rgba(167, 139, 250, 0.85) 100%
    );
    border-color: rgba(255, 255, 255, 0.4);
    box-shadow:
        0 8px 32px rgba(124, 58, 237, 0.4),
        0 4px 16px rgba(0, 0, 0, 0.15),
        inset 0 1px 2px rgba(255, 255, 255, 0.3),
        inset 0 -1px 2px rgba(0, 0, 0, 0.1);
}

.mrt-voice-thinking-dots {
    position: absolute;
    display: flex;
    gap: 4px;
    opacity: 0;
    pointer-events: none;
}

.mrt-voice-fab.is-thinking .mrt-voice-thinking-dots {
    opacity: 1;
}

.mrt-voice-fab.is-thinking .mrt-voice-icon {
    opacity: 0;
}

.mrt-voice-thinking-dots span {
    width: 6px;
    height: 6px;
    background-color: white;
    border-radius: 50%;
    animation: thinking-bounce 1.4s infinite ease-in-out both;
}

.mrt-voice-thinking-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.mrt-voice-thinking-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

.mrt-voice-thinking-dots span:nth-child(3) {
    animation-delay: 0s;
}

@keyframes thinking-bounce {
    0%,
    80%,
    100% {
        transform: scale(0.6);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Speaking State (Sound Bars Animation) - Light Mode Glassmorphism */
.mrt-voice-fab.is-speaking {
    background: linear-gradient(
        135deg,
        rgba(22, 163, 74, 0.9) 0%,
        rgba(34, 197, 94, 0.8) 50%,
        rgba(74, 222, 128, 0.85) 100%
    );
    border-color: rgba(255, 255, 255, 0.4);
    box-shadow:
        0 8px 32px rgba(22, 163, 74, 0.4),
        0 4px 16px rgba(0, 0, 0, 0.15),
        inset 0 1px 2px rgba(255, 255, 255, 0.3),
        inset 0 -1px 2px rgba(0, 0, 0, 0.1);
}

.mrt-voice-speaker-bars {
    position: absolute;
    display: flex;
    align-items: center;
    gap: 3px;
    height: 20px;
    opacity: 0;
    pointer-events: none;
}

.mrt-voice-fab.is-speaking .mrt-voice-speaker-bars {
    opacity: 1;
}

.mrt-voice-fab.is-speaking .mrt-voice-icon {
    opacity: 0;
}

.mrt-voice-speaker-bars span {
    width: 4px;
    background-color: white;
    border-radius: 2px;
    animation: speaker-wave 1s infinite ease-in-out;
}

.mrt-voice-speaker-bars span:nth-child(1) {
    height: 8px;
    animation-delay: 0s;
}

.mrt-voice-speaker-bars span:nth-child(2) {
    height: 14px;
    animation-delay: 0.15s;
}

.mrt-voice-speaker-bars span:nth-child(3) {
    height: 18px;
    animation-delay: 0.3s;
}

.mrt-voice-speaker-bars span:nth-child(4) {
    height: 12px;
    animation-delay: 0.45s;
}

@keyframes speaker-wave {
    0%,
    100% {
        transform: scaleY(0.5);
    }
    50% {
        transform: scaleY(1);
    }
}



/* ==========================================================================
   Voice-Triggered Card Highlight
   ========================================================================== */

/* Card highlight animation for voice search feedback */
.mrt-voice-highlight {
    animation: mrt-voice-pulse 0.5s ease-in-out 2;
    box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.6);
    transition: box-shadow 0.3s ease;
}

/* Pulse animation keyframes */
@keyframes mrt-voice-pulse {
    0%,
    100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.02);
    }
}

/* Respect reduced motion preference */
@media (prefers-reduced-motion: reduce) {
    .mrt-voice-highlight {
        animation: none;
        box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.6);
    }

}

/* ==========================================================================
   Mic Volume Popup — Gain Slider + VU Meter
   ========================================================================== */

.mrt-mic-volume-btn {
    display: none;
    position: fixed;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, 0.35);
    cursor: pointer;
    z-index: 9998;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.85) 0%, rgba(96, 165, 250, 0.85) 100%);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    box-shadow: 0 4px 16px rgba(37, 99, 235, 0.35), 0 2px 8px rgba(0, 0, 0, 0.15);
    color: white;
    font-size: 15px;
    font-weight: 700;
    line-height: 1;
    font-family: inherit;
    margin: 0;
    padding: 0;
    transition: transform 0.2s, opacity 0.25s;
}

/* Button inside FAB — follows FAB position dynamically */
.mrt-voice-fab .mrt-mic-volume-btn {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    margin-left: -14px;
    right: auto;
    top: auto;
    z-index: 1;
    transform: none;
}

/* Popup inside FAB — follows FAB position dynamically */
.mrt-voice-fab .mrt-mic-volume-popup {
    position: absolute;
    bottom: calc(100% + 44px);
    left: 50%;
    right: auto;
    top: auto;
    z-index: 1;
}

.mrt-mic-volume-btn:hover {
    transform: scale(1.12);
}

.mrt-mic-volume-btn:active {
    transform: scale(0.9);
}

.mrt-mic-volume-popup {
    position: fixed;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 7px;
    padding: 14px 4px 10px;
    border-radius: 16px;
    color: white;
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.93) 0%, rgba(96, 165, 250, 0.9) 100%);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow: 0 8px 32px rgba(37, 99, 235, 0.4), 0 4px 16px rgba(0, 0, 0, 0.15);
    transform: translate(-50%, 8px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
}

.mrt-mic-volume-popup.is-open {
    opacity: 1;
    transform: translate(-50%, 0);
    pointer-events: auto;
}

.mrt-mic-volume-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    opacity: 0.85;
}

.mrt-mic-volume-row {
    display: flex;
    align-items: center;
    gap: 4px;
    height: 140px;
}

.mrt-mic-volume-slider {
    -webkit-appearance: none;
    appearance: none;
    writing-mode: vertical-lr;
    direction: rtl;
    width: 20px;
    height: 130px;
    accent-color: white;
    cursor: pointer;
    padding: 0 !important;
    margin: 0 !important;
    border: none !important;
    box-sizing: border-box;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.mrt-mic-volume-slider::-webkit-slider-runnable-track {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    border: none;
}

.mrt-mic-volume-slider::-moz-range-track {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    background: transparent;
    border: none;
}

.mrt-mic-volume-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    border: 2px solid rgba(255, 255, 255, 0.5);
}

.mrt-mic-volume-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    border: none;
}

.mrt-mic-vu-meter {
    width: 8px;
    height: 130px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.mrt-mic-vu-fill {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 0;
    border-radius: 4px;
    background-color: #10B981;
}

.mrt-mic-volume-value {
    font-size: 12px;
    font-weight: 600;
    opacity: 0.9;
}

/* Dark mode */
html.maxreptracker-dark-mode-enabled .mrt-mic-volume-btn {
    border-color: rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35), 0 2px 8px rgba(0, 0, 0, 0.2);
}

html.maxreptracker-dark-mode-enabled .mrt-mic-volume-popup {
    background: linear-gradient(135deg, rgba(30, 30, 35, 0.95) 0%, rgba(45, 45, 55, 0.93) 100%);
    border-color: rgba(255, 255, 255, 0.12);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.25);
}

/* Visitor override — JS sets position:absolute via inline style */
.mrt-visitor-voice-inner .mrt-mic-volume-btn {
    right: auto;
    top: auto;
    bottom: auto;
    left: auto;
}
