/* Reset & Basic Setup */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary-color: #7289da; /* Soft Blue */
    --secondary-color: #99aab5;
    --bg-color: #eef2f9;
    --light-bg: #ffffff;
    --text-primary: #23272a;
    --text-secondary: #6e6e80;
    --border-color: #e3e5e8;
    --hover-color: #e9eaec;
    --user-msg-bg: #7289da;
    --online-color: #43b581;
    --offline-color: #747f8d;
    --error-color: #f04747;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
}

/* Sidebar */
.sidebar {
    height: 100vh;
    z-index: 1000;
    width: 280px;
    background: var(--light-bg);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: margin-left 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    margin-left: -280px;
}

.sidebar.sidebar-locked {
    margin-left: 0;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
}

.new-chat-btn {
    width: 100%;
    padding: 12px 16px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-menu {
    padding: 8px;
    flex-grow: 1;
    overflow-y: auto;
}

.menu-section { margin-bottom: 16px; }
.menu-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    padding: 0 12px;
}

.chat-history-container {
    max-height: 250px;
    overflow-y: auto;
    padding-right: 5px;
}

.history-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    gap: 8px;
}
.history-item:hover { background: var(--hover-color); }
.history-item.active { background-color: var(--primary-color); color: white; }
.history-item .delete-chat-btn {
    background: none; border: none; color: var(--secondary-color);
    cursor: pointer; visibility: hidden; opacity: 0;
    transition: opacity 0.2s; flex-shrink: 0;
}
.history-item:hover .delete-chat-btn, .history-item.active .delete-chat-btn {
    visibility: visible; opacity: 1; color: inherit;
}

.api-key-selector {
    width: calc(100% - 16px); margin: 0 8px 8px; padding: 8px;
    border: 1px solid var(--border-color); border-radius: 6px;
    background-color: var(--bg-color);
}
.menu-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.menu-item:hover { background: var(--hover-color); }
.sidebar-footer { padding: 16px; border-top: 1px solid var(--border-color); }
.auth-view form { display: flex; flex-direction: column; gap: 8px; }
.auth-view input, .auth-view button { padding: 10px; border-radius: 6px; border: 1px solid var(--border-color); }
.auth-view button { background: var(--primary-color); color: white; cursor: pointer; }
#profile-view { display: flex; flex-direction: column; gap: 8px; }
#userInfoSidebar { font-size: 14px; }
.error-message { font-size: 12px; color: var(--error-color); }

/* Chat Area */
.chat-area {
    flex-grow: 1;
    height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--light-bg);
}

/* Hamburger Button */
.hamburger-btn {
    position: relative; 
    background: transparent;
    border: none;
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.3s ease;
}
.hamburger-btn:hover { background-color: var(--hover-color); }
.hamburger-btn i { color: var(--text-primary); font-size: 18px; }

/* Chat Header */
.chat-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 16px;
    justify-content: space-between;
    flex-shrink: 0;
}
.chat-title { font-size: 18px; font-weight: 600; }
.status-badge { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; transition: background-color 0.3s; }
.status-dot.online { background-color: var(--online-color); }
.status-dot.offline { background-color: var(--offline-color); }
.status-dot.error { background-color: var(--error-color); }

.messages-container { flex: 1; overflow-y: auto; padding: 24px; }
.message { margin-bottom: 24px; display: flex; gap: 16px; }
.message.user { flex-direction: row-reverse; }
.message-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: white; flex-shrink: 0;
}
.user .message-avatar { background: var(--secondary-color); }
.ai .message-avatar { background: var(--primary-color); }

.message-text {
    padding: 12px 16px; border-radius: 12px;
    max-width: 70%; line-height: 1.5;
}
.user .message-text { background: var(--user-msg-bg); color: white; border-top-right-radius: 0; }
.ai .message-text {
    background: transparent;
    border: none;
    max-width: 100%;
    padding: 0;
}

/* Input Area */
.input-area { padding: 24px; border-top: 1px solid var(--border-color); flex-shrink: 0; }
.input-wrapper { display: flex; gap: 12px; }
.message-input {
    flex: 1; border: 1px solid var(--border-color);
    border-radius: 8px; padding: 12px; resize: none;
    font-size: 15px;
}
.input-btn {
    width: 48px; height: 48px; border-radius: 8px;
    border: none; background: var(--primary-color);
    color: white; cursor: pointer; font-size: 18px;
}

/* Modals */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6);
    display: none; align-items: center; justify-content: center; z-index: 2000;
}
.modal-content {
    background: var(--light-bg); border-radius: 12px;
    width: 90%; max-width: 500px;
    animation: modal-fade-in 0.3s ease-out;
}
@keyframes modal-fade-in {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}
.modal-header {
    padding: 16px; border-bottom: 1px solid var(--border-color);
    display: flex; justify-content: space-between; align-items: center;
}
.modal-title { font-weight: 600; }
.close-btn { background: none; border: none; font-size: 24px; cursor: pointer; }
.modal-body { padding: 16px; }
.key-item {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px; border-bottom: 1px solid var(--border-color);
}
.delete-key-btn { background: none; border: none; color: var(--error-color); cursor: pointer; }
.add-key-form {
    margin-top: 16px; display: flex; flex-direction: column; gap: 10px;
}
.add-key-form input, .add-key-form button {
    padding: 10px; border: 1px solid var(--border-color); border-radius: 6px;
}
.add-key-form button { background: var(--primary-color); color: white; cursor: pointer; }
.modal-actions {
    margin-top: 24px; display: flex;
    justify-content: flex-end; gap: 12px;
}
.modal-actions button {
    padding: 10px 20px; border: none;
    border-radius: 6px; cursor: pointer; font-weight: 500;
    transition: background-color 0.2s;
}
.btn-secondary { background-color: var(--hover-color); color: var(--text-primary); }
.btn-secondary:hover { background-color: var(--border-color); }
.btn-danger { background-color: var(--error-color); color: white; }
.btn-danger:hover { opacity: 0.9; }

/* Modal Personalisasi */
.modal-description {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 12px;
    line-height: 1.5;
}
.custom-instruction-textarea {
    width: 100%;
    height: 150px;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    resize: vertical;
    font-family: inherit;
    font-size: 14px;
}
.btn-primary {
    background-color: var(--primary-color);
    color: white;
}
.btn-primary:hover {
    opacity: 0.9;
}