/* ============================================
   AUDIO VISUALIZER - Flowing bars
   ============================================ */

/* AI Panel - fills height, input at bottom */
.firm-ai-panel {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Messages area - takes available space, scrolls when full */
.firm-ai-messages {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 16px;
}

/* Input area pinned at bottom */
.firm-ai-input-area {
    flex-shrink: 0;
}

/* Container - holds the flowing bars */
.firm-ai-visualizer {
    flex: 1;
    height: 48px;
    display: flex;
    align-items: center;
    overflow: hidden;
    position: relative;
    transition: box-shadow 0.1s ease;
}

/* Container glow when audio detected - controlled by JS */
.firm-ai-visualizer.recording {
    box-shadow: 0 0 calc(var(--audio-level, 0) * 20px) rgba(34, 197, 94, calc(var(--audio-level, 0) * 0.4));
}

/* Individual bar */
.viz-bar {
    position: absolute;
    right: 0;
    width: 2px;
    background: linear-gradient(to top, rgba(34, 197, 94, 0.5), rgba(74, 222, 128, 0.8));
    border-radius: 1px;
    animation: flowLeft linear forwards;
    will-change: transform;
}

/* The flow animation - bar spawns at right, flows left across container */
@keyframes flowLeft {
    from {
        transform: translateX(0);
    }
    to {
        transform: translateX(-220px);
    }
}

/* Recording indicator - removed, using dynamic glow now */

/* ============================================
   UPDATED INPUT BOX LAYOUT
   ============================================ */

/* Normal state - textarea above, controls below */
.firm-ai-input-box {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Dictation state - visualizer with controls on right */
.firm-ai-input-box.dictating {
    flex-direction: row;
    align-items: center;
}

.firm-ai-input {
    width: 100%;
    min-height: 60px;
    max-height: 200px;
    overflow-y: auto !important;
    resize: none;
    transition: height 0.15s ease;
    border-radius: 12px;
    padding: 12px;
    font-size: 14px;
    line-height: 1.4;
    box-sizing: border-box;
}

/* Allow textarea to expand */
.firm-ai-panel .firm-ai-input {
    height: auto;
}

/* Controls row - sits below textarea */
.firm-ai-input-controls {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

/* Dictate mode controls */
.firm-ai-dictate-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

/* Header actions */
.firm-ai-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.firm-ai-header-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.firm-ai-header-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    color: white;
}

/* Assistant selector dropdown */
.firm-ai-assistant-select {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    color: white;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 22px 4px 8px;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='rgba(255,255,255,0.7)' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 6px center;
    transition: all 0.15s ease;
}

.firm-ai-assistant-select:hover {
    border-color: rgba(255, 255, 255, 0.4);
    background-color: rgba(255, 255, 255, 0.1);
}

.firm-ai-assistant-select:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.5);
}

.firm-ai-assistant-select option {
    background: #1e293b;
    color: white;
}

/* Model selector button (cycles Haiku/Sonnet/Opus) */
.firm-ai-model-btn {
    width: 28px;
    height: 28px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    background: transparent;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.firm-ai-model-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

.firm-ai-model-btn.model-haiku {
    border-color: rgba(34, 197, 94, 0.5);
    color: #22c55e;
}

.firm-ai-model-btn.model-sonnet {
    border-color: rgba(59, 130, 246, 0.5);
    color: #3b82f6;
}

.firm-ai-model-btn.model-opus {
    border-color: rgba(168, 85, 247, 0.5);
    color: #a855f7;
}

/* Voice selector (testing) */
.firm-ai-voice-select {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.7);
    font-size: 11px;
    padding: 4px 20px 4px 8px;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='rgba(255,255,255,0.5)' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 6px center;
    transition: all 0.15s ease;
    margin-left: 6px;
}

.firm-ai-voice-select:hover {
    border-color: rgba(255, 255, 255, 0.3);
    color: white;
}

.firm-ai-voice-select:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.3);
    box-shadow: none;
}

.firm-ai-voice-select option {
    background: #1e293b;
    color: white;
    font-size: 12px;
    padding: 6px 8px;
}

.firm-ai-voice-select option:checked,
.firm-ai-voice-select option:hover {
    background: #334155 !important;
    background-color: #334155 !important;
    color: white;
}

.firm-ai-voice-select optgroup {
    background: #1e293b;
    color: rgba(255, 255, 255, 0.5);
    font-size: 11px;
    font-style: normal;
}

/* Model selector dropdown */
.firm-ai-model-select {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.7);
    font-size: 11px;
    padding: 4px 20px 4px 8px;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='rgba(255,255,255,0.5)' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 6px center;
    transition: all 0.15s ease;
}

.firm-ai-model-select:hover {
    border-color: rgba(255, 255, 255, 0.3);
    color: white;
}

.firm-ai-model-select:focus {
    outline: none;
    border-color: rgba(255, 255, 255, 0.3);
    box-shadow: none;
}

.firm-ai-model-select option {
    background: #1e293b;
    color: white;
    font-size: 12px;
    padding: 6px 8px;
}

.firm-ai-model-select option:checked,
.firm-ai-model-select option:hover {
    background: #334155 !important;
    background-color: #334155 !important;
    color: white;
}

.firm-ai-model-select optgroup {
    background: #1e293b;
    color: rgba(255, 255, 255, 0.5);
    font-size: 11px;
    font-style: normal;
}

/* Persona selector (testing) */
.firm-ai-persona-select {
    background: transparent;
    border: 1px solid rgba(139, 92, 246, 0.3);
    border-radius: 6px;
    color: rgba(167, 139, 250, 0.9);
    font-size: 11px;
    padding: 4px 20px 4px 8px;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='rgba(167,139,250,0.7)' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 6px center;
    transition: all 0.15s ease;
    margin-left: 6px;
}

.firm-ai-persona-select:hover {
    border-color: rgba(139, 92, 246, 0.5);
    color: #a78bfa;
}

.firm-ai-persona-select:focus {
    outline: none;
    border-color: rgba(139, 92, 246, 0.4);
    box-shadow: none;
}

.firm-ai-persona-select option {
    background: #1e293b;
    color: white;
    font-size: 12px;
    padding: 6px 8px;
}

.firm-ai-persona-select option:checked,
.firm-ai-persona-select option:hover {
    background: #334155 !important;
    background-color: #334155 !important;
    color: white;
}

/* Clear chat button */
.firm-ai-clear {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: rgba(148, 163, 184, 0.6);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
    margin-right: auto; /* Push to left */
}

.firm-ai-clear:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

/* Typing indicator - bouncing dots */
.firm-ai-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 0;
}

.firm-ai-typing span {
    width: 8px;
    height: 8px;
    background: rgba(255, 255, 255, 0.6);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.firm-ai-typing span:nth-child(1) {
    animation-delay: -0.32s;
}

.firm-ai-typing span:nth-child(2) {
    animation-delay: -0.16s;
}

.firm-ai-typing span:nth-child(3) {
    animation-delay: 0s;
}

@keyframes bounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Searching indicator - shows during web search */
.firm-ai-searching {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
    color: rgba(255, 255, 255, 0.8);
    font-size: 0.9em;
}

.firm-ai-searching i {
    font-size: 1.1em;
    color: #60a5fa; /* Light blue for globe */
}

.firm-ai-message.searching {
    background: rgba(96, 165, 250, 0.1); /* Subtle blue tint */
    border-left: 2px solid rgba(96, 165, 250, 0.4);
}

/* Static globe badge for messages from web search */
.firm-ai-search-badge {
    position: absolute;
    top: 6px;
    right: 6px;
    color: #60a5fa;
    font-size: 0.75em;
    opacity: 0.7;
}

.firm-ai-message.from-search {
    position: relative;
}

/* Streaming cursor - small and contained */
.firm-ai-cursor {
    display: inline;
    animation: blink 0.8s infinite;
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.85em;
    vertical-align: baseline;
    line-height: 1;
}

@keyframes blink {
    0%, 50% { opacity: 1; }
    51%, 100% { opacity: 0; }
}

/* Ensure message content stays contained */
.firm-ai-message-content {
    overflow-wrap: break-word;
    word-break: break-word;
    max-width: 100%;
    overflow: hidden;
}

/* Clickable assistant messages (click to stop speech) */
.firm-ai-message.assistant.clickable {
    cursor: pointer;
}

.firm-ai-message.assistant.clickable:hover {
    opacity: 0.9;
}

/* Cancel button (X) */
.firm-ai-dictate-cancel {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid #e2e8f0;
    background: white;
    color: #64748b;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.firm-ai-dictate-cancel:hover {
    border-color: #ef4444;
    color: #ef4444;
    background: #fef2f2;
}

/* Confirm button (tick) */
.firm-ai-dictate-done {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid #1e293b;
    background: white;
    color: #1e293b;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.firm-ai-dictate-done:hover {
    background: #1e293b;
    color: white;
}

/* Recording mic indicator (red pulse) */
.firm-ai-recording-indicator {
    width: 12px;
    height: 12px;
    background: #ef4444;
    border-radius: 50%;
    animation: recording-pulse 1.5s ease-in-out infinite;
    flex-shrink: 0;
}

@keyframes recording-pulse {
    0%, 100% { 
        opacity: 1; 
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
    }
    50% { 
        opacity: 0.8; 
        transform: scale(1.1);
        box-shadow: 0 0 0 8px rgba(239, 68, 68, 0);
    }
}
