/* ═════ INSTALL BANNER ═════ */
.install-banner {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(22, 22, 26, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--primary-purple);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5), 0 0 15px rgba(139, 92, 246, 0.15);
    padding: 14px 20px;
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    gap: 16px;
    z-index: 1000;
    transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1), transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    width: max-content;
    max-width: 90vw;
}

/* Hidden state for smooth animations */
.install-banner.hidden {
    opacity: 0;
    pointer-events: none;
    transform: translateX(-50%) translateY(30px);
}

.install-banner span {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary);
}

.install-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

#installBtn {
    background: var(--primary-purple);
    color: #fff;
    border: none;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: background 0.2s, transform 0.2s;
}

#installBtn:hover {
    background: var(--primary-purple-hover);
    transform: scale(1.05);
}

#dismissInstallBtn {
    background: transparent;
    color: var(--text-muted);
    border: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: color 0.2s, background 0.2s;
    font-size: 1.1rem;
}

#dismissInstallBtn:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.1);
}

/* Mobile adjustments */
@media (max-width: 768px) {
    .install-banner {
        flex-direction: column;
        text-align: center;
        gap: 12px;
        padding: 16px;
    }

    .install-actions {
        width: 100%;
        justify-content: center;
    }
}

:root {
    /* Color Palette */
    --bg-main: #0e0e11;
    --sidebar-bg: #16161a;
    --panel-bg: #1a1a21;

    /* Accents */
    --primary-purple: #8b5cf6;
    --primary-purple-hover: #7c3aed;
    --primary-blue: #3b82f6;
    --primary-green: #10b981;
    --danger-red: #ef4444;

    /* Borders & Bubbles */
    --border: rgba(255, 255, 255, 0.08);
    --border-light: rgba(255, 255, 255, 0.15);
    --input-bg: #1c1c22;
    --assistant-bubble: #1a1a21;
    --user-bubble: linear-gradient(135deg, #8b5cf6, #6d28d9);

    /* Typography */
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --disabled-gray: #334155;

    /* Spacing */
    --chat-max-width: 48rem;
    /* 768px */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --radius-xl: 24px;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--bg-main);
    color: var(--text-primary);
    height: 100dvh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    color: var(--primary-purple);
    text-decoration: none;
    transition: color 0.2s;
}

a:hover {
    color: var(--primary-blue);
}

.main-layout {
    display: flex;
    width: 100vw;
    height: 100%;
}

/* ═════ SIDEBAR ═════ */
.sidebar {
    width: 280px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 16px;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
    z-index: 50;
}

.sidebar.collapsed {
    margin-left: -280px;
}

.new-thread-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px;
    background: var(--text-primary);
    color: var(--bg-main);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 24px;
    transition: transform 0.2s, background 0.2s;
}

.new-thread-btn:hover {
    background: #e2e8f0;
    transform: translateY(-1px);
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-right: 4px;
    /* for scrollbar */
}

.chat-item {
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s;
}

.chat-item:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.chat-item.active {
    background: rgba(139, 92, 246, 0.15);
    color: var(--primary-purple);
    font-weight: 500;
}

/* Add to style.css */
.input-area {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    background-color: var(--surface-color);
    border-top: 1px solid var(--border-color);
    gap: 10px;
}

#attach-button {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    font-size: 1.3rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, border-color 0.2s;
    flex-shrink: 0;
}

#attach-button:hover {
    background-color: rgba(255, 255, 255, 0.08);
    border-color: var(--primary-color);
}

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

.attachment-chip {
    background: #252525;
    border: 1px solid var(--border-color);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-color);
}

.attachment-chip button {
    background: none;
    border: none;
    color: #ff5555;
    cursor: pointer;
    font-weight: bold;
    font-size: 1rem;
    padding: 0;
    line-height: 1;
}

.attachment-chip button:hover {
    color: #ff7777;
}

/* Add or replace in style.css */
.chat-container,
#chat-messages {
    flex: 1;
    overflow-y: auto;
    scroll-behavior: smooth;
    display: flex;
    flex-direction: column;
    padding: 20px;
    gap: 12px;
}

#thinking-bubble {
    position: sticky;
    bottom: 16px;
    align-self: flex-start;
    background: var(--surface-color, #1e1e1e);
    border: 1px solid var(--border-color, #333);
    padding: 10px 16px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 10;
    margin-top: auto;
}

.delete-chat-btn {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    font-size: 1.1rem;
    padding: 4px;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.2s, background 0.2s, color 0.2s;
}

.chat-item:hover .delete-chat-btn {
    opacity: 0.6;
}

.delete-chat-btn:hover {
    opacity: 1 !important;
    background: rgba(239, 68, 68, 0.2);
    color: var(--danger-red);
}

.sidebar-footer {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--text-muted);
    padding-top: 16px;
    border-top: 1px solid var(--border);
    margin-top: auto;
}

.sidebar-footer .footer-links {
    display: flex;
    gap: 12px;
}

.sidebar-footer a {
    color: var(--text-secondary);
}

.sidebar-footer a:hover {
    color: var(--text-primary);
}

/* ═════ TERMINAL HEADER ═════ */
.terminal-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
}

.terminal-header {
    padding: 14px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(14, 14, 17, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
    z-index: 10;
    position: sticky;
    top: 0;
}

.header-left,
.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

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

.status-led {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.led-idle {
    background: var(--primary-green);
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
}

.led-thinking {
    background: var(--primary-purple);
    animation: pulse 1s infinite alternate;
    box-shadow: 0 0 8px rgba(139, 92, 246, 0.6);
}

#statusText {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.version-tag {
    font-size: 0.8rem;
    background: var(--border);
    padding: 4px 8px;
    border-radius: 20px;
    color: var(--text-secondary);
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: all 0.2s ease;
}

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

/* ═════ PROGRESS BAR ═════ */
.progress-container {
    width: 100%;
    height: 2px;
    background: transparent;
    position: relative;
    z-index: 11;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary-purple), var(--primary-blue));
    width: 0%;
    transition: width 0.3s ease;
}

/* ═════ CHAT LOG ═════ */
.chat-log {
    flex: 1;
    overflow-y: auto;
    padding: 32px 16px 20px 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    /* Centers the inner message wraps */
    gap: 24px;
    scroll-behavior: smooth;
}

.message-wrap {
    width: 100%;
    max-width: var(--chat-max-width);
    display: flex;
    flex-direction: column;
}

.user-msg {
    align-items: flex-end;
}

.assistant-msg {
    align-items: flex-start;
}

.message-content {
    max-width: 85%;
    padding: 14px 20px;
    border-radius: var(--radius-lg);
    line-height: 1.6;
    font-size: 1rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.user-msg .message-content {
    background: var(--user-bubble);
    color: #fff;
    border-bottom-right-radius: 4px;
    animation: slideInRight 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.assistant-msg .message-content {
    background: var(--assistant-bubble);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
    animation: slideInLeft 0.3s cubic-bezier(0.16, 1, 0.3, 1) both;
}

.user-msg-container {
    display: flex;
    align-items: center;
    gap: 8px;
    justify-content: flex-end;
}

.edit-msg-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    cursor: pointer;
    opacity: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s, transform 0.2s, background 0.2s;
    color: var(--text-secondary);
}

.user-msg-container:hover .edit-msg-btn {
    opacity: 0.6;
}

.edit-msg-btn:hover {
    opacity: 1 !important;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    transform: scale(1.05);
}

/* Markdown styling inside messages */
.message-content pre {
    background: #09090b;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 16px;
    overflow-x: auto;
    font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
    font-size: 0.85rem;
    margin: 1rem 0;
}

.message-content code {
    background: rgba(255, 255, 255, 0.1);
    color: #e2e8f0;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
    font-size: 0.85em;
}

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

.message-content p:first-child {
    margin-top: 0;
}

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

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

.message-content blockquote {
    border-left: 4px solid var(--primary-purple);
    margin: 1rem 0;
    padding: 0.5rem 1rem;
    background: rgba(139, 92, 246, 0.05);
    color: var(--text-secondary);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

/* ═════ INPUT AREA ═════ */
.input-area {
    padding: 0 16px 24px 16px;
    background: linear-gradient(180deg, transparent, var(--bg-main) 20%);
    display: flex;
    justify-content: center;
    position: relative;
    z-index: 10;
}

.input-container {
    width: 100%;
    max-width: var(--chat-max-width);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.input-wrapper {
    display: flex;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 8px 8px 8px 20px;
    transition: border-color 0.3s, box-shadow 0.3s;
    align-items: center;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
}

.input-wrapper:focus-within {
    border-color: var(--primary-purple);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.15), 0 10px 25px -5px rgba(0, 0, 0, 0.5);
}

#cmdInput {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1rem;
    font-family: inherit;
    outline: none;
    padding: 8px 0;
}

#cmdInput::placeholder {
    color: var(--text-muted);
}

#cmdInput:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

#sendBtn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--text-primary);
    color: var(--bg-main);
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
    flex-shrink: 0;
}

#sendBtn:hover:not(:disabled) {
    background: #e2e8f0;
    transform: scale(1.05);
}

#sendBtn:disabled {
    background: var(--disabled-gray);
    color: var(--text-muted);
    cursor: not-allowed;
}

#sendBtn.stop-btn {
    background: var(--danger-red);
    color: white;
}

#sendBtn.stop-btn:hover:not(:disabled) {
    background: #dc2626;
}

.input-footer-text {
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ═════ MODEL PANEL MODAL ═════ */
.model-panel-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 200;
    animation: fadeIn 0.2s ease;
}

.model-panel-overlay.visible {
    display: block;
}

.model-panel {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%) translateY(100%);
    width: min(600px, 95vw);
    max-height: 85dvh;
    background: var(--panel-bg);
    border: 1px solid var(--border-light);
    border-bottom: none;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    z-index: 201;
    display: flex;
    flex-direction: column;
    transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.6);
}

.model-panel.open {
    transform: translateX(-50%) translateY(0);
}

.model-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.model-panel-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.gpu-status-card {
    margin: 20px 24px 8px;
    padding: 16px;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 16px;
}

.gpu-ok {
    border-color: rgba(16, 185, 129, 0.3);
    background: rgba(16, 185, 129, 0.05);
}

.gpu-warn {
    border-color: rgba(245, 158, 11, 0.3);
    background: rgba(245, 158, 11, 0.05);
}

.gpu-none {
    border-color: rgba(239, 68, 68, 0.3);
    background: rgba(239, 68, 68, 0.05);
}

.gpu-status-icon {
    font-size: 24px;
}

.gpu-status-body {
    flex: 1;
}

.gpu-status-title {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 4px;
}

.gpu-status-detail {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.gpu-status-badge {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.1);
}

.gpu-ok .gpu-status-badge {
    color: #34d399;
    background: rgba(16, 185, 129, 0.15);
}

.gpu-warn .gpu-status-badge {
    color: #fbbf24;
    background: rgba(245, 158, 11, 0.15);
}

.gpu-none .gpu-status-badge {
    color: #f87171;
    background: rgba(239, 68, 68, 0.15);
}

.model-panel-section-title {
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    padding: 16px 24px 8px;
}

.model-preset-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.preset-placeholder {
    text-align: center;
    color: var(--text-muted);
    padding: 30px;
    font-size: 0.9rem;
}

.preset-card {
    padding: 14px 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.02);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: all 0.2s;
}

.preset-card:hover:not(.preset-disabled) {
    background: rgba(139, 92, 246, 0.08);
    border-color: rgba(139, 92, 246, 0.4);
}

.preset-card.preset-selected {
    background: rgba(139, 92, 246, 0.15);
    border-color: var(--primary-purple);
}

.preset-icon {
    font-size: 1.2rem;
}

.preset-info {
    flex: 1;
}

.preset-label {
    font-weight: 500;
    font-size: 0.95rem;
    margin-bottom: 4px;
}

.preset-tags {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.preset-pill {
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 12px;
    background: var(--border-light);
    color: var(--text-secondary);
}

.pill-gpu {
    background: rgba(139, 92, 246, 0.2);
    color: #c4b5fd;
}

.pill-cpu {
    background: rgba(59, 130, 246, 0.2);
    color: #93c5fd;
}

.preset-check {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.preset-card.preset-selected .preset-check {
    border-color: var(--primary-purple);
    background: var(--primary-purple);
}

.preset-card.preset-selected .preset-check::after {
    content: '';
    width: 6px;
    height: 6px;
    background: white;
    border-radius: 50%;
}

.model-panel-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px 24px;
    border-top: 1px solid var(--border);
    background: rgba(0, 0, 0, 0.2);
}

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

.active-model-title {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 700;
    margin-bottom: 2px;
}

.active-model-label {
    font-size: 0.9rem;
    color: var(--text-primary);
    font-weight: 500;
}

.apply-model-btn {
    padding: 10px 24px;
    background: var(--text-primary);
    color: var(--bg-main);
    border: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s, background 0.2s;
}

.apply-model-btn:hover:not(:disabled) {
    background: #e2e8f0;
    transform: scale(1.02);
}

.apply-model-btn:disabled {
    background: var(--disabled-gray);
    color: var(--text-muted);
    cursor: not-allowed;
}

/* ═════ ANIMATIONS & MISC ═════ */
@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideInLeft {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes pulse {
    from {
        opacity: 0.6;
        transform: scale(0.9);
    }

    to {
        opacity: 1;
        transform: scale(1.1);
    }
}

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

.typing-indicator span {
    width: 6px;
    height: 6px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.typing-indicator span:nth-child(1) {
    animation-delay: -0.32s;
}

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

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

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

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

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

/* ═════ RESPONSIVE ═════ */
@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        height: 100%;
        box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5);
    }

    #sidebarOverlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.6);
        backdrop-filter: blur(2px);
        z-index: 40;
    }

    #sidebarOverlay.visible {
        display: block;
    }

    .message-content {
        max-width: 92%;
    }

    .input-wrapper {
        border-radius: var(--radius-lg);
    }
}