:root {
    --primary: #a855f7;
    --primary-dark: #9333ea;
    --primary-light: #c084fc;
    --bg-dark: #0a1628;
    --bg-card: #0f1f3a;
    --bg-input: #162544;
    --bg-hover: #1e3a5f;
    --text-primary: #ffffff;
    --text-secondary: #8ba3c7;
    --border-color: #1e3a5f;
    --border-focus: #a855f7;
    --success: #22c55e;
    --warning: #f59e0b;
    --error: #ef4444;
    --accent-gradient: linear-gradient(135deg, #a855f7 0%, #6366f1 100%);
}

[data-theme="light"] {
    --bg-dark: #f0f4f8;
    --bg-card: #ffffff;
    --bg-input: #e8eef4;
    --bg-hover: #dce4ec;
    --text-primary: #1a202c;
    --text-secondary: #4a5568;
    --border-color: #cbd5e0;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-dark);
    color: var(--text-primary);
    height: 100%;
    font-size: 16px;
    overflow: hidden;
}

#app { 
    display: flex; 
    flex-direction: column; 
    height: 100vh;
    overflow: hidden;
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.header-icon {
    flex-shrink: 0;
    border-radius: 6px;
}

.header-controls { display: flex; align-items: center; gap: 0.75rem; }

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    transition: all 0.3s ease;
}

.icon-btn:hover { background: var(--bg-input); color: var(--text-primary); }
.settings-btn:hover { transform: rotate(45deg); }
.login-btn.authenticated { color: var(--gold); }
.login-btn.authenticated::after { content:''; position:absolute; bottom:4px; right:4px; width:8px; height:8px; border-radius:50%; background:#22c55e; border:2px solid var(--bg-primary); }
.mute-btn.muted { color: #ef4444; background: rgba(239,68,68,0.1); border-radius: 50%; }
.mic-mute-btn.muted { color: #ef4444; background: rgba(239,68,68,0.1); border-radius: 50%; }

.theme-toggle {
    width: 50px; height: 26px;
    background: var(--bg-input);
    border-radius: 13px;
    cursor: pointer;
    border: 2px solid var(--border-color);
    position: relative;
}

.theme-toggle::before {
    content: '🌙';
    position: absolute;
    left: 4px; top: 50%;
    transform: translateY(-50%);
    font-size: 12px;
}

.theme-toggle::after {
    content: '';
    position: absolute;
    right: 4px; top: 50%;
    transform: translateY(-50%);
    width: 18px; height: 18px;
    background: var(--accent-gradient);
    border-radius: 50%;
    transition: all 0.3s ease;
}

[data-theme="light"] .theme-toggle::before { content: '☀️'; left: auto; right: 4px; }
[data-theme="light"] .theme-toggle::after { right: auto; left: 4px; }

/* Settings overlay (dimmed background) */
.settings-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.4s cubic-bezier(0.4, 0, 0.2, 1), visibility 0.4s;
}

.settings-overlay.open {
    opacity: 1;
    visibility: visible;
}

.settings-panel {
    position: fixed;
    top: 0; right: 0;
    width: 520px; max-width: 100%; height: 100vh;
    background: var(--bg-card);
    border-left: 1px solid var(--border-color);
    z-index: 1000;
    transform: translateX(100%);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    box-shadow: -10px 0 40px rgba(0, 0, 0, 0.3);
}

.settings-panel.open { transform: translateX(0); }

.settings-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.settings-header h2 {
    font-size: 1.5rem;
    color: var(--text-primary);
}

.close-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.75rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

.close-btn:hover { background: var(--bg-input); color: var(--error); }

.settings-section { margin-bottom: 1rem; }

.settings-label {
    display: block;
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.custom-select { 
    position: relative; 
    width: 100%; 
    user-select: none; 
}

.custom-select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0.75rem;
    background: var(--bg-input);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    z-index: 1;
}

.custom-select-trigger:hover { border-color: var(--primary-light); background: var(--bg-hover); }

.custom-select.open .custom-select-trigger {
    border-color: var(--primary);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    z-index: 1001;
}

.custom-select-value { flex: 1; }
.custom-select-arrow { color: var(--text-secondary); transition: transform 0.3s ease; }
.custom-select.open .custom-select-arrow { transform: rotate(180deg); color: var(--primary); }

.custom-select-options {
    position: absolute;
    top: 100%; 
    left: 0; 
    right: 0;
    background: var(--bg-card);
    border: 2px solid var(--primary);
    border-top: none;
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    z-index: 1000;
    transition: max-height 0.3s ease, opacity 0.3s ease;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.custom-select.open .custom-select-options { 
    max-height: 300px; 
    overflow-y: auto; 
    opacity: 1; 
    visibility: visible;
}

.custom-select-option {
    padding: 0.4rem 0.75rem;
    cursor: pointer;
    font-size: 0.9rem;
    background: var(--bg-card);
    border-left: 3px solid transparent;
    transition: all 0.2s ease;
}

.custom-select-option:hover { background: var(--bg-hover); border-left-color: var(--primary-light); }
.custom-select-option.selected { background: var(--bg-hover); border-left-color: var(--primary); color: var(--primary-light); }

/* Options with descriptions */
.custom-select.has-description .custom-select-option {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    padding: 0.5rem 0.75rem;
}

.option-label {
    font-weight: 500;
    font-size: 0.95rem;
}

.option-description {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 400;
}

.custom-select-option.selected .option-description {
    color: var(--text-secondary);
}

/* Disabled state for settings during conversation */
.settings-disabled {
    position: relative;
}

.settings-disabled::before {
    display: none;
}

.custom-select.disabled .custom-select-trigger {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.settings-textarea:disabled,
.settings-slider:disabled,
.slider-value-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.gender-icon { width: 16px; height: 16px; vertical-align: middle; margin-right: 8px; }
.gender-icon.male { color: #60a5fa; }
.gender-icon.female { color: #f472b6; }
.custom-select-value .gender-icon { margin-right: 6px; }

.settings-textarea {
    width: 100%;
    min-height: 200px;
    padding: 0.75rem;
    background: var(--bg-input);
    border: 2px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-primary);
    font-size: 0.9rem;
    resize: vertical;
    font-family: inherit;
}

.settings-textarea:focus { outline: none; border-color: var(--primary); }

.settings-accordion {
    margin-bottom: 0.5rem;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    overflow: visible;
}

.settings-accordion summary {
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
    background: var(--bg-input);
    list-style: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.settings-accordion summary::before {
    content: '';
    width: 8px; height: 8px;
    border-right: 2px solid var(--primary);
    border-bottom: 2px solid var(--primary);
    transform: rotate(-45deg);
    transition: transform 0.3s ease;
}

.settings-accordion[open] summary::before { transform: rotate(45deg); }
.settings-accordion[open] summary { border-bottom: 1px solid var(--border-color); }
.settings-accordion summary::-webkit-details-marker { display: none; }

.accordion-content { padding: 0.5rem; overflow: visible; }
.setting-item { 
    margin-bottom: 0.5rem; 
    position: relative;
    z-index: 1;
}

.setting-item:last-child { margin-bottom: 0; }

/* Ensure open dropdowns stack above siblings */
.setting-item:has(.custom-select.open) {
    z-index: 100;
}

.slider-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }

.slider-value-input {
    width: 80px;
    padding: 0.5rem;
    background: var(--bg-input);
    border: 2px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
    text-align: center;
}

.slider-value-input:focus { outline: none; border-color: var(--primary); }

.settings-slider {
    width: 100%;
    height: 8px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--bg-input);
    border-radius: 4px;
}

.settings-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 22px; height: 22px;
    background: var(--accent-gradient);
    border-radius: 50%;
    cursor: pointer;
}

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1rem;
    gap: 1rem;
    overflow: hidden;
    min-height: 0;
}



.voice-container {
    position: relative;
    width: 100%;
    flex: 0 0 auto;
    min-height: 180px;
    max-height: 40vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.waveform-canvas { 
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}

.button-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 200px;
    height: 200px;
}

.ring-canvas {
    position: absolute;
    width: 200px;
    height: 200px;
    left: 0;
    top: 0;
    pointer-events: none;
    z-index: 9;
}

.voice-btn {
    width: 100px; height: 100px;
    border-radius: 50%;
    background: linear-gradient(135deg, #0a1628 0%, #162544 50%, #1e3a5f 100%);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.4s ease;
    box-shadow: 0 0 30px rgba(168, 85, 247, 0.3), inset 0 0 40px rgba(168, 85, 247, 0.2);
    z-index: 10;
}

.voice-btn:hover { transform: scale(1.05); box-shadow: 0 0 50px rgba(168, 85, 247, 0.5), inset 0 0 50px rgba(168, 85, 247, 0.3); }
.voice-btn.active { animation: pulse-btn 2s infinite; }

@keyframes pulse-btn {
    0%, 100% { box-shadow: 0 0 30px rgba(168, 85, 247, 0.3), inset 0 0 40px rgba(168, 85, 247, 0.2); }
    50% { box-shadow: 0 0 50px rgba(168, 85, 247, 0.5), inset 0 0 60px rgba(168, 85, 247, 0.3); }
}

.voice-btn svg { width: 40px; height: 40px; color: white; }
.voice-btn .hidden { display: none; }
.voice-hint { color: var(--text-secondary); font-size: 1rem; }

.chat-container {
    width: 100%;
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.75rem;
    background: var(--bg-card);
    border-radius: 16px;
    border: 1px solid var(--border-color);
    min-height: 0;
    scroll-behavior: smooth;
}

.message {
    padding: 0.6rem 0.9rem;
    border-radius: 12px;
    max-width: 80%;
    font-size: 0.875rem;
    line-height: 1.4;
    margin: 0.25rem 0;
    animation: messageSlideIn 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes messageSlideIn { 
    from { opacity: 0; transform: translateY(12px); } 
    to { opacity: 1; transform: translateY(0); } 
}

.message.user { background: var(--accent-gradient); color: white; align-self: flex-end; border-bottom-right-radius: 4px; }
.message.assistant { background: var(--bg-input); color: var(--text-primary); align-self: flex-start; border-bottom-left-radius: 4px; }
.message.system { background: transparent; color: var(--text-secondary); align-self: center; text-align: center; }

/* Session timeout indicators */
.session-warning {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.2) 0%, rgba(245, 158, 11, 0.1) 100%);
    border: 1px solid rgba(245, 158, 11, 0.4);
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--warning);
    animation: warningPulse 2s ease-in-out infinite;
}

.session-renew {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.2) 0%, rgba(99, 102, 241, 0.1) 100%);
    border: 1px solid rgba(99, 102, 241, 0.4);
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--primary-light);
    animation: renewSpin 1s ease-in-out;
    transition: opacity 0.5s ease-out;
}

.session-renew.success {
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.2) 0%, rgba(34, 197, 94, 0.1) 100%);
    border-color: rgba(34, 197, 94, 0.4);
    color: var(--success);
}

.session-renew.error {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.2) 0%, rgba(239, 68, 68, 0.1) 100%);
    border-color: rgba(239, 68, 68, 0.4);
    color: var(--error);
}

.session-renew.fade-out {
    opacity: 0;
}

.warning-icon, .renew-icon {
    font-size: 0.875rem;
}

@keyframes warningPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

@keyframes renewSpin {
    0% { transform: scale(0.9); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* Nova icon for assistant messages */
.message-icon {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    margin-right: 0.5rem;
}

.nova-icon {
    width: 24px;
    height: 24px;
    border-radius: 4px;
}

.message.assistant {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}

.message-content {
    flex: 1;
}

.interrupted-indicator {
    display: block;
    color: var(--text-secondary);
    font-style: italic;
    font-size: 0.8em;
    opacity: 0.7;
    margin-top: 0.25rem;
}

.message.thinking { display: flex; align-items: center; gap: 0.5rem; }
.thinking-text { font-style: italic; opacity: 0.8; }
.thinking-dots { display: flex; gap: 3px; }
.thinking-dots .dot { 
    width: 5px; 
    height: 5px; 
    background: currentColor; 
    border-radius: 50%; 
    animation: bounce 1.2s cubic-bezier(0.4, 0, 0.2, 1) infinite; 
}
.thinking-dots .dot:nth-child(1) { animation-delay: 0s; }
.thinking-dots .dot:nth-child(2) { animation-delay: 0.15s; }
.thinking-dots .dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce { 
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; } 
    30% { transform: translateY(-4px); opacity: 1; } 
}

::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }

@media (max-width: 768px) {
    .settings-panel { width: 100%; }
    .button-wrapper { width: 160px; height: 160px; }
    .ring-canvas { width: 160px; height: 160px; }
    .voice-btn { width: 80px; height: 80px; }
    .voice-btn svg { width: 32px; height: 32px; }
    .message { max-width: 90%; }
    .voice-container { min-height: 140px; }
    .main-content { padding: 0.75rem; gap: 0.75rem; }
    .chat-container { padding: 0.75rem; border-radius: 12px; }
}

@media (max-height: 600px) {
    .voice-container { min-height: 120px; }
    .button-wrapper { width: 140px; height: 140px; }
    .ring-canvas { width: 140px; height: 140px; }
    .voice-btn { width: 70px; height: 70px; }
    .voice-btn svg { width: 28px; height: 28px; }
    .status { padding: 0.4rem 1rem; font-size: 0.875rem; }
}

.hidden { display: none !important; }

.setting-hint {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
    opacity: 0.8;
}

/* Tool Usage Card Styles */
.tool-card {
    background: linear-gradient(135deg, rgba(168, 85, 247, 0.1) 0%, rgba(99, 102, 241, 0.1) 100%);
    border: 1px solid rgba(168, 85, 247, 0.3);
    border-radius: 8px;
    padding: 0;
    max-width: 70%;
    width: fit-content;
    min-width: 200px;
    align-self: flex-start;
    margin: 0.25rem 0 0.25rem 2rem;
    animation: messageSlideIn 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    font-size: 0.8rem;
}

.tool-header {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.7rem;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s ease;
    border-radius: 8px;
}

.tool-card.expanded .tool-header {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.tool-header:hover {
    background: rgba(168, 85, 247, 0.15);
}

.tool-icon {
    width: 14px;
    height: 14px;
    color: var(--primary-light);
    flex-shrink: 0;
    opacity: 0.8;
}

.tool-name {
    font-weight: 500;
    font-size: 0.75rem;
    color: var(--primary-light);
    flex: 1;
}

.tool-status {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.65rem;
    color: var(--text-secondary);
}

.tool-status.running {
    color: var(--warning);
}

.tool-status.completed {
    color: var(--success);
}

.tool-status.error {
    color: var(--error, #ef4444);
}

.tool-elapsed {
    font-size: 0.65rem;
    color: var(--text-secondary);
    opacity: 0.7;
}

.tool-spinner {
    width: 10px;
    height: 10px;
    border: 1.5px solid rgba(168, 85, 247, 0.3);
    border-top-color: var(--warning);
    border-radius: 50%;
    animation: toolSpin 0.8s linear infinite;
}

@keyframes toolSpin {
    to { transform: rotate(360deg); }
}

.tool-check {
    width: 12px;
    height: 12px;
    color: var(--success);
}

.tool-error {
    width: 12px;
    height: 12px;
    color: var(--error, #ef4444);
}

.tool-error-output .tool-section-content {
    color: var(--error, #ef4444);
}

.tool-expand-icon {
    width: 12px;
    height: 12px;
    color: var(--text-secondary);
    transition: transform 0.3s ease;
    flex-shrink: 0;
    opacity: 0.6;
}

.tool-card.expanded .tool-expand-icon {
    transform: rotate(180deg);
}

.tool-details {
    display: none;
    border-top: 1px solid rgba(168, 85, 247, 0.2);
    background: rgba(0, 0, 0, 0.2);
    border-radius: 0 0 8px 8px;
}

.tool-card.expanded .tool-details {
    display: block;
}

.tool-section {
    padding: 0.5rem 0.7rem;
    border-bottom: 1px solid rgba(168, 85, 247, 0.15);
}

.tool-section:last-child {
    border-bottom: none;
}

.tool-section-label {
    font-size: 0.6rem;
    font-weight: 600;
    color: var(--primary-light);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.3rem;
    opacity: 0.7;
}

.tool-section-content {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.65rem;
    color: var(--text-secondary);
    background: rgba(0, 0, 0, 0.3);
    padding: 0.4rem;
    border-radius: 4px;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 120px;
    overflow-y: auto;
}


/* Tools List Styles */
.tools-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.tools-loading {
    color: var(--text-secondary);
    font-size: 0.85rem;
    padding: 0.5rem;
    text-align: center;
}

.tool-toggle-item {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.6rem 0.75rem;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    transition: all 0.2s ease;
}

.tool-toggle-item:hover {
    border-color: var(--primary-light);
    background: var(--bg-hover);
}

.tool-toggle-item.disabled {
    opacity: 0.5;
}

.tool-checkbox {
    position: relative;
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    margin-top: 2px;
}

.tool-checkbox input {
    position: absolute;
    opacity: 0;
    width: 100%;
    height: 100%;
    cursor: pointer;
    z-index: 1;
}

.tool-checkbox .checkmark {
    position: absolute;
    top: 0;
    left: 0;
    width: 18px;
    height: 18px;
    background: var(--bg-dark);
    border: 2px solid var(--border-color);
    border-radius: 4px;
    transition: all 0.2s ease;
}

.tool-checkbox input:checked + .checkmark {
    background: var(--primary);
    border-color: var(--primary);
}

.tool-checkbox .checkmark::after {
    content: '';
    position: absolute;
    display: none;
    left: 5px;
    top: 2px;
    width: 4px;
    height: 8px;
    border: solid white;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.tool-checkbox input:checked + .checkmark::after {
    display: block;
}

.tool-checkbox input:disabled {
    cursor: not-allowed;
}

.tool-checkbox input:disabled + .checkmark {
    opacity: 0.5;
}

.tool-info {
    flex: 1;
    min-width: 0;
}

.tool-info-name {
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--text-primary);
    margin-bottom: 0.2rem;
}

.tool-info-description {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.4;
}


/* Typing Window Styles */
.typing-window {
    width: 100%;
    padding: 0.75rem;
    background: var(--bg-card);
    border-top: 1px solid var(--border-color);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
    display: block !important;
}

.typing-window.hidden {
    transform: translateY(100%) !important;
    pointer-events: none;
}

.typing-window:not(.hidden) {
    transform: translateY(0) !important;
    pointer-events: auto;
}

.typing-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    background: var(--bg-input);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    padding: 0.5rem;
    transition: border-color 0.3s ease;
}

.typing-input-wrapper:focus-within {
    border-color: var(--primary);
}

.text-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 0.95rem;
    font-family: inherit;
    resize: none;
    max-height: 120px;
    min-height: 24px;
    line-height: 1.5;
    padding: 0.25rem 0.5rem;
    outline: none;
}

.text-input::placeholder {
    color: var(--text-secondary);
    opacity: 0.7;
}

.send-text-btn {
    background: var(--accent-gradient);
    border: none;
    border-radius: 50%;
    padding: 0.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
    width: 36px;
    height: 36px;
}

.send-text-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 15px rgba(168, 85, 247, 0.4);
}

.send-text-btn:active {
    transform: scale(0.95);
}

.send-text-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.send-text-btn svg {
    color: white;
}

.hide-typing-btn {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    padding: 0.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    color: var(--text-primary);
}

.hide-typing-btn:hover {
    background: var(--bg-hover);
    border-color: var(--primary-light);
    color: var(--text-primary);
    transform: scale(1.05);
}

.hide-typing-btn:active {
    transform: scale(0.95);
}

/* Keyboard Toggle Button */
.keyboard-toggle {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--bg-card);
    border: 2px solid var(--border-color);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 50;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    opacity: 0;
    visibility: hidden;
}

.keyboard-toggle.visible {
    opacity: 1;
    visibility: visible;
}

.keyboard-toggle:hover {
    background: var(--bg-hover);
    border-color: var(--primary-light);
    color: var(--text-primary);
    transform: scale(1.05);
}

.keyboard-toggle.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

.keyboard-toggle.active:hover {
    background: var(--primary-dark);
}

/* Adjust chat container when typing window is visible */
.main-content {
    transition: padding-bottom 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

.main-content.typing-active {
    padding-bottom: 100px;
}

.main-content:has(.typing-window:not(.hidden)) .chat-container {
    margin-bottom: 0;
    padding-bottom: 80px;
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .keyboard-toggle {
        bottom: 1rem;
        right: 1rem;
        width: 44px;
        height: 44px;
    }
    
    .typing-window {
        padding: 0.5rem;
    }
    
    .text-input {
        font-size: 16px; /* Prevent zoom on iOS */
    }
}

/* ── Billing cost chart card ── */
.billing-chart-card {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    margin: 8px 0;
    animation: messageSlideIn 0.35s ease-out;
    align-self: stretch;
    flex-shrink: 0;
}

.billing-chart-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 14px;
}

.billing-chart-inner {
    display: flex;
    align-items: center;
    gap: 20px;
}

.billing-chart-canvas-wrap {
    position: relative;
    flex-shrink: 0;
    width: 140px;
    height: 140px;
}

.billing-chart-center {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    pointer-events: none;
}

.billing-chart-center-amount {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
}

.billing-chart-center-label {
    font-size: 0.63rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.billing-chart-legend {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 9px;
}

.billing-legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.billing-legend-color {
    width: 10px;
    height: 10px;
    border-radius: 3px;
    flex-shrink: 0;
}

.billing-legend-label {
    flex: 1;
    font-size: 0.78rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.billing-legend-amount {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
}

.billing-legend-pct {
    font-size: 0.7rem;
    color: var(--text-secondary);
    min-width: 28px;
    text-align: right;
}

/* ── Fiber eligibility card ── */
.fiber-card {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    margin: 8px 0;
    max-width: 360px;
    width: 100%;
    animation: messageSlideIn 0.35s ease-out;
}

.fiber-card-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 12px 16px 6px;
}

.fiber-card-body {
    padding: 8px 16px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.fiber-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 6px 14px;
    border-radius: 99px;
    border: 1px solid;
    font-weight: 700;
    font-size: 0.88rem;
    width: fit-content;
}

.fiber-status-label {
    font-size: 0.88rem;
}

.fiber-card-address {
    font-size: 0.82rem;
    color: var(--text-primary);
    font-weight: 600;
}

.fiber-card-message {
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* ── Service case card ── */
.sc-card {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    margin: 8px 0;
    max-width: 400px;
    width: 100%;
    animation: messageSlideIn 0.35s ease-out;
}
.sc-card-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 12px 16px 6px;
    display: flex;
    align-items: center;
    gap: 7px;
}
.sc-card-body {
    padding: 4px 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.sc-card-case {
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
}
.sc-card-case:last-child { border-bottom: none; }
.sc-card-case-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 3px;
}
.sc-card-case-type {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-primary);
    flex: 1;
}
.sc-card-case-status {
    font-size: 0.62rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 4px;
    white-space: nowrap;
}
.sc-card-case-details {
    font-size: 0.72rem;
    color: var(--text-secondary);
    line-height: 1.4;
}
.sc-card-case-id {
    font-size: 0.65rem;
    font-family: monospace;
    color: var(--text-secondary);
    opacity: 0.6;
    margin-top: 2px;
}

/* ── Invoice timeline card ── */
.invoice-timeline-card {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    flex-shrink: 0;
    overflow: hidden;
    margin: 8px 0;
    max-width: 460px;
    width: 100%;
    animation: messageSlideIn 0.35s ease-out;
}

.invoice-timeline-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 12px 16px 8px;
}

.invoice-timeline-card canvas {
    display: block;
    padding: 0 12px 12px;
}

/* ── Roaming tariff card ── */
.roaming-card {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    margin: 8px 0;
    max-width: 400px;
    width: 100%;
    animation: messageSlideIn 0.35s ease-out;
}
.roaming-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px 8px;
    border-bottom: 1px solid var(--border-color);
}
.roaming-card-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.roaming-card-countries {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-primary);
}
.roaming-zone-badge {
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.roaming-card-eu-banner {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 16px;
    background: rgba(34,197,94,0.08);
    font-size: 0.85rem;
    color: var(--text-primary);
    line-height: 1.5;
}
.roaming-card-eu-icon { font-size: 1.4rem; flex-shrink: 0; }
.roaming-rates-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1px;
    background: var(--border-color);
    border-top: 1px solid var(--border-color);
}
.roaming-rate-cell {
    background: var(--bg-input);
    padding: 10px 14px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.roaming-rate-icon { font-size: 1rem; }
.roaming-rate-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.roaming-rate-value {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}
.roaming-pass-banner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: rgba(245,168,0,0.1);
    border-top: 1px solid rgba(245,168,0,0.25);
    font-size: 0.8rem;
    color: var(--text-primary);
    line-height: 1.4;
}

/* ── Telenet Shop Map card ── */
.shop-map-card {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    margin: 8px 0;
    animation: messageSlideIn 0.35s ease-out;
    max-width: 480px;
    width: 100%;
    flex-shrink: 0;
    min-width: 320px;
}

.shop-map-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 12px 16px 8px;
}

.shop-map-container {
    width: 100%;
    height: 280px;
    flex-shrink: 0;
    min-width: 320px;
    max-width: 480px;
}

.shop-map-info {
    padding: 12px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.shop-map-name-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.shop-map-name {
    font-size: 0.88rem;
    font-weight: 700;
    color: #F5A800;
}

.shop-type-badge {
    font-size: 0.65rem;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: 20px;
    white-space: nowrap;
}

.shop-type-own {
    background: rgba(245, 168, 0, 0.15);
    color: #F5A800;
    border: 1px solid rgba(245, 168, 0, 0.35);
}

.shop-type-center {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.shop-map-address {
    font-size: 0.8rem;
    color: var(--text-primary);
}

.shop-map-meta {
    font-size: 0.76rem;
    color: var(--text-secondary);
}

/* Custom Leaflet markers */
.shop-leaflet-marker {
    width: 34px;
    height: 34px;
    background: #F5A800;
    border: 2px solid #111;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.85rem;
    color: #111;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

.customer-leaflet-marker {
    width: 14px;
    height: 14px;
    background: #ffffff;
    border: 3px solid #F5A800;
    border-radius: 50%;
    box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

/* ── Avatar toggle button (header) ── */
.avatar-toggle-btn {
    color: var(--text-secondary);
    transition: color 0.2s, transform 0.2s;
}
.avatar-toggle-btn:hover { color: var(--text-primary); }
.avatar-toggle-btn.active {
    color: var(--primary);
    filter: drop-shadow(0 0 6px rgba(245, 168, 0, 0.6));
}

/* ── Avatar placeholder (shown when no live stream yet) ── */
.avatar-placeholder {
    display: none;
    position: absolute;
    inset: 0;
    align-items: center;
    justify-content: center;
    z-index: 4;
    color: var(--text-secondary);
}
.voice-container.avatar-active .avatar-placeholder {
    display: flex;
}
.voice-container.avatar-active.avatar-live .avatar-placeholder {
    display: none;
}

/* ── Avatar video panel ── */
.avatar-video {
    display: none;
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 16px;
    z-index: 3;
    background: var(--bg-card);
}

.voice-container.avatar-active {
    border-radius: 16px;
    border: 1px solid rgba(245, 168, 0, 0.35);
    overflow: visible;
    background: var(--bg-card);
    box-shadow: 0 0 32px rgba(245, 168, 0, 0.18), inset 0 0 40px rgba(10, 22, 40, 0.4);
    min-height: 520px;
    margin-bottom: 40px;
}

.voice-container.avatar-active .avatar-video {
    display: block;
}

/* Hide waveform in avatar mode — video/placeholder fills the panel */
.voice-container.avatar-active .waveform-canvas {
    display: none;
}

/* Mic button sits at bottom-centre over video */
.voice-container.avatar-active .button-wrapper {
    position: absolute;
    bottom: -28px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 11;
}

/* ── Avatar expand/shrink button ── */
.avatar-expand-btn {
    display: none;
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 13;
    background: rgba(10, 22, 40, 0.72);
    border: 1px solid var(--border-color);
    border-radius: 7px;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 5px 7px;
    transition: background 0.2s, color 0.2s;
    backdrop-filter: blur(4px);
}
.voice-container.avatar-active .avatar-expand-btn {
    display: flex;
    align-items: center;
    justify-content: center;
}
.avatar-expand-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* ── Expanded avatar layout ── */
.main-content.avatar-expanded .voice-container {
    min-height: 65vh;
    max-height: 65vh;
}


/* Waveform already hidden in avatar-active; nothing extra needed for expanded */

.message-content {
    min-width: 0;
}

.shop-map-card,
.fiber-card,
.roaming-card,
.sc-card,
.invoice-timeline-card,
.billing-chart-card,
.usage-gauge-card,
.appointment-calendar-card,
.appointment-confirm-card {
    min-width: 320px;
    flex-shrink: 0;
}

/* ── Appointment calendar widget ─────────────────────────────────────────── */
.appointment-calendar-card {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 18px;
    margin: 8px 0;
    animation: messageSlideIn 0.35s ease-out;
}

.appointment-cal-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border-color);
}

.appointment-cal-icon {
    width: 34px;
    height: 34px;
    background: rgba(255,255,255,0.06);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: #22c55e;
}

.appointment-cal-header-text { flex: 1; min-width: 0; }

.appointment-cal-title {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.appointment-cal-subtitle {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.appointment-cal-badge {
    flex-shrink: 0;
    padding: 3px 9px;
    border-radius: 99px;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: rgba(34,197,94,0.12);
    color: #22c55e;
    border: 1px solid rgba(34,197,94,0.25);
}

.appointment-week { margin-bottom: 14px; }
.appointment-week:last-child { margin-bottom: 0; }

.appointment-week-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.appointment-week-label {
    font-size: 0.67rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.07em;
    white-space: nowrap;
}

.appointment-week-line {
    flex: 1;
    height: 1px;
    background: var(--border-color);
}

.appointment-days {
    display: flex;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
}

.appointment-day {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    border-right: 1px solid var(--border-color);
}

.appointment-day:last-child { border-right: none; }

.appointment-day-label {
    font-size: 0.64rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-align: center;
    padding: 5px 4px;
    background: rgba(255,255,255,0.03);
    border-bottom: 1px solid var(--border-color);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.appointment-slots-col {
    padding: 5px 4px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.appointment-slot {
    background: rgba(34,197,94,0.1);
    color: #4ade80;
    border: 1px solid rgba(34,197,94,0.2);
    border-radius: 5px;
    padding: 5px 3px;
    font-size: 0.64rem;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    transition: background 0.15s, border-color 0.15s;
    line-height: 1.3;
    white-space: nowrap;
}

.appointment-slot:hover {
    background: rgba(34,197,94,0.2);
    border-color: rgba(34,197,94,0.45);
}

.appointment-slot.selected {
    background: #F5A800;
    border-color: #F5A800;
    color: #1a1a1a;
    font-weight: 700;
}

.appointment-calendar-card.booked .appointment-slot:not(.selected) {
    opacity: 0.3;
    cursor: default;
    pointer-events: none;
}

/* ── Appointment confirmation card ──────────────────────────────────────── */
.appointment-confirm-card {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    margin: 8px 0;
    animation: messageSlideIn 0.35s ease-out;
}

.appointment-confirm-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
}

.appointment-confirm-icon {
    width: 30px;
    height: 30px;
    background: rgba(34,197,94,0.15);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    flex-shrink: 0;
    color: #4ade80;
}

.appointment-confirm-title {
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--text-primary);
}

.appointment-confirm-subtitle {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.appointment-confirm-rows {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-bottom: 10px;
}

.appointment-confirm-row {
    display: flex;
    font-size: 0.82rem;
}

.appointment-confirm-row-label {
    color: var(--text-secondary);
    flex-shrink: 0;
    width: 68px;
}

.appointment-confirm-row-value {
    color: var(--text-primary);
    font-weight: 500;
}

.appointment-confirm-number {
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border-color);
    border-radius: 7px;
    padding: 8px 12px;
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.appointment-confirm-number strong {
    font-size: 0.9rem;
    color: var(--text-primary);
    letter-spacing: 0.08em;
    font-family: monospace;
}
