/* --- RESET & BASE --- */
* { 
    margin: 0; 
    padding: 0; 
    box-sizing: border-box; 
    font-family: 'Poppins', sans-serif; 
}

body { 
    background: #343541; 
    color: #ececf1; 
    overflow: hidden; 
}

.container { 
    display: flex; 
    height: 100vh; 
}

/* --- SIDEBAR --- */
.sidebar { 
    width: 260px; 
    background: #202123; 
    padding: 10px; 
    display: flex; 
    flex-direction: column; 
    transition: 0.3s ease-in-out; 
    z-index: 20;
}

.sidebar.hidden { 
    width: 0; 
    padding: 0; 
    overflow: hidden; 
    opacity: 0; 
}

.sidebar-top { 
    flex: 1; 
    display: flex; 
    flex-direction: column; 
    overflow: hidden; 
}

.sidebar-controls { 
    display: flex; 
    gap: 8px; 
    margin-bottom: 10px; 
}

.new-chat-btn { 
    flex: 1; 
    padding: 12px; 
    border: 1px solid #4d4d4d; 
    background: transparent; 
    color: white; 
    border-radius: 6px; 
    cursor: pointer; 
    text-align: left; 
    font-size: 14px; 
    transition: 0.2s; 
}

.new-chat-btn:hover { background: #2b2c2f; }

.clear-all-btn { 
    width: 44px; height: 44px; 
    border: 1px solid #4d4d4d; 
    background: transparent; 
    color: #8e8ea0; 
    border-radius: 6px; 
    cursor: pointer; 
    display: flex; 
    align-items: center; 
    justify-content: center; 
    transition: 0.2s; 
}

.clear-all-btn:hover { 
    color: #ff4d4d; 
    border-color: #ff4d4d; 
    background: rgba(255, 77, 77, 0.1); 
}

.history-list { flex: 1; overflow-y: auto; margin-top: 5px; }
.history-list::-webkit-scrollbar { width: 4px; }
.history-list::-webkit-scrollbar-thumb { background: #4d4d4d; border-radius: 10px; }

.history-item { 
    display: flex; justify-content: space-between; align-items: center; 
    padding: 10px; border-radius: 8px; cursor: pointer; 
    font-size: 14px; margin-bottom: 4px; transition: 0.2s; color: #ececf1; 
}

.history-item:hover { background: #2b2c2f; }
.history-item.active { background: #343541; border: 1px solid #4d4d4d; }

.chat-title-text { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-right: 10px; }
.delete-chat-btn { opacity: 0; color: #565656; transition: 0.2s; }
.history-item:hover .delete-chat-btn { opacity: 1; }
.delete-chat-btn:hover { color: #ff4d4d; }

.sidebar-footer { border-top: 1px solid #4d4d4d; padding-top: 10px; }
.settings-btn { 
    width: 100%; padding: 12px; background: transparent; 
    border: 1px solid #4d4d4d; color: white; border-radius: 6px; 
    cursor: pointer; text-align: left; display: flex; 
    align-items: center; gap: 10px; margin-bottom: 10px; font-size: 14px; 
}
.settings-btn:hover { background: #2b2c2f; border-color: #19c37d; }
.sidebar-footer p { font-size: 11px; color: #8e8ea0; text-align: center; }

/* --- MAIN CONTENT --- */
.main-content { 
    flex: 1; display: flex; flex-direction: column; 
    background: #343541; position: relative; width: 100%;
}

.chat-header { 
    padding: 15px; border-bottom: 1px solid #2d2d2d; 
    text-align: center; background: #343541; 
    display: flex; justify-content: center; align-items: center;
}

.toggle-sidebar-btn { 
    position: absolute; left: 15px; background: transparent; 
    border: none; color: #acacbe; cursor: pointer; font-size: 18px; z-index: 10; 
}

.chat-messages { 
    flex: 1; overflow-y: auto; overflow-x: hidden; 
    padding: 20px 10%; display: flex; flex-direction: column; 
    gap: 25px; width: 100%; 
}

@media (max-width: 768px) { 
    .chat-messages { 
        padding: 20px 5%; 
    } 
}

/* --- MESSAGES --- */
.message { display: flex; width: 100%; position: relative; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.message.user { justify-content: flex-end; }
.bubble { 
    max-width: 85%; padding: 12px 16px; border-radius: 12px; 
    font-size: 15px; line-height: 1.6; position: relative; 
}

.user .bubble { background: #0b93f6; color: white; border-bottom-right-radius: 2px; }
.ai .bubble { 
    background: #444654; color: #ececf1; border-bottom-left-radius: 2px; 
    width: 100%; max-width: 100%; box-sizing: border-box; 
}

.main-copy-btn { 
    position: absolute; bottom: -25px; right: 5px; 
    background: #40414f; border: 1px solid #565656; color: #acacbe; 
    padding: 2px 8px; border-radius: 4px; font-size: 10px; 
    cursor: pointer; opacity: 0; transition: 0.2s; 
}
.message.ai:hover .main-copy-btn { opacity: 1; }

/* --- CODE BLOCKS (TERSTRUKTUR & WRAPPED) --- */
.code-container { 
    background: #1e1e1e; border-radius: 8px; margin: 15px 0; 
    border: 1px solid #4d4d4d; width: 100%; max-width: 100%; 
    display: block;
}

.code-header { 
    display: flex; justify-content: space-between; align-items: center; 
    padding: 8px 12px; background: #2d2d2d; border-bottom: 1px solid #4d4d4d;
}

.code-lang { font-size: 11px; color: #acacbe; font-weight: 600; }
.code-copy-btn { 
    background: transparent; border: none; color: #acacbe; 
    cursor: pointer; font-size: 11px; display: flex; align-items: center; gap: 5px; 
}

/* FIX UTAMA: Menjaga struktur kodingan kebawah */
pre[class*="language-"] {
    margin: 0 !important;
    padding: 15px !important;
    background: #1e1e1e !important;
    font-size: 14px !important;
    line-height: 1.6 !important; /* Jarak antar baris biar gak pusing */
    
    /* Agar kodingan turun kebawah tapi spasi/tab awal baris terjaga */
    white-space: pre-wrap !important; 
    word-break: break-word !important;
    overflow-wrap: anywhere !important;
    
    tab-size: 4; /* Lebar indentasi */
    border: none !important;
}

code[class*="language-"] {
    font-family: 'Fira Code', 'Courier New', monospace !important;
    text-shadow: none !important;
    color: #f8f8f2 !important;
    /* Pastikan struktur 'tab' dari AI nggak dihilangkan browser */
    white-space: pre-wrap !important; 
}

.inline-code { 
    background: #2d2d2d; color: #e91e63; padding: 2px 5px; 
    border-radius: 4px; font-family: monospace; 
}

/* --- INPUT AREA --- */
.input-area { padding: 20px 15%; background: #343541; }
.input-wrapper { 
    display: flex; align-items: center; background: #40414f; 
    border-radius: 10px; padding: 10px 15px; border: 1px solid #565656; 
}

textarea#message-input { 
    flex: 1; background: transparent; border: none; color: white; 
    outline: none; resize: none; font-size: 16px; max-height: 200px; 
    line-height: 1.5; height: 24px;
}

.send-btn { background: transparent; border: none; color: #acacbe; cursor: pointer; padding-left: 10px; font-size: 18px; }
.send-btn:hover { color: #19c37d; }

/* --- TYPING --- */
.typing { display: flex; gap: 4px; padding: 10px 0; }
.typing span { width: 8px; height: 8px; background: #acacbe; border-radius: 50%; animation: typing 1.4s infinite; }
.typing span:nth-child(2) { animation-delay: 0.2s; }
.typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing { 0%, 60%, 100% { opacity: 0.4; } 30% { opacity: 1; } }

/* --- WELCOME SCREEN --- */
.welcome-screen { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; margin-top: -50px; }
.main-logo { width: 80px; height: 80px; margin-bottom: 20px; }
.welcome-text { font-size: 24px; font-weight: 600; color: white; }

/* --- MODAL --- */
.modal { 
    display: none; position: fixed; z-index: 100; left: 0; top: 0; width: 100%; height: 100%; 
    background: rgba(0,0,0,0.8); backdrop-filter: blur(5px); align-items: center; justify-content: center; 
}
.modal-content { background: #202123; width: 90%; max-width: 450px; padding: 25px; border-radius: 12px; border: 1px solid #4d4d4d; }
.modal-content textarea { width: 100%; height: 120px; background: #40414f; border: 1px solid #565656; color: white; padding: 12px; border-radius: 8px; resize: none; margin: 15px 0; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; }
.save-btn { background: #19c37d; color: white; border: none; padding: 10px 20px; border-radius: 6px; cursor: pointer; font-weight: bold; }
.cancel-btn { background: #444654; color: white; border: none; padding: 10px 20px; border-radius: 6px; cursor: pointer; }

/* --- RESPONSIVE FIXES FOR MOBILE --- */
/* Untuk tablet dan mobile kecil (max-width: 768px) */
@media (max-width: 768px) {
    .sidebar {
        width: 0; /* Sembunyikan sidebar secara default di mobile */
        padding: 0;
        overflow: hidden;
        opacity: 0;
    }
    .sidebar:not(.hidden) {
        width: 260px; /* Tampilkan jika tidak hidden */
        padding: 10px;
        opacity: 1;
    }
    .chat-messages {
        padding: 20px 5%;
        gap: 20px; /* Kurangi gap untuk ruang lebih */
    }
    .bubble {
        max-width: 90%; /* Lebih lebar di mobile */
        font-size: 14px; /* Font lebih kecil */
        padding: 10px 14px;
    }
    .input-area {
        padding: 15px 5%; /* Kurangi padding */
    }
    .input-wrapper {
        padding: 8px 12px; /* Kurangi padding input */
    }
    textarea#message-input {
        font-size: 15px; /* Font input lebih kecil */
    }
    .send-btn {
        font-size: 16px; /* Ukuran ikon send */
    }
    .chat-header {
        padding: 10px; /* Kurangi padding header */
    }
    .toggle-sidebar-btn {
        left: 10px; /* Posisi toggle button */
    }
    .welcome-text {
        font-size: 20px; /* Font welcome lebih kecil */
    }
    .main-logo {
        width: 60px; height: 60px; /* Logo lebih kecil */
    }
}

/* Untuk mobile sangat kecil (max-width: 480px) */
@media (max-width: 480px) {
    .chat-messages {
        padding: 15px 3%;
        gap: 15px;
    }
    .bubble {
        max-width: 95%;
        font-size: 13px;
        padding: 8px 12px;
    }
    .input-area {
        padding: 10px 3%;
    }
    .input-wrapper {
        padding: 6px 10px;
    }
    textarea#message-input {
        font-size: 14px;
    }
    .send-btn {
        font-size: 14px;
        padding-left: 8px;
    }
    .chat-header {
        padding: 8px;
    }
    .toggle-sidebar-btn {
        left: 8px;
        font-size: 16px;
    }
    .welcome-text {
        font-size: 18px;
    }
    .main-logo {
        width: 50px; height: 50px;
    }
    .modal-content {
        width: 95%;
        padding: 20px;
    }
    .modal-content textarea {
        height: 100px;
        padding: 10px;
    }
    .code-header {
        padding: 6px 10px;
    }
    pre[class*="language-"] {
        padding: 10px !important;
        font-size: 12px !important;
    }
}

/* --- FIX FOR HIGH DPI DEVICES (e.g., DPI 702) --- */
/* Menggunakan unit relatif untuk mencegah elemen terlalu kecil atau tidak muncul di layar high DPI */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    /* Pastikan viewport di HTML: <meta name="viewport" content="width=device-width, initial-scale=1.0"> */
    .container {
        height: 100vh; /* Gunakan vh untuk tinggi penuh */
    }
    .main-content {
        flex: 1;
        min-height: 0; /* Mencegah flex item shrink ke nol */
    }
    .chat-messages {
        flex: 1;
        overflow-y: auto;
        padding: 2vh 5%; /* Gunakan vh untuk padding vertikal */
        gap: 2vh; /* Gap relatif */
    }
    .input-area {
        padding: 2vh 5%; /* Padding relatif */
        flex-shrink: 0; /* Mencegah input area hilang */
    }
    .bubble {
        max-width: 90%;
        padding: 1vh 1.5vw; /* Padding relatif */
        font-size: 1rem; /* Gunakan rem untuk font */
    }
    textarea#message-input {
        font-size: 1rem;
        height: 2.5rem; /* Tinggi relatif */
    }
    .send-btn {
        font-size: 1.2rem;
        padding-left: 0.5rem;
    }
    .chat-header {
        padding: 1vh;
    }
    .welcome-screen {
        margin-top: -5vh;
    }
    .main-logo {
        width: 5rem; height: 5rem; /* Ukuran relatif */
    }
    .welcome-text {
        font-size: 1.5rem;
    }
    /* Pastikan tidak ada overflow yang menyembunyikan elemen */
    body {
        overflow: auto; /* Ubah ke auto jika diperlukan, tapi coba hidden dulu */
    }
    .main-content {
        overflow: hidden; /* Tetap hidden untuk scroll internal */
    }
}