/* ===== CSS Variables & Design Tokens ===== */
:root {
    /* Colors */
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fc;
    --bg-tertiary: #f3f4f6;
    --bg-hover: #e5e7eb;
    --bg-input: #ffffff;
    --text-primary: #0a0a0a;
    --text-secondary: #525252;
    --text-muted: #6b6b6b;
    --border-color: #e4e6e6;
    --accent: #b13b50;
    --accent-hover: #942d42;
    --accent-light: #b13b5018;
    --accent-glow: #b13b5040;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --success: #22c55e;
    --success-dim: #22c55e18;
    --warning: #f59e0b;
    --warning-dim: #f59e0b18;
    --agent-a: #6366f1;
    --agent-a-light: #ede9fe;
    --agent-b: #22c55e;
    --agent-b-light: #ecfdf5;

    /* Glassmorphism */
    --glass-bg: rgba(255, 255, 255, 0.72);
    --glass-bg-heavy: rgba(255, 255, 255, 0.88);
    --glass-border: rgba(255, 255, 255, 0.5);
    --glass-blur: 16px;
    --glass-shadow: 0 4px 30px rgba(0, 0, 0, 0.06);

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 12px;
    --space-lg: 16px;
    --space-xl: 24px;
    --space-2xl: 32px;
    --space-3xl: 48px;

    /* Radius */
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.12);

    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --font-mono: 'SF Mono', Monaco, Consolas, 'Liberation Mono', monospace;

    /* Layout */
    --sidebar-width: 340px;
    --header-height: 56px;

    /* Transitions */
    --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-spring: 0.35s cubic-bezier(0.34, 1.56, 0.64, 1);

    /* Sound Wave */
    --sound-wave-color: #5765CA;
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

body {
    font-family: var(--font-sans);
    background: linear-gradient(135deg, #f5f3ff 0%, #fdf2f4 50%, #f0f9ff 100%);
    color: var(--text-primary);
    font-size: 16px;
    line-height: 1.5;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ===== Utility ===== */
.hidden { display: none !important; }

/* ===== Layout ===== */
.app-container {
    display: flex;
    height: 100dvh;
    height: 100vh; /* fallback */
    width: 100%;
    position: relative;
}

/* ===== Sidebar ===== */
.sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 200;
    padding: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    transform: translateX(-100%);
    transition: transform var(--transition-normal);
    will-change: transform;
}

.sidebar.open {
    transform: translateX(0);
}

.sidebar-scroll {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--glass-bg-heavy);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow-y: auto;
    font-size: 13px;
    padding: var(--space-lg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.sidebar-scroll::-webkit-scrollbar { width: 5px; }
.sidebar-scroll::-webkit-scrollbar-track { background: transparent; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.15); border-radius: 3px; }
.sidebar-scroll::-webkit-scrollbar-thumb:hover { background: rgba(0, 0, 0, 0.25); }
.sidebar-scroll { scrollbar-width: thin; scrollbar-color: rgba(0, 0, 0, 0.15) transparent; }

.sidebar-close {
    position: absolute;
    top: var(--space-lg);
    right: var(--space-lg);
    z-index: 10;
    background: rgba(0, 0, 0, 0.06);
    border: none;
    border-radius: var(--radius-sm);
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}
.sidebar-close:hover {
    background: rgba(0, 0, 0, 0.1);
    color: var(--text-primary);
}

.sidebar-title {
    font-size: 15px;
    font-weight: 700;
    margin-bottom: var(--space-lg);
    padding: 0 var(--space-xs);
    color: var(--text-primary);
    letter-spacing: -0.01em;
}

/* ===== Settings Groups (Details/Summary) ===== */
.settings-group {
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.settings-group:last-of-type {
    border-bottom: none;
}

.settings-group summary {
    padding: var(--space-md) 0;
    cursor: pointer;
    font-weight: 600;
    font-size: 14px;
    color: var(--text-primary);
    user-select: none;
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    transition: color var(--transition-fast);
}

.settings-group summary:hover {
    color: var(--accent);
}

.settings-group summary::after {
    content: '';
    width: 6px;
    height: 6px;
    border-right: 2px solid var(--text-muted);
    border-bottom: 2px solid var(--text-muted);
    transform: rotate(-45deg);
    transition: transform var(--transition-normal);
    flex-shrink: 0;
}

.settings-group[open] summary::after {
    transform: rotate(45deg);
}

.settings-group summary::-webkit-details-marker { display: none; }

.settings-content {
    padding: var(--space-sm) 0 var(--space-lg);
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

#avatarSettings {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

/* ===== Form Elements ===== */
label {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

input[type="text"],
input[type="password"],
input[type="number"],
textarea,
select {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    padding: 8px 12px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
    width: 100%;
    box-shadow: var(--shadow-xs);
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
textarea:focus,
select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

textarea { resize: vertical; }

input:disabled,
textarea:disabled,
select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.toggle-label input[type="checkbox"]:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    pointer-events: none;
}

select {
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236b6b6b' d='M3 5l3 3 3-3'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 28px;
}

/* Range Slider */
input[type="range"] {
    width: 100%;
    height: 20px;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
}

input[type="range"]::-webkit-slider-runnable-track {
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    margin-top: -7px;
    cursor: pointer;
    box-shadow: 0 1px 4px rgba(177, 59, 80, 0.3);
    transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.15);
    box-shadow: 0 2px 8px rgba(177, 59, 80, 0.4);
}

input[type="range"]:active::-webkit-slider-thumb {
    transform: scale(1.2);
}

input[type="range"]:disabled::-webkit-slider-thumb {
    transform: none;
    box-shadow: none;
}

/* ===== Toggle Labels ===== */
.toggle-label {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-sm);
    padding: var(--space-xs) 0;
}

.toggle-label.compact {
    padding: 0;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.toggle-label input[type="checkbox"] {
    width: 40px;
    height: 22px;
    -webkit-appearance: none;
    appearance: none;
    background: #d4d4d8;
    border: none;
    border-radius: 11px;
    cursor: pointer;
    position: relative;
    transition: background var(--transition-normal);
    flex-shrink: 0;
}

.toggle-label input[type="checkbox"]::before {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: white;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
    transition: transform var(--transition-spring);
}

.toggle-label input[type="checkbox"]:checked {
    background: var(--accent);
}

.toggle-label input[type="checkbox"]:checked::before {
    transform: translateX(18px);
}

#clearChatBtn path {
    fill: currentColor;
}

/* ===== Header Icon Button (Transcript toggle) ===== */
.header-icon-btn {
    background: rgba(0, 0, 0, 0.04);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: var(--radius-sm);
    padding: var(--space-sm);
    cursor: pointer;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    min-height: 36px;
}

.header-icon-btn:hover {
    background: rgba(0, 0, 0, 0.08);
    color: var(--text-primary);
}

.header-icon-btn.active {
    background: var(--accent-light);
    color: var(--accent);
    border-color: var(--accent);
}

/* ===== Config Sections ===== */
.config-section {
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: var(--radius);
    padding: var(--space-lg);
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    background: rgba(255, 255, 255, 0.6);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.section-title {
    font-weight: 700;
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

.subsection-title {
    font-weight: 600;
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: var(--space-xs);
}

.scene-slider {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: var(--space-sm);
}

.scene-label {
    font-size: 12px;
    color: var(--text-secondary);
    font-weight: 500;
}

.voice-variant {
    padding: var(--space-md);
    border-radius: var(--radius-sm);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    background: rgba(0, 0, 0, 0.02);
    border-left: 3px solid var(--border-color);
}

.standard-border { border-left-color: var(--accent); }
.custom-border { border-left-color: var(--warning); }
.personal-border { border-left-color: var(--success); }

/* ===== Interim Response Settings ===== */
#interimResponseSettings {
    padding: var(--space-md);
    border-radius: var(--radius-sm);
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
    background: rgba(0, 0, 0, 0.02);
    border-left: 3px solid var(--accent);
    margin-top: var(--space-xs);
}

#interimLlmFields,
#interimStaticFields {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

/* ===== Instructions Box ===== */
.instructions-box {
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    padding: var(--space-md);
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
}

.instructions-box ol {
    padding-left: 20px;
    margin-top: var(--space-sm);
}

.instructions-box li {
    margin-bottom: var(--space-xs);
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    cursor: pointer;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    font-weight: 500;
    transition: all var(--transition-fast);
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
}

.btn-connect {
    width: 100%;
    padding: 12px var(--space-lg);
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
    color: #fff;
    border-radius: var(--radius);
    font-weight: 600;
    font-size: 15px;
    box-shadow: 0 2px 12px rgba(177, 59, 80, 0.25);
    letter-spacing: 0.01em;
    position: relative;
    overflow: hidden;
}

.btn-connect:hover {
    box-shadow: 0 4px 20px rgba(177, 59, 80, 0.35);
    transform: translateY(-1px);
}

.btn-connect.connected {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
}
.btn-connect.connected:hover {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.btn-connect.connecting {
    background: linear-gradient(135deg, var(--accent-hover) 0%, var(--accent) 100%);
    cursor: wait;
    animation: connectPulse 1.5s ease-in-out infinite;
}

@keyframes connectPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.75; }
}

.btn-icon {
    background: transparent;
    color: var(--text-secondary);
    padding: var(--space-sm);
    border-radius: var(--radius-sm);
    min-width: 36px;
    min-height: 36px;
}
.btn-icon:hover {
    background: rgba(0, 0, 0, 0.06);
    color: var(--text-primary);
    transform: none;
}

.btn-text {
    background: transparent;
    color: var(--text-secondary);
    padding: var(--space-xs) var(--space-sm);
}
.btn-text:hover {
    color: var(--accent);
    transform: none;
}

.btn-primary {
    background: var(--accent);
    color: white;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    box-shadow: 0 1px 4px rgba(177, 59, 80, 0.2);
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-icon-svg {
    width: 18px;
    height: 18px;
}

/* ===== Sidebar Footer ===== */
.sidebar-footer {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
    min-height: 0;
    padding: var(--space-md);
    gap: var(--space-sm);
}

/* ===== Header Bar ===== */
.header-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) var(--space-lg);
    min-height: var(--header-height);
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    min-width: 0;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    min-width: 0;
}

.header-brand img {
    width: auto;
    height: 32px;
    object-fit: contain;
    flex-shrink: 0;
}

.header-brand-text {
    font-weight: 700;
    font-size: 16px;
    line-height: 1;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--accent) 0%, #7c3aed 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.settings-toggle-btn {
    background: rgba(0, 0, 0, 0.04);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: var(--radius-sm);
    padding: var(--space-sm);
    cursor: pointer;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    min-height: 36px;
}

.settings-toggle-btn:hover {
    background: rgba(0, 0, 0, 0.08);
    color: var(--text-primary);
}

.settings-toggle-btn[aria-expanded="true"] {
    background: var(--accent-light);
    color: var(--accent);
    border-color: var(--accent);
}

/* Connection status indicator */
.connection-status {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-muted);
    padding: var(--space-xs) var(--space-md);
    background: rgba(0, 0, 0, 0.03);
    border-radius: var(--radius-full);
}

.connection-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #d4d4d8;
    transition: background var(--transition-normal);
}

.connection-status.connected .connection-dot {
    background: var(--success);
    box-shadow: 0 0 6px rgba(34, 197, 94, 0.4);
}

.connection-status.connecting .connection-dot {
    background: var(--warning);
    animation: pulse-glow 1.5s ease-in-out infinite;
}

/* Fullscreen button */
.fullscreen-btn {
    background: rgba(0, 0, 0, 0.04);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: var(--radius-sm);
    padding: var(--space-sm);
    cursor: pointer;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    min-height: 36px;
}

.fullscreen-btn:hover {
    background: rgba(0, 0, 0, 0.08);
    color: var(--text-primary);
}

/* Header Connect/Disconnect button */
.header-connect-btn {
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 600;
    border-radius: var(--radius-full);
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
    color: #fff;
    box-shadow: 0 1px 6px rgba(177, 59, 80, 0.2);
    gap: var(--space-xs);
    min-height: 36px;
    transition: all var(--transition-fast);
}

.header-connect-btn:hover {
    box-shadow: 0 2px 12px rgba(177, 59, 80, 0.3);
}

.header-connect-btn.connected {
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.15);
}

.header-connect-btn.connected:hover {
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.25);
}

.header-connect-btn.connecting {
    background: linear-gradient(135deg, var(--accent-hover) 0%, var(--accent) 100%);
    cursor: wait;
    animation: connectPulse 1.5s ease-in-out infinite;
}

/* ===== Welcome State (Disconnected) ===== */
.welcome-state {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--glass-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-radius: var(--radius-lg);
    border: 1px solid var(--glass-border);
    padding: var(--space-xl);
}

.welcome-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-lg);
    text-align: center;
    max-width: 340px;
}

.welcome-icon {
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--accent-light) 0%, rgba(124, 58, 237, 0.08) 100%);
    color: var(--accent);
}

.welcome-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.welcome-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    line-height: 1.5;
}

.welcome-connect-btn {
    margin-top: var(--space-sm);
    width: auto;
    padding: 12px 32px;
    font-size: 15px;
}

/* ===== Content Area ===== */
.content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: auto;
    position: relative;
    border-radius: var(--radius);
    min-height: 0;
}

.content-area.developer-layout {
    flex-direction: row;
    gap: var(--space-sm);
}

/* ===== Avatar Container ===== */
.avatar-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    background: var(--glass-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    overflow: hidden;
    border-radius: var(--radius-lg);
    border: 1px solid var(--glass-border);
}

.avatar-agent-wrapper {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity var(--transition-normal);
}

.avatar-container.photo-avatar,
.avatar-container.photo-avatar .avatar-video,
.avatar-container.photo-avatar .avatar-video video {
    border-radius: 10%;
}

.avatar-video {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.avatar-video video {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
}

/* ===== Volume Animation ===== */
.volume-animation {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--glass-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border-radius: var(--radius-lg);
    border: 1px solid var(--glass-border);
}

.volume-circle {
    position: relative;
    width: 160px;
    height: 160px;
    border-radius: 50%;
    background: linear-gradient(135deg, #e2e8f0 0%, #cbd5e1 100%);
    transition: width 0.3s ease, height 0.3s ease, background-color 0.3s ease;
}

.volume-circle.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 50%;
    opacity: 0;
    animation: ripple 2s linear 1s infinite;
}

@keyframes ripple {
    0%   { transform: scale(1);    opacity: 0.0; }
    25%  { transform: scale(1.25); opacity: 0.08; }
    50%  { transform: scale(1.5);  opacity: 0.15; }
    75%  { transform: scale(1.75); opacity: 0.08; }
    100% { transform: scale(2);    opacity: 0.0; }
}

.robot-svg {
    position: absolute;
    margin-top: 5px;
    filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.1));
}

/* ===== Chat Area ===== */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.chat-area-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) var(--space-lg);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    flex-shrink: 0;
}

.chat-area-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.chat-clear-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    transition: all var(--transition-fast);
}

.chat-clear-btn:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.08);
}

.chat-clear-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-lg);
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.messages::-webkit-scrollbar { width: 5px; }
.messages::-webkit-scrollbar-track { background: transparent; }
.messages::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.12); border-radius: 3px; }
.messages::-webkit-scrollbar-thumb:hover { background: rgba(0, 0, 0, 0.2); }
.messages { scrollbar-width: thin; scrollbar-color: rgba(0, 0, 0, 0.12) transparent; }

.message {
    display: flex;
    flex-direction: column;
    gap: 3px;
    max-width: 80%;
    animation: messageSlideIn 0.3s ease;
}

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

.message.user {
    align-self: flex-end;
}

.message.assistant {
    align-self: flex-start;
}

.message-role {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    padding: 0 var(--space-xs);
}

.message-content {
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius);
    font-size: 14px;
    line-height: 1.55;
    word-wrap: break-word;
    box-shadow: var(--shadow-xs);
}

.message.user .message-content {
    background: linear-gradient(135deg, #dbeafe 0%, #c7d2fe 100%);
    color: var(--text-primary);
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    background: white;
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.message.system .message-content {
    background: linear-gradient(135deg, #fffbeb 0%, #fef3c7 100%);
    color: var(--text-primary);
    font-size: 13px;
    text-align: left;
    padding: var(--space-md) var(--space-lg);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(234, 179, 8, 0.2);
}

.message.system {
    align-self: flex-start;
    max-width: 90%;
}

.message.dev .message-content {
    background: var(--bg-tertiary);
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 12px;
    white-space: pre-wrap;
    border-left: 2px solid var(--warning);
}

/* ===== Input Area ===== */
.input-area {
    padding: var(--space-md) var(--space-lg);
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border-radius: var(--radius);
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
}

.input-row {
    display: flex;
    gap: var(--space-sm);
    max-width: 700px;
    margin: 0 auto;
    align-items: center;
}

.input-row input[type="text"] {
    flex: 1;
}

.mic-btn {
    padding: var(--space-sm);
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    min-width: 40px;
    min-height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}
.mic-btn:hover {
    border-color: var(--accent);
}
.mic-btn.recording {
    background: #fee2e2;
    border-color: var(--danger);
    animation: micPulse 1.5s ease-in-out infinite;
}

@keyframes micPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.2); }
    50% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
}

.send-btn {
    padding: 8px 14px;
    min-height: 40px;
}

/* ===== Footer / Record Button ===== */
.footer-area {
    padding: var(--space-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    flex-shrink: 0;
}

/* Hide footer when empty (no record container visible) */
.footer-area.footer-empty {
    display: none;
}

.record-container {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.recording-border {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 500px;
    padding: 6px 12px;
    border-radius: var(--radius-full);
    border: 1px solid transparent;
    transition: all var(--transition-fast);
}

.recording-border.active {
    background: rgba(239, 68, 68, 0.04);
    border-color: rgba(239, 68, 68, 0.15);
}

.record-btn {
    background: white;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    padding: 10px 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-sm);
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-sm);
    min-height: 48px;
}

.record-btn:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-md);
    transform: translateY(-1px);
}

.record-btn.recording {
    background: linear-gradient(135deg, #fee2e2 0%, #fecaca 100%);
    border-color: var(--danger);
    animation: recordBtnPulse 1.5s ease-in-out infinite;
}

@keyframes recordBtnPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.15), var(--shadow-sm); }
    50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0), var(--shadow-md); }
}

.microphone-label {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    color: var(--text-primary);
}

.sound-wave {
    width: clamp(40px, 12%, 80px);
    height: 38px;
    display: flex;
    align-items: center;
    gap: 3px;
    margin: 0 var(--space-md);
}

.sound-wave .bar {
    width: 4px;
    flex-shrink: 0;
    background: linear-gradient(180deg, var(--sound-wave-color) 0%, var(--accent) 100%);
    border-radius: var(--radius-full);
    transition: height 0.15s ease;
}

/* ===== Sidebar Overlay ===== */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 199;
    transition: opacity var(--transition-normal);
}
.sidebar-overlay.active {
    display: block;
}

/* ===== Agent Selector Bar ===== */
.agent-selector-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) var(--space-lg);
    background: var(--glass-bg);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--glass-border);
    gap: var(--space-md);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
}

.agent-selector-inner {
    display: flex;
    gap: var(--space-sm);
}

.agent-btn {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 7px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    background: white;
    cursor: pointer;
    font-family: inherit;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-xs);
    min-height: 36px;
}

.agent-btn:hover {
    border-color: var(--text-muted);
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}

.agent-btn.active {
    border-color: var(--accent);
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
    color: #fff;
    box-shadow: 0 2px 10px rgba(177, 59, 80, 0.25);
}

.agent-btn.active .agent-dot {
    background: rgba(255, 255, 255, 0.9);
}

.agent-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    transition: background var(--transition-fast);
}

.agent-a-dot { background: var(--agent-a); }
.agent-b-dot { background: var(--agent-b); }

.agent-name {
    font-weight: 600;
}

.agent-role {
    font-weight: 400;
    opacity: 0.65;
    font-size: 11px;
}

.agent-status {
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-weight: 500;
}

.agent-status strong {
    color: var(--text-primary);
}

.agent-status.active-agent_a strong { color: var(--agent-a); }
.agent-status.active-agent_b strong { color: var(--agent-b); }

.listening-pulse {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--agent-a);
    animation: pulse-glow 1.5s ease-in-out infinite;
}

.active-agent_a .listening-pulse { background: var(--agent-a); }
.active-agent_b .listening-pulse { background: var(--agent-b); }

@keyframes pulse-glow {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.4; transform: scale(1.4); }
}

/* ===== Agent Tags in Chat ===== */
.agent-tag {
    display: inline-block;
    font-size: 10px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: var(--radius-full);
    color: #fff;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

.agent-tag-agent_a { background: var(--agent-a); }
.agent-tag-agent_b { background: var(--agent-b); }

/* Agent-specific message styling */
.message.assistant[data-agent="agent_a"] .message-content {
    background: var(--agent-a-light);
    border: 1px solid rgba(99, 102, 241, 0.15);
    border-left: 3px solid var(--agent-a);
}

.message.assistant[data-agent="agent_b"] .message-content {
    background: var(--agent-b-light);
    border: 1px solid rgba(34, 197, 94, 0.15);
    border-left: 3px solid var(--agent-b);
}

/* ===== Conversation End Overlay ===== */
.conversation-end-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    animation: overlayFadeIn 0.6s ease;
}

@keyframes overlayFadeIn {
    from { opacity: 0; backdrop-filter: blur(0); }
    to { opacity: 1; backdrop-filter: blur(20px); }
}

.conversation-end-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-xl);
    padding: var(--space-3xl);
    animation: contentScaleIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.2s both;
}

@keyframes contentScaleIn {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

.conversation-end-content h2 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    text-align: center;
    letter-spacing: -0.02em;
}

.qr-code-image {
    width: 200px;
    height: 200px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
}

.qr-caption {
    font-size: 16px;
    font-weight: 500;
    color: var(--text-secondary);
    text-align: center;
}

.btn-new-conversation {
    padding: 14px 32px;
    font-size: 16px;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, var(--accent) 0%, var(--accent-hover) 100%);
    border: none;
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: 0 4px 16px rgba(177, 59, 80, 0.3);
    letter-spacing: 0.01em;
}

.btn-new-conversation:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 24px rgba(177, 59, 80, 0.4);
}

/* ===== Architecture Diagram Overlay (Screen Share Mode) ===== */
.diagram-overlay {
    position: absolute;
    inset: 0;
    background: #0a0a0a;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    border-radius: var(--radius-lg);
    animation: diagramFadeIn 0.4s ease;
    overflow: hidden;
}

@keyframes diagramFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.diagram-overlay img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
}

.diagram-close-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 25;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: var(--radius-sm);
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    transition: all var(--transition-fast);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.diagram-close-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    color: #fff;
}

/* PiP avatar in diagram mode */
.content-area.diagram-mode .avatar-container {
    position: absolute;
    bottom: 16px;
    right: 16px;
    width: 20%;
    height: auto;
    aspect-ratio: 16 / 9;
    z-index: 20;
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    border: 2px solid rgba(255, 255, 255, 0.25);
    overflow: hidden;
    flex: none;
    min-height: unset;
    max-height: unset;
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: grab;
    touch-action: none;
}

/* PiP volume animation (audio-only mode) in diagram mode */
.content-area.diagram-mode .volume-animation {
    position: absolute;
    bottom: 16px;
    right: 16px;
    width: 20%;
    height: auto;
    aspect-ratio: 1;
    z-index: 20;
    border-radius: var(--radius);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    border: 2px solid rgba(255, 255, 255, 0.25);
    overflow: hidden;
    flex: none;
    min-height: unset;
    max-height: unset;
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    cursor: grab;
    touch-action: none;
}

/* PiP dragging state — disable transition and change cursor */
.content-area.diagram-mode .avatar-container.pip-dragging,
.content-area.diagram-mode .volume-animation.pip-dragging {
    cursor: grabbing;
    transition: none;
    user-select: none;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.6);
}

/* Ensure avatar container has transition for smooth PiP animation */
.avatar-container {
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.volume-animation {
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Developer mode + diagram: overlay covers avatar area only */
.content-area.developer-layout.diagram-mode .diagram-overlay {
    flex: 1;
    position: relative;
    inset: unset;
}

.content-area.developer-layout.diagram-mode .avatar-container {
    position: absolute;
    bottom: 16px;
    right: 16px;
    width: 25%;
}

/* Diagram image error/loading state */
.diagram-overlay .diagram-fallback {
    color: rgba(255, 255, 255, 0.6);
    font-size: 16px;
    font-weight: 500;
    text-align: center;
}

/* ===== Responsive: Desktop Large (1440px+) ===== */
@media (min-width: 1440px) {
    .messages { max-width: 800px; }
    .input-row { max-width: 800px; }
}

/* ===== Responsive: Tablet (768-1023px) ===== */
@media (max-width: 1023px) {
    .sidebar-scroll,
    .sidebar-footer {
        width: 320px;
        min-width: 320px;
    }
    .content-area.developer-layout {
        flex-direction: column;
    }
    .content-area.developer-layout .avatar-container {
        flex: none;
        max-height: 280px;
    }

    /* Reduce header gap on tablet */
    .header-right { gap: var(--space-sm); }

    /* PiP avatar larger on tablet */
    .content-area.diagram-mode .avatar-container,
    .content-area.diagram-mode .volume-animation { width: 30%; }
}

/* ===== Responsive: Mobile (< 768px) ===== */
@media (max-width: 768px) {
    body { font-size: 15px; }

    .app-container {
        height: 100dvh;
        height: 100vh; /* fallback */
    }

    .main-content {
        padding: var(--space-sm);
        gap: var(--space-xs);
        min-height: 0;
        overflow-y: auto;
    }

    .header-bar {
        padding: var(--space-sm) var(--space-md);
        min-height: 48px;
        border-radius: var(--radius-sm);
    }

    .header-brand-text { font-size: 14px; }
    .header-brand img { height: 28px; }
    .header-brand { gap: 6px; }

    /* Compact header connect/disconnect button — icon only on mobile */
    #headerConnectBtnText { display: none; }
    .header-connect-btn { padding: 6px 10px; min-width: 36px; }

    /* Reduce header gap */
    .header-right { gap: var(--space-sm); }

    /* Hide fullscreen on mobile */
    .fullscreen-btn { display: none; }

    /* Agent selector: compact on mobile */
    .agent-selector-bar {
        flex-wrap: nowrap;
        justify-content: space-between;
        gap: var(--space-sm);
        padding: var(--space-xs) var(--space-md);
        border-radius: var(--radius-sm);
        flex-shrink: 0;
    }

    .agent-selector-inner {
        flex-shrink: 0;
    }

    .agent-status {
        font-size: 11px;
    }

    .sidebar-scroll,
    .sidebar-footer {
        width: calc(100vw - 60px);
        min-width: auto;
        max-width: 320px;
    }

    .sound-wave {
        width: 40px;
        height: 28px;
        gap: 2px;
        margin: 0 var(--space-sm);
    }

    .sound-wave .bar { width: 3px; }

    .content-area.developer-layout { flex-direction: column; }

    .content-area.developer-layout .chat-area {
        flex: 1;
        padding: var(--space-md) 0;
    }

    .content-area.developer-layout .avatar-container {
        flex: none;
        max-height: 200px;
    }

    .content-area {
        flex: 1 1 auto;
        overflow: visible;
        min-height: 0;
    }

    .avatar-container {
        min-height: 200px;
        max-height: 50vh;
        flex: 0 0 auto;
    }

    .volume-animation {
        min-height: 200px;
        max-height: 50vh;
        flex: 0 0 auto;
    }

    .message { max-width: 90%; }

    .footer-area {
        padding: var(--space-md);
        border-radius: var(--radius-sm);
        flex-shrink: 0;
        position: relative;
        z-index: 10;
        min-height: 80px;
    }

    .record-container {
        width: 100%;
    }

    .record-btn {
        padding: 8px 16px;
        min-height: 44px;
        width: 100%;
        justify-content: center;
    }

    .microphone-label { font-size: 13px; }

    .input-area {
        padding: var(--space-sm) var(--space-md);
        border-radius: var(--radius-sm);
    }

    .conversation-end-content { padding: var(--space-xl); }

    /* PiP avatar larger on mobile */
    .content-area.diagram-mode .avatar-container,
    .content-area.diagram-mode .volume-animation { width: 30%; bottom: 12px; right: 12px; }

    .diagram-close-btn { top: 8px; right: 8px; width: 28px; height: 28px; }

    .qr-code-image { width: 180px; height: 180px; }

    .btn-new-conversation { padding: 12px 24px; font-size: 15px; }

    /* Welcome state mobile tweaks */
    .welcome-state { 
        border-radius: var(--radius-sm); 
        flex: 0 0 auto;
        max-height: 60vh;
    }
    .welcome-icon { width: 64px; height: 64px; }
    .welcome-icon svg { width: 36px; height: 36px; }
    .welcome-title { font-size: 18px; }
    .welcome-subtitle { font-size: 13px; }
    .welcome-connect-btn { padding: 10px 28px; font-size: 14px; }
}

/* ===== Responsive: Small Mobile (< 480px) ===== */
@media (max-width: 480px) {
    .header-brand-text { font-size: 11px; }
    .header-brand img { height: 24px; }
    .header-brand { gap: 4px; }

    .toggle-label.compact span { font-size: 12px; }

    .agent-btn { padding: 6px 12px; font-size: 12px; }

    .sidebar-scroll,
    .sidebar-footer { width: calc(100vw - 32px); }

    .conversation-end-content { padding: var(--space-lg); }

    /* PiP avatar even larger on small mobile */
    .content-area.diagram-mode .avatar-container,
    .content-area.diagram-mode .volume-animation { width: 35%; bottom: 8px; right: 8px; }

    .qr-code-image { width: 150px; height: 150px; }

    /* Welcome state smaller */
    .welcome-icon { width: 56px; height: 56px; }
    .welcome-icon svg { width: 32px; height: 32px; }
    .welcome-title { font-size: 16px; }
    .welcome-content { gap: var(--space-md); }
}

/* ===== Focus Visible ===== */
:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

input[type="range"]:focus-visible { outline: none; }

input[type="range"]:focus-visible::-webkit-slider-thumb {
    box-shadow: 0 0 0 3px var(--accent-light), 0 1px 4px rgba(177, 59, 80, 0.3);
}

button:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* ===== Safe Area (notched devices) ===== */
@supports (padding: env(safe-area-inset-bottom)) {
    .main-content {
        padding-bottom: max(var(--space-sm), env(safe-area-inset-bottom));
    }

    .footer-area {
        padding-bottom: calc(var(--space-lg) + env(safe-area-inset-bottom));
        margin-bottom: env(safe-area-inset-bottom);
    }
    .input-area {
        padding-bottom: calc(var(--space-md) + env(safe-area-inset-bottom));
        margin-bottom: env(safe-area-inset-bottom);
    }
}
