* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
    background-color: #131314;
    color: #e3e3e3;
    display: flex;
    height: 100vh;
    overflow: hidden;
}

#app-layout {
    display: flex;
    width: 100vw;
    height: 100vh;
    overflow: hidden;
}

#sidebar {
    width: 280px;
    background-color: #1e1f20;
    display: flex;
    flex-direction: column;
    padding: 16px;
    gap: 16px;
    transition: width 0.3s ease;
    z-index: 20;
    overflow: hidden;
    flex-shrink: 0;
}

#sidebar.collapsed {
    width: 76px;
}

.sidebar-top {
    display: flex;
    align-items: center;
    gap: 12px;
}

.icon-btn {
    background: transparent;
    border: none;
    color: #c4c7c5;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
    font-size: 18px;
    flex-shrink: 0;
}

.icon-btn:hover {
    background-color: #333538;
}

.sidebar-brand {
    font-size: 16px;
    font-weight: 600;
    color: #e3e3e3;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

#new-chat-btn {
    background-color: #282a2c;
    color: #e3e3e3;
    border: none;
    border-radius: 28px;
    padding: 12px 18px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: background 0.2s;
    white-space: nowrap;
    overflow: hidden;
}

#new-chat-btn:hover {
    background-color: #333538;
}

.sidebar-title {
    font-size: 12px;
    color: #8e918f;
    padding-left: 12px;
    font-weight: 600;
    letter-spacing: 0.5px;
    white-space: nowrap;
}

#sidebar.collapsed .sidebar-brand,
#sidebar.collapsed .sidebar-title,
#sidebar.collapsed .history-item-wrapper,
#sidebar.collapsed .btn-text {
    display: none;
}

#history-container {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.history-item-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
    border-radius: 18px;
    font-size: 14px;
    color: #c4c7c5;
    cursor: pointer;
    transition: background 0.2s;
}

.history-item-wrapper:hover {
    background-color: #282a2c;
}

.history-item-wrapper.active {
    background-color: #333538;
    color: #ffffff;
}

.history-title-text {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-menu-btn {
    background: transparent;
    border: none;
    color: #8e918f;
    font-size: 16px;
    padding: 2px 6px;
    border-radius: 4px;
    cursor: pointer;
    display: none;
}

.history-item-wrapper:hover .history-menu-btn {
    display: block;
}

.history-menu-btn:hover {
    background: #3c3f41;
    color: #e3e3e3;
}

.history-dropdown {
    display: none;
    position: absolute;
    right: 12px;
    top: 36px;
    background: #282a2c;
    border: 1px solid #333537;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    z-index: 50;
    width: 120px;
    overflow: hidden;
}

.dropdown-item {
    padding: 8px 12px;
    font-size: 13px;
    color: #c4c7c5;
    cursor: pointer;
}

.dropdown-item:hover {
    background: #333538;
    color: #e3e3e3;
}

.dropdown-item.delete-opt {
    color: #f28b82;
}

#main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: #131314;
    position: relative;
    height: 100vh;
}

#chat-container {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 20px 140px 20px;
    scroll-behavior: smooth;
}

#welcome-screen {
    max-width: 768px;
    width: 100%;
    margin-top: 18vh;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

#welcome-screen h1 {
    font-size: 40px;
    font-weight: 500;
    background: linear-gradient(90deg, #4285f4, #9b72cb, #d96570);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    letter-spacing: -0.5px;
}

#welcome-screen p {
    font-size: 40px;
    font-weight: 500;
    color: #444746;
    letter-spacing: -0.5px;
}

#message-stream {
    max-width: 768px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 28px;
}

.message-row {
    display: flex;
    flex-direction: column;
    width: 100%;
    animation: fadeIn 0.3s ease-out;
}

.message-row.user {
    align-items: flex-end;
}

.message-row.ai {
    align-items: flex-start;
}

.message-bubble {
    max-width: 85%;
    padding: 12px 18px;
    font-size: 15px;
    line-height: 1.6;
    word-wrap: break-word;
}

.message-row.user .message-bubble {
    background-color: #282a2c;
    color: #e3e3e3;
    border-radius: 20px;
    border-bottom-right-radius: 4px;
}

.msg-attachment-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 10px;
}

.msg-attached-image {
    max-width: 100%;
    max-height: 280px;
    object-fit: contain;
    border-radius: 12px;
    border: 1px solid #3c3f41;
}

.msg-attached-file {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #1e1f20;
    border: 1px solid #3c3f41;
    border-radius: 10px;
    padding: 8px 12px;
    font-size: 13px;
    color: #e3e3e3;
}

.msg-attached-file-icon {
    font-size: 20px;
}

.msg-attached-file-info {
    display: flex;
    flex-direction: column;
}

.msg-attached-file-name {
    font-weight: 500;
}

.msg-attached-file-size {
    font-size: 11px;
    color: #8e918f;
}

.message-row.ai .message-bubble {
    background-color: transparent;
    color: #c4c7c5;
    padding: 0;
    width: 100%;
}

.model-badge {
    font-size: 11px;
    color: #8e918f;
    margin-top: 12px;
    font-family: Consolas, monospace;
    background: #1e1f20;
    padding: 3px 8px;
    border-radius: 6px;
    display: inline-block;
    border: 1px solid #333537;
    margin-top: 0;
}

.ai-message-footer {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: 12px;
    flex-wrap: wrap;
}

.copy-msg-btn {
    background: transparent;
    border: none;
    color: #8e918f;
    font-size: 12px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 8px;
    border-radius: 6px;
    transition: color 0.2s, background 0.2s;
    outline: none;
}

.copy-msg-btn:hover {
    color: #e3e3e3;
    background-color: #282a2c;
}

.copy-msg-btn.copied {
    color: #81c995;
}

.message-bubble p { margin-bottom: 12px; }
.message-bubble p:last-child { margin-bottom: 0; }
.message-bubble ul, .message-bubble ol { margin-left: 20px; margin-bottom: 12px; }
.message-bubble li { margin-bottom: 4px; }
.message-bubble strong { color: #f2f2f2; font-weight: 600; }

.message-bubble table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
    font-size: 14.5px;
    background: #1e1f20;
    border-radius: 8px;
    overflow: hidden;
}
.message-bubble th {
    text-align: left;
    padding: 10px 14px;
    color: #e3e3e3;
    font-weight: 600;
    background: #282a2c;
    border-bottom: 1px solid #333537;
}
.message-bubble td {
    padding: 10px 14px;
    color: #c4c7c5;
    border-bottom: 1px solid #333537;
}
.message-bubble hr {
    border: none;
    border-top: 1px solid #333537;
    margin: 16px 0;
}
.message-bubble pre {
    background: #1e1f20;
    padding: 14px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 12px 0;
    border: 1px solid #333537;
}
.message-bubble code {
    font-family: Consolas, monospace;
    color: #75c1f9;
    background: #282a2c;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13.5px;
}
.message-bubble pre code { background: transparent; padding: 0; color: #c4c7c5; }

#input-container-wrapper {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: linear-gradient(transparent, #131314 50%);
    padding: 20px 20px 24px 20px;
    display: flex;
    justify-content: center;
    z-index: 20;
}

#input-box-wrapper {
    position: relative;
    max-width: 768px;
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.upload-btn-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Menu chọn Tải tệp / Tải ảnh bật lên từ dấu cộng */
.upload-menu {
    display: none;
    position: absolute;
    bottom: calc(100% + 14px);
    left: 0;
    background: #282a2c;
    border: 1px solid #3c3f41;
    border-radius: 16px;
    padding: 6px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.5);
    z-index: 100;
    width: 230px;
    flex-direction: column;
    gap: 4px;
    animation: fadeIn 0.2s ease-out;
}

.upload-menu.show {
    display: flex;
}

.upload-option {
    display: flex;
    align-items: center;
    padding: 10px 14px;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.2s;
}

.upload-option:hover {
    background-color: #333538;
}

.opt-text {
    display: flex;
    flex-direction: column;
}

.opt-title {
    font-size: 14px;
    font-weight: 500;
    color: #e3e3e3;
}

.opt-desc {
    font-size: 11px;
    color: #8e918f;
}

/* Thanh xem trước đính kèm */
.attachment-preview-bar {
    display: none;
    flex-wrap: wrap;
    gap: 8px;
    padding: 4px 6px;
}

.attachment-preview-bar.has-items {
    display: flex;
}

.attachment-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #282a2c;
    border: 1px solid #3c3f41;
    border-radius: 12px;
    padding: 6px 12px;
    font-size: 13px;
    color: #e3e3e3;
    animation: fadeIn 0.2s ease-out;
    max-width: 280px;
}

.attachment-thumb {
    width: 36px;
    height: 36px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid #3c3f41;
}

.attachment-file-icon {
    font-size: 20px;
}

.attachment-info {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex: 1;
}

.attachment-name {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.attachment-meta {
    font-size: 11px;
    color: #8e918f;
}

.attachment-remove {
    background: transparent;
    border: none;
    color: #8e918f;
    cursor: pointer;
    font-size: 16px;
    padding: 2px 4px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s, background 0.2s;
}

.attachment-remove:hover {
    color: #f28b82;
    background: rgba(242, 139, 130, 0.15);
}

#input-box {
    width: 100%;
    background-color: #1e1f20;
    border: 1px solid #333537;
    border-radius: 28px;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.4);
    transition: border-color 0.2s;
}

#input-box:focus-within {
    border-color: #555759;
}

.input-icon-btn {
    background: transparent;
    border: none;
    color: #c4c7c5;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
    font-size: 18px;
}

.input-icon-btn:hover {
    background-color: #333538;
}

textarea {
    flex: 1;
    background: transparent;
    border: none;
    color: #e3e3e3;
    font-size: 15px;
    resize: none;
    outline: none;
    max-height: 180px;
    line-height: 1.5;
    padding-top: 6px;
}

textarea::placeholder {
    color: #8e918f;
}

button#send-btn {
    background-color: #d3e3fd;
    color: #001d35;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
    flex-shrink: 0;
}

button#send-btn:hover {
    background-color: #a8c7fa;
}

button#send-btn:disabled {
    background-color: #282a2c;
    color: #444746;
    cursor: not-allowed;
}

.typing-indicator {
    display: none;
    align-items: center;
    gap: 6px;
    padding: 12px 0;
    width: 100%;
    max-width: 768px;
}

.typing-dot {
    width: 7px;
    height: 7px;
    background-color: #8e918f;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

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

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #333537; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #555759; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.retry-msg-btn {
    background-color: #282a2c;
    color: #e3e3e3;
    border: 1px solid #3c3f41;
    border-radius: 8px;
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 10px;
    transition: background 0.2s, border-color 0.2s;
    outline: none;
}

.retry-msg-btn:hover {
    background-color: #333538;
    border-color: #555759;
}

.message-row.error-msg .message-bubble {
    color: #f28b82;
}
