/**
 * AI Assistant Styles
 * Extends glassmorphic-theme.css for AI Assistant page
 */

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

html {
    height: 100%;
    height: 100vh;
    height: 100dvh;  /* Dynamic viewport height for mobile */
    overflow: hidden;  /* Prevent page scroll - only chat scrolls */
}

body {
    font-family: 'Roboto', sans-serif;
    background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
    color: #fff;
    height: 100%;      /* STRICT height - no expansion */
    max-height: 100vh;
    max-height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;  /* Contain everything - only internal scroll */
}

.main-container {
    /* Fluid width: fills screen with max constraint */
    width: 100%;
    max-width: min(1800px, 98vw);
    margin: 0 auto;
    padding: 0.75rem clamp(0.5rem, 2vw, 2rem);
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;  /* Contain children - prevents chat from pushing page down */
    min-height: 0;  /* Critical for nested flex scrolling */
}

/* Page Header */
.page-header {
    text-align: center;
    margin-bottom: 0.75rem;
    flex-shrink: 0;  /* Don't shrink header */
}

.page-title {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.5rem;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.15rem;
}

.page-subtitle {
    font-size: 0.85rem;
    opacity: 0.7;
}

/* Loading Screen */
.loading-screen {
    max-width: 500px;
    margin: 4rem auto;
    padding: 3rem;
    text-align: center;
}

.loading-content h2 {
    margin-bottom: 1rem;
    font-family: 'Orbitron', sans-serif;
}

.loading-spinner {
    width: 60px;
    height: 60px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--gradient-primary, #667eea);
    border-radius: 50%;
    margin: 0 auto 1.5rem;
    animation: spin 1s linear infinite;
}

.progress-container {
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    overflow: hidden;
    margin: 1.5rem 0;
}

.progress-bar {
    height: 100%;
    background: var(--gradient-primary);
    border-radius: 4px;
    width: 0%;
    transition: width 0.3s ease;
}

.loading-note {
    font-size: 0.85rem;
    opacity: 0.6;
    margin-top: 1rem;
}

/* Error Display */
.error-display {
    max-width: 500px;
    margin: 4rem auto;
    padding: 2rem;
    text-align: center;
    border: 1px solid rgba(245, 101, 101, 0.3);
}

.error-display h2 {
    color: var(--error-color);
    margin-bottom: 1rem;
}

.error-help {
    margin-top: 1.5rem;
    text-align: left;
}

.error-help ul {
    margin-left: 1.5rem;
    margin-top: 0.5rem;
}

.error-help li {
    margin: 0.25rem 0;
}

/* AI App wrapper - ensures proper height chain */
.ai-app {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

/* App Layout - Fluid responsive grid */
.app-layout {
    display: grid;
    /* Fluid columns: side panels scale with viewport, chat fills remaining */
    grid-template-columns:
        minmax(180px, min(22vw, 300px))
        minmax(400px, 1fr)
        minmax(160px, min(18vw, 260px));
    grid-template-rows: 1fr;  /* Single row that fills available space */
    gap: clamp(0.5rem, 1.2vw, 1.25rem);
    flex: 1;
    min-height: 0;    /* Allow shrinking - critical for scroll containment */
    height: 100%;     /* Fill available space exactly */
    width: 100%;
}

/* Ensure all grid children fill their cells and can scroll internally */
.app-layout > * {
    min-height: 0;
    max-height: 100%;
    overflow: hidden;
}

/* Vision Panel */
.vision-panel {
    padding: 0.875rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    overflow-y: auto;
}

.vision-panel h3 {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* Dual Vision Feeds Container */
.vision-feeds {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.vision-feed {
    background: rgba(0, 0, 0, 0.25);
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.feed-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    background: rgba(0, 0, 0, 0.2);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.feed-label {
    font-size: 0.8rem;
    font-weight: 500;
    opacity: 0.8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.feed-controls {
    display: flex;
    gap: 0.25rem;
}

.feed-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: var(--radius-sm);
    padding: 0.5rem;
    min-width: 44px;
    min-height: 44px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1.1rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.feed-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

.feed-btn.camera-btn.active {
    background: rgba(102, 126, 234, 0.4);
    border: 1px solid rgba(102, 126, 234, 0.6);
    box-shadow: 0 0 10px rgba(102, 126, 234, 0.3);
}

.feed-btn.camera-switch-btn:active {
    transform: rotate(180deg);
}

.feed-btn.stop-btn {
    background: rgba(239, 68, 68, 0.3);
}

.feed-btn.stop-btn:hover {
    background: rgba(239, 68, 68, 0.5);
}

.feed-preview {
    aspect-ratio: 16/9;
    position: relative;
    background: rgba(0, 0, 0, 0.4);
}

.feed-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.35);
    font-size: 0.8rem;
}

.feed-preview video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: none;
}

.feed-status {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.75rem;
    padding: 0.4rem 0.75rem;
    background: rgba(0, 0, 0, 0.15);
}

/* Capture Indicator */
.capture-indicator {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 12px;
    height: 12px;
    opacity: 0;
    transition: opacity 0.15s ease;
    pointer-events: none;
}

.capture-indicator.capturing {
    opacity: 1;
}

.capture-ring {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: #ef4444;
    box-shadow: 0 0 10px #ef4444, 0 0 20px rgba(239, 68, 68, 0.5);
    animation: pulse-ring 0.3s ease-out;
}

@keyframes pulse-ring {
    0% {
        transform: scale(0.8);
        opacity: 1;
    }
    100% {
        transform: scale(1.5);
        opacity: 0;
    }
}

/* Upload Section */
.upload-section {
    padding-top: 0.5rem;
}

.upload-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.6rem;
    cursor: pointer;
    font-size: 0.85rem;
}

/* Sampling Info */
.sampling-info {
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
    border-left: 3px solid #667eea;
}

.sampling-header {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 0.4rem;
}

.sampling-icon {
    font-size: 0.9rem;
}

.sampling-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.7;
}

.sampling-rate {
    display: flex;
    align-items: baseline;
    gap: 0.3rem;
    margin-bottom: 0.3rem;
}

.rate-value {
    font-family: 'Orbitron', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.rate-unit {
    font-size: 0.75rem;
    opacity: 0.6;
}

.sampling-stats {
    font-size: 0.75rem;
    opacity: 0.6;
}

.sampling-stats span {
    font-weight: 600;
    color: #667eea;
}

/* Status Dot */
.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    flex-shrink: 0;
}

.status-dot.active {
    background: #22c55e;
    box-shadow: 0 0 6px #22c55e;
    animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Current Caption */
.current-caption {
    font-size: 0.85rem;
    padding: 0.75rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-sm);
    border-left: 3px solid #667eea;
}

.current-caption strong {
    display: block;
    margin-bottom: 0.25rem;
    opacity: 0.7;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.current-caption p {
    line-height: 1.4;
}

/* Chat Panel - Using CSS Grid for reliable scrolling */
.chat-panel {
    display: grid;
    grid-template-rows: 1fr auto auto auto;  /* messages | thinking | input | hints */
    padding: 0;
    overflow: hidden;
    min-width: 0;
    min-height: 0;
    height: 100%;      /* Fill grid cell exactly */
    max-height: 100%;  /* Never exceed grid cell */
    position: relative;
}

.chat-messages {
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    scroll-behavior: smooth;
    /* Let CSS Grid handle height - this is row 1 (1fr) in chat-panel */
    min-height: 0;    /* Critical for flex/grid children to scroll */
    max-height: 100%; /* Constrain to grid row */
}

.welcome-message {
    text-align: center;
    padding: 3rem 2rem;
    opacity: 0.8;
}

.welcome-message h2 {
    font-family: 'Orbitron', sans-serif;
    margin-bottom: 1rem;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.welcome-message p {
    margin: 0.5rem 0;
}

/* Chat Messages */
.chat-message {
    display: flex;
    gap: 0.75rem;
    animation: slideUp 0.3s ease;
}

.chat-message-user {
    flex-direction: row-reverse;
}

.chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--glass-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    flex-shrink: 0;
}

.chat-message-user .chat-avatar {
    background: var(--gradient-primary);
    color: white;
}

.chat-message-assistant .chat-avatar {
    background: var(--gradient-secondary);
    color: white;
}

.chat-content {
    /* Fluid max-width: narrower on wide screens, wider on narrow */
    max-width: clamp(200px, 70%, 700px);
    padding: 0.75rem 1rem;
    background: var(--glass-bg);
    border-radius: var(--radius-md);
    border: 1px solid var(--glass-border);
}

.chat-message-user .chat-content {
    background: rgba(102, 126, 234, 0.2);
    border-color: rgba(102, 126, 234, 0.3);
}

.chat-message-error .chat-content {
    background: rgba(245, 101, 101, 0.2);
    border-color: rgba(245, 101, 101, 0.3);
}

.chat-text {
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

.chat-timestamp {
    font-size: 0.7rem;
    opacity: 0.5;
    margin-top: 0.25rem;
}

/* Vision Messages in Chat */
.chat-message-vision {
    padding: 0.5rem 0;
}

.chat-message-vision .chat-avatar {
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
}

.vision-avatar {
    font-size: 1.1rem !important;
    display: flex;
    align-items: center;
    justify-content: center;
}

.vision-content {
    background: rgba(139, 92, 246, 0.15) !important;
    border-color: rgba(139, 92, 246, 0.3) !important;
    padding: 0.5rem !important;
}

/* Search Badge - Shows when web search was performed */
.search-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.6rem;
    background: rgba(37, 225, 237, 0.15);
    border: 1px solid rgba(37, 225, 237, 0.35);
    border-radius: 4px;
    font-size: 0.7rem;
    color: #25E1ED;
    margin-bottom: 0.5rem;
    cursor: default;
}

.search-badge .search-icon {
    font-size: 0.8rem;
}

.search-badge .search-text {
    font-weight: 500;
}

.vision-thumbnail-container {
    margin-bottom: 0.5rem;
    border-radius: 6px;
    overflow: hidden;
    max-width: 200px;
}

.vision-thumbnail {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 4px;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.vision-thumbnail:hover {
    transform: scale(1.02);
}

.vision-caption {
    font-size: 0.8rem;
    line-height: 1.4;
    opacity: 0.9;
    font-style: italic;
}

/* Vision thumbnail modal (fullscreen view) */
.vision-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.vision-modal.active {
    opacity: 1;
    visibility: visible;
}

.vision-modal img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: 8px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.vision-modal-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    font-size: 1.5rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    transition: background 0.2s ease;
}

.vision-modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Vision Context Panel */
.vision-context {
    background: rgba(0, 0, 0, 0.25);
    border-radius: var(--radius-md, 8px);
    padding: 0.75rem;
    margin-top: 0.75rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.context-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.context-label {
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    opacity: 0.7;
    font-family: 'Orbitron', sans-serif;
}

.context-clear-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    opacity: 0.5;
    transition: opacity 0.2s, transform 0.2s;
    padding: 0.25rem;
    font-size: 0.9rem;
}

.context-clear-btn:hover {
    opacity: 1;
    transform: scale(1.1);
}

/* Latest Frame Preview */
.context-preview {
    width: 100%;
    aspect-ratio: 16/9;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 6px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.context-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.preview-placeholder {
    color: rgba(255, 255, 255, 0.3);
    font-size: 0.7rem;
    font-style: italic;
}

/* Accumulated Descriptions */
.context-descriptions {
    max-height: 120px;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    padding: 0.5rem;
    font-size: 0.75rem;
    line-height: 1.4;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.context-descriptions::-webkit-scrollbar {
    width: 4px;
}

.context-descriptions::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 2px;
}

.descriptions-empty {
    color: rgba(255, 255, 255, 0.35);
    font-style: italic;
    text-align: center;
    padding: 0.5rem;
}

.description-entry {
    padding: 0.3rem 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.description-entry:last-child {
    border-bottom: none;
}

.description-time {
    color: rgba(102, 126, 234, 0.8);
    font-size: 0.65rem;
    font-family: 'Orbitron', sans-serif;
}

.description-text {
    color: rgba(255, 255, 255, 0.85);
    margin-top: 0.15rem;
}

/* Context Footer */
.context-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-top: 0.25rem;
}

.context-stats {
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.5);
    font-family: 'Orbitron', sans-serif;
}

.context-summarize-btn {
    font-size: 0.7rem;
    padding: 0.35rem 0.75rem;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.3), rgba(118, 75, 162, 0.3));
    border: 1px solid rgba(102, 126, 234, 0.4);
}

.context-summarize-btn:hover {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.5), rgba(118, 75, 162, 0.5));
}

.context-summarize-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Thinking Indicator */
.thinking-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    font-size: 0.9rem;
    opacity: 0.7;
}

.thinking-dots {
    display: flex;
    gap: 4px;
}

.thinking-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: white;
    animation: thinking 1.4s infinite ease-in-out both;
}

.thinking-dots span:nth-child(1) { animation-delay: -0.32s; }
.thinking-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes thinking {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ============================================
   Enhanced Status Indicator
   Real-time status display with state-based styling
   ============================================ */

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 1rem;
    margin: 0.5rem 1rem;
    background: rgba(0, 0, 0, 0.4);
    border-radius: 4px;
    border-left: 3px solid var(--cp-cyan, #25E1ED);
    font-family: 'Share Tech Mono', monospace;

    /* Hidden by default - animate in/out */
    opacity: 0;
    max-height: 0;
    overflow: hidden;
    transition: opacity 200ms ease-out, max-height 200ms ease-out, border-color 300ms ease;
}

.status-indicator.visible {
    opacity: 1;
    max-height: 80px;
}

/* State-based border colors */
.status-indicator.searching { border-left-color: #FFD700; }
.status-indicator.vision { border-left-color: #FF00FF; }
.status-indicator.generating { border-left-color: #00FF00; }
.status-indicator.research { border-left-color: #2196F3; }
.status-indicator.loading { border-left-color: #FF9800; }

/* Icon with pulse animation */
.status-icon {
    font-size: 1.1rem;
    width: 24px;
    text-align: center;
    animation: status-pulse 1.5s ease-in-out infinite;
}

@keyframes status-pulse {
    0%, 100% { opacity: 0.6; transform: scale(1); }
    50% { opacity: 1; transform: scale(1.1); }
}

/* Status text content */
.status-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.status-primary {
    font-size: 0.85rem;
    font-weight: 600;
    color: #fff;
    text-transform: uppercase;
    letter-spacing: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.status-secondary {
    font-size: 0.7rem;
    color: #888;
    margin-top: 0.15rem;
    display: none;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.status-secondary.visible {
    display: block;
}

/* Text change animation */
.status-text-enter {
    animation: status-text-in 200ms ease-out;
}

@keyframes status-text-in {
    from {
        opacity: 0;
        transform: translateY(-4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Thinking dots */
.status-dots {
    display: flex;
    gap: 4px;
    margin-left: auto;
}

.status-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--cp-cyan, #25E1ED);
    box-shadow: 0 0 6px var(--cp-cyan, #25E1ED);
    animation: status-dot 1.4s infinite ease-in-out both;
}

.status-dots span:nth-child(1) { animation-delay: -0.32s; }
.status-dots span:nth-child(2) { animation-delay: -0.16s; }
.status-dots span:nth-child(3) { animation-delay: 0s; }

@keyframes status-dot {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* State-specific dot colors */
.status-indicator.searching .status-dots span {
    background: #FFD700;
    box-shadow: 0 0 6px #FFD700;
}

.status-indicator.vision .status-dots span {
    background: #FF00FF;
    box-shadow: 0 0 6px #FF00FF;
}

.status-indicator.generating .status-dots span {
    background: #00FF00;
    box-shadow: 0 0 6px #00FF00;
}

.status-indicator.research .status-dots span {
    background: #2196F3;
    box-shadow: 0 0 6px #2196F3;
}

/* Progress bar for research/downloads */
.status-progress {
    flex: 1;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    max-width: 100px;
    margin-left: auto;
    display: none;
    overflow: hidden;
}

.status-progress.visible {
    display: block;
}

.status-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #25E1ED, #FF00FF);
    border-radius: 2px;
    transition: width 300ms ease;
    width: 0%;
}

/* Chat Input */
.chat-input-area {
    display: flex;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--glass-border);
    position: sticky;
    bottom: 0;
    z-index: 10;
    background: inherit;
}

.chat-input {
    flex: 1;
    resize: none;
    min-height: 44px;
    max-height: 150px;
    line-height: 1.5;
}

.send-button {
    align-self: flex-end;
    padding: 0.6rem 1.25rem;
}

/* Controls Panel */
.controls-panel {
    padding: 0.875rem;
    overflow-y: auto;
}

.controls-panel h3 {
    font-family: 'Orbitron', sans-serif;
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.controls-panel h4 {
    font-size: 0.85rem;
    opacity: 0.7;
    margin-bottom: 0.5rem;
    margin-top: 1.25rem;
}

.controls-panel h4:first-of-type {
    margin-top: 1rem;
}

.full-width {
    width: 100%;
}

.model-info {
    margin-top: 1rem;
    padding: 0.75rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-sm);
    transition: all 0.3s ease;
    border-left: 3px solid transparent;
}

.model-info p {
    font-size: 0.9rem;
}

.model-detail {
    font-size: 0.8rem !important;
    opacity: 0.6;
    margin-top: 0.25rem;
}

/* Moondream VLM Status States */
.model-info.loading {
    border-left-color: #fbbf24;
    background: rgba(251, 191, 36, 0.1);
}

.model-info.loading .model-detail {
    color: #fde047;
    animation: pulse-text 1.5s ease-in-out infinite;
}

.model-info.ready {
    border-left-color: #22c55e;
    background: rgba(34, 197, 94, 0.1);
}

.model-info.ready .model-detail {
    color: #86efac;
}

.model-info.error {
    border-left-color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

.model-info.error .model-detail {
    color: #fca5a5;
}

@keyframes pulse-text {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* Vision Model Manager */
.vision-model-manager {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--glass-border);
}

.vision-model-manager h4 {
    margin-top: 0;
    margin-bottom: 0.75rem;
}

/* Model Cards */
.model-cards {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.model-card {
    background: rgba(0, 0, 0, 0.25);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    transition: all 0.2s ease;
}

.model-card:hover {
    background: rgba(0, 0, 0, 0.35);
    border-color: rgba(255, 255, 255, 0.2);
}

.model-card.active {
    border-color: rgba(102, 126, 234, 0.5);
    background: rgba(102, 126, 234, 0.15);
}

.model-card.loading {
    opacity: 0.7;
}

.model-card.error {
    border-color: rgba(239, 68, 68, 0.5);
}

.model-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.35rem;
}

.model-card-name {
    font-weight: 600;
    font-size: 0.85rem;
}

.model-card-badge {
    font-size: 0.65rem;
    padding: 0.15rem 0.4rem;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.1);
}

.model-card-badge.active {
    background: rgba(34, 197, 94, 0.3);
    color: #4ade80;
}

.model-card-badge.ready {
    background: rgba(34, 197, 94, 0.2);
    color: #86efac;
}

.model-card-badge.loading {
    background: rgba(234, 179, 8, 0.2);
    color: #fde047;
}

.model-card-badge.error {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
}

.model-card-meta {
    display: flex;
    gap: 0.75rem;
    font-size: 0.7rem;
    opacity: 0.6;
    margin-bottom: 0.35rem;
}

.model-card-desc {
    font-size: 0.7rem;
    opacity: 0.5;
    line-height: 1.3;
    margin-bottom: 0.5rem;
}

.model-select-btn {
    width: 100%;
    padding: 0.4rem 0.75rem;
    font-size: 0.75rem;
    background: rgba(102, 126, 234, 0.2);
    border: 1px solid rgba(102, 126, 234, 0.3);
}

.model-select-btn:hover:not(.disabled) {
    background: rgba(102, 126, 234, 0.3);
    border-color: rgba(102, 126, 234, 0.5);
}

.model-select-btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.1);
}

/* Model Dropdown Selector */
.model-selector {
    margin-bottom: 1rem;
}

.model-selector h4 {
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    opacity: 0.8;
}

.model-dropdown {
    position: relative;
}

.model-dropdown-trigger {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: var(--radius-sm);
    color: #fff;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
}

.model-dropdown-trigger:hover {
    background: rgba(0, 0, 0, 0.5);
    border-color: rgba(102, 126, 234, 0.4);
}

.model-dropdown.open .model-dropdown-trigger {
    border-color: rgba(102, 126, 234, 0.6);
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
}

.selected-model-info {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.15rem;
}

.selected-model-name {
    font-weight: 600;
    font-size: 0.9rem;
}

.selected-model-meta {
    font-size: 0.7rem;
    opacity: 0.6;
}

.dropdown-arrow {
    font-size: 0.7rem;
    opacity: 0.6;
    transition: transform 0.2s ease;
}

.model-dropdown.open .dropdown-arrow {
    transform: rotate(180deg);
}

.model-dropdown-menu {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    max-height: 0;
    overflow: hidden;
    background: rgba(15, 15, 25, 0.98);
    border: 1px solid rgba(102, 126, 234, 0.4);
    border-top: none;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    z-index: 100;
    transition: max-height 0.3s ease, opacity 0.2s ease;
    opacity: 0;
    backdrop-filter: blur(10px);
}

.model-dropdown.open .model-dropdown-menu {
    max-height: min(400px, 60vh);
    overflow-y: auto;
    opacity: 1;
}

/* Custom scrollbar for dropdown */
.model-dropdown-menu::-webkit-scrollbar {
    width: 6px;
}

.model-dropdown-menu::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.2);
}

.model-dropdown-menu::-webkit-scrollbar-thumb {
    background: rgba(102, 126, 234, 0.4);
    border-radius: 3px;
}

/* Model Categories */
.model-category {
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.model-category:last-child {
    border-bottom: none;
}

.category-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    background: rgba(102, 126, 234, 0.1);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.9;
}

.category-icon {
    font-size: 0.9rem;
}

.category-desc {
    margin-left: auto;
    opacity: 0.5;
    font-weight: 400;
    font-size: 0.7rem;
}

/* Model Options */
.model-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.65rem 1rem;
    cursor: pointer;
    transition: all 0.15s ease;
    border-left: 3px solid transparent;
}

.model-option:hover {
    background: rgba(102, 126, 234, 0.15);
    border-left-color: rgba(102, 126, 234, 0.5);
}

.model-option.active {
    background: rgba(102, 126, 234, 0.2);
    border-left-color: #667eea;
}

.model-option.loading {
    opacity: 0.6;
    pointer-events: none;
}

.model-option-info {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.model-option-name {
    font-size: 0.85rem;
    font-weight: 500;
}

.model-option-desc {
    font-size: 0.7rem;
    opacity: 0.5;
}

.model-option-stats {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.1rem;
}

.model-option-size {
    font-size: 0.75rem;
    font-weight: 600;
    color: rgba(102, 126, 234, 0.9);
}

.model-option-context {
    font-size: 0.65rem;
    opacity: 0.5;
}

.model-option-badge {
    font-size: 0.6rem;
    padding: 0.1rem 0.35rem;
    border-radius: 8px;
    background: rgba(34, 197, 94, 0.25);
    color: #4ade80;
    margin-top: 0.15rem;
}

/* Quality/Speed indicators */
.model-option[data-quality="premium"] .model-option-name::after {
    content: " ★";
    color: #fbbf24;
}

.model-option[data-quality="excellent"] .model-option-name::after {
    content: " ●";
    color: #4ade80;
}

.model-option[data-speed="instant"] .model-option-size {
    color: #22d3ee;
}

.model-option[data-speed="fast"] .model-option-size {
    color: #4ade80;
}

/* Dropdown loading state */
.model-dropdown.loading .model-dropdown-trigger {
    opacity: 0.7;
    pointer-events: none;
}

.model-dropdown.loading .dropdown-arrow {
    animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 1; }
}

/* Download Progress */
.model-download-progress {
    margin-top: 0.75rem;
    padding: 0.75rem;
    background: rgba(0, 0, 0, 0.3);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(234, 179, 8, 0.3);
}

.download-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    margin-bottom: 0.5rem;
}

.download-model-name {
    font-weight: 500;
}

.download-percent {
    font-family: 'Orbitron', sans-serif;
    color: #fde047;
}

.download-bar {
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
}

.download-fill {
    height: 100%;
    background: linear-gradient(90deg, #fbbf24, #fde047);
    border-radius: 2px;
    width: 0%;
    transition: width 0.3s ease;
}

/* Current Model Status */
.current-model-status {
    margin-top: 0.75rem;
    font-size: 0.75rem;
    display: flex;
    gap: 0.4rem;
    align-items: center;
}

.current-model-status .label {
    opacity: 0.6;
}

.current-model-status .model-name-active {
    font-weight: 600;
    color: #86efac;
}

.stats-section {
    margin-top: 1rem;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    padding: 0.35rem 0;
}

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

/* Performance Metrics Section */
.performance-section {
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--glass-border, rgba(255, 255, 255, 0.1));
}

.performance-section h4 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    opacity: 0.7;
    margin-bottom: 0.5rem;
}

.perf-value {
    font-family: 'Share Tech Mono', monospace;
    font-weight: 500;
}

/* Speed color coding */
.speed-fast {
    color: #4ade80;  /* Green */
}

.speed-medium {
    color: #fbbf24;  /* Yellow */
}

.speed-slow {
    color: #f87171;  /* Red */
}

/* Backend badges */
.backend-badge {
    padding: 0.1rem 0.4rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
}

.backend-webgpu {
    background: linear-gradient(135deg, #4ade80, #22c55e);
    color: #000;
}

.backend-wasm {
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
    color: #000;
}

.backend-unknown {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

/* GPU features row */
.gpu-features .perf-value {
    font-size: 0.75rem;
    color: #a78bfa;  /* Purple for features */
}

.memory-controls {
    margin-top: 1rem;
}

/* Web Search Settings */
.search-settings {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--glass-border);
}

.search-settings h4 {
    margin: 0 0 0.75rem 0;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.api-key-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0;
}

.api-key-row .glass-input {
    flex: 1;
    padding: 0.5rem 0.75rem;
    background: var(--glass-background);
    border: 1px solid var(--glass-border);
    border-radius: 6px;
    color: var(--text-primary);
    font-family: monospace;
    font-size: 0.85rem;
}

.api-key-row .glass-input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.api-key-row .glass-button.small {
    padding: 0.5rem 0.75rem;
    font-size: 1rem;
}

.setting-hint {
    margin: 0.5rem 0;
    font-size: 0.75rem;
}

.setting-hint a {
    color: var(--accent-primary);
    text-decoration: none;
}

.setting-hint a:hover {
    text-decoration: underline;
}

.search-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.search-status .status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #666;
}

.search-status .status-dot.active {
    background: #4caf50;
    box-shadow: 0 0 6px #4caf50;
}

.search-status .status-text {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Thinking Mode Settings */
.thinking-mode-settings {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--glass-border);
}

.thinking-mode-settings h4 {
    margin: 0 0 0.75rem 0;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.toggle-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    margin-bottom: 0.5rem;
}

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

.toggle-label {
    font-size: 0.85rem;
    color: var(--text-primary);
}

.glass-select {
    width: 100%;
    padding: 0.5rem;
    margin-top: 0.25rem;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
}

.glass-select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.glass-select:focus {
    outline: none;
    border-color: var(--accent-primary);
}

/* Research Mode Settings */
.research-mode-settings {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--glass-border);
}

.research-mode-settings h4 {
    margin: 0 0 0.75rem 0;
    font-size: 0.9rem;
    color: var(--text-primary);
}

/* Research Progress Display */
.research-progress {
    margin-top: 1rem;
    padding: 0.75rem;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 8px;
}

.research-progress .progress-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.research-progress .phase-icon {
    font-size: 1.2rem;
}

.research-progress .phase-label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
}

.progress-bar-container {
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary, #00d4ff));
    border-radius: 3px;
    transition: width 0.3s ease;
}

.research-progress .progress-details {
    margin-bottom: 0.25rem;
}

.research-progress .current-step {
    font-size: 0.75rem;
    color: var(--text-secondary);
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.research-progress .progress-stats {
    display: flex;
    gap: 1rem;
    font-size: 0.7rem;
    color: var(--text-secondary);
}

.about-section {
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--glass-border);
}

.about-section p {
    font-size: 0.8rem;
    opacity: 0.6;
    margin-bottom: 0.5rem;
}

.about-section .version {
    font-family: 'Orbitron', sans-serif;
    opacity: 0.4;
}

/* Responsive */

/* Large desktop (1400-1600px) */
@media (min-width: 1400px) and (max-width: 1600px) {
    .app-layout {
        grid-template-columns:
            minmax(220px, 280px)
            minmax(500px, 1fr)
            minmax(200px, 240px);
    }
}

/* Medium-large desktop (1200-1399px) */
@media (max-width: 1399px) and (min-width: 1200px) {
    .app-layout {
        grid-template-columns:
            minmax(200px, 250px)
            minmax(450px, 1fr)
            minmax(180px, 220px);
        gap: 0.875rem;
    }

    .chat-content {
        max-width: clamp(200px, 75%, 600px);
    }
}

/* Tablet landscape / Small desktop (1000-1199px) */
@media (max-width: 1199px) and (min-width: 1000px) {
    .app-layout {
        grid-template-columns:
            minmax(180px, 220px)
            minmax(400px, 1fr)
            minmax(160px, 200px);
        gap: 0.75rem;
    }

    .chat-content {
        max-width: clamp(180px, 80%, 550px);
    }

    .controls-panel h4 {
        font-size: 0.8rem;
    }

    .vision-panel,
    .controls-panel {
        padding: 0.75rem;
    }
}

/* Tablet portrait (768-999px) - 2-column layout */
@media (max-width: 999px) and (min-width: 768px) {
    .main-container {
        padding: 0.5rem clamp(0.5rem, 2vw, 1.5rem);
    }

    .app-layout {
        grid-template-columns: 1fr 1fr;
        grid-template-rows: minmax(50vh, 1fr) auto;  /* chat fills most of viewport */
        grid-template-areas:
            "chat chat"
            "vision controls";
        gap: 0.6rem;
        width: 100%;
    }

    .chat-panel {
        grid-area: chat;
    }

    .vision-panel {
        grid-area: vision;
        max-height: 35vh;
        overflow-y: auto;
    }

    .controls-panel {
        grid-area: controls;
        max-height: 35vh;
        overflow-y: auto;
    }

    /* Side-by-side feeds on tablet */
    .vision-feeds {
        flex-direction: row;
    }

    .vision-feed {
        flex: 1;
        min-width: 0;  /* Allow shrinking */
    }

    .chat-content {
        max-width: clamp(200px, 85%, 100%);
    }

    .chat-messages {
        padding: 0.75rem;
    }
}

/* Mobile (below 768px) - single column, chat-first layout */
@media (max-width: 767px) {
    .main-container {
        padding: 0.25rem 0.5rem;
        max-width: 100%;
    }

    .app-layout {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr auto auto;  /* chat | vision | controls */
        gap: 0.25rem;
        height: 100%;
        min-height: 0;  /* Allow grid to shrink */
        width: 100%;
    }

    .chat-panel {
        order: 0;
        min-height: 0;  /* Allow flex shrink - no artificial minimum */
        height: 100%;   /* Fill available space */
        max-height: none;  /* No upper limit */
        width: 100%;
    }

    .vision-panel {
        order: 1;
    }

    .controls-panel {
        order: 2;
    }

    /* Collapse panels by default to maximize chat space */
    .vision-panel,
    .controls-panel {
        max-height: 0;
        overflow: hidden;
        padding: 0;
        opacity: 0;
        transition: max-height 0.3s ease, padding 0.3s ease, opacity 0.2s ease;
        border: none;
        width: 100%;
    }

    .vision-panel.expanded,
    .controls-panel.expanded {
        max-height: 400px;  /* Fallback for older browsers */
        max-height: min(50vh, 400px);
        padding: 0.75rem;
        opacity: 1;
        overflow-y: auto;
        border: 1px solid var(--glass-border);
    }

    .chat-content {
        max-width: 90%;
    }

    /* Mobile camera button ordering - back camera first */
    .feed-controls {
        gap: 0.5rem;
        flex-wrap: wrap;
        justify-content: center;
    }

    #btn-camera-back {
        order: 1;
    }

    #btn-camera-front {
        order: 2;
    }

    /* When camera is active, show switch button instead */
    .webcam-active #btn-camera-switch {
        display: flex !important;
    }

    .webcam-active #btn-camera-front,
    .webcam-active #btn-camera-back {
        display: none;
    }

    /* Stack feeds on mobile */
    .vision-feeds {
        flex-direction: column;
    }

    .vision-feed {
        flex: none;
    }

    /* Compact chat input on mobile */
    .chat-input-area {
        padding: 0.5rem;
        gap: 0.5rem;
    }

    .chat-input {
        min-height: 40px;
        font-size: 16px;  /* Prevents iOS zoom */
        padding: 0.4rem 0.6rem;
    }

    .send-button {
        padding: 0.4rem 0.75rem;
        font-size: 0.85rem;
    }

    .voice-btn {
        padding: 0.4rem;
        min-width: 40px;
    }
}

/* Mobile panel toggle buttons */
.mobile-panel-toggles {
    display: none;
}

@media (max-width: 767px) {
    .mobile-panel-toggles {
        display: flex;
        gap: 0.35rem;
        padding: 0.2rem 0.3rem;
        justify-content: center;
        background: var(--glass-bg, rgba(255,255,255,0.05));
        border: 1px solid var(--glass-border, rgba(255,255,255,0.1));
        border-radius: 6px;
        margin-bottom: 0.2rem;
        flex-shrink: 0;  /* Don't shrink toggles */
    }

    .panel-toggle-btn {
        padding: 0.6rem 0.8rem;
        min-height: 44px;
        min-width: 44px;
        font-size: 0.85rem;
        border-radius: 6px;
        background: rgba(255,255,255,0.08);
        border: 1px solid var(--glass-border, rgba(255,255,255,0.15));
        color: inherit;
        cursor: pointer;
        transition: background 0.2s, transform 0.1s;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 0.4rem;
    }

    .panel-toggle-btn:hover {
        background: rgba(255,255,255,0.15);
    }

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

    .panel-toggle-btn.active {
        background: var(--accent-color, #667eea);
        border-color: var(--accent-color, #667eea);
    }
}

/* Small mobile (600px and below) */
@media (max-width: 600px) {
    .main-container {
        padding: 0.25rem 0.35rem;
        max-width: 100%;
    }

    .page-header {
        margin-bottom: 0.15rem;
        padding: 0;
    }

    .page-title {
        font-size: 0.95rem;
        margin: 0;
        line-height: 1.2;
    }

    .page-subtitle {
        display: none;  /* Hide subtitle on small phones */
    }

    .feed-preview {
        aspect-ratio: 16/10;  /* Compromise ratio */
    }

    .chat-content {
        max-width: 92%;
        min-width: 120px;
    }

    .chat-messages {
        padding: 0.4rem;
        gap: 0.4rem;
    }

    .message-content {
        padding: 0.5rem 0.75rem;
        font-size: 0.9rem;
    }

    .chat-avatar {
        width: 28px;
        height: 28px;
    }

    .vision-thumbnail-container {
        max-width: 150px;
    }

    .controls-panel {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.75rem;
        max-height: 40vh;
        overflow-y: auto;
    }

    .controls-panel h3 {
        grid-column: 1 / -1;
    }

    .controls-panel .full-width {
        grid-column: 1 / -1;
    }

    .chat-input-area {
        padding: 0.4rem;
    }
}

/* Very small mobile (480px and below) */
@media (max-width: 480px) {
    .main-container {
        padding: 0.25rem 0.3rem;
        max-width: 100%;
    }

    .page-header {
        margin-bottom: 0.25rem;
    }

    .page-title {
        font-size: 0.9rem;
    }

    .page-subtitle {
        display: none;
    }

    .feed-header {
        padding: 0.35rem 0.5rem;
    }

    .feed-preview {
        aspect-ratio: 4/3;
    }

    .chat-messages {
        padding: 0.35rem;
        gap: 0.35rem;
    }

    .chat-content {
        max-width: 94%;
        padding: 0.5rem 0.7rem;
    }

    .chat-avatar {
        width: 26px;
        height: 26px;
        font-size: 0.65rem;
    }

    .sampling-rate {
        flex-direction: column;
        align-items: flex-start;
        gap: 0;
    }

    .rate-value {
        font-size: 1.2rem;
    }

    /* Single column controls on very small screens */
    .controls-panel {
        grid-template-columns: 1fr;
    }

    .chat-input-area {
        padding: 0.35rem;
        gap: 0.35rem;
    }

    .send-button {
        padding: 0.4rem 0.6rem;
        font-size: 0.8rem;
    }
}

/* Extra small (360px and below) */
@media (max-width: 360px) {
    .main-container {
        padding: 0.2rem;
        max-width: 100%;
    }

    .chat-messages {
        padding: 0.25rem;
        gap: 0.25rem;
    }

    .chat-content {
        max-width: 96%;
        padding: 0.4rem 0.6rem;
    }

    .chat-message {
        gap: 0.35rem;
    }

    .page-title {
        font-size: 0.85rem;
    }

    .chat-avatar {
        width: 24px;
        height: 24px;
        font-size: 0.6rem;
    }

    .chat-input-area {
        padding: 0.25rem;
        gap: 0.25rem;
    }

    .chat-input {
        font-size: 14px;
        padding: 0.35rem 0.5rem;
    }
}

/* Keyboard visibility on mobile - hide panels when keyboard is open */
@media (max-height: 500px) and (max-width: 767px) {
    .vision-panel,
    .controls-panel {
        display: none;
    }

    .chat-panel {
        max-height: 100%;
    }

    /* Even smaller panel heights when keyboard might be visible */
    .vision-panel.expanded,
    .controls-panel.expanded {
        max-height: 200px;  /* Fallback */
        max-height: min(35vh, 200px);
    }
}

/* Smaller screens - reduce panel heights */
@media (max-height: 700px) and (max-width: 767px) {
    .vision-panel.expanded,
    .controls-panel.expanded {
        max-height: 300px;  /* Fallback */
        max-height: min(40vh, 300px);
    }
}

/* Desktop - front camera first, hide switch button */
@media (min-width: 768px) {
    #btn-camera-front {
        order: 1;
    }

    #btn-camera-back {
        order: 2;
    }

    #btn-camera-switch {
        display: none !important;
    }
}

/* Hide keyboard hints on short viewports to save space */
@media (max-height: 800px) {
    .keyboard-hints {
        display: none;
    }
}

/* Scrollbar styling */
.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* HiDPI / Retina display optimizations */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 2dppx) {
    /* Sharper borders for HiDPI */
    .glass-card {
        border-width: 0.5px;
    }

    /* Thinner scrollbar */
    .chat-messages::-webkit-scrollbar {
        width: 4px;
    }

    /* Crisper text rendering */
    .chat-text {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }

    /* Finer dividers */
    .chat-input-area {
        border-top-width: 0.5px;
    }
}

/* Safe area support for notched devices */
.chat-input-area {
    padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
}

@media (min-width: 768px) {
    .main-container {
        padding-left: max(1.5rem, env(safe-area-inset-left));
        padding-right: max(1.5rem, env(safe-area-inset-right));
    }
}

@media (max-width: 767px) {
    .main-container {
        padding-left: max(0.5rem, env(safe-area-inset-left));
        padding-right: max(0.5rem, env(safe-area-inset-right));
    }
}

/* Touch device optimizations */
@media (pointer: coarse) {
    /* Larger touch targets */
    .chat-send,
    .send-button,
    .voice-btn,
    .feed-btn {
        min-height: 48px;
        min-width: 48px;
    }

    /* More spacing between interactive elements */
    .feed-controls {
        gap: 0.5rem;
    }

    /* Larger input field for touch */
    .chat-input {
        min-height: 52px;
        font-size: 16px;  /* Prevents iOS zoom */
    }

    /* Better spacing for buttons */
    .chat-input-area {
        gap: 1rem;
    }

    /* Easier to tap chat actions */
    .chat-action-btn {
        padding: 0.5rem 0.75rem;
    }
}

/* Large screens (1600px+) */
@media (min-width: 1600px) {
    .main-container {
        max-width: min(2000px, 96vw);
        padding: 0.75rem 2rem;
    }

    .page-title {
        font-size: 1.75rem;
    }

    .page-subtitle {
        font-size: 1rem;
    }

    .chat-text {
        font-size: 1rem;
    }

    .app-layout {
        grid-template-columns:
            minmax(280px, 340px)
            minmax(600px, 1fr)
            minmax(240px, 300px);
        gap: 1.5rem;
    }

    .chat-content {
        max-width: clamp(300px, 65%, 800px);
    }
}

/* Extra large screens (1920px+) */
@media (min-width: 1920px) {
    .main-container {
        max-width: min(2200px, 95vw);
    }

    .app-layout {
        grid-template-columns:
            minmax(300px, 380px)
            minmax(700px, 1fr)
            minmax(260px, 340px);
        gap: 1.75rem;
    }
}

/* Ultra-wide screens (2560px+) */
@media (min-width: 2560px) {
    .main-container {
        max-width: min(2600px, 92vw);
        padding: 1rem 3rem;
    }

    .app-layout {
        grid-template-columns:
            minmax(320px, 420px)
            minmax(800px, 1fr)
            minmax(280px, 380px);
        gap: 2rem;
    }

    .chat-content {
        max-width: clamp(400px, 60%, 900px);
    }
}

/* Scroll-to-bottom button */
.scroll-to-bottom-btn {
    position: absolute;
    bottom: 80px;
    right: 24px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--glass-bg, rgba(255, 255, 255, 0.1));
    border: 1px solid var(--glass-border, rgba(255, 255, 255, 0.2));
    color: inherit;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px);
    transition: all 0.2s ease;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.scroll-to-bottom-btn.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.scroll-to-bottom-btn:hover {
    background: var(--glass-light, rgba(255, 255, 255, 0.15));
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

.scroll-to-bottom-btn:active {
    transform: translateY(0);
}

.scroll-icon {
    font-size: 1.2rem;
    line-height: 1;
}

/* Responsive scroll button */
@media (max-width: 767px) {
    .scroll-to-bottom-btn {
        width: 36px;
        height: 36px;
        bottom: calc(70px + env(safe-area-inset-bottom, 0px));
        right: 16px;
    }

    .scroll-icon {
        font-size: 1rem;
    }
}

/* =====================================================
   13" MacBook / Small Laptop Optimization
   Target: 1440x900, 1280x800 viewports
   Ensures entire app fits on one screen without scrolling
   ===================================================== */
@media (min-width: 1024px) and (max-height: 950px) {
    /* Reduce container padding */
    .main-container {
        padding: 0.5rem 1rem;
    }

    /* Compact page header */
    .page-header {
        margin-bottom: 0.4rem;
    }

    .page-title {
        font-size: 1.2rem;
        margin-bottom: 0.1rem;
    }

    .page-subtitle {
        font-size: 0.75rem;
    }

    /* Tighter grid gap */
    .app-layout {
        gap: 0.6rem;
    }

    /* Compact vision panel */
    .vision-panel {
        padding: 0.6rem;
        gap: 0.5rem;
    }

    .vision-panel h3 {
        font-size: 0.8rem;
        margin-bottom: 0.3rem;
    }

    .vision-feeds {
        gap: 0.4rem;
    }

    .feed-preview {
        aspect-ratio: 16/10;  /* Slightly shorter than 16/9 */
    }

    .vision-controls {
        padding: 0.4rem;
        gap: 0.3rem;
    }

    /* Compact chat area */
    .chat-messages {
        padding: 0.6rem;
        gap: 0.6rem;
    }

    .chat-input-container {
        padding: 0.5rem;
    }

    .chat-textarea {
        min-height: 36px;
        padding: 0.4rem 0.6rem;
        font-size: 0.9rem;
    }

    .chat-hints {
        padding: 0.3rem 0.5rem;
        font-size: 0.7rem;
    }

    /* Compact controls panel */
    .controls-panel {
        padding: 0.6rem;
        gap: 0.4rem;
    }

    .controls-panel h4 {
        font-size: 0.75rem;
        margin-top: 0.5rem;
        margin-bottom: 0.25rem;
    }

    .controls-panel h4:first-child {
        margin-top: 0;
    }

    .model-card {
        padding: 0.5rem;
    }

    .model-card-header h5 {
        font-size: 0.75rem;
    }

    .model-card-body {
        font-size: 0.7rem;
    }

    .glass-button {
        padding: 0.4rem 0.8rem;
        font-size: 0.8rem;
    }

    .sampling-info,
    .model-info,
    .current-caption {
        font-size: 0.75rem;
        padding: 0.4rem;
        margin-top: 0.4rem;
    }

    /* Compact status indicators */
    .status-indicator {
        font-size: 0.7rem;
        padding: 0.2rem 0.5rem;
    }
}

/* Extra compact for very small laptop screens (1280x800) */
@media (min-width: 1024px) and (max-height: 820px) {
    .main-container {
        padding: 0.35rem 0.75rem;
    }

    .page-header {
        margin-bottom: 0.25rem;
    }

    .page-title {
        font-size: 1rem;
    }

    .page-subtitle {
        display: none;  /* Hide subtitle on very small screens */
    }

    .app-layout {
        gap: 0.5rem;
    }

    .vision-panel,
    .controls-panel {
        padding: 0.5rem;
    }

    .chat-messages {
        padding: 0.5rem;
        gap: 0.5rem;
    }
}

/* ================================================
   Image Generation Styles
   ================================================ */

/* Image Generation Message Container */
.image-gen-message .chat-content {
    max-width: 100%;
}

.image-gen-container {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* Progress Section */
.image-gen-progress {
    padding: 1.5rem;
}

.image-gen-progress .progress-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.image-gen-progress .progress-icon {
    font-size: 1.5rem;
    animation: image-gen-pulse 2s ease-in-out infinite;
}

.image-gen-progress .progress-label {
    font-family: 'Orbitron', 'Segoe UI', sans-serif;
    font-size: 1rem;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.image-gen-progress .progress-bar-container {
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
    overflow: hidden;
    margin-bottom: 0.75rem;
}

.image-gen-progress .progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 50%, #667eea 100%);
    background-size: 200% 100%;
    border-radius: 4px;
    width: 0%;
    transition: width 0.3s ease;
    animation: image-gen-shimmer 2s linear infinite;
}

.image-gen-progress .progress-details {
    display: flex;
    justify-content: space-between;
    font-size: 0.85rem;
    opacity: 0.7;
}

/* Result Section */
.image-gen-result {
    padding: 1rem;
}

.image-gen-result .result-image {
    width: 100%;
    max-width: 512px;
    height: auto;
    border-radius: 12px;
    display: block;
    margin: 0 auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.image-gen-result .result-image:hover {
    transform: scale(1.02);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}

.image-gen-result .result-actions {
    display: flex;
    justify-content: center;
    gap: 1rem;
    margin-top: 1rem;
}

.image-gen-result .action-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 8px;
    color: white;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.image-gen-result .action-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: #667eea;
}

.image-gen-result .action-btn:active {
    transform: scale(0.95);
}

.image-gen-result .result-prompt {
    margin-top: 1rem;
    padding: 0.75rem;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    font-size: 0.85rem;
    opacity: 0.7;
    font-style: italic;
    text-align: center;
}

/* Animations */
@keyframes image-gen-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(1.1); }
}

@keyframes image-gen-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Mobile responsiveness for image generation */
@media (max-width: 768px) {
    .image-gen-container {
        border-radius: 8px;
    }

    .image-gen-progress {
        padding: 1rem;
    }

    .image-gen-progress .progress-label {
        font-size: 0.9rem;
    }

    .image-gen-result .result-image {
        max-width: 100%;
        border-radius: 8px;
    }

    .image-gen-result .result-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .image-gen-result .action-btn {
        justify-content: center;
    }

    .image-gen-result .result-prompt {
        font-size: 0.8rem;
    }
}

@media (max-width: 480px) {
    .image-gen-progress {
        padding: 0.75rem;
    }

    .image-gen-progress .progress-header {
        gap: 0.5rem;
    }

    .image-gen-progress .progress-icon {
        font-size: 1.25rem;
    }

    .image-gen-result {
        padding: 0.75rem;
    }
}

