:root {
    --primary-color: #4285F4;
    --primary-hover: #1d4ed8;
    --primary-light: rgba(66, 133, 244, 0.1);
    --primary-light-hover: #bfdbfe;
    --danger-color: #ef4444; /* Đỏ */
    --danger-hover: #dc2626;
    --neutral-light: #f8f9fa;
    --neutral-medium: #e2e2e2;
    --neutral-dark: #6c757d;
    --text-primary: #343a40;
    --success-color: #10b981; /* Xanh lá */
    --border-radius-sm: 0.25rem;
    --border-radius-md: 0.5rem;
    --border-radius-lg: 0.75rem;
    --shadow-subtle: 0 2px 4px rgba(0, 0, 0, 0.05);
    --shadow-medium: 0 4px 6px rgba(0, 0, 0, 0.08);
    --shadow-strong: 0 10px 15px rgba(0, 0, 0, 0.1);
    --secondary-color: #34A853;
    --accent-color: #FBBC05;
    --text-color: #202124;
    --text-muted: #5F6368;
    --bg-color: #FFFFFF;
    --bg-secondary: #F8F9FA;
    --border-color: #E8EAED;
    --shadow-color: rgba(0, 0, 0, 0.15);
    --user-message-color: #F0F4FE;
    --bot-message-color: #F8F9FA;
    --code-bg: #2d2d2d;
    --code-color: #f8f8f2;
    --inline-code-bg: #f5f5f5;
    --inline-code-color: #e01e5a;
    --vh: 1vh;
}

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

html, body {
    height: 100%;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Roboto', -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    scroll-behavior: smooth;
    overscroll-behavior-y: contain;
    overflow-y: auto;
}

/* Thanh cuộn mảnh */
::-webkit-scrollbar {
    width: 5px;
    height: 5px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--neutral-medium);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--neutral-dark);
}

/* Hỗ trợ Firefox */
* {
    scrollbar-width: thin;
    /* scrollbar-color: var(--neutral-medium) transparent; */
}

/* Định dạng chung cho các phần tử văn bản trong khung chat */
.chat-messages p {
    line-height: 1.6;
    margin-bottom: 16px;
    font-size: 16px;
}

.chat-messages h1,
.chat-messages h2,
.chat-messages h3,
.chat-messages h4,
.chat-messages h5,
.chat-messages h6 {
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 20px;
}

.chat-messages h1 {
    font-size: 28px;
    line-height: 1.25;
    margin-top: 32px;
}

.chat-messages h2 {
    font-size: 24px;
    line-height: 1.3;
    margin-top: 28px;
}

.chat-messages h3 {
    font-size: 20px;
    line-height: 1.4;
    margin-top: 24px;
}

.chat-messages h4 {
    font-size: 18px;
    line-height: 1.45;
    margin-top: 20px;
}

.chat-messages ul,
.chat-messages ol {
    margin-left: 24px;
    margin-bottom: 16px;
}

.chat-messages li {
    line-height: 1.6;
    margin-bottom: 8px;
    font-size: 16px;
}

/* Container chính */
.container-fluid {
    height: 100%;
    overflow: visible;
}

/* Sidebar */
.sidebar {
    background: var(--neutral-light);
    padding: 20px;
    height: 100vh;
    overflow-y: auto;
    position: fixed;
    max-width: 320px;
    width: 100%;
    transition: transform 0.3s ease;
    z-index: 1040;
    box-shadow: var(--shadow-medium);
}

.sidebar.closed {
    transform: translateX(-100%);
}

.sidebar-header {
    padding-bottom: 15px;
    margin-bottom: 15px;
    border-bottom: 1px solid var(--neutral-medium);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h3 {
    font-size: 18px;
    font-weight: 500;
    color: var(--primary-color);
    margin: 0;
}

.sidebar-close-btn {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: var(--primary-color);
    cursor: pointer;
    display: none;
}

.recent-label {
    padding: 10px 0;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--neutral-dark);
    margin-bottom: 10px;
}

.chat-history {
    overflow-y: auto;
    max-height: calc(100vh - 200px);
}

/* Hiển thị lịch sử trò chuyện */
.history-item {
    padding: 12px;
    margin-bottom: 10px;
    border-radius: var(--border-radius-md);
    cursor: pointer;
    display: flex;
    align-items: flex-start;
    background: white;
    box-shadow: var(--shadow-subtle);
    transition: all 0.2s ease;
}

.history-item-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    margin-left: 12px;
    overflow: hidden;
}

.history-title {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-primary);
}

.history-category {
    font-size: 12px;
    color: var(--primary-color);
    margin-top: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-category i {
    font-size: 11px;
    margin-right: 4px;
    color: var(--primary-color);
}

.history-item:hover {
    background: var(--primary-light);
    transform: translateY(-2px);
    box-shadow: var(--shadow-medium);
}

.history-item.active {
    background: white;
    border-left: 3px solid var(--primary-color);
}

.history-item .delete-btn {
    display: none;
    margin-left: auto;
    align-self: center;
}

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

.history-item i.fas.fa-comment {
    margin-top: 4px;
    color: var(--primary-color);
    flex-shrink: 0;
}

.delete-btn {
    background: var(--danger-color);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.delete-btn:hover {
    background: var(--danger-hover);
    transform: scale(1.1);
}

/* Chat container */
.chat-container {
    margin-left: 320px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    position: relative;
    transition: margin-left 0.3s ease;
    width: calc(100% - 320px);
}

.chat-container.fullscreen {
    margin-left: 0;
    width: 100%;
}

.chat-header {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    background-color: white;
    border-bottom: 1px solid var(--border-color);
    z-index: 10;
    position: sticky;
    top: 0;
    gap: 15px;
    box-shadow: var(--shadow-subtle);
    width: 100%;
}

.chat-header h2 {
    font-size: 20px;
    font-weight: 500;
    margin: 0;
    color: var(--primary-color);
}

.status {
    background: var(--success-color);
    color: #fff;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 500;
}

.toggle-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--primary-color);
}

.chat-messages {
    flex: 1;
    padding: 20px;
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    overflow-y: visible;
    margin-top: 60px;
    padding-bottom: 100px;
    padding-top: 60px;
}

/* Welcome layout và categories */
.welcome-message {
    font-size: 24px;
    text-align: center;
    color: var(--primary-color);
    padding: 30px;
    border-radius: 20px;
    background: white;
    max-width: 90%;
    margin: 0 auto 30px;
    line-height: 1.4;
    box-shadow: 0 10px 30px rgba(37, 99, 235, 0.1);
    align-self: center;
    background: linear-gradient(135deg, var(--primary-light) 0%, white 40%, white 60%, var(--primary-light) 100%);
    animation: fadeIn 0.8s ease;
    font-weight: 500;
    border: none;
    position: relative;
    overflow: hidden;
}

.welcome-message::after {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255,255,255,0.8) 0%, rgba(255,255,255,0) 70%);
    opacity: 0.4;
    animation: shine 8s linear infinite;
}

@keyframes shine {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

.categories-container {
    margin-top: 20px;
    width: 100%;
    max-width: 800px;
    background: white;
    padding: 30px;
    border-radius: 24px;
    box-shadow: 0 15px 35px rgba(37, 99, 235, 0.08);
    border: none;
    align-self: center;
    animation: fadeIn 0.8s ease;
    position: relative;
    overflow: hidden;
    margin-bottom: 80px;
}

.categories-container::before {
    content: '';
    position: absolute;
    width: 200px;
    height: 200px;
    background: radial-gradient(circle, var(--primary-light) 0%, rgba(219, 234, 254, 0) 70%);
    top: -100px;
    right: -100px;
    border-radius: 50%;
    opacity: 0.4;
    z-index: 0;
}

.categories-container::after {
    content: '';
    position: absolute;
    width: 150px;
    height: 150px;
    background: radial-gradient(circle, var(--primary-light) 0%, rgba(219, 234, 254, 0) 70%);
    bottom: -75px;
    left: -75px;
    border-radius: 50%;
    opacity: 0.3;
    z-index: 0;
}

.category-title {
    font-size: 22px;
    color: var(--primary-color);
    margin-bottom: 25px;
    text-align: center;
    font-weight: 500;
    position: relative;
    z-index: 1;
}

.categories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 15px;
    margin-top: 15px;
    max-height: 450px;
    overflow-y: auto;
    padding-right: 5px;
    position: relative;
    z-index: 1;
    touch-action: pan-y;
    -webkit-overflow-scrolling: touch;
}

.category-btn {
    background: white;
    border: 1px solid var(--neutral-medium);
    border-radius: var(--border-radius-md);
    padding: 14px 12px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    box-shadow: var(--shadow-subtle);
    position: relative;
    overflow: hidden;
}

.category-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, rgba(219, 234, 254, 0), rgba(219, 234, 254, 0.5));
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 1;
}

.category-btn i {
    font-size: 1.8rem;
    color: var(--primary-color);
    transition: transform 0.3s ease;
    position: relative;
    z-index: 2;
}

.category-btn span {
    font-size: 0.9rem;
    font-weight: 500;
    position: relative;
    z-index: 2;
}

.category-btn:hover {
    transform: translateY(-5px);
    background: white;
    box-shadow: 0 8px 20px rgba(37, 99, 235, 0.2);
    border-color: var(--primary-color);
}

.category-btn:hover::before {
    opacity: 1;
}

.category-btn:hover i {
    transform: scale(1.1);
    animation: pulseIcon 1.5s ease infinite;
}

.category-btn.selected {
    background: var(--primary-light);
    border-color: var(--primary-color);
    box-shadow: 0 0 20px rgba(37, 99, 235, 0.3);
    transform: scale(1.05);
}

.category-btn.selected i {
    animation: pulse 1.5s infinite;
    color: var(--primary-color);
}

.category-btn.selected::before {
    opacity: 1;
}

@keyframes pulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.2);
    }
    100% {
        transform: scale(1);
    }
}

/* Input container */
.chat-input {
    padding: 15px 20px;
    border-top: 1px solid var(--neutral-medium);
    background: white;
    display: flex;
    align-items: center;
    position: sticky;
    bottom: 0;
    z-index: 50;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    /* box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05); */
}

.input-container {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    width: 100%;
    position: relative;
}

.input-container textarea.form-control {
    /* resize: none; */
    /* border: 1px solid var(--border-color); */
    /* border-radius: var(--border-radius-md); */
    /* padding: 10px 15px; */
    font-size: 1rem;
    line-height: 1.5;
    width: 100%;
    background: white;
    transition: all 0.3s ease;
    height: auto;
    min-height: 44px;
    max-height: 120px;
    /* box-shadow: none; */
}

.input-container:focus-within {
    border-color: var(--primary-color);
}

.input-container textarea.form-control:focus {
    box-shadow: none;
}

.input-container #sendButton {
    background: var(--primary-light);
    color: var(--primary-color);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 5px;
    transition: all 0.2s ease;
}

.input-container #sendButton:hover {
    background: var(--primary-color);
    color: white;
}

/* Message styling */
.message {
    margin-bottom: 20px;
    padding: 16px 18px;
    border-radius: var(--border-radius-md);
    position: relative;
    max-width: 65%;
    word-wrap: break-word;
    /* box-shadow: var(--shadow-subtle); */
    align-self: flex-start;
}

.message.user {
    background: var(--primary-light);
    margin-left: auto;
    align-self: flex-end;
    text-align: left;
    border-radius: 24px 4px 24px 24px;
    color: var(--text-primary);
}

.message.bot {
    margin-right: auto;
    text-align: left;
    max-width: 70%;
    position: relative;
    padding-left: 30px;
    padding-top: 12px;
    /* background: white; */
    /* border: 1px solid var(--neutral-medium); */
    /* border-radius: var(--border-radius-md); */
}

.message.bot::before {
    content: '';
    position: absolute;
    left: -15px;
    top: 5px;
    width: 30px;
    height: 30px;
    background-image: url('icon.png');
    background-size: cover;
    border-radius: 50%;
}

/* Hiệu ứng typing animation cho tin nhắn đang gõ */
.message.bot-typing {
    display: flex;
    align-items: center;
    background: var(--neutral-light);
    padding: 12px 15px;
    max-width: 150px;
    margin-right: auto;
    border-radius: var(--border-radius-md);
    color: var(--text-primary);
    font-size: 14px;
    position: relative;
}

.message.bot-typing::after {
    content: "";
    display: inline-block;
    margin-left: 6px;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background-color: var(--primary-color);
    animation: typingDots 1.5s infinite;
    position: relative;
    top: 0;
}

.message.bot-typing::before {
    display: none;
}

@keyframes typingDots {
    0% { box-shadow: 6px 0 0 0 transparent, 12px 0 0 0 transparent; }
    20% { box-shadow: 6px 0 0 0 var(--primary-color), 12px 0 0 0 transparent; }
    40% { box-shadow: 6px 0 0 0 var(--primary-color), 12px 0 0 0 var(--primary-color); }
    60% { box-shadow: 6px 0 0 0 var(--primary-color), 12px 0 0 0 var(--primary-color); }
    80% { box-shadow: 6px 0 0 0 transparent, 12px 0 0 0 var(--primary-color); }
    100% { box-shadow: 6px 0 0 0 transparent, 12px 0 0 0 transparent; }
}

/* Share feature */
.share-btn {
    background: var(--primary-light);
    border: 1px solid var(--primary-light-hover);
    padding: 8px 16px;
    border-radius: var(--border-radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
    font-weight: 500;
    color: var(--primary-color);
}

.share-btn:hover {
    background: var(--primary-light-hover);
}

.share-popup {
    display: none;
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    padding: 30px;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-strong);
    z-index: 1050;
    width: 350px;
    border: 1px solid var(--neutral-medium);
}

.share-popup-content {
    display: flex;
    gap: 20px;
    justify-content: center;
    position: relative;
    padding-top: 30px;
    padding-bottom: 30px;
}

.share-close-btn {
    position: absolute;
    top: -15px;
    right: -15px;
    background: var(--neutral-light);
    border: none;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    font-size: 1rem;
    cursor: pointer;
    color: var(--danger-color);
    display: flex;
    align-items: center;
    justify-content: center;
}

.share-close-btn:hover {
    background: var(--danger-color);
    color: white;
}

.share-icon {
    width: 45px;
    height: 45px;
    background: var(--neutral-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    font-size: 1.5rem;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-primary);
}

.share-icon:hover {
    transform: translateY(-5px);
    background: var(--primary-light-hover);
    color: var(--primary-color);
}

/* Gợi ý câu hỏi nhanh */
.quick-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 15px;
    margin: 0 auto 10px auto;
    width: 100%;
    max-width: 800px;
    background-color: transparent;
    border-radius: 10px;
    z-index: 5;
    justify-content: center;
    position: relative;
}

.suggestion-btn {
    border: 1px solid var(--primary-color);
    background-color: transparent;
    color: var(--primary-color);
    padding: 8px 15px;
    border-radius: 18px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    margin-bottom: 8px;
}

.suggestion-btn:hover {
    background-color: var(--primary-light);
}

/* Code blocks */
.message.bot pre {
    background: var(--neutral-light);
    border-radius: var(--border-radius-sm);
    padding: 15px;
    overflow: auto;
    position: relative;
    margin: 15px 0;
    font-size: 14px;
    box-shadow: var(--shadow-subtle);
    border-left: 3px solid var(--primary-color);
}

.message.bot code {
    font-family: 'Roboto Mono', monospace;
    font-size: 14px;
}

pre {
    position: relative;
    border-radius: var(--border-radius-md);
    margin: 15px 0;
    overflow: hidden;
    background: var(--neutral-light);
    box-shadow: var(--shadow-subtle);
}

pre code {
    display: block;
    padding: 15px 20px;
    overflow-x: auto;
    font-family: 'Roboto Mono', monospace;
    line-height: 1.5;
    font-size: 0.9rem;
}

.copy-btn {
    background: white;
    color: var(--primary-color);
    border: none;
    border-radius: var(--border-radius-sm);
    padding: 5px 10px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 4px;
    position: absolute;
    top: 5px;
    right: 5px;
}

.copy-btn:hover {
    background: var(--primary-light-hover);
}

.copy-btn.copied {
    background: var(--primary-color) !important;
    color: white !important;
}

/* Nút chat mới cho mobile */
.new-chat-mobile {
    position: fixed;
    top: 60px;
    left: 10px;
    right: 10px;
    z-index: 50;
    padding: 8px;
    margin: 0;
    width: calc(100% - 20px);
    background: var(--primary-light);
    color: var(--primary-color);
    border: none;
    border-radius: var(--border-radius-md);
    cursor: pointer;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    box-shadow: var(--shadow-subtle);
    opacity: 0.9;
}

.new-chat-mobile:hover {
    background: var(--primary-light-hover);
}

/* Media queries */
@media (min-width: 1440px) {
    .chat-messages, 
    .chat-input,
    .quick-suggestions {
        max-width: 900px;
    }
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(15px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pulseIcon {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.message, .input-container, .quick-suggestions, .history-item, .category-btn {
    animation: fadeIn 0.3s ease;
}

.category-btn {
    animation: fadeIn 0.5s ease;
}

/* Thêm vào cuối file để điều chỉnh scroll behavior */
.categories-grid::-webkit-scrollbar {
    width: 8px;
}

.categories-grid::-webkit-scrollbar-track {
    background: var(--neutral-light);
    border-radius: 10px;
}

.categories-grid::-webkit-scrollbar-thumb {
    background: var(--primary-light-hover);
    border-radius: 10px;
}

.categories-grid::-webkit-scrollbar-thumb:hover {
    background: var(--primary-color);
}

/* Thêm phần CSS để xử lý khi không có tin nhắn trong chat */
.empty-chat-message {
    text-align: center;
    padding: 30px;
    color: var(--neutral-dark);
    font-size: 1.2rem;
}

/* CSS cho checkbox ẩn/hiện password */
.password-toggle {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    color: var(--neutral-dark);
}

/* Ngăn không cho người dùng resize textarea */
textarea {
    resize: none;
}

/* Thêm các cải tiến chung cho cả mobile và desktop */
.response-content {
    width: 100%;
}

/* Thêm các media queries để tối ưu cho các màn hình khác nhau */
@media (max-width: 360px) {
    .categories-grid {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    }
    
    .chat-header h2 {
        font-size: 16px;
    }
}

@media (min-width: 768px) and (max-width: 991.98px) {
    .sidebar {
        max-width: 280px;
    }
    
    .chat-container {
        margin-left: 280px;
        width: calc(100% - 280px);
    }
}

/* Cải thiện hiển thị cho iPhone và các thiết bị nhỏ */
@media screen and (max-width: 375px) {
    .categories-grid {
        grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    }
    
    .category-btn {
        padding: 6px 4px;
    }
    
    .category-btn span {
        font-size: 0.7rem;
    }
    
    .welcome-message {
        font-size: 16px;
        padding: 12px;
    }
}

/* Cải thiện độ cao trên các thiết bị nhỏ */
@media screen and (max-height: 700px) {
    .categories-grid {
        max-height: 420px;
    }
    
    .welcome-message {
        margin-top: 50px;
    }
}

/* Fix các vấn đề trên iOS */
@supports (-webkit-touch-callout: none) {
    /* Sửa lỗi scrolling trên iOS */
    .chat-container, 
    .categories-grid, 
    .chat-messages, 
    .sidebar {
        -webkit-overflow-scrolling: touch;
    }
    
    /* Fix khoảng cách bottom cho iOS */
    .chat-input {
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    }
    
    .bottom-spacer {
        height: calc(60px + env(safe-area-inset-bottom, 0px));
    }
}

.bottom-spacer {
    height: 60px;
    width: 100%;
}

/* Fix chiều cao của container trên điện thoại */
@supports (-webkit-touch-callout: none) {
    /* iOS không hiển thị chiều cao 100vh chính xác */
    .chat-container, .chat-messages {
        height: -webkit-fill-available;
    }
    
    html {
        height: -webkit-fill-available;
    }
    
    body {
        min-height: 100vh;
        min-height: -webkit-fill-available;
    }
    
    /* Fix khoảng cách bottom cho iOS */
    .chat-input {
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    }
    
    .bottom-spacer {
        height: calc(60px + env(safe-area-inset-bottom, 0px));
    }
}

/* Điều chỉnh cấu trúc chat mới */
.chat-content {
    flex: 1;
    width: 100%;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow-y: visible;
}

.quick-suggestions-container {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    padding: 0 15px;
}

/* Media queries điều chỉnh cho mobile - đặt ở cuối file để ưu tiên cao hơn */
@media (max-width: 767.98px) {
    /* Reset một số styles chung */
    .chat-container {
        margin-left: 0;
        width: 100%;
        height: 100%;
        display: flex;
        flex-direction: column;
        padding-top: 55px;
        padding-bottom: 0;
        overflow: visible;
    }
    
    /* Sửa scroll cho nội dung chat */
    .chat-content {
        padding-bottom: 60px;
        height: auto;
        overflow-y: visible !important;
        position: relative;
    }
    
    .chat-messages {
        padding: 15px 10px;
        margin: 0 !important;
        margin-bottom: 80px !important;
        height: auto !important;
        min-height: fit-content;
        flex: 1;
        overflow-y: visible;
    }
    
    /* Điều chỉnh vị trí nút new chat mobile để không che nội dung */
    .new-chat-mobile {
        position: fixed;
        top: 60px;
        left: 10px;
        right: 10px;
        z-index: 50;
        padding: 8px;
        margin: 0;
        width: calc(100% - 20px);
        background: rgb(237 237 237);
        color: var(--primary-color);
        border: none;
        border-radius: var(--border-radius-md);
        cursor: pointer;
        font-weight: 500;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 8px;
        box-shadow: var(--shadow-subtle);
        opacity: 0.9;
    }
    
    /* Điều chỉnh vị trí chat-messages để không bị che bởi nút new chat */
    .chat-messages {
        margin-top: 110px !important;
    }
    
    /* Fix iOS scrolling - áp dụng cho body thay vì container */
    body, html {
        -webkit-overflow-scrolling: touch;
        height: 100%;
        overflow-y: auto;
    }
    
    /* Fix Chat Input khi bàn phím hiện lên */
    .chat-input {
        padding: 10px;
        position: fixed !important;
        bottom: 0 !important;
        left: 0;
        right: 0;
        background: white;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.08);
        z-index: 1000;
        width: 100%;
        max-width: 100%;
        transition: transform 0.3s ease;
    }
    
    /* Thêm class để di chuyển input lên khi focus */
    .chat-input.keyboard-open {
        transform: translateY(-10px);
        max-height: 60px;
        background-color: rgba(255, 255, 255, 0.95);
    }
    
    /* Đảm bảo textarea không bị ẩn */
    .chat-input .input-container {
        position: relative;
        z-index: 1010;
    }
    
    /* Fix Header */
    .chat-header {
        padding: 10px 15px;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 1000;
        background: white;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    }
    
    .chat-header h2 {
        font-size: 18px;
    }
    
    .toggle-btn {
        font-size: 1.3rem;
    }
    
    .share-btn span {
        display: none;
    }
    
    /* Điều chỉnh tin nhắn */
    .message {
        max-width: 85%;
        padding: 12px 15px;
        margin-bottom: 15px;
    }
    
    .message.bot {
        max-width: 90%;
        padding-left: 25px;
    }
    
    .message.bot::before {
        width: 24px;
        height: 24px;
        left: -10px;
        top: 5px;
    }
    
    .message.bot pre {
        padding: 12px;
        margin: 10px 0;
        font-size: 13px;
    }
    
    .message.bot code {
        font-size: 13px;
    }
    
    /* Fix Quick Suggestions */
    .quick-suggestions-container {
        position: fixed;
        bottom: 60px;
        left: 0;
        right: 0;
        z-index: 40;
        padding: 0;
        background-color: rgba(255, 255, 255, 0.95);
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
    }
    
    .quick-suggestions {
        padding: 8px 5px;
        /* margin-bottom: 0; */
        gap: 5px;
        position: fixed;
        bottom: 60px;
        left: 0;
        right: 0;
        background-color: rgba(255, 255, 255, 0.95);
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
        z-index: 40;
    }
    
    .suggestion-btn {
        padding: 6px 12px;
        font-size: 0.75rem;
        margin-bottom: 4px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 140px;
    }
    
    /* Fix welcome message và categories */
    .welcome-message {
        font-size: 18px;
        padding: 15px;
        max-width: 95%;
        margin-top: 50px;
        margin-bottom: 20px;
        text-align: center;
        font-weight: 500;
        color: var(--primary-color);
    }
    
    .categories-container {
        margin-bottom: 20px;
        padding: 15px 10px;
        border-radius: 16px;
        position: relative;
        z-index: 5;
        touch-action: pan-y;
    }
    
    .category-title {
        font-size: 18px;
        margin-bottom: 15px;
    }
    
    .categories-grid {
        grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
        gap: 8px;
        max-height: 450px;
        overflow-y: auto;
        padding-bottom: 10px;
        -webkit-overflow-scrolling: touch;
        touch-action: pan-y;
        z-index: 10;
    }
    
    .category-btn {
        padding: 8px 5px;
        gap: 6px;
    }
    
    .category-btn i {
        font-size: 1.5rem;
    }
    
    .category-btn span {
        font-size: 0.75rem;
    }
    
    .category-btn.selected {
        transform: scale(1.05);
        background-color: var(--primary-light);
        border: 1px solid var(--primary-color);
        transition: all 0.3s ease;
    }
    
    /* Fix share popup */
    .share-popup {
        width: 90%;
        max-width: 320px;
        padding: 20px;
    }
    
    .share-popup-content {
        gap: 15px;
        padding: 20px 0;
    }
    
    .share-icon {
        width: 40px;
        height: 40px;
        font-size: 1.3rem;
    }
    
    .copy-btn {
        top: 3px;
        right: 3px;
        padding: 3px 8px;
        font-size: 11px;
    }
    
    /* Fix iOS scrolling */
    .chat-content, .chat-messages, .categories-grid {
        -webkit-overflow-scrolling: touch;
    }
    
    /* Fix bottom padding for iOS */
    @supports (-webkit-touch-callout: none) {
        .chat-content {
            padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px));
        }
        
        .chat-input {
            padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
        }
        
        .bottom-spacer {
            height: calc(60px + env(safe-area-inset-bottom, 0px));
        }
    }
    
    /* Fix sidebar */
    .sidebar {
        transform: translateX(-100%);
        max-width: 280px;
        z-index: 1050;
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        width: 80%;
    }
    
    .sidebar.active {
        transform: translateX(0);
    }
    
    .sidebar-close-btn {
        display: block;
    }

    /* Tăng kích thước và padding cho input trên mobile */
    .input-container textarea.form-control {
        padding: 12px 15px;
        min-height: 44px;
        font-size: 16px; /* Ngăn iOS zoom khi focus */
        line-height: 1.4;
    }

    /* Điều chỉnh container input */
    .input-container {
        padding: 0;
        margin: 0;
        align-items: center;
    }

    /* Fix Chat Input khi bàn phím hiện lên */
    .chat-input {
        padding: 10px;
        position: fixed !important;
        bottom: 0 !important;
        left: 0;
        right: 0;
        background: white;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.08);
        z-index: 1000;
        width: 100%;
        max-width: 100%;
        transition: transform 0.3s ease;
    }
    
    /* Thêm class để di chuyển input lên khi focus */
    .chat-input.keyboard-open {
        transform: translateY(-10px);
        max-height: 60px;
        background-color: rgba(255, 255, 255, 0.95);
    }
    
    /* Cuộn trang lên khi focus textarea */
    .chat-input.keyboard-open ~ .chat-messages {
        padding-bottom: 100px;
    }
    
    /* Đảm bảo nút gửi luôn hiển thị */
    .input-container #sendButton {
        position: relative;
        z-index: 1020;
        min-width: 40px;
        min-height: 40px;
    }

    /* Thêm padding để tạo không gian khi bàn phím mở */
    body {
        padding-bottom: env(safe-area-inset-bottom, 20px);
    }
    
    /* Fix khoảng cách dưới cho nội dung chat */
    .chat-messages {
        margin-bottom: 80px !important; /* Tăng margin bottom để tránh bị che khi input hiện lên */
    }
    
    /* Cố định ô nhập liệu phía dưới */
    .chat-input {
        position: fixed !important;
        bottom: 0 !important;
        left: 0;
        right: 0;
        z-index: 1000;
        background-color: white;
        padding: 10px;
        padding-bottom: calc(10px + env(safe-area-inset-bottom, 10px)); /* Thêm padding phù hợp cho iPhone có notch */
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    }
    
    /* Ẩn ô input khi đang cuộn nhưng không focus */
    .chat-input:not(.keyboard-open) {
        opacity: 0.98;
    }
    
    /* Khi input có focus và bàn phím hiện lên */
    .chat-input.keyboard-open {
        transform: translateY(-8px); /* Đẩy lên một chút khi bàn phím hiện */
        background-color: rgba(255, 255, 255, 0.98);
        padding-bottom: 10px; /* Giảm padding khi đã hiện bàn phím */
    }
    
    /* Style cho textarea để dễ thao tác */
    .input-container textarea.form-control {
        border-radius: 20px;
        padding: 12px 15px;
        min-height: 44px;
        max-height: 120px;
        font-size: 16px; /* Ngăn iOS tự động zoom */
        line-height: 1.3;
        background-color: var(--neutral-light);
        border: 1px solid var(--border-color);
    }
}

/* AI Version Selector */
.ai-version-selector {
    margin-left: 15px;
    display: flex;
    align-items: center;
}

.ai-version-selector select {
    background-color: #f0f2f5;
    border: 1px solid #ddd;
    border-radius: 20px;
    font-size: 0.8rem;
    padding: 0.25rem 1.5rem 0.25rem 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
    max-width: 110px;
}

.ai-version-selector select:hover {
    background-color: #e4e6eb;
}

.ai-version-selector select:focus {
    box-shadow: 0 0 0 2px rgba(24, 119, 242, 0.2);
    border-color: #1877f2;
    outline: none;
}

/* Mobile responsive styles for AI selector */
@media (max-width: 767.98px) {
    .ai-version-selector {
        margin-left: 10px;
    }
    
    .ai-version-selector select {
        font-size: 0.7rem;
        padding: 0.15rem 1.2rem 0.15rem 0.5rem;
        max-width: 95px;
    }
    
    .chat-header h2 {
        font-size: 1rem;
    }
}

/* System message styles */
.message.system {
    background-color: rgba(0, 123, 255, 0.1);
    border-radius: 15px;
    margin: 5px auto;
    max-width: 85%;
    padding: 8px 15px;
    text-align: center;
    color: #0056b3;
    font-size: 0.85rem;
    border: 1px solid rgba(0, 123, 255, 0.2);
    box-shadow: 0 1px 3px rgba(0, 123, 255, 0.1);
    animation: fadeIn 0.3s ease-in-out;
}

.message.system .message-content {
    display: flex;
    align-items: center;
    justify-content: center;
}

.message.system .system-icon {
    margin-right: 8px;
    font-size: 1rem;
}

.message.system .system-text {
    font-weight: 500;
}

/* Responsive system message styles */
@media (max-width: 767.98px) {
    .message.system {
        max-width: 90%;
        font-size: 0.8rem;
        padding: 6px 12px;
    }
    
    .message.system .system-icon {
        margin-right: 6px;
        font-size: 0.9rem;
    }
}

/* AI Version Selector ở trên khung chat */
.ai-version-selector-bottom {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 10px;
    padding: 0 15px;
}

.ai-version-selector-bottom select {
    background-color: #f0f2f5;
    border: 1px solid #ddd;
    border-radius: 20px;
    font-size: 0.8rem;
    padding: 0.25rem 1.5rem 0.25rem 0.75rem;
    cursor: pointer;
    transition: all 0.2s ease;
    max-width: 150px;
}

.ai-version-selector-bottom select:hover {
    background-color: #e4e6eb;
}

.ai-version-selector-bottom select:focus {
    box-shadow: 0 0 0 2px rgba(24, 119, 242, 0.2);
    border-color: #1877f2;
    outline: none;
}

.ai-version-selector-bottom .version-label {
    font-size: 0.8rem;
    color: #65676b;
    margin-right: 8px;
}

/* Responsive styles for the bottom AI selector */
@media (max-width: 767.98px) {
    .ai-version-selector-bottom {
        padding: 0 10px;
        margin-bottom: 8px;
    }
    
    .ai-version-selector-bottom select {
        font-size: 0.75rem;
        padding: 0.2rem 1.2rem 0.2rem 0.5rem;
    }
    
    .ai-version-selector-bottom .version-label {
        font-size: 0.75rem;
    }
}