/* AGI POC - Apple-Inspired Glassmorphism UI */

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

html {
    scroll-behavior: smooth;
}

::selection {
    background: rgba(0, 0, 0, 0.15);
    color: var(--white);
}

::-moz-selection {
    background: rgba(0, 0, 0, 0.15);
    color: var(--white);
}

:root {
    --primary: #2D2D2D;
    --primary-dark: #1A1A1A;
    --secondary: #4A4A4A;
    --success: #5A5A5A;
    --danger: #8A8A8A;
    --warning: #6A6A6A;
    --dark: #1D1D1F;
    --dark-light: #2C2C2E;
    --gray: #86868B;
    --light: #F5F5F7;
    --white: #FFFFFF;
    --border: rgba(0, 0, 0, 0.08);
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(255, 255, 255, 0.2);
    --input-accent: #FF9500;
    /* Safe area for notched iPhones (X and later) and home indicator */
    --sat: env(safe-area-inset-top, 0px);
    --sab: env(safe-area-inset-bottom, 0px);
    --sal: env(safe-area-inset-left, 0px);
    --sar: env(safe-area-inset-right, 0px);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Helvetica Neue', sans-serif;
    background: linear-gradient(135deg, #e0e5ec 0%, #f5f7fa 50%, #e8eef5 100%);
    min-height: 100vh;
    min-height: -webkit-fill-available;
    padding: 0;
    margin: 0;
    color: var(--dark);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-tap-highlight-color: transparent;
}

.container {
    display: flex;
    height: 100vh;
    height: 100dvh;
    min-height: -webkit-fill-available;
    overflow: hidden;
    background: var(--white);
}

/* Sidebar Toggle Button */
.sidebar-toggle {
    position: fixed;
    top: max(12px, var(--sat));
    left: max(12px, var(--sal));
    z-index: 1001;
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--dark);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.sidebar-toggle:hover {
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.sidebar-toggle svg {
    width: 18px;
    height: 18px;
}

/* Header - Hidden for ChatGPT-style layout */
.header {
    display: none;
}

/* Main Content */
.main-content {
    display: flex;
    flex: 1;
    width: 100%;
    height: 100vh;
    position: relative;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(40px) saturate(180%);
    -webkit-backdrop-filter: blur(40px) saturate(180%);
    border-right: 1px solid rgba(0, 0, 0, 0.08);
    color: var(--dark);
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    height: 100dvh;
    min-height: -webkit-fill-available;
    padding-top: var(--sat);
    z-index: 1000;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
}

.sidebar.hidden {
    transform: translateX(-100%);
}

.sidebar-content {
    flex: 1;
    padding: 72px 12px 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.sidebar-footer {
    padding: 12px;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

/* Sidebar Buttons */
.btn-sidebar {
    background: transparent;
    color: var(--dark);
    border: none;
    width: 100%;
    text-align: left;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 400;
    cursor: pointer;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-sidebar:hover {
    background: rgba(0, 0, 0, 0.05);
}

.lang-switcher .btn-lang {
    padding: 4px 10px;
    border-radius: 6px;
    border: 1px solid rgba(0, 0, 0, 0.12);
    background: transparent;
    color: var(--dark);
    font-size: 0.8rem;
    cursor: pointer;
}
.lang-switcher .btn-lang:hover {
    background: rgba(0, 0, 0, 0.05);
}
.lang-switcher .btn-lang[aria-pressed="true"] {
    font-weight: 700;
    background: rgba(0, 0, 0, 0.08);
    border-color: rgba(0, 0, 0, 0.2);
}

.btn-danger-sidebar {
    background: transparent;
    color: var(--gray);
    border: none;
    width: 100%;
    text-align: left;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 400;
    cursor: pointer;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-danger-sidebar:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--dark);
}

/* Sidebar Sections */
.sidebar-section {
    margin-bottom: 16px;
    padding-bottom: 16px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

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

/* Your chats - small scrollable bar */
.chats-history-section {
    flex-shrink: 0;
}
.chats-history-scroll {
    max-height: 140px;
    overflow-y: auto;
    margin-bottom: 10px;
    padding-right: 4px;
}
.chats-history-scroll::-webkit-scrollbar {
    width: 6px;
}
.chats-history-scroll::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.2);
    border-radius: 3px;
}
.chats-history-empty {
    font-size: 0.8rem;
    color: var(--gray);
    padding: 8px 0;
}
.chats-history-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.chat-history-item {
    padding: 8px 10px;
    font-size: 0.85rem;
    color: var(--dark);
    background: rgba(0,0,0,0.03);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.chat-history-item:hover {
    background: rgba(0,0,0,0.06);
}
.chat-history-item-selected {
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.35);
}
.chat-history-item-selected:hover {
    background: rgba(59, 130, 246, 0.2);
}

.chat-history-item-left {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}
.chat-waiting-spinner-placeholder {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    min-width: 18px;
    min-height: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.chat-waiting-spinner,
.chat-waiting-dot {
    flex-shrink: 0;
    display: inline-block;
}
.chat-waiting-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(234, 88, 12, 0.25);
    border-top-color: #ea580c;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
.chat-waiting-dot {
    width: 10px;
    height: 10px;
    min-width: 10px;
    min-height: 10px;
    border-radius: 50%;
    background: #ea580c;
    box-shadow: 0 0 0 2px rgba(234, 88, 12, 0.35);
    animation: pulse-dot 1.2s ease-in-out infinite;
}
@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.85; transform: scale(1.05); }
}

/* Siri-style loader circles for processing message */
.central-loader-circle {
    position: relative;
    width: 80px;
    height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.central-loader-ring {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 3px solid transparent;
    border-top-color: #ea580c;
    border-right-color: #ea580c;
    animation: siri-spin 1.2s cubic-bezier(0.68, -0.55, 0.27, 1.55) infinite;
}

.central-loader-ring:nth-child(2) {
    animation-delay: 0.15s;
    border-top-color: #fb923c;
    border-right-color: #fb923c;
    opacity: 0.7;
}

.central-loader-ring:nth-child(3) {
    animation-delay: 0.3s;
    border-top-color: #fdba74;
    border-right-color: #fdba74;
    opacity: 0.5;
}

.central-loader-core {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ea580c, #fb923c);
    box-shadow: 0 0 16px rgba(234, 88, 12, 0.4);
    animation: siri-pulse 1.2s ease-in-out infinite;
}

html[data-theme="dark"] .central-loader-ring {
    border-top-color: #fb923c;
    border-right-color: #fb923c;
}

html[data-theme="dark"] .central-loader-ring:nth-child(2) {
    border-top-color: #fdba74;
    border-right-color: #fdba74;
}

html[data-theme="dark"] .central-loader-ring:nth-child(3) {
    border-top-color: #fed7aa;
    border-right-color: #fed7aa;
}

html[data-theme="dark"] .central-loader-core {
    background: linear-gradient(135deg, #fb923c, #fdba74);
    box-shadow: 0 0 16px rgba(251, 146, 60, 0.4);
}

@keyframes siri-spin {
    0% {
        transform: rotate(0deg) scale(1);
    }
    50% {
        transform: rotate(180deg) scale(1.05);
    }
    100% {
        transform: rotate(360deg) scale(1);
    }
}

@keyframes siri-pulse {
    0%, 100% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.15);
        opacity: 0.85;
    }
}

/* Avatar panel: chat-style spinner, visible only when AI is speaking (voice mode) */
.avatar-siri-wrap {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.avatar-voice-indicator {
    position: absolute;
    left: 50%;
    top: 50%;
    margin-left: -14px;
    margin-top: -14px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
}
.avatar-voice-indicator.visible {
    opacity: 1;
}
/* Same style as chat-waiting-spinner: orange border, spin animation */
.avatar-voice-spinner {
    display: block;
    width: 28px;
    height: 28px;
    border: 2px solid rgba(234, 88, 12, 0.25);
    border-top-color: #ea580c;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
html[data-theme="dark"] .avatar-voice-spinner {
    border-color: rgba(251, 146, 60, 0.3);
    border-top-color: #fb923c;
}
html[data-theme="dark"] .chat-waiting-spinner {
    border-color: rgba(251, 146, 60, 0.3);
    border-top-color: #fb923c;
}
html[data-theme="dark"] .chat-waiting-dot {
    background: #fb923c;
    box-shadow: 0 0 0 2px rgba(251, 146, 60, 0.3);
}

.chat-history-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.chat-history-delete {
    width: 26px;
    height: 26px;
    border-radius: 8px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    background: rgba(0, 0, 0, 0.04);
    color: var(--dark);
    cursor: pointer;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.chat-history-delete:hover {
    background: rgba(0, 0, 0, 0.08);
}

/* Video (live) chat sessions - separate history, reopen = view */
.video-sessions-section .video-sessions-scroll {
    max-height: 120px;
    overflow-y: auto;
    margin-bottom: 6px;
}
.video-sessions-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.video-session-item {
    padding: 6px 8px;
    font-size: 0.8rem;
    color: var(--dark);
    background: rgba(0, 0, 0, 0.04);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.video-session-item:hover {
    background: rgba(0, 0, 0, 0.08);
}
.video-session-item-selected {
    background: rgba(59, 130, 246, 0.15);
    border: 1px solid rgba(59, 130, 246, 0.35);
}
.video-session-item-selected:hover {
    background: rgba(59, 130, 246, 0.2);
}
.video-session-item-content {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}
.video-session-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.video-session-date {
    font-size: 0.7rem;
    color: var(--gray);
}
.video-session-delete {
    width: 26px;
    height: 26px;
    border-radius: 8px;
    border: 1px solid rgba(0, 0, 0, 0.08);
    background: rgba(0, 0, 0, 0.04);
    color: var(--dark);
    cursor: pointer;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.video-session-delete:hover {
    background: rgba(0, 0, 0, 0.08);
}
.video-session-modal h3 { margin: 0 0 4px 0; font-size: 1rem; }
.video-session-meta { font-size: 0.75rem; color: var(--gray); margin-bottom: 12px; }
.video-session-messages { max-height: 60vh; overflow-y: auto; margin-bottom: 12px; }
.video-session-msg { margin-bottom: 10px; }
.video-session-msg-label { font-weight: 600; font-size: 0.8rem; display: block; margin-bottom: 2px; }
.video-session-msg-user .video-session-msg-label { color: #1a365d; }
.video-session-msg-assistant .video-session-msg-label { color: #2d3748; }
.video-session-msg-content { font-size: 0.9rem; line-height: 1.4; }

/* Video session header in main chat area (when a video session is selected) */
.video-session-header {
    padding: 12px 16px;
    margin-bottom: 12px;
    background: rgba(59, 130, 246, 0.08);
    border-radius: 10px;
    border: 1px solid rgba(59, 130, 246, 0.2);
}
.video-session-header-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray);
}
.video-session-header-title {
    display: block;
    font-size: 1rem;
    font-weight: 600;
    color: var(--dark);
    margin-top: 2px;
}
.video-session-header-hint {
    font-size: 0.8rem;
    color: var(--gray);
    margin: 6px 0 0 0;
}

/* Video chat welcome (main area when Live is on, before first message) */
.video-chat-welcome {
    padding: 12px 16px;
    background: rgba(59, 130, 246, 0.08);
    border-radius: 10px;
    border: 1px solid rgba(59, 130, 246, 0.2);
}

/* Expert Remove button in Manage Experts modal */
.btn-expert-remove:hover {
    background: #FECACA !important;
}

/* User profile at bottom */
.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 0;
    margin-top: 12px;
    border-top: 1px solid rgba(0,0,0,0.06);
}
.user-avatar {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 50%;
    background: #1a365d;
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 600;
    overflow: hidden;
    cursor: pointer;
}
.user-avatar .user-avatar-img,
.user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}
.user-info {
    flex: 1;
    min-width: 0;
}
.user-name {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--dark);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.user-actions {
    display: flex;
    gap: 12px;
    margin-top: 4px;
}
.user-actions button {
    padding: 8px 12px;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--dark);
    background: rgba(0, 0, 0, 0.06);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 6px;
    cursor: pointer;
    margin-right: 4px;
}
.user-actions button:hover {
    background: rgba(0, 0, 0, 0.1);
}

/* Settings modal nav (ChatGPT-style) */
.settings-nav-item {
    padding: 10px 12px;
    font-size: 0.9rem;
    cursor: pointer;
    border-radius: 8px;
    color: var(--gray);
}
.settings-nav-item:hover {
    background: rgba(0,0,0,0.04);
    color: var(--dark);
}
.settings-nav-item.active {
    background: rgba(0,0,0,0.06);
    color: var(--dark);
    font-weight: 500;
}

.section-label {
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--gray);
    margin-bottom: 8px;
    font-weight: 600;
}

.scaling-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.02);
    border-radius: 8px;
    font-size: 0.8125rem;
    margin-bottom: 8px;
    color: var(--dark);
}

.scaling-info strong {
    color: var(--dark);
    font-weight: 500;
}

/* System Agent status (orange circle) */
.system-agent-status-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
}
.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.status-dot-orange {
    background: #FF9500;
}
.status-dot-orange.disconnected {
    background: #86868B;
    opacity: 0.7;
}
.system-agent-status-text {
    font-size: 0.85rem;
    color: var(--gray);
}

/* Hide expert count until first API response */
.scaling-info strong.expert-count-pending {
    visibility: hidden;
}

.btn-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-bottom: 6px;
}

.btn-sidebar-small {
    background: rgba(0, 0, 0, 0.03);
    color: var(--dark);
    border: none;
    padding: 7px 10px;
    border-radius: 8px;
    font-size: 0.8125rem;
    font-weight: 400;
    cursor: pointer;
    transition: all 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-sidebar-small:hover {
    background: rgba(0, 0, 0, 0.06);
}

/* Human-like / Turing Test mode toggle */
.human-like-toggle {
    padding: 10px 12px;
    background: rgba(0, 0, 0, 0.03);
    border-radius: 8px;
    border: 1px solid rgba(0, 0, 0, 0.08);
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--dark);
}

.toggle-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
    cursor: pointer;
}

.expert-toggles-mini {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 8px;
}

.expert-toggle-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
    background: rgba(0, 0, 0, 0.02);
    border-radius: 6px;
    font-size: 0.8125rem;
    color: var(--dark);
}

.expert-toggle-btn {
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.6875rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all 0.15s;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.expert-toggle-btn.active {
    background: rgba(0, 0, 0, 0.5);
    color: var(--white);
}

.expert-toggle-btn.inactive {
    background: rgba(0, 0, 0, 0.06);
    color: var(--gray);
}

.expert-toggle-btn:hover {
    opacity: 0.8;
}

/* Sidebar Groups */
.sidebar-group {
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-group:last-child {
    border-bottom: none;
}

.sidebar-group-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.5;
    margin-bottom: 10px;
}

/* Stat Rows */
.stat-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 14px;
    border-radius: 6px;
    font-size: 0.875rem;
    margin-bottom: 4px;
    background: rgba(255, 255, 255, 0.05);
}

.stat-row span:first-child {
    opacity: 0.7;
}

.stat-row span:last-child {
    font-weight: 600;
    color: var(--primary);
}

/* Expert List Compact */
.expert-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 8px;
}

.expert-item-compact {
    padding: 6px 10px;
    background: rgba(255, 255, 255, 0.08);
    border-radius: 6px;
    font-size: 0.8rem;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.expert-item-compact.active {
    background: rgba(0, 0, 0, 0.08);
    border-color: rgba(0, 0, 0, 0.15);
}

.expert-item-compact.inactive {
    opacity: 0.4;
}

/* Expert Toggles */
.expert-toggles {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 8px 0;
}

.expert-toggle {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 14px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 6px;
    font-size: 0.8rem;
}

.expert-toggle-label {
    opacity: 0.85;
}

.expert-toggle-btn {
    padding: 4px 12px;
    font-size: 0.75rem;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    color: var(--white);
    cursor: pointer;
    transition: all 0.2s;
}

.expert-toggle-btn:hover {
    background: rgba(255, 255, 255, 0.2);
}

.expert-toggle-btn.active {
    background: var(--success);
    border-color: var(--success);
}

/* Button Group */
.button-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    margin-bottom: 6px;
}


/* Chat Container */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    width: 100%;
    margin-left: 0;
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: transparent;
}

.sidebar:not(.hidden) ~ .chat-container {
    margin-left: 260px;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
    padding: 24px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    background: transparent;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
}

.welcome-message {
    text-align: center;
    padding: 16px 24px;
    margin: 0;
    color: var(--dark);
}

.welcome-message h2 {
    color: var(--dark);
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 1.5rem;
    letter-spacing: -0.5px;
}

.welcome-message p {
    color: var(--gray);
    font-size: 0.875rem;
    font-weight: 400;
}

/* Message Bubbles */
.message {
    margin-bottom: 20px;
    animation: fadeIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

@media (max-width: 768px) {
    .message:first-child {
        margin-top: 50px;
    }
}

@keyframes fadeIn {
    from { 
        opacity: 0; 
        transform: translateY(15px) scale(0.95);
    }
    to { 
        opacity: 1; 
        transform: translateY(0) scale(1);
    }
}

.message-user {
    display: flex;
    justify-content: flex-end;
}

.message-ai {
    display: flex;
    justify-content: flex-start;
}

.message-bubble {
    max-width: 100%;
    padding: 16px 0;
    position: relative;
}

.message-user .message-bubble {
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(0, 0, 0, 0.06);
    color: var(--dark);
    padding: 12px 18px;
    border-radius: 18px;
}

.message-ai .message-bubble {
    background: transparent;
    color: var(--dark);
}

.message-label {
    font-size: 0.875rem;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--dark);
}

.message-content {
    line-height: 1.6;
    font-size: 1rem;
}

.message-attachment-summary {
    margin-top: 8px;
    padding: 6px 10px;
    font-size: 0.8rem;
    color: var(--gray);
    background: rgba(0, 0, 0, 0.05);
    border-radius: 6px;
    border-left: 3px solid #2563eb;
}

.message-attachment-sent {
    border-left-color: #059669;
    color: #047857;
}

.message-attachment-none {
    border-left-color: var(--gray);
    color: var(--gray);
    font-style: italic;
}

.message-text {
    line-height: 1.6;
    white-space: pre-wrap;
    font-size: 1rem;
}

/* Code block window (ChatGPT / Claude / Cursor style) */
.message-code-block {
    margin: 12px 0;
    border-radius: 10px;
    overflow: hidden;
    border: 1px solid var(--border);
    background: var(--code-bg, #1e1e1e);
    max-width: 100%;
}

.message-code-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.25);
    border-bottom: 1px solid var(--border);
    font-size: 0.8125rem;
}

.message-code-block-lang {
    color: var(--gray);
    text-transform: capitalize;
    font-weight: 500;
}

.message-code-block-copy {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #e5e5e5;
    padding: 4px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.75rem;
    transition: background 0.15s, border-color 0.15s;
}

.message-code-block-copy:hover {
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.3);
}

.message-code-block-copy-done {
    color: #86efac;
    border-color: rgba(134, 239, 172, 0.4);
}

.message-code-block-content {
    max-height: 400px;
    overflow: auto;
    padding: 12px 16px;
}

.message-code-block-content pre {
    margin: 0;
    padding: 0;
    font-family: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
    font-size: 0.875rem;
    line-height: 1.5;
    white-space: pre;
    color: #e5e5e5;
}

.message-code-block-content code {
    font-family: inherit;
    background: none;
    padding: 0;
}

.processing-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 32px 20px;
    margin-bottom: 20px;
    background: rgba(59, 130, 246, 0.05);
    border-radius: 12px;
    animation: fadeIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--dark);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

.expert-analyses {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.expert-analysis {
    margin: 10px 0;
    padding: 12px 0;
    font-size: 0.9375rem;
    line-height: 1.6;
}

.expert-name {
    font-weight: 600;
    color: var(--dark);
    margin-bottom: 4px;
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.6;
}

/* Chat Input */
.main-status-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    font-size: 0.8rem;
    color: var(--gray);
}
.main-status-label {
    font-weight: 500;
    color: var(--dark);
}
.main-status-value {
    font-weight: 500;
}
html[data-theme="dark"] .main-status-label {
    color: #e5e5e7;
}
html[data-theme="dark"] .main-status-row {
    color: #a1a1a6;
}

.chat-input-container {
    padding: 16px 20px 20px;
    background: transparent;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 6px 8px 6px 12px;
    border: 2px solid var(--input-accent);
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.btn-voice {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    background: rgba(0, 0, 0, 0.04);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    color: var(--gray);
}

.btn-voice:hover {
    background: rgba(0, 0, 0, 0.08);
    color: var(--dark);
    border-color: rgba(0, 0, 0, 0.12);
}

.btn-voice.recording {
    background: rgba(255, 59, 48, 0.15);
    color: #ff3b30;
    border-color: rgba(255, 59, 48, 0.3);
    animation: pulse-recording 1.5s ease-in-out infinite;
}

@keyframes pulse-recording {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.85; }
}

.hidden {
    display: none !important;
}

.voice-transcript {
    padding: 10px 14px;
    background: rgba(0, 0, 0, 0.04);
    border-radius: 12px;
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--dark);
    border: 1px solid rgba(0, 0, 0, 0.08);
}

.voice-transcript.hidden {
    display: none;
}

.voice-transcript .interim {
    color: var(--gray);
}

.attachment-preview-wrap {
    margin-top: 6px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.04);
    border-radius: 10px;
    border: 1px solid rgba(0, 0, 0, 0.08);
}

.attachment-preview-wrap:has(.attachment-preview.hidden) {
    display: none;
}

.attachment-chip-uploading {
    opacity: 0.85;
}

.attachment-preview-label {
    font-size: 0.75rem;
    color: var(--gray);
    margin-bottom: 6px;
    font-weight: 500;
}

.attachment-preview-label.hidden {
    display: none !important;
}

.attachment-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 4px;
    padding: 0;
}

.attachment-preview.hidden {
    display: none !important;
}

.attachment-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 9px;
    background: rgba(0, 0, 0, 0.06);
    border-radius: 8px;
    font-size: 0.8rem;
    color: var(--dark);
    border: 1px solid rgba(0, 0, 0, 0.08);
}

.attachment-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--gray);
}

.attachment-icon-image {
    color: #2563eb;
}

.attachment-chip .attachment-name {
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.attachment-chip .attachment-remove {
    width: 18px;
    height: 18px;
    padding: 0;
    background: none;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    color: var(--gray);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    line-height: 1;
}

.attachment-chip .attachment-remove:hover {
    background: rgba(255, 59, 48, 0.15);
    color: #ff3b30;
}

/* Floating panels (draggable) */
.floating-panel {
    position: fixed;
    z-index: 999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}
.panel-drag-handle {
    cursor: move;
    user-select: none;
    -webkit-user-select: none;
}

/* Camera Panel */
.camera-panel {
    left: calc(100vw - 344px);
    top: calc(100vh - 500px);
    width: 320px;
    max-height: 400px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.camera-panel.hidden {
    display: none !important;
}

/* Avatar Panel - Siri-sized (iPhone/Mac), transparent, just the orb, draggable */
.avatar-panel {
    left: calc(100vw - 88px);
    top: 24px;
    width: 64px;
    height: 64px;
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    overflow: visible;
}
.avatar-panel.hidden {
    display: none !important;
}
.avatar-container {
    position: relative;
    z-index: 1;
    width: 64px;
    height: 64px;
    min-width: 64px;
    min-height: 64px;
    background: transparent;
    border-radius: 50%;
    cursor: move;
}
.avatar-container canvas {
    display: block;
    width: 100% !important;
    height: 100% !important;
    border-radius: 50%;
    pointer-events: none;
}
.avatar-fallback {
    width: 100%;
    height: 100%;
    min-height: 80px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255,255,255,0.7);
    font-size: 0.875rem;
    padding: 16px;
    text-align: center;
}

.camera-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: rgba(0, 0, 0, 0.04);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--dark);
}

.btn-close-camera {
    width: 28px;
    height: 28px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 50%;
    font-size: 1.25rem;
    color: var(--gray);
    cursor: pointer;
    transition: all 0.2s;
}

.btn-close-camera:hover {
    background: rgba(0, 0, 0, 0.06);
    color: var(--dark);
}

.camera-panel-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.camera-video {
    width: 100%;
    aspect-ratio: 4/3;
    object-fit: cover;
    background: #000;
}

.camera-transcript {
    padding: 12px 16px;
    flex: 1;
    min-height: 80px;
    max-height: 120px;
    overflow-y: auto;
}

.camera-transcript-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--gray);
    margin-bottom: 8px;
    font-weight: 600;
}

.camera-transcript-text {
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--dark);
}

.camera-transcript-text .interim {
    color: var(--gray);
}

.camera-vlm-hint {
    font-size: 0.75rem;
    color: var(--gray);
    margin-top: 8px;
    margin-bottom: 8px;
    line-height: 1.4;
}

.live-option-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--dark);
    margin-top: 6px;
    cursor: pointer;
}

.btn-use-transcript {
    margin-top: 10px;
    padding: 8px 14px;
    background: rgba(0, 0, 0, 0.05);
    color: var(--dark);
    border: 1px solid rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    font-size: 0.8125rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-use-transcript:hover {
    background: rgba(0, 0, 0, 0.08);
}

.live-response-section {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
}
.live-response-section.hidden {
    display: none;
}
.live-response-section {
    flex-shrink: 0;
    min-height: 72px;
}
.live-response-status {
    min-height: 1.4em;
}

.live-response-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--gray);
    margin-bottom: 6px;
    font-weight: 600;
}
.live-response-status {
    font-size: 0.8rem;
    color: var(--gray);
    margin-bottom: 6px;
    min-height: 1.2em;
}
.live-response-text {
    font-size: 0.9rem;
    line-height: 1.5;
    color: var(--dark);
    background: rgba(0, 0, 0, 0.04);
    padding: 10px 12px;
    border-radius: 8px;
    border-left: 3px solid var(--primary);
}

#liveBtn.recording .icon-live { display: none; }
#liveBtn.recording .icon-live-stop { display: block; }
#liveBtn .icon-live-stop { display: none; }
#liveBtn .icon-live { display: block; }

.chat-input {
    flex: 1;
    padding: 10px 12px;
    background: transparent;
    border: none;
    border-radius: 18px;
    font-size: 0.9375rem;
    font-family: inherit;
    resize: none;
    color: var(--dark);
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    max-height: 200px;
    min-height: 44px;
    line-height: 1.5;
}

.chat-input:focus {
    outline: none;
}

.chat-input::placeholder {
    color: var(--gray);
}

.btn-send {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    background: rgba(0, 0, 0, 0.05);
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    color: var(--gray);
}

.btn-send:hover {
    background: rgba(0, 0, 0, 0.1);
}

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

.btn-send svg {
    width: 20px;
    height: 20px;
}

/* Focus visible styles for accessibility */
*:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

button:focus-visible {
    outline-offset: 4px;
}

/* Additional polish */
.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.btn:active:not(:disabled) {
    transform: scale(0.98);
}

/* Smooth transitions for all interactive elements */
a, button, input, textarea, select {
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Buttons */
.btn {
    padding: 10px 18px;
    border: none;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 400;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
}

.btn-primary {
    background: rgba(0, 0, 0, 0.8);
    color: var(--white);
    border: none;
}

.btn-primary:hover {
    background: rgba(0, 0, 0, 0.9);
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-secondary {
    background: rgba(0, 0, 0, 0.04);
    color: var(--dark);
    border: none;
    width: 100%;
    margin-bottom: 8px;
}

.btn-secondary:hover {
    background: rgba(0, 0, 0, 0.08);
}

.btn-danger {
    background: rgba(0, 0, 0, 0.06);
    color: var(--dark);
    width: 100%;
    border: none;
}

.btn-danger:hover {
    background: rgba(0, 0, 0, 0.1);
}

/* Modal buttons (Settings, etc.) */
.btn-modal {
    flex: 1;
    padding: 12px 24px;
    font-size: 0.9375rem;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-modal-primary {
    background: #2D2D2D;
    color: white;
}
.btn-modal-primary:hover {
    background: #1D1D1F;
}
.btn-modal-secondary {
    background: #E5E7EB;
    color: #1D1D1F;
}
.btn-modal-secondary:hover {
    background: #D2D2D7;
}

/* Login page secondary buttons (Create account, Continue without sign in) */
.btn-login-link {
    padding: 10px 16px;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--dark);
    background: rgba(0, 0, 0, 0.04);
    border: 1px solid #D2D2D7;
    border-radius: 8px;
    cursor: pointer;
}
.btn-login-link:hover {
    background: rgba(0, 0, 0, 0.08);
}


/* Notifications */
.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 14px 20px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    z-index: 2000;
    transform: translateX(400px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    max-width: 340px;
    font-size: 0.875rem;
    font-weight: 400;
    color: var(--dark);
}

.notification.show {
    transform: translateX(0);
}

.notification-success,
.notification-error,
.notification-info {
    color: var(--dark);
}


/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    animation: fadeIn 0.2s;
}

.modal-content {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(40px) saturate(180%);
    -webkit-backdrop-filter: blur(40px) saturate(180%);
    border: 1px solid rgba(0, 0, 0, 0.08);
    margin: 5% auto;
    padding: 32px;
    width: 90%;
    max-width: 700px;
    max-height: 80vh;
    overflow-y: auto;
    border-radius: 20px;
    position: relative;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
    animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.close {
    position: absolute;
    right: 24px;
    top: 24px;
    width: 32px;
    height: 32px;
    font-size: 1.8rem;
    cursor: pointer;
    color: var(--gray);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.close:hover {
    color: var(--dark);
    background: rgba(0, 0, 0, 0.05);
    transform: scale(1.1);
}

/* Generated image in chat (ChatGPT-style): card + separate window with download */
.message-generated-image-wrap {
    margin: 12px 0;
}
.message-generated-image-card {
    display: inline-block;
    max-width: 100%;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid rgba(0, 0, 0, 0.08);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
    cursor: pointer;
    transition: box-shadow 0.2s, transform 0.2s;
    background: rgba(0, 0, 0, 0.03);
}
.message-generated-image-card:hover {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
    transform: scale(1.01);
}
.message-generated-image-thumb {
    display: block;
    max-width: 100%;
    max-height: 320px;
    width: auto;
    height: auto;
    vertical-align: middle;
}
.message-generated-image-hint {
    display: block;
    font-size: 0.75rem;
    color: var(--gray);
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.04);
}
.generated-image-modal {
    width: 100%;
    max-width: 90vw;
}
.generated-image-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
}
.generated-image-modal-title {
    font-weight: 600;
    font-size: 1.1rem;
}
.generated-image-modal-actions {
    display: flex;
    gap: 8px;
}
.generated-image-modal-body {
    text-align: center;
    background: rgba(0, 0, 0, 0.04);
    border-radius: 12px;
    padding: 16px;
    overflow: auto;
    max-height: 70vh;
}
.generated-image-modal-img {
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    display: block;
    margin: 0 auto;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 10px;
}

::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
}

::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 10px;
    border: 2px solid transparent;
    background-clip: padding-box;
    transition: all 0.2s;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.35);
    background-clip: padding-box;
}

/* Responsive – tablets and below */
@media (max-width: 768px) {
    body {
        padding: 0;
        margin: 0;
    }

    .container {
        height: 100vh;
        height: 100dvh;
        min-height: -webkit-fill-available;
        border-radius: 0;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }

    /* 44px min touch target (Apple HIG) for hamburger */
    .sidebar-toggle {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
    }

    /* Mobile: sidebar as overlay; keep slide toggle, don't force display:none */
    .sidebar {
        width: min(300px, 85vw);
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
    }
    .sidebar.hidden {
        transform: translateX(-100%);
    }
    /* Sidebar overlay: tap to close on mobile */
    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 999;
        pointer-events: none;
    }
    .main-content.sidebar-open .sidebar-overlay {
        display: block;
        pointer-events: auto;
    }
    /* Keep chat full-width on mobile; sidebar overlays */
    .sidebar:not(.hidden) ~ .chat-container {
        margin-left: 0;
    }

    /* Chat container - 80% height to push content up by 20% */
    .chat-container {
        position: relative;
        z-index: 1;
        width: 100%;
        margin-left: 0 !important;
        display: flex;
        flex-direction: column;
        height: 80vh;
        height: 80dvh;
        max-height: 80vh;
        max-height: 80dvh;
        align-self: flex-start;
    }

    /* Chat messages area - scrollable */
    .chat-messages {
        padding: 16px;
        padding-top: 16px;
        padding-bottom: 16px;
        flex: 1 1 auto;
        overflow-y: auto;
        overflow-x: hidden;
        -webkit-overflow-scrolling: touch;
        max-width: 100%;
        min-height: 0;
    }

    /* Chat input - always visible at bottom */
    .chat-input-container {
        flex: 0 0 auto;
        position: relative;
        z-index: 2;
        background: var(--white);
        padding: 16px;
        padding-bottom: max(16px, var(--sab));
        border-top: 1px solid rgba(0, 0, 0, 0.08);
    }

    /* Adjust message bubbles for better mobile display */
    .message-bubble {
        max-width: 90%;
    }

    .welcome-message {
        padding: 0 20px 16px;
        margin: 0;
        margin-top: 50px;
    }

    .header {
        padding: 24px 20px;
    }

    .header h1 {
        font-size: 2rem;
    }

    .subtitle {
        font-size: 1rem;
    }

    .message-bubble {
        max-width: 85%;
    }

    /* 16px input prevents iOS zoom on focus (all iPhones) */
    .chat-input {
        font-size: 16px;
    }

    .chat-input-container {
        padding: 16px;
        padding-left: max(16px, var(--sal));
        padding-right: max(16px, var(--sar));
        padding-bottom: max(16px, var(--sab));
        gap: 12px;
    }

    .modal-content {
        margin: 10% auto;
        margin-bottom: max(10%, var(--sab));
        padding: 24px;
        padding-bottom: max(24px, var(--sab));
        width: 95%;
        max-height: calc(100vh - 20px);
        max-height: calc(100dvh - 20px);
    }

    /* Fixed panels: respect safe area on iPhones */
    .camera-panel {
        left: max(16px, var(--sal));
        right: max(16px, var(--sar));
        top: max(calc(100vh - 420px), var(--sat));
        width: auto;
        max-width: calc(100vw - 32px);
    }
    .avatar-panel {
        left: auto;
        right: max(24px, var(--sar));
        top: max(24px, var(--sat));
    }
    .notification {
        top: max(20px, var(--sat));
        right: max(20px, var(--sar));
        left: max(20px, var(--sal));
        max-width: calc(100vw - 40px);
    }
    .close {
        top: max(24px, var(--sat));
        right: max(24px, var(--sar));
    }

    /* Login page: safe areas on iPhones */
    .login-page {
        padding: max(24px, var(--sat)) max(16px, var(--sar)) max(24px, var(--sab)) max(16px, var(--sal));
        min-height: 100vh;
        min-height: 100dvh;
        min-height: -webkit-fill-available;
    }
    .login-card {
        padding: 32px 24px;
        padding-bottom: max(32px, var(--sab));
    }
}

/* Small phones (e.g. iPhone SE, 12/13 mini) */
@media (max-width: 390px) {
    body {
        padding: 0;
        margin: 0;
    }

    .container {
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
    }

    .sidebar {
        width: min(280px, 90vw);
    }

    .chat-container {
        width: 100%;
        height: 80vh;
        height: 80dvh;
        max-height: 80vh;
        max-height: 80dvh;
        align-self: flex-start;
    }

    .chat-messages {
        padding: 12px;
        padding-top: 16px;
        padding-bottom: 12px;
        min-height: 0;
        flex: 1 1 auto;
    }

    .welcome-message {
        padding: 0 12px 12px;
        margin: 0;
        margin-top: 50px;
    }
    
    /* Reduce spacing between messages on mobile */
    .message {
        margin-bottom: 12px;
    }
    
    /* First message should start high */
    .message:first-child {
        margin-top: 50px;
    }

    .chat-input-container {
        flex: 0 0 auto;
        padding: 12px;
        padding-bottom: max(12px, var(--sab));
    }

    .modal-content {
        width: 98%;
        padding: 20px;
        padding-bottom: max(20px, var(--sab));
    }
}

/* ========== Dark mode (data-theme="dark" on html) ========== */
html[data-theme="dark"] {
    color-scheme: dark;
}

html[data-theme="dark"] body {
    background: linear-gradient(135deg, #0f0f12 0%, #1a1a1f 50%, #151518 100%);
    color: #e5e5e7;
}

html[data-theme="dark"] .container {
    background: #1c1c1e;
}

html[data-theme="dark"] .sidebar-toggle {
    background: rgba(44, 44, 46, 0.9);
    border-color: rgba(255, 255, 255, 0.08);
    color: #e5e5e7;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}
html[data-theme="dark"] .sidebar-toggle:hover {
    background: rgba(58, 58, 60, 0.95);
}

html[data-theme="dark"] .sidebar {
    background: rgba(28, 28, 30, 0.92);
    border-right-color: rgba(255, 255, 255, 0.08);
    color: #e5e5e7;
}

html[data-theme="dark"] .sidebar-footer {
    border-top-color: rgba(255, 255, 255, 0.08);
}

html[data-theme="dark"] .btn-sidebar,
html[data-theme="dark"] .btn-danger-sidebar {
    color: #e5e5e7;
}
html[data-theme="dark"] .btn-sidebar:hover,
html[data-theme="dark"] .btn-danger-sidebar:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}
html[data-theme="dark"] .btn-danger-sidebar {
    color: #a1a1a6;
}

html[data-theme="dark"] .sidebar-section {
    border-bottom-color: rgba(255, 255, 255, 0.08);
}

html[data-theme="dark"] .chats-history-scroll::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
}
html[data-theme="dark"] .chats-history-empty {
    color: #a1a1a6;
}
html[data-theme="dark"] .chat-history-item {
    color: #e5e5e7;
    background: rgba(255, 255, 255, 0.06);
}
html[data-theme="dark"] .chat-history-item:hover {
    background: rgba(255, 255, 255, 0.1);
}
html[data-theme="dark"] .chat-history-item-selected {
    background: rgba(59, 130, 246, 0.25);
    border-color: rgba(59, 130, 246, 0.45);
}
html[data-theme="dark"] .chat-history-item-selected:hover {
    background: rgba(59, 130, 246, 0.3);
}
html[data-theme="dark"] .chat-history-delete {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.12);
    color: #e5e5e7;
}
html[data-theme="dark"] .chat-history-delete:hover {
    background: rgba(255, 255, 255, 0.15);
}
html[data-theme="dark"] .video-session-delete {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.12);
    color: #e5e5e7;
}
html[data-theme="dark"] .video-session-delete:hover {
    background: rgba(255, 255, 255, 0.15);
}

html[data-theme="dark"] .section-label {
    color: #a1a1a6;
}
html[data-theme="dark"] .scaling-info {
    color: #e5e5e7;
}
html[data-theme="dark"] .scaling-info strong {
    color: #e5e5e7;
}
html[data-theme="dark"] .status-dot-orange {
    background: #FF9500;
}
html[data-theme="dark"] .status-dot-orange.disconnected {
    background: #6e6e73;
    opacity: 0.8;
}
html[data-theme="dark"] .system-agent-status-text {
    color: #a1a1a6;
}
html[data-theme="dark"] .btn-sidebar-small {
    background: rgba(255, 255, 255, 0.08);
    color: #e5e5e7;
}
html[data-theme="dark"] .btn-sidebar-small:hover {
    background: rgba(255, 255, 255, 0.15);
}
html[data-theme="dark"] .human-like-toggle {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
}
html[data-theme="dark"] .toggle-label {
    color: #e5e5e7;
}
html[data-theme="dark"] .expert-toggle-item {
    background: rgba(255, 255, 255, 0.05);
    color: #e5e5e7;
}
html[data-theme="dark"] .expert-toggle-btn.inactive {
    background: rgba(255, 255, 255, 0.1);
    color: #a1a1a6;
}
html[data-theme="dark"] .expert-toggle-btn.active {
    background: rgba(255, 255, 255, 0.25);
    color: #fff;
}

html[data-theme="dark"] .user-avatar {
    background: #3a3a3c;
    color: #e5e5e7;
}
html[data-theme="dark"] .user-name {
    color: #e5e5e7;
}
html[data-theme="dark"] .user-actions button {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.12);
    color: #e5e5e7;
}
html[data-theme="dark"] .user-actions button:hover {
    background: rgba(255, 255, 255, 0.18);
}

html[data-theme="dark"] .chat-container {
    background: #1c1c1e;
}
html[data-theme="dark"] .welcome-message h2,
html[data-theme="dark"] .welcome-message p {
    color: #a1a1a6;
}
html[data-theme="dark"] .message-bubble.user {
    background: rgba(99, 102, 241, 0.35);
    border-color: rgba(99, 102, 241, 0.4);
    color: #e5e5e7;
}
html[data-theme="dark"] .message-bubble.ai {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.1);
    color: #e5e5e7;
}
html[data-theme="dark"] .message-bubble .message-text {
    color: #e5e5e7;
}

html[data-theme="dark"] .message-attachment-summary {
    background: rgba(255, 255, 255, 0.08);
    color: #a1a1a6;
    border-left-color: #5e9cff;
}
html[data-theme="dark"] .chat-input-container {
    background: #1c1c1e;
    border-top-color: rgba(255, 255, 255, 0.08);
}
html[data-theme="dark"] .chat-input-row {
    border-color: var(--input-accent);
    background: rgba(44, 44, 46, 0.9);
}
html[data-theme="dark"] .chat-input {
    background: transparent;
    border: none;
    color: #e5e5e7;
}
html[data-theme="dark"] .chat-input:focus {
    background: transparent;
}
html[data-theme="dark"] .chat-input::placeholder {
    color: #636366;
}
html[data-theme="dark"] .btn-send {
    background: rgba(255, 255, 255, 0.1);
    color: #a1a1a6;
}
html[data-theme="dark"] .btn-send:hover {
    background: rgba(255, 255, 255, 0.18);
    color: #e5e5e7;
}

html[data-theme="dark"] .modal {
    background: rgba(0, 0, 0, 0.6);
}
html[data-theme="dark"] .modal-content {
    background: rgba(28, 28, 30, 0.98);
    border-color: rgba(255, 255, 255, 0.1);
    color: #e5e5e7;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}
html[data-theme="dark"] .modal-content h2,
html[data-theme="dark"] .modal-content h3 {
    color: #e5e5e7;
}
html[data-theme="dark"] .modal-content label {
    color: #e5e5e7;
}
html[data-theme="dark"] .modal-content input,
html[data-theme="dark"] .modal-content select,
html[data-theme="dark"] .modal-content textarea {
    background: rgba(44, 44, 46, 0.8);
    border-color: rgba(255, 255, 255, 0.15);
    color: #e5e5e7;
}
html[data-theme="dark"] .modal-content input::placeholder {
    color: #636366;
}
html[data-theme="dark"] .close {
    color: #a1a1a6;
}
html[data-theme="dark"] .message-generated-image-card {
    border-color: rgba(255, 255, 255, 0.12);
    background: rgba(255, 255, 255, 0.05);
}
html[data-theme="dark"] .message-generated-image-card:hover {
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}
html[data-theme="dark"] .message-generated-image-hint {
    color: #a1a1a6;
    background: rgba(255, 255, 255, 0.06);
}
html[data-theme="dark"] .generated-image-modal-header {
    border-bottom-color: rgba(255, 255, 255, 0.1);
}
html[data-theme="dark"] .generated-image-modal-title {
    color: #e5e5e7;
}
html[data-theme="dark"] .generated-image-modal-body {
    background: rgba(255, 255, 255, 0.06);
}
html[data-theme="dark"] .close:hover {
    color: #e5e5e7;
    background: rgba(255, 255, 255, 0.1);
}
html[data-theme="dark"] .btn-modal-secondary {
    background: #3a3a3c;
    color: #e5e5e7;
}
html[data-theme="dark"] .btn-modal-secondary:hover {
    background: #48484a;
}
html[data-theme="dark"] .settings-nav-item {
    color: #a1a1a6;
}
html[data-theme="dark"] .settings-nav-item:hover,
html[data-theme="dark"] .settings-nav-item.active {
    background: rgba(255, 255, 255, 0.08);
    color: #e5e5e7;
}

/* API Keys section - theme-aware (matches General/other settings) */
.api-keys-add-form {
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 12px;
    background: rgba(0, 0, 0, 0.04);
    border: 1px solid rgba(0, 0, 0, 0.08);
}
.api-key-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 8px;
    background: rgba(0, 0, 0, 0.04);
    border: 1px solid rgba(0, 0, 0, 0.08);
}
html[data-theme="dark"] .api-keys-add-form,
html[data-theme="dark"] .api-key-item {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.1);
}
.api-key-meta {
    font-size: 0.8rem;
    opacity: 0.75;
}
.api-key-lastused {
    font-size: 0.75rem;
    opacity: 0.65;
    margin-top: 4px;
}
.api-keys-empty {
    font-size: 0.9rem;
    opacity: 0.8;
}
.api-key-btn {
    font-size: 0.8rem;
    padding: 4px 10px;
}
.api-key-delete {
    color: #ef4444;
}
html[data-theme="dark"] .api-key-delete {
    color: #f87171;
}

html[data-theme="dark"] .notification {
    background: rgba(44, 44, 46, 0.98);
    border-color: rgba(255, 255, 255, 0.1);
    color: #e5e5e7;
}

html[data-theme="dark"] .floating-panel {
    background: rgba(28, 28, 30, 0.95);
    border-color: rgba(255, 255, 255, 0.1);
    color: #e5e5e7;
}
html[data-theme="dark"] .camera-panel-content .camera-transcript-label,
html[data-theme="dark"] .live-response-label {
    color: #a1a1a6;
}
html[data-theme="dark"] .live-response-text,
html[data-theme="dark"] .camera-transcript-text {
    background: rgba(255, 255, 255, 0.06);
    color: #e5e5e7;
}

html[data-theme="dark"] .btn-voice {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.12);
    color: #a1a1a6;
}
html[data-theme="dark"] .btn-voice:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #e5e5e7;
}
html[data-theme="dark"] .attachment-preview-wrap {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.1);
}
html[data-theme="dark"] .attachment-preview-label {
    color: #a1a1a6;
}
html[data-theme="dark"] .attachment-icon-image {
    color: #5e9cff;
}
html[data-theme="dark"] .attachment-chip {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.12);
    color: #e5e5e7;
}
html[data-theme="dark"] .attachment-chip .attachment-remove {
    color: #a1a1a6;
}
html[data-theme="dark"] .attachment-chip .attachment-remove:hover {
    background: rgba(255, 59, 48, 0.2);
    color: #ff6b6b;
}
html[data-theme="dark"] .loading-spinner {
    border-color: rgba(255, 255, 255, 0.2);
    border-top-color: #e5e5e7;
}
html[data-theme="dark"] .message-code-block {
    border-color: rgba(255, 255, 255, 0.12);
}
html[data-theme="dark"] .expert-analyses,
html[data-theme="dark"] .expert-detail {
    color: #a1a1a6;
}
html[data-theme="dark"] .expert-analyses .expert-name,
html[data-theme="dark"] .expert-detail .expert-name {
    color: #fff;
}

html[data-theme="dark"] ::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}
html[data-theme="dark"] ::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
}
html[data-theme="dark"] ::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.35);
}

/* Dark mode mobile fixes */
@media (max-width: 768px) {
    html[data-theme="dark"] .chat-input-container {
        background: #1c1c1e;
    }

    html[data-theme="dark"] .chat-container {
        background: #1c1c1e;
    }
}

/* Login page dark mode */
html[data-theme="dark"] .login-page {
    background: #0f0f12;
}
html[data-theme="dark"] .login-card {
    background: #1c1c1e;
}
html[data-theme="dark"] .aaa-logo span {
    color: #e5e5e7;
}
html[data-theme="dark"] .aaa-logo .divider {
    background: #e5e5e7;
}
html[data-theme="dark"] .login-card h1 {
    color: #e5e5e7;
}
html[data-theme="dark"] .login-card .subtitle {
    color: #a1a1a6;
}
html[data-theme="dark"] .login-form label {
    color: #e5e5e7;
}
html[data-theme="dark"] .login-form input {
    background: #2c2c2e;
    border-color: rgba(255, 255, 255, 0.15);
    color: #e5e5e7;
}
html[data-theme="dark"] .login-form input:focus {
    border-color: #6366f1;
}
html[data-theme="dark"] .login-form input::placeholder {
    color: #636366;
}
html[data-theme="dark"] .login-form .btn-submit {
    background: #6366f1;
    color: #fff;
}
html[data-theme="dark"] .login-form .btn-submit:hover {
    background: #4f46e5;
}
html[data-theme="dark"] .btn-login-secondary {
    background: #3a3a3c;
    color: #e5e5e7;
}
html[data-theme="dark"] .btn-login-secondary:hover {
    background: #48484a;
}
