:root {
    --bg-color: #0f172a;
    --sidebar-bg: #1e293b;
    --chat-bg: #0f172a;
    --user-msg-bg: #3b82f6; /* Moviy rang */
    --ai-msg-bg: #1e293b;
    --text-color: #f1f5f9;
    --text-muted: #94a3b8;
    --border-color: #334155;
    --accent-color: #3b82f6;
}

* { margin: 0; padding: 0; box-sizing: border-box; font-family: 'Outfit', sans-serif; }

body { background-color: var(--bg-color); color: var(--text-color); height: 100vh; overflow: hidden; transition: font-size 0.2s ease; /* Yumshoq o'zgarish uchun */ }

.app-container { display: flex; height: 100%; width: 100%; }

/* Sidebar */
.sidebar {
    width: 280px; background: var(--sidebar-bg); border-right: 1px solid var(--border-color);
    display: flex; flex-direction: column; padding: 20px; transition: 0.3s;
    z-index: 100;
}

.brand { font-size: 22px; font-weight: 700; color: white; display: flex; align-items: center; gap: 10px; margin-bottom: 25px; }
.brand i { color: var(--accent-color); }

.new-chat-btn {
    width: 100%; padding: 12px; background: var(--accent-color); color: white; border: none; border-radius: 10px;
    font-size: 14px; font-weight: 500; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 8px;
    transition: 0.2s; box-shadow: 0 4px 15px rgba(59, 130, 246, 0.3);
}
.new-chat-btn:hover { background: #2563eb; transform: translateY(-2px); }

.history-label { margin-top: 30px; margin-bottom: 10px; font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; }

.history-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 5px; }

.history-item {
    padding: 10px 15px; border-radius: 8px; cursor: pointer; color: var(--text-muted); font-size: 0.95em;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: 0.2s;
}
.history-item:hover { background: #334155; color: white; }
.history-item.active { background: #334155; color: white; border-left: 3px solid var(--accent-color); }
.history-item .delete-chat { float: right; opacity: 0; transition: 0.2s; }
.history-item:hover .delete-chat { opacity: 1; }

/* Chat Area */
.chat-area { flex: 1; display: flex; flex-direction: column; position: relative; background: var(--chat-bg); }

.mobile-menu { display: none; position: absolute; top: 15px; left: 15px; z-index: 10; font-size: 20px; cursor: pointer; }

.chat-wrapper { flex: 1; overflow-y: auto; padding: 20px; scroll-behavior: smooth; display: flex; flex-direction: column; gap: 20px; }

/* Welcome Screen */
.welcome-screen { margin: auto; text-align: center; animation: fadeIn 0.8s ease; }
.ai-logo { font-size: 60px; color: var(--accent-color); margin-bottom: 20px; animation: float 3s ease-in-out infinite; }
.welcome-screen h2 { margin-bottom: 10px; }
.welcome-screen p { color: var(--text-muted); }

/* Messages */
.message { display: flex; gap: 15px; max-width: 850px; width: 100%; margin: 0 auto; animation: slideUp 0.3s ease; }
.message.user { justify-content: flex-end; }
.message.ai { justify-content: flex-start; }

.avatar { width: 35px; height: 35px; border-radius: 8px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.ai .avatar { background: var(--accent-color); color: white; }
.user .avatar { display: none; }

.bubble {
    padding: 15px 18px; border-radius: 12px; font-size: 1em; line-height: 1.6; position: relative; max-width: 80%;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    min-width: 0;
    word-wrap: break-word;
    word-break: break-word; 
    overflow-wrap: break-word;
}
.user .bubble { background: var(--user-msg-bg); color: white; border-bottom-right-radius: 2px; }
.ai .bubble { background: var(--ai-msg-bg); color: var(--text-color); border-bottom-left-radius: 2px; }

/* Typing Cursor */
.cursor { display: inline-block; width: 6px; height: 16px; background: var(--accent-color); animation: blink 1s infinite; vertical-align: middle; margin-left: 2px; }

/* Input Area */
.input-container { padding: 20px; background: var(--chat-bg); display: flex; flex-direction: column; align-items: center; }
.input-box {
    width: 100%; max-width: 850px; background: var(--sidebar-bg); border-radius: 15px; padding: 8px 15px;
    display: flex; align-items: flex-end; gap: 10px; border: 1px solid var(--border-color);
}
textarea {
    flex: 1; background: transparent; border: none; color: white; font-size: 1em; resize: none; max-height: 150px; padding: 10px 0; outline: none;
}
#sendBtn {
    background: var(--accent-color); color: white; border: none; width: 40px; height: 40px; border-radius: 10px;
    cursor: pointer; display: flex; align-items: center; justify-content: center; transition: 0.2s; margin-bottom: 2px;
}
#sendBtn:hover { background: #2563eb; }
#sendBtn:disabled { background: #475569; cursor: not-allowed; }

.footer-text { font-size: 11px; color: #475569; margin-top: 10px; text-align: center;}

/* Animatsiyalar */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-10px); } }
@keyframes blink { 50% { opacity: 0; } }

/* Code Block */
pre { background: #0d0d0d !important; padding: 15px; border-radius: 8px; overflow-x: auto; margin: 10px 0; position: relative; }
.copy-btn { position: absolute; top: 5px; right: 5px; font-size: 11px; background: #333; color: white; border: none; padding: 4px 8px; border-radius: 4px; cursor: pointer; }

@media (max-width: 768px) {
    .sidebar { position: fixed; left: -100%; height: 100%; }
    .sidebar.active { left: 0; }
    .mobile-menu { display: block; }
}
/* --- YANGI QO'SHILGAN STILLAR --- */

/* 1. Send tugmasi aktiv bo'lishi uchun */
#sendBtn { z-index: 5; } 

/* 2. User xabarini nusxalash (Copy) */
.message.user { align-items: center; }
.copy-user-btn {
    opacity: 0;
    color: #64748b;
    cursor: pointer;
    margin-right: 10px;
    font-size: 14px;
    transition: 0.2s;
    padding: 5px;
}
.message.user:hover .copy-user-btn { opacity: 1; }
.copy-user-btn:hover { color: white; }

/* 3. Sidebar (Menu) Yopish tugmasi (Mobile & Desktop) */
.close-sidebar-btn {
    display: none; /* Desktopda yashirin */
    color: white;
    font-size: 20px;
    cursor: pointer;
    margin-left: auto;
}

/* Mobilda Sidebarni to'liq ekran qilish va yopish tugmasini ko'rsatish */
@media (max-width: 768px) {
    .sidebar {
        width: 100%; /* To'liq ekran */
        transform: translateX(-100%); /* Yashirin */
        position: fixed;
        transition: transform 0.3s ease;
    }
    .sidebar.active {
        transform: translateX(0); /* Chiqish */
    }
    .close-sidebar-btn { display: block; } /* Mobilda ko'rinadi */
    
    /* Menu ochilganda orqa fon qorayishi uchun */
    .overlay {
        position: fixed; top: 0; left: 0; width: 100%; height: 100%;
        background: rgba(0,0,0,0.5); z-index: 90; display: none;
    }
    .overlay.active { display: block; }
}

/* 4. Desktop Sidebar Toggle (Chap burchakdagi tugma) */
.toggle-sidebar-desktop {
    position: absolute;
    top: 20px;
    left: 20px;
    color: #94a3b8;
    cursor: pointer;
    z-index: 9;
    font-size: 20px;
    transition: 0.2s;
}
.toggle-sidebar-desktop:hover { color: white; }

/* Sidebar yopilganda Chat kengayishi */
body.sidebar-closed .sidebar { margin-left: -280px; }
body.sidebar-closed .toggle-sidebar-desktop { left: 20px; color: white; }

/* 5. Tezkor va silliq animatsiyalar */
.bubble { animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275); }

@keyframes popIn {
    from { opacity: 0; transform: scale(0.9) translateY(10px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* --- TOAST NOTIFICATION (Nusxalandi xabari) --- */
/* --- TOAST NOTIFICATION (TUZATILDI) --- */
.toast {
    position: fixed;
    top: -100px; /* Ekranda tashqarida bo'lsin */
    left: 50%;
    transform: translateX(-50%);
    background: #10b981;
    color: white;
    padding: 10px 20px;
    border-radius: 30px;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.4);
    z-index: 1000;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    
    /* Eng muhimi: Boshida yashirin bo'lsin */
    opacity: 0;
    visibility: hidden;
}

.toast.show {
    top: 20px;       /* Pastga tushadi */
    opacity: 1;      /* Ko'rinadi */
    visibility: visible;
}

/* --- SOZLAMALAR TUGMASI (Sidebar) --- */
.settings-btn {
    width: 100%; padding: 12px; background: transparent; color: #94a3b8;
    border: 1px solid #334155; border-radius: 10px; margin-top: auto; /* Pastga tushiradi */
    cursor: pointer; display: flex; align-items: center; gap: 10px; transition: 0.2s;
}
.settings-btn:hover { background: #334155; color: white; }

/* --- MODAL OYNA (Sozlamalar) --- */
.modal-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.6); backdrop-filter: blur(5px);
    z-index: 200; display: none; align-items: center; justify-content: center;
    animation: fadeIn 0.2s;
}
.modal-overlay.active { display: flex; }

.modal-content {
    background: #1e293b; width: 90%; max-width: 400px; border-radius: 15px;
    padding: 20px; border: 1px solid #334155; box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    transform: scale(0.9); transition: 0.3s;
}
.modal-overlay.active .modal-content { transform: scale(1); }

.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; color: white; }
.close-modal { font-size: 24px; cursor: pointer; color: #94a3b8; }
.close-modal:hover { color: white; }

.setting-item { margin-bottom: 20px; }
.setting-item label { display: block; color: #94a3b8; font-size: 0.9em; margin-bottom: 8px; }
.setting-item select { width: 100%; padding: 8px; background: #0f172a;font-size: 0.9em; color: white; border: 1px solid #334155; border-radius: 8px; }

/* Ranglar palitrasi */
.theme-colors { display: flex; gap: 10px; }
.color-circle { width: 30px; height: 30px; border-radius: 50%; cursor: pointer; border: 2px solid transparent; }
.color-circle.active { border-color: white; transform: scale(1.1); }
.blue { background: #3b82f6; }
.purple { background: #8b5cf6; }
.emerald { background: #10b981; }
.orange { background: #f97316; }

.danger-btn { width: 100%; padding: 10px; background: rgba(239, 68, 68, 0.1); color: #ef4444; border: 1px solid #ef4444; border-radius: 8px; cursor: pointer; }
.danger-btn:hover { background: #ef4444; color: white; }

/* Dinamik Ranglar (JS orqali o'zgaradi) */
body[data-theme="purple"] { --accent-color: #8b5cf6; --user-msg-bg: #8b5cf6; }
body[data-theme="emerald"] { --accent-color: #10b981; --user-msg-bg: #10b981; }
body[data-theme="orange"] { --accent-color: #f97316; --user-msg-bg: #f97316; }

/* --- CHIROYLI SCROLLBAR --- */
/* Butun sayt uchun */
::-webkit-scrollbar {
    width: 8px; /* Eni */
    height: 8px;
}

/* Orqa foni (Track) */
::-webkit-scrollbar-track {
    background: #0f172a; 
}

/* Yuradigan qismi (Thumb) */
::-webkit-scrollbar-thumb {
    background: #334155; 
    border-radius: 4px;
}

/* Sichqoncha borganda (Hover) */
::-webkit-scrollbar-thumb:hover {
    background: #475569; 
}

/* Sidebar uchun alohida ingichkaroq scrollbar */
.history-list::-webkit-scrollbar {
    width: 4px;
}
/* --- SIDEBAR PASTKI LOGO --- */
.bottom-logo-container {
    margin-top: 15px;      /* Sozlamalar tugmasidan uzoqlashtirish */
    padding-top: 15px;
    border-top: 1px solid #334155; /* Ajratib turuvchi chiziq */
    text-align: center;    /* O'rtaga joylash */
    display: flex;
    justify-content: center;
    align-items: center;
}

.my-logo {
    max-width: 80%;        /* Juda katta bo'lib ketmasligi uchun */
    max-height: 50px;      /* Balandligini cheklash */
    object-fit: contain;   /* Rasmni cho'zilib ketishdan saqlash */
    opacity: 0.7;          /* Biroz shaffof (dizaynga mos) */
    transition: 0.3s;
    filter: grayscale(100%); /* Oq-qora qilish (ixtiyoriy, olib tashlash mumkin) */
}

/* Sichqoncha borganda yonsin */
.my-logo:hover {
    opacity: 1;
    filter: grayscale(0%);
}
/* --- TASDIQLASH OYNASI DIZAYNI --- */
.confirm-box {
    max-width: 350px;
    text-align: center;
    padding: 25px;
    animation: popIn 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.confirm-icon {
    font-size: 40px;
    color: #ef4444; /* Qizil rang */
    margin-bottom: 15px;
    animation: shake 0.5s ease-in-out;
}

.confirm-box h3 {
    margin-bottom: 10px;
    color: white;
    font-size: 18px;
}

.confirm-box p {
    color: #94a3b8;
    font-size: 14px;
    margin-bottom: 25px;
}

.confirm-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.btn-cancel {
    padding: 10px 20px;
    background: #334155;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: 0.2s;
    font-weight: 500;
}
.btn-cancel:hover { background: #475569; }

.btn-delete {
    padding: 10px 20px;
    background: #ef4444;
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: 0.2s;
    font-weight: 500;
    box-shadow: 0 4px 10px rgba(239, 68, 68, 0.3);
}
.btn-delete:hover { background: #dc2626; transform: translateY(-2px); }

/* Qaltirash animatsiyasi (Icon uchun) */
@keyframes shake {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(-10deg); }
    75% { transform: rotate(10deg); }
}

/* Oyna ochilishi (Kattalashib chiqish) */
@keyframes popIn {
    from { opacity: 0; transform: scale(0.8); }
    to { opacity: 1; transform: scale(1); }
}

/* --- PROFESSIONAL KOD BLOKI DIZAYNI --- */
pre {
    padding: 0 !important; /* Ichki bo'shliqni olib tashlaymiz (header sig'ishi uchun) */
    background: #0d0d0d !important; /* To'q fon */
    border: 1px solid #334155;
    border-radius: 10px;
    overflow: hidden; /* Burchaklardan chiqib ketmasin */
    margin: 15px 0;
    position: relative;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
}

/* Kod bloki "shapkasi" (Header) */
.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #1e293b; /* Ochroq kulrang fon */
    padding: 8px 15px;
    border-bottom: 1px solid #334155;
    font-family: 'Consolas', sans-serif;
    font-size: 12px;
    color: #e2e8f0;
}

/* Til nomi (Python, JS...) */
.lang-name {
    font-weight: 600;
    text-transform: uppercase;
    color: #3b82f6; /* Moviy rang */
    display: flex;
    align-items: center;
    gap: 5px;
}

/* Kodning o'zi */
code {
    display: block;
    padding: 15px !important;
    overflow-x: auto;
    font-family: 'Fira Code', monospace; /* Agar bo'lsa, bo'lmasa default */
    font-size: 14px;
}

/* Copy tugmasini header ichiga olamiz */
.code-header .copy-btn {
    position: static; /* Absolyut emas */
    background: transparent;
    color: #94a3b8;
    border: 1px solid transparent;
    font-size: 12px;
    padding: 4px 8px;
    cursor: pointer;
    transition: 0.2s;
    display: flex;
    align-items: center;
    gap: 5px;
}

.code-header .copy-btn:hover {
    color: white;
    background: rgba(255,255,255,0.1);
    border-radius: 4px;
}
/* Kod Bloki Shapkasi (Aniq ko'rinishi uchun) */
.code-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #1e293b !important; /* Aniq to'q kulrang fon */
    padding: 8px 12px;
    border-bottom: 1px solid #334155;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
}

/* Til nomi (PYTHON, JS...) */
.lang-name span {
    color: #fff !important; /* OQ RANG (Ko'rinishi shart) */
    font-family: 'Outfit', sans-serif;
    font-size: 13px;
    font-weight: 600;
}

/* Copy tugmasi */
.code-header .copy-btn {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.2);
    color: #cbd5e1;
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 5px;
    cursor: pointer;
    transition: 0.2s;
}

.code-header .copy-btn:hover {
    background: rgba(255,255,255,0.1);
    color: white;
}

/* Kod bloki tashqi chegarasi */
pre {
    border: 1px solid #334155 !important;
    border-radius: 10px !important;
    background: #0f172a !important;
    margin-top: 10px;
}

/* --- MOBIL CHAT TARIHI (YIRIK CARD STYLES) --- */
@media (max-width: 768px) {

    /* 1. Tarix ro'yxati orasi ochilsin */
    .history-list {
        padding: 10px;
        display: flex;
        flex-direction: column;
        gap: 12px; /* Kartalar orasi kengroq */
    }

    /* 2. Chat Kartasi (KATTALASHTIRILDI) */
    .history-item {
        display: flex;
        align-items: center;
        justify-content: space-between;
        
        /* O'lchamlarni kattalashtiramiz */
        padding: 18px 20px; /* Tepadan/pastdan 18px, yonlardan 20px */
        min-height: 60px;   /* Minimal balandlik beramiz */
        
        background-color: #1e293b; /* To'qroq fon */
        border: 1px solid #334155;
        border-radius: 15px; /* Burchaklari yanada yumaloq */
        box-shadow: 0 4px 6px rgba(0, 0, 0, 0.2); /* Soya beramiz (3D effekt) */
        
        margin-bottom: 5px;
    }

    /* Aktiv holat */
    .history-item.active {
        background: #334155;
        border: 1px solid #3b82f6;
        box-shadow: 0 0 15px rgba(59, 130, 246, 0.2);
    }

    /* 3. Matn (YIRIKLASHTIRILDI) */
    .history-item span {
        font-size: 18px; /* Yozuvni kattalashtirdik (14px edi) */
        font-weight: 500; /* Qalinroq */
        color: #f8fafc;
        
        /* Uzun matnni qirqish */
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        flex: 1;
        margin-right: 15px;
    }

    .history-item span i {
        font-size: 18px; /* Icon ham kattalashdi */
        margin-right: 12px;
        color: #94a3b8;
    }

    /* 4. Delete Tugmasi (KATTALASHTIRILDI) */
    .history-item .delete-chat {
        width: 45px;  /* Tugma katta bo'ldi */
        height: 45px;
        font-size: 18px; /* Iconi katta */
        
        display: flex;
        align-items: center;
        justify-content: center;
        
        background: rgba(239, 68, 68, 0.15);
        color: #ef4444;
        border-radius: 12px;
    }
    
    /* 5. Sidebarning o'zi (Orqa fon) */
    .sidebar {
        background-color: #0f172a; /* To'q fon */
        padding-top: 20px;
    }

    .history-item .delete-chat {
        /* 1. Yashirinishni to'xtatamiz */
        opacity: 1 !important;
        visibility: visible !important;
        display: flex !important;
        
        /* 2. O'lcham va joylashuv */
        width: 40px !important;
        height: 40px !important;
        margin-left: 10px; /* Matndan uzoqlashtirish */
        
        /* 3. Dizayn (Qizil fon) */
        background: rgba(239, 68, 68, 0.2) !important;
        color: #ef4444 !important;
        border-radius: 10px !important;
        
        /* 4. Markazlash */
        align-items: center;
        justify-content: center;
        font-size: 16px;
    }
    
    /* Matn tugmaning tagiga kirib ketmasligi uchun */
    .history-item span {
        width: calc(100% - 60px); /* Tugma joyini hisobga olish */
    }
}

/* --- SIDEBAR CHAT ITEM (TUZATILDI) --- */
.history-item {
    display: flex;
    align-items: center;
    justify-content: space-between; /* Yozuv chapda, tugma o'ngda */
    padding: 10px 12px;
    margin-bottom: 5px;
    border-radius: 8px;
    cursor: pointer;
    transition: 0.2s;
    overflow: hidden; /* Tashqariga chiqib ketmasin */
    width: 100%; /* Kenglikni to'liq olsin */
    box-sizing: border-box;
}

/* Matn qismi */
.history-item span {
    flex: 1; /* Bor bo'sh joyni egallasin */
    min-width: 0; /* MUHIM: Siqilishga ruxsat berish */
    white-space: nowrap; /* Matn pastga tushmasin */
    overflow: hidden; /* Ortiqchasini yashirish */
    text-overflow: ellipsis; /* Uch nuqta (...) qo'yish */
    margin-right: 10px; /* Tugmaga yopishib qolmasligi uchun */
    font-size: 14px;
    color: #cbd5e1;
    display: block; /* Block element kabi ishlashi uchun */
}

/* Delete tugmasi */
.history-item .delete-chat {
    flex-shrink: 0; /* MUHIM: Tugma hech qachon kichraymasin */
    width: 30px; 
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: 0.2s;
    opacity: 0; /* Kompyuterda yashirin */
}

/* Hover (Kompyuterda) */
.history-item:hover .delete-chat { opacity: 1; background: rgba(255,255,255,0.1); }
.history-item:hover { background: #334155; }
.history-item.active { background: #334155; color: white; border-left: 3px solid #3b82f6; }


/* --- IKIKKITA TUGMA MUAMMOSINI HAL QILISH --- */

/* 1. Header ichida bo'lmagan barcha copy tugmalarni yashiramiz */
pre > .copy-btn {
    display: none !important;
}

/* 2. Faqat biz yasagan Header ichidagi tugma ko'rinsin */
.code-header .copy-btn {
    display: flex !important;
}

/* 3. Ba'zi hollarda highlight.js fonni o'zgartirib yuboradi, buni to'g'irlaymiz */
pre code.hljs {
    background: transparent !important; /* Kod foni Header foni bilan bir xil bo'lsin */
    padding: 15px !important;
}
/* --- HAVOLALAR DIZAYNI --- */
.bubble a {
    color: #3b82f6; /* Moviy rang */
    text-decoration: none;
    font-weight: 600;
    border-bottom: 1px dashed #3b82f6;
    transition: 0.2s;
}

.bubble a:hover {
    color: #60a5fa;
    border-bottom-style: solid;
}

/* --- TARIX SCROLL MUAMMOSINI HAL QILISH --- */

/* 1. Tarix ro'yxati konteyneri */
.history-list {
    flex: 1; /* Bor bo'sh joyni egallasin */
    overflow-y: auto; /* Sig'masa Scroll bo'lsin */
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-bottom: 20px; /* Pastdan biroz joy qolsin */
    min-height: 0; /* Flexbox ichida scroll ishlashi uchun muhim */
}

/* 2. Chat kartochkasi (Item) */
.history-item {
    flex-shrink: 0; /* DIQQAT: Bu eng muhim kod! Ezilib qolishni taqiqlaydi */
    /* ... qolgan stillar o'z holicha qolsin ... */
    width: 100%;
}

/* --- 1. HARFLAR ORASINI OCHISH (TYPOGRAPHY) --- */
.bubble {
    letter-spacing: 0.6px; /* Harflar orasini biroz ochish */
    line-height: 1.7;      /* Qatorlar orasini kengaytirish (o'qish oson bo'ladi) */
    font-weight: 400;      /* Shrift qalinligini normallashtirish */
}

/* --- 2. BLUR EFFEKT VA CHAT KIRIB KETISHI --- */

/* Asosiy chat maydoni */
.chat-area {
    position: relative; /* Ichidagi elementlarni joylashtirish uchun */
    height: 100vh;
    overflow: hidden;
}

/* Xabarlar ro'yxati (Scroll bo'ladigan joy) */
.chat-wrapper {
    height: 100%;
    overflow-y: auto;
    /* Pastdan joy qoldiramiz, aks holda oxirgi xabar input orqasida qolib ketadi */
    padding-bottom: 165px !important; 
    padding-top: 20px;
}

/* Yozish maydoni (Input) - BLUR EFFEKT */
.input-container {
    position: absolute; /* Chat ustida suzib turadi */
    bottom: 0;
    left: 0;
    width: 100%;
    
    /* Shaffof fon va Blur */
    background: rgba(15, 23, 42, 0.75); /* Yarim shaffof to'q ko'k */
    backdrop-filter: blur(12px); /* Orqasidagi narsalarni xiralashtirish (Eng muhimi shu) */
    -webkit-backdrop-filter: blur(12px); /* Safari uchun */
    
    border-top: 1px solid rgba(255, 255, 255, 0.08); /* Tepasiga ingichka chiziq */
    box-shadow: 0 -10px 30px rgba(0,0,0,0.2); /* Yuqoriga soya tashlash */
    
    z-index: 50; /* Xabarlar ustida turishi shart */
    padding: 20px;
}

/* --- 3. SCROLL SILLIQROQ BO'LISHI UCHUN --- */
html, body {
    scroll-behavior: smooth;
}

/* Mobil telefonda input to'liq ko'rinishi uchun */
@media (max-width: 768px) {
    .chat-wrapper {
        padding-bottom: 145px !important; /* Mobilda klaviatura hisobiga */
    }
    
    .input-container {
        padding: 15px;
        background: rgba(15, 23, 42, 0.85); /* Mobilda sal to'qroq */
        backdrop-filter: blur(15px);
    }
}

/* --- BOT XABARINI NUSXALASH TUGMASI --- */
.copy-ai-btn {
    opacity: 0; /* Boshida ko'rinmaydi */
    color: #64748b;
    cursor: pointer;
    margin-left: 10px; /* Xabardan biroz o'ngda turadi */
    font-size: 14px;
    transition: 0.2s;
    padding: 5px;
}

/* Xabar ustiga sichqoncha borganda ko'rinsin */
.message.ai:hover .copy-ai-btn {
    opacity: 1;
}

.copy-ai-btn:hover {
    color: #3b82f6; /* Bosmoqchi bo'lganda ko'karadi */
    transform: scale(1.1);
}

/* Mobilda doim ko'rinsin (hover yo'qligi uchun) */
@media (max-width: 768px) {
    .copy-ai-btn { opacity: 1; }
    .copy-user-btn {opacity: 1;}
}

/* STOP tugmasi dizayni */
.fa-stop {
    color: #ef4444; /* Qizil */
    animation: pulse 1s infinite; /* Yonib-o'chish effekti */
}

@keyframes pulse {
    0% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(0.9); }
    100% { opacity: 1; transform: scale(1); }
}

/* --- AI YOZAYOTGANDA MENYUNI BLOKLASH --- */
body.generating .sidebar {
    opacity: 0.6; /* Xiralashadi */
    pointer-events: none; /* Bosib bo'lmaydi */
    filter: grayscale(0.8); /* Oq-qora bo'lib qoladi */
    cursor: not-allowed;
}

/* Lekin STOP tugmasi va Input ishlashi kerak */
body.generating .input-container {
    pointer-events: auto;
}

/* --- DOWNLOAD TUGMASI --- */
.code-header .download-btn {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.2);
    color: #cbd5e1;
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 5px;
    cursor: pointer;
    transition: 0.2s;
    margin-right: 8px; /* Copy tugmasidan biroz uzoqlashtiramiz */
    display: flex;
    align-items: center;
    gap: 5px;
}

.code-header .download-btn:hover {
    background: rgba(16, 185, 129, 0.1); /* Yashilroq fon */
    color: #10b981;
    border-color: #10b981;
}

/* Tugmalar guruhi (O'ng tomonda turishi uchun) */
.code-actions {
    display: flex;
    align-items: center;
}

/* --- MOBILDA KOD BLOKI TUGMALARINI IXCHAMLASH --- */
@media (max-width: 768px) {
    
    /* 1. Header ichki masofasini kamaytirsh */
    .code-header {
        padding: 5px 10px !important;
    }

    /* 2. Tugmalar ichidagi YOZUVLARNI yashirish */
    .code-header .download-btn,
    .code-header .copy-btn {
        font-size: 0 !important; /* Matn ko'rinmasin */
        padding: 6px 10px !important; /* Tugma kichikroq bo'lsin */
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* 3. Ikonkalarni (Rasmchalarni) qaytarib ko'rsatish */
    .code-header .download-btn i,
    .code-header .copy-btn i {
        font-size: 16px !important; /* Icon kattaligi */
        margin: 0 !important; /* Ortiqcha masofani olib tashlash */
    }

    /* 4. Til nomini biroz kichraytirish */
    .lang-name span {
        font-size: 11px !important;
    }
    
    .lang-name i {
        font-size: 12px !important;
    }

    /* 5. Tugmalar orasidagi masofani tartiblash */
    .code-actions {
        gap: 5px; /* Tugmalar bir-biriga yaqinroq bo'lsin */
    }
    
    .code-header .download-btn {
        margin-right: 0 !important; /* Ortiqcha o'ng masofani olish */
    }
}

/* --- MATEMATIK BLOKLAR DIZAYNI (KOD KABI) --- */

/* 1. Katta formulalar ($$ ... $$) - Kod bloki kabi ko'rinadi */
.katex-display {
    background-color: #0d0d0d !important; /* Kod bloki foni (qora) */
    border: 1px solid #334155;             /* Kod bloki chegarasi */
    border-radius: 10px;                   /* Yumaloq burchaklar */
    padding: 20px !important;              /* Ichidan joy tashlash */
    margin: 15px 0 !important;             /* Tepadan/pastdan joy */
    
    overflow-x: auto;                      /* Uzun formula bo'lsa scroll bo'lsin */
    overflow-y: hidden;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1); /* Kichik soya */
    
    text-align: center;                    /* Formula o'rtada tursin */
    font-size: 1.2em;                      /* Formula yaqqol ko'rinsin */
}

/* 2. Matn ichidagi kichik formulalar ($ ... $) */
/* Bularni ham ajratib ko'rsatish uchun orqasiga sal qoramtir fon beramiz */
p .katex {
    background-color: rgba(0, 0, 0, 0.3);  /* Shaffof qora fon */
    padding: 2px 6px;
    border-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

/* LEKIN: Katta blok ichidagi formulaga 2-qoida ta'sir qilmasin */
.katex-display .katex {
    background-color: transparent !important;
    border: none !important;
    padding: 0 !important;
}

/* 3. Formulalar rangi */
.katex {
    color: #e2e8f0 !important; /* Oqish rang (aniq ko'rinishi uchun) */
}

