:root {
    --bg-dark: #0a0b10;
    --bg-panel: rgba(20, 22, 30, 0.6);
    --border-color: rgba(255, 255, 255, 0.1);
    --text-main: #e2e8f0;
    --text-muted: #94a3b8;
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --accent: #06b6d4;
    --user-msg: rgba(99, 102, 241, 0.2);
    --bot-msg: rgba(255, 255, 255, 0.03);
}

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

html {
    height: -webkit-fill-available;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-main);
    height: 100vh;
    height: 100dvh;
    min-height: -webkit-fill-available;
    display: flex;
    overflow: hidden;
    background-image: 
        radial-gradient(circle at 15% 50%, rgba(99, 102, 241, 0.08), transparent 25%),
        radial-gradient(circle at 85% 30%, rgba(6, 182, 212, 0.08), transparent 25%);
}

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

/* Sidebar */
.sidebar {
    width: 320px;
    background: var(--bg-panel);
    backdrop-filter: blur(20px);
    border-right: 1px solid var(--border-color);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 32px;
}

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

.sidebar-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
    background: linear-gradient(135deg, #e2e8f0, #94a3b8);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.badge {
    background: rgba(99, 102, 241, 0.2);
    color: #818cf8;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.config-section label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.glass-select {
    width: 100%;
    padding: 12px;
    background: rgba(0,0,0,0.2);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-main);
    font-family: 'Inter', sans-serif;
    outline: none;
    cursor: pointer;
    transition: all 0.2s;
}

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

.glass-select option {
    background-color: var(--bg-dark);
}

.stats-box {
    margin-top: 12px;
    padding: 12px;
    background: rgba(0,0,0,0.2);
    border-radius: 8px;
    font-size: 0.85rem;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    color: var(--text-muted);
}
.highlight {
    color: var(--accent);
    font-weight: 500;
}

.metrics-panel {
    background: rgba(0,0,0,0.15);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    flex: 1;
}

.metrics-panel h3 {
    font-size: 0.9rem;
    margin-bottom: 16px;
    color: var(--text-muted);
    font-weight: 500;
}

.metric {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.metric-label { font-size: 0.85rem; color: var(--text-muted); }
.metric-value { font-size: 1.1rem; font-weight: 600; color: #e2e8f0; }
.blur-glow { color: #34d399; text-shadow: 0 0 10px rgba(52, 211, 153, 0.4); }

/* Chat Main */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}

.chat-header {
    height: 64px;
    padding: 0 32px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(10, 11, 16, 0.6);
    backdrop-filter: blur(10px);
}

.model-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #10b981;
    box-shadow: 0 0 8px rgba(16, 185, 129, 0.6);
}

.model-info h1 {
    font-size: 1.1rem;
    font-weight: 500;
}

.secondary-btn {
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    font-size: 0.85rem;
}
.secondary-btn:hover { background: rgba(255,255,255,0.05); color: #fff; }

.chat-history {
    flex: 1;
    overflow-y: auto;
    padding: 32px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.message {
    display: flex;
    gap: 16px;
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    animation: fadeIn 0.3s ease-out forwards;
}

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

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 600;
    flex-shrink: 0;
}
.assistant .avatar {
    background: linear-gradient(135deg, var(--primary), var(--accent));
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}
.user .avatar {
    background: #334155;
}

.bubble {
    padding: 16px 20px;
    border-radius: 12px;
    font-size: 0.95rem;
    line-height: 1.6;
    word-break: break-word;
    border: 1px solid transparent;
}
.assistant .bubble {
    background: var(--bot-msg);
    border-color: var(--border-color);
    border-top-left-radius: 2px;
}
.user .bubble {
    background: var(--user-msg);
    border-color: rgba(99, 102, 241, 0.3);
    border-top-right-radius: 2px;
}

.bubble pre {
    background: #000;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 10px 0;
    border: 1px solid #333;
}
.bubble code { font-family: monospace; }
.bubble p { margin-bottom: 8px; }
.bubble p:last-child { margin-bottom: 0; }

.thumbnail {
    max-width: 300px;
    border-radius: 8px;
    margin-bottom: 8px;
    display: block;
}

/* Input Area */
.input-area {
    padding: 24px 32px;
    background: linear-gradient(to top, var(--bg-dark) 50%, transparent);
}

.input-wrapper {
    max-width: 800px;
    margin: 0 auto;
    position: relative;
    background: rgba(20, 22, 30, 0.8);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    display: flex;
    align-items: flex-end;
    padding: 12px 16px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.input-wrapper:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.15);
}

.upload-btn {
    cursor: pointer;
    color: var(--text-muted);
    padding: 8px;
    transition: color 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}
.upload-btn:hover { color: var(--primary); background: rgba(255,255,255,0.05); }

#chat-input {
    flex: 1;
    background: transparent;
    border: none;
    color: #fff;
    font-family: inherit;
    font-size: 16px;
    resize: none;
    padding: 8px 12px;
    max-height: 150px;
    outline: none;
}
#chat-input::placeholder { color: var(--text-muted); }

.primary-btn {
    background: var(--primary);
    color: #fff;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}
.primary-btn:hover { background: var(--primary-hover); transform: translateY(-1px); }
.primary-btn:disabled { background: #334155; color: #94a3b8; cursor: not-allowed; }

.attachment-preview {
    max-width: 800px;
    margin: 0 auto 12px auto;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.preview-item {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid var(--border-color);
}
.preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.remove-preview {
    position: absolute;
    top: 2px;
    right: 2px;
    background: rgba(0,0,0,0.6);
    color: white;
    border: none;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

/* Animations loading */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.loader {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--primary);
    animation: bounce 1.4s infinite ease-in-out both;
    margin-right: 4px;
}
.loader.l1 { animation-delay: -0.32s; }
.loader.l2 { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}

.think-block {
    margin: 12px 0;
    padding: 12px;
    border-left: 3px solid var(--primary);
    background: rgba(99, 102, 241, 0.05);
    border-radius: 4px;
    font-size: 0.9em;
    color: var(--text-muted);
}

.think-header {
    font-weight: 600;
    margin-bottom: 8px;
    color: #818cf8;
    display: flex;
    align-items: center;
    gap: 8px;
}

.think-header.blinking-cursor::after {
    content: '';
    width: 6px;
    height: 14px;
    background: #818cf8;
    display: inline-block;
    animation: blink 1s step-end infinite;
}

@keyframes blink { 50% { opacity: 0; } }

.mobile-only-btn {
    display: none;
    background: transparent;
    border: none;
    color: var(--text-main);
    cursor: pointer;
    margin-right: 12px;
}

@media (max-width: 768px) {
    .app-container {
        position: relative;
    }
    .sidebar {
        position: absolute;
        top: 0;
        left: 0;
        height: 100%;
        width: 280px;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 4px 0 24px rgba(0,0,0,0.8);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .mobile-only-btn {
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .chat-header {
        padding: 0 16px;
    }
    .chat-history {
        padding: 16px;
    }
    .message {
        max-width: 100%;
    }
    .input-area {
        padding: 16px;
    }
    .bubble {
        font-size: 0.9rem;
        padding: 12px 16px;
    }
    .chat-container.dimmed::after {
        content: '';
        position: absolute;
        top: 0; left: 0; right: 0; bottom: 0;
        background: rgba(0, 0, 0, 0.6);
        z-index: 999;
        backdrop-filter: blur(2px);
    }
}
