/* ============================================
   ANTIGRAVITY — Design System
   Premium dark theme with violet accents
   ============================================ */

:root {
    /* Colors */
    --bg-primary: #0a0a0f;
    --bg-secondary: #111118;
    --bg-tertiary: #1a1a24;
    --bg-elevated: #1e1e2a;
    --bg-hover: #252533;
    --bg-active: #2a2a3a;
    
    --surface-glass: rgba(255, 255, 255, 0.03);
    --surface-glass-hover: rgba(255, 255, 255, 0.06);
    --surface-glass-border: rgba(255, 255, 255, 0.06);
    
    --text-primary: #f0f0f5;
    --text-secondary: #9898a8;
    --text-tertiary: #6b6b7b;
    --text-placeholder: #505060;
    
    --accent-primary: #7c3aed;
    --accent-secondary: #a78bfa;
    --accent-tertiary: #6d28d9;
    --accent-glow: rgba(124, 58, 237, 0.25);
    --accent-subtle: rgba(124, 58, 237, 0.08);
    
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --info: #3b82f6;
    
    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-default: rgba(255, 255, 255, 0.1);
    --border-strong: rgba(255, 255, 255, 0.15);
    
    /* Spacing */
    --sidebar-width: 280px;
    --input-max-width: 768px;
    --message-max-width: 768px;
    
    /* Typography */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', monospace;
    
    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-default: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Shadows */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px var(--accent-glow);
    
    /* Radii */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 24px;
    --radius-full: 9999px;
}

/* Light Theme (Premium) */
[data-theme="light"] {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --bg-elevated: #ffffff;
    --bg-hover: #e2e8f0;
    --bg-active: #cbd5e1;
    
    --surface-glass: rgba(0, 0, 0, 0.02);
    --surface-glass-hover: rgba(0, 0, 0, 0.04);
    --surface-glass-border: rgba(0, 0, 0, 0.08);
    
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-tertiary: #64748b;
    --text-placeholder: #94a3b8;
    
    --border-subtle: rgba(0, 0, 0, 0.06);
    --border-default: rgba(0, 0, 0, 0.1);
    --border-strong: rgba(0, 0, 0, 0.15);
    
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

/* Vanilla Theme (Minimalist) */
[data-theme="vanilla"] {
    --bg-primary: #ffffff;
    --bg-secondary: #fdfdfd;
    --bg-tertiary: #f5f5f5;
    --bg-elevated: #ffffff;
    --bg-hover: #f0f0f0;
    --bg-active: #e5e5e5;
    
    --surface-glass: transparent;
    --surface-glass-hover: #f9f9f9;
    --surface-glass-border: #eaeaea;
    
    --text-primary: #111111;
    --text-secondary: #555555;
    --text-tertiary: #777777;
    --text-placeholder: #aaaaaa;
    
    --accent-primary: #333333;
    --accent-secondary: #555555;
    --accent-tertiary: #111111;
    --accent-glow: rgba(0, 0, 0, 0.1);
    --accent-subtle: rgba(0, 0, 0, 0.04);
    
    --border-subtle: #f0f0f0;
    --border-default: #e0e0e0;
    --border-strong: #cccccc;
    
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.03);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.04);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.06);
    --shadow-glow: 0 0 0 transparent;
}

/* ============================================
   Reset & Base
   ============================================ */

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

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    overflow: hidden;
    height: 100dvh;
}

::selection {
    background: var(--accent-primary);
    color: white;
}

::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-default);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-strong);
}

/* ============================================
   Layout
   ============================================ */

.app-container {
    display: flex;
    height: 100dvh;
    overflow: hidden;
}

/* ============================================
   Sidebar
   ============================================ */

.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    transition: width var(--transition-default), min-width var(--transition-default), transform var(--transition-default);
    z-index: 100;
    overflow: hidden;
}

.sidebar.collapsed {
    width: 0;
    min-width: 0;
    border-right: none;
}

.metrics-btn {
    font-size: 0.65rem;
    color: var(--text-tertiary);
    cursor: pointer;
    margin-left: 8px;
    padding: 2px 6px;
    border-radius: 4px;
    background: var(--bg-tertiary);
}
.metrics-btn:hover {
    color: var(--text-primary);
    background: var(--border-default);
}
.sidebar-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px; 
    border-bottom: 1px solid var(--border-subtle);
    height: 60px;
}

.sidebar-new-chat-btn {
    margin-left: auto; /* Pushes it to the right within the header */
    color: var(--text-secondary);
}

.sidebar-new-chat-btn:hover {
    color: var(--accent-primary);
    background: var(--bg-hover);
}

.sidebar-collapse-btn {
    display: none;
    align-items: center;
    justify-content: center;
    width: 36px; /* Match #desktopSidebarToggle width */
    height: 36px; /* Match #desktopSidebarToggle height */
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.sidebar-collapse-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

@media (min-width: 769px) {
    .sidebar-collapse-btn {
        display: flex;
    }
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    display: flex;
    align-items: center;
    animation: float 6s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-3px); }
}

.logo-text {
    font-size: 1.05rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent-secondary), var(--accent-primary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}

.workspace-section {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-tertiary);
}

.workspace-switcher {
    display: flex;
    align-items: center;
    gap: 8px;
}

.workspace-select {
    flex: 1;
    background: var(--bg-primary);
    border: 1px solid var(--border-default);
    color: var(--text-primary);
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-weight: 600;
    outline: none;
    cursor: pointer;
    font-family: var(--font-sans);
}

.workspace-select:focus {
    border-color: var(--accent-primary);
}

.workspace-btn {
    width: 28px;
    height: 28px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
}
.workspace-btn:hover {
    background: var(--accent-subtle);
    color: var(--accent-primary);
    border-color: var(--accent-primary);
}

.sidebar-search {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid var(--border-subtle);
}

.sidebar-search svg {
    color: var(--text-tertiary);
    flex-shrink: 0;
}

.sidebar-search input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    color: var(--text-primary);
}

.sidebar-search input::placeholder {
    color: var(--text-placeholder);
}

.sidebar-chats {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    position: relative;
    group: chat-item;
}

.chat-item:hover {
    background: var(--bg-hover);
}

.chat-item.active {
    background: var(--accent-subtle);
    border: 1px solid rgba(124, 58, 237, 0.15);
}

.chat-item-text {
    flex: 1;
    min-width: 0;
}

.chat-item-title {
    font-size: 0.85rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-primary);
}

.chat-item-date {
    font-size: 0.7rem;
    color: var(--text-tertiary);
    margin-top: 2px;
}

.chat-item-actions {
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.chat-item:hover .chat-item-actions {
    opacity: 1;
}

.chat-item-actions .btn-icon {
    width: 28px;
    height: 28px;
}

.sidebar-footer {
    padding: 12px 24px; /* Matched with site-footer */
    border-top: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 52px; /* Consistent baseline */
}

.model-status {
    display: flex;
    align-items: center;
    gap: 8px;
}

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

.status-dot.online {
    background: var(--success);
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
    animation: pulse-green 2s ease-in-out infinite;
}

.status-dot.offline {
    background: var(--danger);
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.4);
}

.status-dot.loading {
    background: var(--warning);
    animation: pulse-yellow 1s ease-in-out infinite;
}

@keyframes pulse-green {
    0%, 100% { box-shadow: 0 0 4px rgba(34, 197, 94, 0.4); }
    50% { box-shadow: 0 0 12px rgba(34, 197, 94, 0.7); }
}

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

.status-info {
    display: flex;
    flex-direction: column;
}

.status-model {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.status-text {
    font-size: 0.68rem;
    color: var(--text-tertiary);
}

.desktop-floating-nav {
    display: none;
}

@media (min-width: 769px) {
    .desktop-floating-nav {
        display: flex;
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        padding: 14px 20px;
        z-index: 50;
        justify-content: space-between;
        align-items: center;
        pointer-events: none;
        transition: all var(--transition-default);
    }
    
    .desktop-floating-nav * {
        pointer-events: auto;
    }
    
    .floating-left {
        display: flex;
        align-items: center;
        gap: 16px;
    }
    
    #desktopSidebarToggle {
        background: var(--bg-primary);
        border: 1px solid var(--border-subtle);
        color: var(--text-secondary);
        transition: all var(--transition-fast);
        border-radius: var(--radius-md);
        box-shadow: 0 2px 8px rgba(0,0,0,0.05);
        width: 36px;
        height: 36px;
        opacity: 0;
        pointer-events: none;
    }
    
    #desktopSidebarToggle:hover {
        color: var(--text-primary);
        background: var(--bg-hover);
    }
    
    .floating-brand {
        display: flex;
        align-items: center;
        gap: 10px;
        opacity: 0;
        transform: translateX(-15px);
        transition: all 0.4s cubic-bezier(0.16, 1, 0.3, 1);
        pointer-events: none;
    }
    
    .floating-logo-img {
        width: 30px;
        height: 30px;
        border-radius: 6px;
        object-fit: contain;
    }
    
    .floating-new-chat-btn {
        background: transparent;
        color: var(--text-secondary);
        transition: all var(--transition-fast);
        opacity: 0;
        transform: translateX(-15px);
        pointer-events: none;
    }
    
    .floating-new-chat-btn:hover {
        color: var(--accent-primary);
        background: var(--bg-hover);
        transform: scale(1.1);
    }
    
    body.sidebar-collapsed .floating-new-chat-btn {
        opacity: 1;
        transform: translateX(0);
        pointer-events: auto;
        transition-delay: 0.1s;
    }
    
    body.sidebar-collapsed #desktopSidebarToggle,
    body.sidebar-collapsed .floating-brand {
        opacity: 1;
        transform: translate(0, 0);
        pointer-events: auto;
    }
}

/* ============================================
   Main Content
   ============================================ */

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
    background: var(--bg-primary);
}

.mobile-header {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-secondary);
}

.mobile-title {
    font-weight: 600;
    font-size: 1rem;
    background: linear-gradient(135deg, var(--accent-secondary), var(--accent-primary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

/* ============================================
   Welcome Screen
   ============================================ */

.welcome-screen {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 24px;
    animation: fadeIn 0.6s ease-out;
}

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

.welcome-content {
    text-align: center;
    max-width: 640px;
    width: 100%;
}

.welcome-logo {
    margin-bottom: 24px;
    animation: float 6s ease-in-out infinite;
}

.welcome-logo svg {
    filter: drop-shadow(0 0 30px rgba(124, 58, 237, 0.3));
}

.welcome-title {
    font-size: 2.5rem;
    font-weight: 800;
    letter-spacing: -0.04em;
    background: linear-gradient(135deg, #f0f0f5 0%, var(--accent-secondary) 50%, var(--accent-primary) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
}

.welcome-subtitle {
    font-size: 1.05rem;
    color: var(--text-secondary);
    margin-bottom: 40px;
}

.welcome-subtitle strong {
    color: var(--accent-secondary);
    font-weight: 600;
}

.welcome-cards {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.welcome-card {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px;
    background: var(--surface-glass);
    border: 1px solid var(--surface-glass-border);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all var(--transition-default);
    text-align: left;
    font-family: var(--font-sans);
    color: var(--text-primary);
}

.welcome-card:hover {
    background: var(--surface-glass-hover);
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-glow);
    transform: translateY(-2px);
}

.welcome-card-icon {
    font-size: 1.3rem;
    flex-shrink: 0;
    margin-top: 2px;
}

.welcome-card-text {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.welcome-card-text strong {
    font-size: 0.85rem;
    font-weight: 600;
}

.welcome-card-text span {
    font-size: 0.78rem;
    color: var(--text-tertiary);
    line-height: 1.4;
}

/* ============================================
   Messages
   ============================================ */

.messages-container {
    flex: 1;
    overflow: hidden;
    display: none;
}

.messages-container.active {
    display: flex;
    flex-direction: column;
}

.messages-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 24px 0;
    scroll-behavior: smooth;
}

.message {
    padding: 12px 24px;
    animation: messageIn 0.35s ease-out;
}

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

.message-inner {
    max-width: var(--message-max-width);
    margin: 0 auto;
    display: flex;
    gap: 16px;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.85rem;
    font-weight: 600;
    margin-top: 2px;
}

.message.user .message-avatar {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-tertiary));
    color: white;
}

.message.assistant .message-avatar {
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    color: var(--accent-secondary);
}

.message-body {
    flex: 1;
    min-width: 0;
}

.message-sender {
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-secondary);
}

.message.user .message-sender {
    color: var(--accent-secondary);
}

.message-content {
    font-size: 0.92rem;
    line-height: 1.7;
    color: var(--text-primary);
}

.message.user .message-content {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    text-align: right;
    padding: 10px 16px;
    border-radius: 12px 0 12px 12px;
    display: inline-block;
    max-width: 85%;
}

.message.user .message-body {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
}

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

.message.user .message-sender {
    text-align: right;
}

/* Markdown content styles */
.message-content h1, .message-content h2, .message-content h3,
.message-content h4, .message-content h5, .message-content h6 {
    margin-top: 1.2em;
    margin-bottom: 0.6em;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.3;
}

.message-content h1 { font-size: 1.4rem; }
.message-content h2 { font-size: 1.2rem; }
.message-content h3 { font-size: 1.05rem; }

.message-content p {
    margin-bottom: 0.8em;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content ul, .message-content ol {
    margin: 0.6em 0;
    padding-left: 1.5em;
}

.message-content li {
    margin-bottom: 0.3em;
}

.message-content blockquote {
    border-left: 3px solid var(--accent-primary);
    padding-left: 16px;
    margin: 0.8em 0;
    color: var(--text-secondary);
    font-style: italic;
}

.message-content a {
    color: var(--accent-secondary);
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition: border-color var(--transition-fast);
}

.message-content a:hover {
    border-bottom-color: var(--accent-secondary);
}

.message-content strong {
    font-weight: 600;
    color: var(--text-primary);
}

.message-content em {
    font-style: italic;
    color: var(--text-secondary);
}

/* Inline code */
.message-content code:not(pre code) {
    font-family: var(--font-mono);
    font-size: 0.85em;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    padding: 2px 6px;
    border-radius: 4px;
    color: var(--accent-secondary);
}

/* Code blocks */
.message-content pre {
    margin: 1em 0;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 1px solid var(--border-subtle);
    position: relative;
}

.code-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--bg-elevated);
    border-bottom: 1px solid var(--border-subtle);
    font-size: 0.75rem;
}

.code-block-lang {
    font-family: var(--font-mono);
    color: var(--text-tertiary);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.code-copy-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: 0.75rem;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.code-copy-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.code-copy-btn.copied {
    color: var(--success);
}

.message-content pre code {
    display: block;
    padding: 16px;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    line-height: 1.6;
    overflow-x: auto;
    background: var(--bg-tertiary);
}

/* Tables */
.message-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1em 0;
    font-size: 0.88rem;
}

.message-content th, .message-content td {
    padding: 8px 12px;
    border: 1px solid var(--border-default);
    text-align: left;
}

.message-content th {
    background: var(--bg-elevated);
    font-weight: 600;
    color: var(--text-secondary);
}

.message-content hr {
    border: none;
    border-top: 1px solid var(--border-subtle);
    margin: 1.5em 0;
}

/* Thinking block */
.thinking-block {
    margin: 8px 0;
    border-radius: var(--radius-md);
    border: 1px solid rgba(124, 58, 237, 0.15);
    overflow: hidden;
    background: rgba(124, 58, 237, 0.04);
}

.thinking-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--accent-secondary);
    font-weight: 500;
    transition: background var(--transition-fast);
}

.thinking-header:hover {
    background: rgba(124, 58, 237, 0.08);
}

.thinking-header svg {
    transition: transform var(--transition-fast);
}

.thinking-header.open svg {
    transform: rotate(90deg);
}

.thinking-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid var(--accent-subtle);
    border-top-color: var(--accent-secondary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.thinking-content {
    padding: 0 14px 12px;
    font-size: 0.82rem;
    color: var(--text-tertiary);
    line-height: 1.6;
    display: none;
    font-style: italic;
}

.thinking-content.open {
    display: block;
}

/* Typing indicator */
.typing-indicator {
    display: inline-flex;
    gap: 4px;
    padding: 4px 0;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    background: var(--accent-secondary);
    border-radius: 50%;
    animation: typing 1.4s infinite;
    opacity: 0.4;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

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

/* ============================================
   Input Area
   ============================================ */

.input-area {
    padding: 0 24px 20px;
}

.input-wrapper {
    max-width: var(--input-max-width);
    margin: 0 auto;
    background: var(--bg-secondary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    padding: 4px;
    transition: all var(--transition-default);
    display: flex;
    flex-direction: column;
}

.input-wrapper:focus-within {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-subtle), var(--shadow-glow);
}

.input-wrapper textarea {
    width: 100%;
    background: none;
    border: none;
    outline: none;
    font-family: var(--font-sans);
    font-size: 0.92rem;
    color: var(--text-primary);
    padding: 12px 14px 4px;
    resize: none;
    max-height: 200px;
    line-height: 1.5;
}

.input-wrapper textarea::placeholder {
    color: var(--text-placeholder);
}

.input-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 8px 8px;
}

.toolbar-tools {
    display: flex;
    align-items: center;
    gap: 4px;
}

.toolbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.toolbar-btn {
    width: 32px;
    height: 32px;
    color: var(--text-tertiary);
}

.toolbar-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.feature-toggle.active {
    color: var(--accent-primary);
    background: var(--accent-subtle);
}

.feature-toggle.active:hover {
    color: var(--accent-tertiary);
}

/* Attachment Preview */
.attachment-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 14px 4px;
    border-bottom: 1px solid var(--border-subtle);
}

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

.attachment-item {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-default);
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    color: var(--text-secondary);
    position: relative;
    max-width: 150px;
}

.attachment-item.image {
    padding: 2px;
}

.attachment-item img {
    height: 32px;
    width: 32px;
    object-fit: cover;
    border-radius: 4px;
}

.attachment-name {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-family: var(--font-mono);
}

.attachment-remove {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--bg-elevated);
    border: 1px solid var(--border-strong);
    color: var(--text-primary);
    cursor: pointer;
    position: absolute;
    top: -6px;
    right: -6px;
    font-size: 10px;
    transition: all var(--transition-fast);
}

.attachment-remove:hover {
    background: var(--danger);
    border-color: var(--danger);
    color: white;
}

.char-count {
    font-size: 0.7rem;
    color: var(--text-tertiary);
    font-family: var(--font-mono);
}

.send-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    background: var(--accent-primary);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.send-btn:hover:not(:disabled) {
    background: var(--accent-tertiary);
    box-shadow: var(--shadow-glow);
    transform: scale(1.05);
}

.send-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.stop-btn {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-md);
    background: var(--danger);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    animation: pulse-stop 1.5s ease-in-out infinite;
}

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

.stop-btn:hover {
    background: var(--danger-hover);
}

.input-disclaimer {
    text-align: center;
    font-size: 0.7rem;
    color: var(--text-tertiary);
    margin-top: 10px;
    letter-spacing: 0.01em;
}

/* ============================================
   Buttons
   ============================================ */

.btn-icon {
    width: 34px;
    height: 34px;
    border-radius: var(--radius-md);
    border: none;
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.btn-icon:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-primary {
    padding: 8px 20px;
    border-radius: var(--radius-md);
    border: none;
    background: var(--accent-primary);
    color: white;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-primary:hover {
    background: var(--accent-tertiary);
    box-shadow: var(--shadow-glow);
}

.btn-secondary {
    padding: 8px 20px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-default);
    background: none;
    color: var(--text-secondary);
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-secondary:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.btn-danger {
    padding: 8px 20px;
    border-radius: var(--radius-md);
    border: none;
    background: var(--danger);
    color: white;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-danger:hover {
    background: var(--danger-hover);
}

/* ============================================
   Modal
   ============================================ */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease-out;
}

.modal-overlay.hidden {
    display: none;
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-xl);
    width: 90%;
    max-width: 520px;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
    animation: modalIn 0.3s ease-out;
}

.modal-small {
    max-width: 400px;
}

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

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px 12px;
}

.modal-header h2 {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.modal-body {
    padding: 12px 24px 16px;
    overflow-y: auto;
    flex-shrink: 1;
}

.modal-body p {
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 12px 24px 20px;
}

.setting-group {
    margin-bottom: 16px;
}

.setting-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
    cursor: pointer;
}

.setting-label input[type="checkbox"] {
    accent-color: var(--accent-primary);
    width: 16px;
    height: 16px;
}

.setting-value {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    color: var(--accent-secondary);
    margin-left: 4px;
}

.setting-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 0.88rem;
    outline: none;
    transition: all var(--transition-fast);
}

.setting-input:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px var(--accent-subtle);
}

.setting-textarea {
    resize: vertical;
    min-height: 80px;
    font-size: 0.82rem;
    line-height: 1.5;
}

select.setting-input {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%239898a8' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 32px;
}

.setting-range {
    width: 100%;
    accent-color: var(--accent-primary);
    cursor: pointer;
}

/* ============================================
   Utilities
   ============================================ */

.hidden {
    display: none !important;
}

/* Empty state */
.empty-chats {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: var(--text-tertiary);
    text-align: center;
}

.empty-chats svg {
    margin-bottom: 12px;
    opacity: 0.3;
}

.empty-chats p {
    font-size: 0.82rem;
}

/* ============================================
   Responsive
   ============================================ */

@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
        box-shadow: var(--shadow-lg);
    }

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

    .mobile-header {
        display: flex;
    }

    .welcome-title {
        font-size: 1.8rem;
    }

    .welcome-cards {
        grid-template-columns: 1fr;
    }

    .message {
        padding: 12px 16px;
    }

    .input-area {
        padding: 0 12px 16px;
    }
}

/* Mobile sidebar overlay */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
}

.sidebar-overlay.active {
    display: block;
}

@media (max-width: 768px) {
    .sidebar-overlay.active {
        display: block;
    }
}
/* ============================================
   Footer
   ============================================ */

.site-footer {
    border-top: 1px solid var(--border-subtle);
    padding: 12px 24px;
    margin-top: auto;
    background: var(--bg-secondary);
    transition: all var(--transition-default);
}

.footer-bottom {
    max-width: var(--message-max-width);
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
}

.footer-left-link {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    transition: opacity var(--transition-fast);
}

.footer-left-link:hover {
    opacity: 0.8;
}

.version-tag {
    font-size: 0.65rem;
    font-weight: 500;
    color: var(--text-tertiary);
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid var(--border-subtle);
    margin-right: 4px;
}

.copyright {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.lock-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-default);
    border-radius: 6px;
    color: var(--text-tertiary);
}

.footer-center {
    flex: 1;
    display: flex;
    justify-content: center;
}

.footer-contact-link {
    color: #8b0000; /* Dark Red */
    text-decoration: none;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    transition: all var(--transition-fast);
    padding: 4px 8px;
}

.footer-contact-link:hover {
    color: var(--danger);
    text-decoration: underline;
    text-underline-offset: 4px;
}

.footer-right {
    display: flex;
    justify-content: flex-end;
}

.footer-link {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-decoration: none;
    border-bottom: 2px solid var(--text-secondary);
    padding-bottom: 1px;
    transition: all var(--transition-fast);
}

.footer-link:hover {
    color: var(--text-primary);
    border-color: var(--text-primary);
}

@media (max-width: 768px) {
    .footer-bottom {
        flex-direction: column;
        text-align: center;
        gap: 24px;
    }
    
    .footer-left {
        justify-content: center;
    }
    
    .footer-right {
        justify-content: center;
    }
}

/* Improve Prompt Button */
.improve-btn {
    color: var(--accent-secondary);
    transition: all var(--transition-fast);
}

.improve-btn:hover:not(:disabled) {
    color: var(--accent-primary);
    background: var(--accent-subtle);
    transform: scale(1.1);
}

.improve-btn.active-optimization {
    animation: pulse-improve 1s ease-in-out infinite;
    color: var(--accent-primary);
}

@keyframes pulse-improve {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); opacity: 0.7; }
    100% { transform: scale(1); opacity: 1; }
}
/* Proposal Actions */
.proposal-actions {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px dashed var(--border-subtle);
    display: flex;
    justify-content: flex-end;
}

.apply-proposal-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    font-size: 0.8rem;
    font-weight: 600;
    background: var(--accent-primary);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.apply-proposal-btn:hover {
    background: var(--accent-tertiary);
    transform: translateY(-1px);
    box-shadow: var(--shadow-glow);
}

.apply-proposal-btn svg {
    transition: transform var(--transition-fast);
}

.apply-proposal-btn:hover svg {
    transform: rotate(45deg);
}

/* ============================================
   Provider / API Key Styles
   ============================================ */

.provider-auth-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    margin-top: 6px;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    transition: all var(--transition-default);
    width: fit-content;
}

.provider-auth-badge.auth-none {
    background: rgba(34, 197, 94, 0.1);
    color: var(--success);
    border: 1px solid rgba(34, 197, 94, 0.2);
}

.provider-auth-badge.auth-apikey {
    background: rgba(245, 158, 11, 0.1);
    color: var(--warning);
    border: 1px solid rgba(245, 158, 11, 0.2);
}

.provider-auth-badge.auth-bearer {
    background: rgba(59, 130, 246, 0.1);
    color: var(--info);
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.apikey-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.apikey-input-wrapper .setting-input {
    padding-right: 42px;
    font-family: var(--font-mono);
    font-size: 0.82rem;
    letter-spacing: 0.5px;
}

.apikey-toggle {
    position: absolute;
    right: 6px;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-tertiary);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    cursor: pointer;
    background: transparent;
    border: none;
}

.apikey-toggle:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

.apikey-security-note {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 6px;
    font-size: 0.68rem;
    color: var(--text-tertiary);
    line-height: 1.4;
}

.apikey-security-note svg {
    flex-shrink: 0;
    color: var(--success);
}

/* Provider status color indicators in footer */
.status-provider-icon {
    font-size: 0.7rem;
    margin-right: 2px;
}

/* ============================================
   Settings: Inline Groups (top-p / top-k row)
   ============================================ */
.setting-inline-group {
    display: flex;
    gap: 16px;
}
.setting-inline-group .setting-group {
    flex: 1;
    min-width: 0;
}

/* ============================================
   Settings: IP Whitelist Section
   ============================================ */
.ip-whitelist-section {
    margin-top: 8px;
}
.ip-whitelist-current {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    font-size: 0.8rem;
    margin-bottom: 8px;
}
.ip-whitelist-current code {
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--accent-primary);
}
.ip-whitelist-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}
.ip-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    font-family: var(--font-mono);
    color: var(--text-secondary);
}
.ip-tag.hardcoded {
    background: rgba(34, 197, 94, 0.08);
    border-color: rgba(34, 197, 94, 0.2);
    color: var(--success);
}
.ip-tag .remove-ip {
    cursor: pointer;
    opacity: 0.6;
    transition: opacity var(--transition-fast);
    background: none;
    border: none;
    color: inherit;
    font-size: 0.8rem;
    padding: 0;
    line-height: 1;
}
.ip-tag .remove-ip:hover {
    opacity: 1;
    color: var(--danger);
}

/* ============================================
   Secure Gate — PIN + IP Auth Overlay
   ============================================ */
#secureGateOverlay {
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: #f5f5f7;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.4s ease, transform 0.4s ease;
}

#secureGateOverlay.sg-success {
    opacity: 0;
    transform: scale(1.05);
    pointer-events: none;
}

.sg-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
    max-width: 380px;
    padding: 32px 24px;
    user-select: none;
}

/* Logo */
.sg-logo {
    margin-bottom: 20px;
}
.sg-logo-circle {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    border: 3px solid #b22222;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #b22222;
    font-size: 1.4rem;
    font-weight: 800;
    letter-spacing: 1px;
    font-family: 'Inter', sans-serif;
}

/* Titles */
.sg-title {
    font-family: 'Inter', sans-serif;
    font-size: 1.4rem;
    font-weight: 800;
    letter-spacing: 3px;
    color: #1a1a2e;
    margin: 0 0 4px 0;
}
.sg-subtitle {
    font-family: 'Inter', sans-serif;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 3px;
    color: #888;
    margin: 0 0 32px 0;
}

/* PIN indicators - Grouped Slot Layout */
.sg-input-display {
    display: flex;
    gap: 32px;
    margin-bottom: 32px;
    justify-content: center;
}

.sg-slot {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 48px;
    gap: 12px;
}

.sg-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #ccc;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    opacity: 0.3;
}

.sg-dot.filled {
    background: #1a1a2e;
    transform: scale(1.2);
    opacity: 1;
}

.sg-dot.error {
    background: #b22222;
    opacity: 1;
}

.sg-line {
    width: 100%;
    height: 3px;
    background: #ddd;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.sg-line.filled {
    background: #1a1a2e;
    height: 4px;
}

.sg-line.error {
    background: #b22222;
}

/* Keypad Grid */
.sg-keypad {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    width: 100%;
    max-width: 340px;
    margin-bottom: 24px;
}
.sg-key {
    aspect-ratio: 1;
    border: 2px solid #e0e0e4;
    border-radius: 16px;
    background: #fff;
    font-family: 'Inter', sans-serif;
    font-size: 1.5rem;
    font-weight: 700;
    color: #1a1a2e;
    cursor: pointer;
    transition: all 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    -webkit-tap-highlight-color: transparent;
}
.sg-key:hover {
    background: #f0f0f4;
    border-color: #c0c0c8;
    transform: translateY(-1px);
}
.sg-key:active,
.sg-key.sg-key-pressed {
    background: #e8e8f0;
    border-color: #999;
    transform: translateY(0) scale(0.96);
}

/* Clear Button */
.sg-clear-btn {
    background: none;
    border: none;
    font-family: 'Inter', sans-serif;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 2px;
    color: #888;
    cursor: pointer;
    padding: 8px 16px;
    transition: color 0.2s ease;
}
.sg-clear-btn:hover {
    color: #b22222;
}

/* IP Info */
.sg-ip-info {
    margin-top: 16px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.65rem;
    color: #bbb;
    letter-spacing: 0.5px;
}

/* Shake animation */
@keyframes sgShake {
    0%, 100% { transform: translateX(0); }
    15% { transform: translateX(-12px); }
    30% { transform: translateX(10px); }
    45% { transform: translateX(-8px); }
    60% { transform: translateX(6px); }
    75% { transform: translateX(-3px); }
}
.sg-shake {
    animation: sgShake 0.5s ease;
}

@keyframes dotPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.4); }
    100% { transform: scale(1.15); }
}

/* Responsive */
@media (max-width: 480px) {
    .sg-container {
        padding: 24px 16px;
        max-width: 320px;
    }
    .sg-keypad {
        gap: 8px;
    }
    .sg-key {
        font-size: 1.3rem;
        border-radius: 12px;
    }
    .sg-logo-circle {
        width: 60px;
        height: 60px;
        font-size: 1.2rem;
    }
}
/* ─── Error Message Cards ──────────────────── */
.error-message-card {
    background: rgba(var(--danger-rgb), 0.05);
    border: 1px solid rgba(var(--danger-rgb), 0.2);
    border-radius: var(--radius-lg);
    padding: 16px;
    margin: 8px 0;
    max-width: 500px;
    animation: sg-shake 0.4s cubic-bezier(.36,.07,.19,.97) both;
}

.error-header {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--danger);
    font-size: 0.85rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.error-body {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.error-body code {
    background: rgba(var(--danger-rgb), 0.1);
    color: var(--danger);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: var(--font-mono);
}

.message-error .message-avatar {
    border-color: var(--danger) !important;
    background: rgba(var(--danger-rgb), 0.1) !important;
    color: var(--danger) !important;
}

@keyframes sg-shake {
    10%, 90% { transform: translate3d(-1px, 0, 0); }
    20%, 80% { transform: translate3d(2px, 0, 0); }
    30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
    40%, 60% { transform: translate3d(4px, 0, 0); }
}

:root {
    --danger-rgb: 239, 68, 68;
}

/* ─── Smart Model Filter (Premium) ────────── */
.smart-model-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: border-color 0.2s ease;
}

.smart-model-container:focus-within {
    border-color: var(--accent-primary);
}

.model-filter-bar {
    display: flex;
    align-items: center;
    padding: 6px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-subtle);
    gap: 8px;
}

.model-filter-bar .search-box {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
}

.model-filter-bar .search-box svg {
    position: absolute;
    left: 10px;
    color: var(--text-tertiary);
    pointer-events: none;
}

.model-filter-bar .search-input {
    width: 100%;
    background: transparent;
    border: none;
    padding: 8px 8px 8px 32px;
    font-size: 0.8rem;
    color: var(--text-primary);
    outline: none;
}

.filter-actions {
    display: flex;
    gap: 4px;
}

.filter-pill {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    font-size: 0.65rem;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.filter-pill:hover {
    background: var(--bg-primary);
    color: var(--text-primary);
}

.filter-pill.active {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
    box-shadow: 0 2px 8px rgba(var(--accent-primary-rgb, 99, 102, 241), 0.3);
}

.setting-input-premium {
    width: 100%;
    background: transparent;
    border: none;
    padding: 10px;
    font-size: 0.85rem;
    color: var(--text-primary);
    outline: none;
    cursor: pointer;
}

optgroup {
    background: var(--bg-primary);
    color: var(--accent-secondary);
    font-size: 0.7rem;
    font-weight: 800;
    text-transform: uppercase;
    padding: 6px;
    border-bottom: 1px solid var(--border-subtle);
}

option {
    padding: 10px;
    background: var(--bg-secondary);
}

:root {
    --accent-primary-rgb: 99, 102, 241;
}

.btn-retry {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--danger, #ef4444);
    color: white !important;
    border: none;
    padding: 8px 18px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.2);
}

.btn-retry:hover {
    background: #dc2626; /* Darker red */
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(239, 68, 68, 0.4);
}

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

.btn-retry svg {
    transition: transform 0.3s ease;
}

.btn-retry:hover svg {
    transform: rotate(180deg);
}

/* ============================================
   Model Manager Styles
   ============================================ */
   
.model-list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--bg-primary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.model-list-item:hover {
    border-color: var(--border-strong);
    background: var(--bg-elevated);
}

.model-item-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.model-item-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    font-family: var(--font-mono);
}

.model-item-size {
    font-size: 0.7rem;
    color: var(--text-tertiary);
}

.remove-model-btn {
    color: var(--text-tertiary);
    transition: all var(--transition-fast);
}

.remove-model-btn:hover {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
}

.suggestion-chip {
    padding: 4px 10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-full);
    font-size: 0.7rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.suggestion-chip:hover {
    background: var(--accent-subtle);
    color: var(--accent-secondary);
    border-color: var(--accent-primary);
}

.progress-bar-bg {
    background: var(--bg-primary);
    border-radius: 4px;
    height: 8px;
    width: 100%;
    margin: 8px 0;
}

#pullProgressBar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-primary), var(--accent-secondary));
    border-radius: 4px;
    transition: width 0.3s ease;
}

#manageModelsBtn {
    font-weight: 600;
    transition: opacity var(--transition-fast);
}

#manageModelsBtn:hover {
    opacity: 0.8;
}

/* Animations */
@keyframes pulse-subtle {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.7; }
}

.pulling-active {
    animation: pulse-subtle 2s infinite;
}

.alert-box.warning {
    border-left: 4px solid var(--warning);
}

.code-block-container code {
    white-space: pre-wrap;
    word-break: break-all;
}

#copyCorsBtn:active {
    background: var(--accent-primary);
    color: white;
}

/* Chat Grouping Headers */
.chat-group-header {
    padding: 16px 12px 6px;
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: pointer;
    display: flex;
    align-items: center;
    user-select: none;
    transition: color 0.2s;
}

.chat-group-header:hover {
    color: var(--accent-secondary);
}

.chat-group summary {
    list-style: none;
}

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

.chat-group {
    border-bottom: 1px solid transparent;
}

.chat-group[open] {
    padding-bottom: 8px;
}

.copy-btn-mini {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.65rem;
    cursor: pointer;
    transition: all 0.2s;
}

.copy-btn-mini:hover {
    background: var(--accent-primary);
    color: white;
    border-color: var(--accent-primary);
}

.cors-tabs .code-block-container code {
    padding-right: 60px;
    display: block;
}

/* CORS Warning Badge */
#corsWarningBadge {
    animation: pulse-warning 3s infinite;
    transition: all 0.2s;
}

#corsWarningBadge:hover {
    background: rgba(245, 158, 11, 0.2);
    border-color: var(--warning);
}

@keyframes pulse-warning {
    0% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0.4); }
    70% { box-shadow: 0 0 0 6px rgba(245, 158, 11, 0); }
    100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0); }
}

/* ============================================
   MOBILE RESPONSIVE FIXES
   ============================================ */

.mobile-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

@media (max-width: 768px) {
    .mobile-header {
        display: flex;
        padding: 8px 12px;
        gap: 8px;
    }

    .sidebar-footer {
        padding: 10px 12px;
        flex-wrap: wrap;
        height: auto;
        min-height: 48px;
    }

    .model-status {
        min-width: 0;
        overflow: hidden;
    }

    .status-model {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 140px;
    }

    .site-footer {
        padding: 8px 12px;
    }

    .footer-bottom {
        gap: 8px;
    }

    .footer-left-link { gap: 6px; }
    .version-tag { font-size: 0.6rem; padding: 1px 4px; }
    .copyright { font-size: 0.65rem; }
    .footer-contact-link { font-size: 0.65rem; padding: 2px 4px; }
    .footer-link { font-size: 0.65rem; }

    .modal {
        width: 95%;
        max-height: 90vh;
        border-radius: var(--radius-lg);
    }

    .modal-header { padding: 16px 16px 8px; }
    .modal-body { padding: 8px 16px 12px; }
    .modal-footer { padding: 8px 16px 16px; }

    .setting-inline-group {
        flex-direction: column;
        gap: 0;
    }

    .welcome-screen { padding: 24px 16px; }
    .welcome-content { max-width: 100%; }

    .input-area { padding: 0 8px 12px; }
    .input-disclaimer { font-size: 0.62rem; margin-top: 6px; }
}

@media (max-width: 480px) {
    .welcome-title { font-size: 1.5rem; }
    .welcome-subtitle { font-size: 0.9rem; margin-bottom: 24px; }
    .welcome-card { padding: 12px; gap: 10px; }
    .welcome-card-icon { font-size: 1.1rem; }
    .welcome-card-text strong { font-size: 0.8rem; }
    .welcome-card-text span { font-size: 0.72rem; }

    .message { padding: 8px 10px; }
    .message-inner { gap: 10px; }
    .message-avatar { width: 28px; height: 28px; }
    .message-content { font-size: 0.85rem; }

    .footer-bottom { flex-direction: column; gap: 6px; }
    .footer-center { order: -1; }
}

/* ============================================
   MESSAGE ACTION BUTTONS (Copy, Regen, Edit, Bookmark)
   ============================================ */

.message-actions {
    display: flex;
    gap: 4px;
    margin-top: 8px;
    opacity: 0;
    transition: opacity var(--transition-fast);
}

.message:hover .message-actions,
.message .message-actions:focus-within {
    opacity: 1;
}

.msg-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    color: var(--text-tertiary);
    font-size: 0.7rem;
    font-family: var(--font-sans);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.msg-action-btn:hover {
    color: var(--text-primary);
    border-color: var(--border-strong);
    background: var(--bg-hover);
}

.msg-action-btn.bookmarked {
    color: #f59e0b;
    border-color: rgba(245, 158, 11, 0.3);
    background: rgba(245, 158, 11, 0.08);
}

.msg-action-btn.copied-feedback {
    color: var(--success);
    border-color: rgba(34, 197, 94, 0.3);
}

/* ============================================
   DRAG & DROP OVERLAY
   ============================================ */

.drop-zone-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: rgba(124, 58, 237, 0.15);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease-out;
}

.drop-zone-overlay.hidden { display: none !important; }

.drop-zone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 48px;
    border: 3px dashed var(--accent-primary);
    border-radius: var(--radius-xl);
    background: var(--bg-secondary);
    color: var(--accent-secondary);
    animation: pulse-drop 2s ease-in-out infinite;
}

.drop-zone-content p {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

@keyframes pulse-drop {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.02); }
}

/* ============================================
   VOICE INPUT
   ============================================ */

#voiceBtn.voice-active {
    color: var(--danger);
    background: rgba(239, 68, 68, 0.1);
    animation: voice-pulse 1.5s ease-in-out infinite;
}

@keyframes voice-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.3); }
    50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

/* ============================================
   TOKEN ESTIMATOR
   ============================================ */

.token-estimate {
    font-size: 0.65rem;
    color: var(--text-tertiary);
    font-family: var(--font-mono);
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.token-bar {
    width: 40px;
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    overflow: hidden;
}

.token-bar-fill {
    height: 100%;
    background: var(--accent-primary);
    border-radius: 2px;
    transition: width 0.3s ease;
}

.token-bar-fill.warn { background: var(--warning); }
.token-bar-fill.danger { background: var(--danger); }

/* ============================================
   KEYBOARD SHORTCUTS MODAL
   ============================================ */

.shortcuts-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.shortcut-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
}

.shortcut-item span {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.shortcut-item kbd {
    display: inline-block;
    padding: 2px 8px;
    background: var(--bg-primary);
    border: 1px solid var(--border-default);
    border-radius: 4px;
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-primary);
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

/* ============================================
   EXPORT BUTTON IN CHAT ACTIONS
   ============================================ */
.export-chat-btn { color: var(--text-tertiary); }
.export-chat-btn:hover { color: var(--accent-secondary); }

/* ============================================
   CHAT FAVORITES (STAR) FEATURE
   ============================================ */

/* Star color token — amber/gold, adapts to all themes */
:root {
    --star-color: #f59e0b;
    --star-glow: rgba(245, 158, 11, 0.35);
    --star-bg: rgba(245, 158, 11, 0.08);
}

[data-theme="light"] {
    --star-color: #d97706;
    --star-glow: rgba(217, 119, 6, 0.25);
    --star-bg: rgba(217, 119, 6, 0.07);
}

[data-theme="vanilla"] {
    --star-color: #b45309;
    --star-glow: rgba(180, 83, 9, 0.15);
    --star-bg: rgba(180, 83, 9, 0.05);
}

/* Star button — initially invisible, fades on hover */
.star-chat-btn {
    color: var(--text-tertiary);
    transition: color var(--transition-fast), transform var(--transition-fast), opacity var(--transition-fast);
    opacity: 0;
}

.chat-item:hover .star-chat-btn {
    opacity: 1;
}

/* Always show star when chat is starred */
.star-chat-btn.star-active {
    color: var(--star-color) !important;
    opacity: 1 !important;
}

.star-chat-btn:hover {
    color: var(--star-color);
    transform: scale(1.2);
}

/* Pop animation when starring */
@keyframes star-pop {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.45) rotate(-12deg); }
    70%  { transform: scale(0.9) rotate(6deg); }
    100% { transform: scale(1) rotate(0deg); }
}

.star-chat-btn.star-active svg {
    animation: star-pop 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}

/* Starred chat row highlight */
.chat-item.starred {
    border-left: 2px solid var(--star-color);
    background: var(--star-bg);
}

.chat-item.starred:hover {
    background: color-mix(in srgb, var(--star-bg) 60%, var(--bg-hover));
}

.chat-item.starred.active {
    background: color-mix(in srgb, var(--accent-subtle) 70%, var(--star-bg));
    border-left-color: var(--star-color);
    border-top: 1px solid rgba(124, 58, 237, 0.15);
    border-right: 1px solid rgba(124, 58, 237, 0.15);
    border-bottom: 1px solid rgba(124, 58, 237, 0.15);
}

/* ── Favoritos section (chat-group variant) ─── */
.chat-group-starred {
    margin-bottom: 8px;
}

.chat-group-header-starred {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--star-color) !important;
    font-weight: 700;
    font-size: 0.7rem;
    letter-spacing: 0.03em;
    text-transform: none;
    background: var(--star-bg);
    border-radius: var(--radius-md);
    padding: 6px 10px;
    margin-bottom: 4px;
    border: 1px solid rgba(245, 158, 11, 0.15);
    box-shadow: 0 0 12px var(--star-glow);
    text-shadow: 0 0 8px var(--star-glow);
}

/* Glow pulse on the ★ icon in the header */
@keyframes star-glow-pulse {
    0%, 100% { filter: drop-shadow(0 0 3px var(--star-glow)); }
    50%       { filter: drop-shadow(0 0 8px var(--star-color)); }
}

.chat-group-header-starred svg {
    animation: star-glow-pulse 2.5s ease-in-out infinite;
}

