/* Reset default styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Prevent scrolling on body and html */
html, body {
    height: 100vh;
    font-family: Arial, sans-serif;
    line-height: 1.6;
}

.dark-theme {
    background-color: #1a202c;
    color: #e2e8f0;
}

.light-theme {
    background-color: #f7fafc;
    color: #1a202c;
}

/* Container for the entire layout */
.container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 72px); /* Subtract header height (p-4 = 16px padding top and bottom, 40px content) */
    width: 100%;
}

/* Header */
header {
    height: 72px; /* Fixed height for header (16px padding top + 16px padding bottom + 40px content) */
}

/* Sidebar (chat history) */
.sidebar {
    background-color: #2d3748;
    padding: 1rem;
    overflow-y: auto;
    width: 80%; /* Lebar sidebar di mobile */
    max-width: 300px; /* Batasi lebar maksimum */
    height: 100%;
    position: fixed;
    top: 0;
    left: -100%;
    transition: left 0.3s ease-in-out;
    z-index: 10;
}

.sidebar.active {
    left: 0;
}

.chat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: #4a5568;
    margin-bottom: 0.5rem;
    padding: 0.5rem;
    border-radius: 5px;
    cursor: pointer;
}

.chat-item.pinned {
    background-color: #2d3748;
}

.chat-item:hover {
    background-color: #718096;
}

.chat-item-title {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-buttons {
    flex-shrink: 0;
}

/* Style untuk tombol close di sidebar */
#sidebar-close {
    padding: 0.5rem;
}

#sidebar-close svg {
    stroke: #e53e3e; /* Warna merah untuk ikon close agar lebih menonjol */
}

/* Chat container */
.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    min-height: 0; /* Mencegah overflow di flex container */
}

#chat-box {
    flex: 1;
    padding: 1rem;
    overflow-y: auto; /* Only allow scrolling here */
    overflow-x: hidden;
    width: 100%;
}

.input-container {
    padding: 1rem;
    border-top: 1px solid #4a5568;
    width: 100%;
    flex-shrink: 0; /* Mencegah input-container menyusut */
    background-color: inherit; /* Warna latar belakang sesuai tema */
    z-index: 5; /* Pastikan input di atas elemen lain */
}

/* Message styling */
.message {
    margin-bottom: 1rem;
    word-wrap: break-word;
    display: flex;
    align-items: flex-start;
    max-width: 100%;
    overflow-x: hidden;
}

.message strong {
    margin-right: 0.5rem;
    flex-shrink: 0;
}

.message .markdown {
    flex: 1;
    max-width: 100%;
    overflow-x: auto;
}

/* Code block styling */
pre {
    background-color: #2d2d2d;
    padding: 10px;
    border-radius: 5px;
    overflow-x: auto;
    position: relative;
    white-space: pre-wrap;
    word-wrap: break-word;
    max-width: 100%;
}

code {
    font-family: 'Courier New', Courier, monospace;
    font-size: 14px;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.copy-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    background-color: #4a5568;
    color: #e2e8f0;
    border: none;
    padding: 5px 10px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
    transition: background-color 0.2s;
}

.copy-btn:hover {
    background-color: #718096;
}

.copy-btn.copied {
    background-color: #48bb78;
}

.copy-btn.error {
    background-color: #e53e3e;
}

/* Typing indicator */
.typing-indicator span {
    animation: blink 1s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes blink {
    0%, 50%, 100% { opacity: 1; }
    25%, 75% { opacity: 0; }
}

/* Drag and drop */
textarea.dragover {
    border-color: #48bb78;
}

/* Dropdown */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-content {
    display: none;
    position: absolute;
    right: 0;
    background-color: #2d3748;
    min-width: 160px;
    z-index: 1;
}

.dropdown-content a {
    color: #e2e8f0;
    padding: 12px 16px;
    text-decoration: none;
    display: block;
}

.dropdown-content a:hover {
    background-color: #4a5568;
}

.show {
    display: block;
}

/* Chat image */
.chat-image {
    max-width: 200px;
    cursor: pointer;
    transition: transform 0.2s;
}

.chat-image:hover {
    transform: scale(1.05);
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.8);
    align-items: center;
    justify-content: center;
}

.modal-content {
    max-width: 90%;
    max-height: 90%;
    transform: scale(1);
    transition: transform 0.2s;
}

.close {
    position: absolute;
    top: 20px;
    right: 30px;
    color: white;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
}

/* Image preview */
#image-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-bottom: 10px;
}

.preview-item {
    position: relative;
    display: inline-block;
}

.preview-item img {
    max-width: 100px;
    max-height: 100px;
    object-fit: cover;
    border-radius: 5px;
}

.remove-btn {
    position: absolute;
    top: -5px;
    right: -5px;
    background-color: #e53e3e;
    color: white;
    border: none;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 12px;
}

.remove-btn:hover {
    background-color: #c53030;
}

/* Desktop styles (min-width: 768px) */
@media (min-width: 768px) {
    .container {
        flex-direction: row;
    }

    .sidebar {
        position: static;
        width: 250px;
        max-width: none;
        border-right: 1px solid #4a5568;
        left: 0;
    }

    /* Membuat tombol New Chat panjang penuh di desktop */
    .sidebar button[onclick="newChat()"] {
        width: 100%;
    }

    #chat-box {
        max-width: 800px;
        margin: 0 auto;
    }

    .input-container {
        max-width: 800px;
        margin: 0 auto;
    }
}

/* Mobile-specific styles */
@media (max-width: 767px) {
    html, body {
        overflow-y: auto; /* Izinkan scrolling pada body di mobile */
    }

    .container {
        min-height: calc(100vh - 72px); /* Pastikan container mengisi tinggi layar */
    }

    .chat-container {
        height: auto; /* Biarkan tinggi menyesuaikan konten */
    }

    .input-container {
        position: sticky; /* Membuat input tetap di bagian bawah */
        bottom: 0;
        padding-bottom: env(safe-area-inset-bottom); /* Menangani notch/keyboard */
    }

    #user-input {
        max-height: 100px; /* Batasi tinggi textarea */
        resize: vertical; /* Izinkan resize vertikal */
    }
}