/* ==========================================================================
   CHATGPT CLONE STYLESHEET - CLEAN WHITE THEME (NỀN TRẮNG CHỮ ĐEN)
   ========================================================================== */

:root {
    --bg-main: #ffffff;
    --bg-sidebar: #f9f9f9;
    --bg-composer: #f4f4f4;
    --bg-hover: #ececec;
    --bg-active: #e3e3e3;
    --border-color: #e5e5e5;
    --text-primary: #0d0d0d;
    --text-secondary: #676767;
    --text-muted: #8e8e8e;
    --accent-green: #10a37f;
    --accent-blue: #1a73e8;
    --card-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
    --font-stack: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    
    /* HOAPI Official Brand Palette */
    --hoapi-emerald: #10a37f;
    --hoapi-teal: #14b8a6;
    --hoapi-cyan: #06b6d4;
    --hoapi-midnight: #0f172a;
    --hoapi-quantum-mint: #34d399;
    --hoapi-quantum-sky: #38bdf8;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-stack);
    background-color: var(--bg-main);
    color: var(--text-primary);
    line-height: 1.6;
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

/* BỐ CỤC CHUNG */
.app-layout {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* ==========================================================================
   SIDEBAR BÊN TRÁI
   ========================================================================== */
.sidebar {
    width: 260px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100%;
    user-select: none;
    transition: transform 0.25s ease;
}

.sidebar-header {
    padding: 16px 14px 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 15px;
}

.brand-logo-img {
    width: 26px;
    height: 26px;
    object-fit: contain;
    flex-shrink: 0;
}

.chatgpt-icon {
    width: 22px;
    height: 22px;
    color: var(--accent-green);
}

.badge-ver {
    font-size: 10px;
    background: #e6f4ea;
    color: #137333;
    padding: 2px 6px;
    border-radius: 10px;
    font-weight: 600;
}

.icon-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    padding: 6px;
    transition: background 0.15s;
}

.icon-btn:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

/* MENU CHÍNH */
.sidebar-menu {
    padding: 0 10px 10px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 12px;
    border-radius: 8px;
    font-size: 13.5px;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.15s;
    font-weight: 500;
}

.nav-item:hover {
    background-color: var(--bg-hover);
}

.nav-item.active {
    background-color: var(--bg-active);
}

/* VÙNG CUỘN TRONG SIDEBAR */
.sidebar-scrollable {
    flex: 1;
    overflow-y: auto;
    padding: 6px 10px;
}

.sidebar-scrollable::-webkit-scrollbar {
    width: 4px;
}

.sidebar-scrollable::-webkit-scrollbar-thumb {
    background: #d8d8d8;
    border-radius: 4px;
}

.section-header-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 10px 4px;
}

.section-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0;
    margin: 0;
}

.section-action-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 3px 5px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
    transition: all 0.2s ease;
}

.section-action-btn:hover {
    opacity: 1;
    color: var(--text-primary);
    background-color: var(--bg-hover);
}

.projects-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.empty-list-hint {
    padding: 6px 10px;
    font-size: 11px;
    color: var(--text-muted);
    font-style: italic;
}

.project-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    position: relative;
    user-select: none;
    transition: background-color 0.15s ease;
}

.project-item:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.project-item.highlight {
    color: #1a73e8;
    font-weight: 500;
}

.project-item-left {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.project-item-left span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.project-item-actions {
    display: none;
    align-items: center;
    gap: 2px;
}

.project-item:hover .project-item-actions {
    display: flex;
}

.btn-item-delete {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 3px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.btn-item-delete:hover {
    color: #ea4335 !important;
    background-color: rgba(234, 67, 53, 0.12) !important;
}

.recent-list {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.recent-chat-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 10px;
    border-radius: 8px;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    user-select: none;
    transition: background-color 0.15s ease;
}

.recent-chat-title:hover {
    background-color: var(--bg-hover);
}

.recent-chat-left {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.recent-chat-actions {
    display: none;
    align-items: center;
}

.recent-chat-title:hover .recent-chat-actions {
    display: flex;
}

/* FOOTER PROFILE */
.sidebar-footer {
    padding: 14px 12px;
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #202124;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
}

.user-info {
    line-height: 1.2;
}

.user-name {
    font-size: 13px;
    font-weight: 600;
}

.user-plan {
    font-size: 11px;
    color: var(--text-muted);
}

/* ==========================================================================
   VÙNG CHAT CHÍNH (MAIN CONTENT)
   ========================================================================== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative;
    background: var(--bg-main);
}

/* TOPBAR */
.topbar {
    height: 52px;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(0,0,0,0.05);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.mobile-menu-btn {
    display: none;
}

.model-badge {
    display: flex;
    align-items: center;
    gap: 10px;
}

.model-select-dropdown {
    font-family: inherit;
    font-size: 14.5px;
    font-weight: 600;
    color: var(--text-primary);
    background: #ffffff;
    border: 1px solid #d1d5db;
    padding: 5px 12px;
    border-radius: 8px;
    cursor: pointer;
    outline: none;
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.model-select-dropdown:hover {
    border-color: #9ca3af;
    background: #f9fafb;
}

.model-select-dropdown:focus {
    border-color: #10a37f;
    box-shadow: 0 0 0 2px rgba(16, 163, 127, 0.2);
}

.model-name {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.guard-pill {
    background: #e6f4ea;
    color: #137333;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 12px;
    border: 1px solid #ceead6;
    white-space: nowrap;
    flex-shrink: 0;
}

.router-pill {
    background: #eef2ff;
    color: #4338ca;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 12px;
    border: 1px solid #c7d2fe;
    white-space: nowrap;
    flex-shrink: 0;
}

.topbar-action-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: 1px solid var(--border-color);
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background 0.15s;
}

.topbar-action-btn:hover {
    background-color: var(--bg-hover);
}

/* Co giãn linh hoạt các nút trên thanh Topbar khi màn hình hẹp */
@media (max-width: 1400px) {
    .btn-cleanup-tabs span,
    .btn-cleanup-history span,
    .topbar-right > button:last-child span {
        display: none;
    }
    .topbar-action-btn {
        padding: 6px 8px;
    }
}

@media (max-width: 1200px) {
    .btn-api-keys span {
        display: none;
    }
    .router-pill, .guard-pill {
        font-size: 10.5px;
        padding: 2px 6px;
    }
}

@media (max-width: 1050px) {
    .router-pill, .guard-pill {
        display: none;
    }
}

/* VIEWPORT CHAT */
.chat-viewport {
    flex: 1;
    overflow-y: auto;
    display: flex;
    justify-content: center;
    padding: 24px 16px 0;
    scroll-behavior: smooth;
}

.messages-container {
    width: 100%;
    max-width: 820px;
    display: flex;
    flex-direction: column;
    gap: 32px;
    padding-bottom: 220px;
}

/* WELCOME BOX */
.welcome-box {
    margin: auto 0;
    text-align: center;
    padding: 30px 20px 40px;
}

.welcome-hero-wrap {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;
}

.welcome-hero-img {
    width: min(360px, 80vw);
    height: auto;
    max-height: 220px;
    object-fit: contain;
    filter: drop-shadow(0 12px 28px rgba(20, 184, 166, 0.18));
    animation: heroPulse 5s ease-in-out infinite alternate;
}

@keyframes heroPulse {
    from { transform: scale(1); filter: drop-shadow(0 10px 24px rgba(20, 184, 166, 0.15)); }
    to { transform: scale(1.02); filter: drop-shadow(0 16px 36px rgba(6, 182, 212, 0.25)); }
}

.welcome-box h2 {
    font-size: 24px;
    font-weight: 700;
    color: var(--hoapi-midnight);
    letter-spacing: -0.3px;
    margin-bottom: 8px;
}

.welcome-sub {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.quick-prompts {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
    text-align: left;
}

.quick-card {
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 14px 16px;
    cursor: pointer;
    transition: all 0.2s;
    background: #ffffff;
}

.quick-card:hover {
    border-color: #b0b0b0;
    box-shadow: var(--card-shadow);
}

.quick-card strong {
    display: block;
    font-size: 13.5px;
    margin-bottom: 4px;
}

.quick-card span {
    font-size: 12px;
    color: var(--text-secondary);
}

/* ==========================================================================
   BONG BÓNG TIN NHẮN (MESSAGES)
   ========================================================================== */
.message-row {
    display: flex;
    flex-direction: column;
    width: 100%;
}

/* TIN NHẮN NGƯỜI DÙNG */
.message-row.user {
    align-items: flex-end;
}

.user-bubble {
    background-color: #f4f4f4;
    color: var(--text-primary);
    padding: 12px 18px;
    border-radius: 20px;
    max-width: 80%;
    font-size: 15px;
    line-height: 1.5;
    word-break: break-word;
}

.user-attachments-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.attachment-badge {
    background: #e8f0fe;
    color: #1a73e8;
    border: 1px solid #d2e3fc;
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* TIN NHẮN CỦA AI TRỢ LÝ */
.message-row.assistant {
    align-items: flex-start;
}

.assistant-body {
    width: 100%;
    font-size: 15px;
    color: var(--text-primary);
    line-height: 1.7;
}

.assistant-header-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    padding: 3px 10px 3px 4px;
    border-radius: 8px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
}

.assistant-avatar {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    object-fit: cover;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.15);
}

.assistant-brand-tag {
    font-size: 12px;
    font-weight: 700;
    color: var(--hoapi-midnight);
    letter-spacing: -0.2px;
}

/* HUY HIỆU BOT KIỂM TRA */
.inspector-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 14px;
}

.inspector-badge.passed {
    background-color: #e6f4ea;
    color: #137333;
    border: 1px solid #ceead6;
}

.inspector-badge.warning {
    background-color: #fef7e0;
    color: #b06000;
    border: 1px solid #feefc3;
}

/* CARD HÌNH ẢNH / PREVIEW (CHUẨN CHATGPT - KHÔNG BỊ CẮT XÉN) */
.media-preview-card {
    position: relative;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    margin: 14px 0 16px;
    max-width: 520px;
    width: fit-content;
    background: transparent;
    border: 1px solid rgba(0,0,0,0.06);
}

.media-preview-card img {
    max-width: 520px;
    width: 100%;
    height: auto;
    max-height: 80vh;
    object-fit: contain; /* Giữ nguyên 100% tỉ lệ gốc của ảnh, không bị cắt */
    display: block;
    border-radius: 16px;
    cursor: zoom-in;
}

.media-card-badge {
    position: absolute;
    bottom: 12px;
    left: 14px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(8px);
    color: #fff;
    font-size: 11px;
    padding: 4px 10px;
    border-radius: 6px;
}

.media-card-download-btn {
    position: absolute;
    bottom: 12px;
    right: 14px;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(8px);
    color: #ffffff;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    transition: all 0.2s ease;
}

.media-card-download-btn:hover {
    background: rgba(0, 0, 0, 0.9);
    transform: scale(1.08);
}

/* NÚT TẢI FILE KẾT QUẢ (GIỐNG ẢNH MẪU "Tải báo cáo PDF 5 trang >") */
.file-download-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    font-size: 13.5px;
    font-weight: 500;
    color: var(--text-primary);
    text-decoration: none;
    cursor: pointer;
    transition: all 0.15s ease;
    margin: 10px 0 16px;
}

.file-download-pill:hover {
    background-color: #f8f9fa;
    border-color: #b0b0b0;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}

.file-download-pill svg {
    color: var(--text-secondary);
}

/* VIDEO CARD & MEDIA PREVIEW */
.media-preview-card.video-card {
    display: flex;
    flex-direction: column;
    max-width: 560px;
    width: 100%;
    background: #0f1117;
    border-radius: 16px;
    border: 1px solid rgba(0, 0, 0, 0.12);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
    overflow: hidden;
    margin: 14px 0 16px;
}

.media-preview-video {
    width: 100%;
    max-height: 420px;
    background: #000000;
    display: block;
    outline: none;
}

.video-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 16px;
    background: #f8fafc;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
}

.video-card-title {
    font-size: 13.5px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 280px;
}

.video-card-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.file-download-pill.video-pill {
    margin: 0;
    padding: 6px 14px;
    background: #2563eb;
    color: #ffffff;
    border: none;
    font-size: 13px;
    font-weight: 600;
}

.file-download-pill.video-pill:hover {
    background: #1d4ed8;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.35);
    transform: translateY(-1px);
}

.file-download-pill.video-pill svg {
    color: #ffffff;
}

/* BẢNG BIỂU MARKDOWN (CLEAN TABLE) */
.assistant-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
    font-size: 14px;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
}

.assistant-body th {
    background-color: #f6f8fa;
    font-weight: 600;
    text-align: left;
    padding: 10px 14px;
    border: 1px solid #e0e0e0;
}

.assistant-body td {
    padding: 10px 14px;
    border: 1px solid #e0e0e0;
    vertical-align: top;
}

.assistant-body tr:nth-child(even) td {
    background-color: #fafbfc;
}

.assistant-body ol, .assistant-body ul {
    margin: 12px 0 12px 24px;
}

.assistant-body li {
    margin-bottom: 6px;
}

/* THANH NÚT THAO TÁC DƯỚI CÂU TRẢ LỜI */
.action-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 14px;
    color: var(--text-muted);
}

.action-icon-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.action-icon-btn:hover {
    color: var(--text-primary);
    background: var(--bg-hover);
}

/* ==========================================================================
   KHUNG NHẬP LIỆU PHÍA DƯỚI (COMPOSER)
   ========================================================================== */
.composer-container {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    background: linear-gradient(180deg, rgba(255,255,255,0) 0%, rgba(255,255,255,0.92) 25%, #ffffff 80%);
    padding: 12px 16px 14px;
    pointer-events: none;
    z-index: 10;
}

.composer-box, .attached-chips-area, .composer-footer {
    pointer-events: auto;
}

.attached-chips-area {
    width: 100%;
    max-width: 800px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 6px;
}

.attached-chip {
    background: #f0f4f9;
    border: 1px solid #dce2e9;
    border-radius: 8px;
    padding: 4px 10px;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.attached-chip .remove-chip-btn {
    cursor: pointer;
    font-weight: bold;
    color: #888;
}

.attached-chip .remove-chip-btn:hover {
    color: #e53935;
}

.composer-box {
    width: 100%;
    max-width: 800px;
    background: var(--bg-composer);
    border: 1px solid #e0e0e0;
    border-radius: 26px;
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all 0.2s ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04);
}

.composer-box:focus-within {
    border-color: #b0b0b0;
    background: #ffffff;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.hidden-file-input {
    display: none;
}

.attach-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: background 0.15s;
    flex-shrink: 0;
}

.attach-btn:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.prompt-textarea {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    font-family: var(--font-stack);
    font-size: 15px;
    color: var(--text-primary);
    resize: none;
    max-height: 160px;
    min-height: 24px;
    line-height: 24px;
}

.composer-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.format-select {
    background: transparent;
    border: 1px solid #dcdcdc;
    border-radius: 14px;
    padding: 4px 8px;
    font-size: 12px;
    color: var(--text-secondary);
    outline: none;
    cursor: pointer;
}

.send-btn {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: none;
    background: #000000;
    color: #ffffff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.send-btn:disabled {
    background: #d7d7d7;
    cursor: not-allowed;
}

.send-btn:not(:disabled):hover {
    transform: scale(1.05);
}

.composer-disclaimer {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 8px;
    text-align: center;
}

/* HIỆU ỨNG LOADING (SPINNER) & NÚT HỦY */
.loading-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13.5px;
    color: var(--text-secondary);
}

.cancel-request-btn {
    background: #fce8e6;
    color: #c5221f;
    border: 1px solid #fad2cf;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    margin-left: 10px;
    transition: all 0.15s;
}

.cancel-request-btn:hover {
    background: #fad2cf;
    transform: scale(1.05);
}

.send-btn.stop-mode {
    background: #111111 !important;
    color: #ffffff !important;
    cursor: pointer !important;
}

.send-btn.stop-mode:hover {
    background: #e53935 !important;
}

.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #ccc;
    border-top-color: var(--accent-green);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* RESPONSIVE CHO MÀN HÌNH NHỎ */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 99;
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .mobile-menu-btn {
        display: flex;
    }
}

/* ==========================================================================
   BỘ ĐỔI NHANH TÀI KHOẢN (ACCOUNT SWITCHER) & AUTO-ROTATION
   ========================================================================== */
.account-switcher-container {
    position: relative;
    display: inline-flex;
    align-items: center;
}

.account-pill-btn {
    display: flex;
    align-items: center;
    gap: 7px;
    background: #ffffff;
    border: 1px solid #d1d5db;
    padding: 4px 10px;
    border-radius: 20px;
    font-family: inherit;
    font-size: 13px;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.account-pill-btn:hover {
    background: #f9fafb;
    border-color: #9ca3af;
}

.account-pill-btn.open {
    border-color: #1a73e8;
    box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.15);
}

.account-avatar-sm {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: linear-gradient(135deg, #4285f4, #34a853);
    color: #ffffff;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    text-transform: uppercase;
}

.account-name-sm {
    font-weight: 600;
    max-width: 110px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pro-tag {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #ffffff;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 8px;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

.pro-tag.free {
    background: #e5e7eb;
    color: #4b5563;
}

.chevron-icon {
    color: #6b7280;
    transition: transform 0.2s;
}

.account-pill-btn.open .chevron-icon {
    transform: rotate(180deg);
}

/* MENU DROPDOWN */
.account-menu-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    width: 320px;
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: fadeInDown 0.15s ease-out;
}

.account-menu-dropdown.show {
    display: flex;
}

@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-6px); }
    to { opacity: 1; transform: translateY(0); }
}

.account-menu-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px 10px;
    border-bottom: 1px solid #f3f4f6;
    background: #f9fafb;
}

.account-menu-header .menu-title {
    font-size: 12px;
    font-weight: 700;
    color: #374151;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.menu-refresh-btn {
    background: transparent;
    border: none;
    color: #6b7280;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.menu-refresh-btn:hover {
    background: #e5e7eb;
    color: #111827;
}

.accounts-list {
    max-height: 240px;
    overflow-y: auto;
    padding: 6px 8px;
}

.account-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    position: relative;
}

.account-item:hover {
    background: #f3f4f6;
}

.account-item.active {
    background: #eff6ff;
}

.account-item-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #10b981);
    color: #ffffff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.account-item-info {
    flex: 1;
    min-width: 0;
}

.account-item-name {
    font-size: 13px;
    font-weight: 600;
    color: #111827;
    display: flex;
    align-items: center;
    gap: 6px;
}

.account-item-email {
    font-size: 11.5px;
    color: #6b7280;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.account-item-status {
    flex-shrink: 0;
    font-size: 11px;
    font-weight: 600;
}

.account-item-status.active-badge {
    color: #2563eb;
    background: #dbeafe;
    padding: 2px 7px;
    border-radius: 10px;
}

.account-item-status.limited-badge {
    color: #dc2626;
    background: #fee2e2;
    padding: 2px 7px;
    border-radius: 10px;
}

.auto-rotate-row {
    padding: 10px 14px;
    background: #fafafa;
    border-top: 1px solid #f3f4f6;
    border-bottom: 1px solid #f3f4f6;
}

.switch-label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    user-select: none;
    font-size: 12px;
    color: #374151;
    font-weight: 500;
}

.switch-label input {
    display: none;
}

.switch-slider {
    width: 32px;
    height: 18px;
    background-color: #cbd5e1;
    border-radius: 20px;
    position: relative;
    transition: background 0.2s;
    flex-shrink: 0;
}

.switch-slider::before {
    content: "";
    position: absolute;
    width: 14px;
    height: 14px;
    left: 2px;
    top: 2px;
    background-color: white;
    border-radius: 50%;
    transition: transform 0.2s;
}

.switch-label input:checked + .switch-slider {
    background-color: #10a37f;
}

.switch-label input:checked + .switch-slider::before {
    transform: translateX(14px);
}

.account-menu-footer {
    padding: 8px 10px;
    background: #ffffff;
}

.add-account-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 7px 12px;
    background: #f8fafc;
    border: 1px dashed #cbd5e1;
    border-radius: 8px;
    color: #475569;
    font-size: 12.5px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.add-account-btn:hover {
    background: #f1f5f9;
    border-color: #94a3b8;
    color: #0f172a;
}

/* THẺ THÔNG BÁO TỰ ĐỘNG ĐỔI TÀI KHOẢN TRONG ĐOẠN CHAT */
.rotation-notice-card {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 8px;
    padding: 10px 14px;
    margin-bottom: 12px;
    font-size: 13px;
    color: #166534;
    line-height: 1.4;
    animation: fadeIn 0.3s ease-out;
}

.rotation-notice-card .rotation-icon {
    font-size: 16px;
    flex-shrink: 0;
}

.rotation-notice-card code {
    background: rgba(22, 101, 52, 0.1);
    padding: 2px 5px;
    border-radius: 4px;
    font-weight: 600;
}

/* HUY HIỆU SMART MODEL ROUTER */
.smart-router-badge {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    border-radius: 8px;
    padding: 6px 12px;
    margin-bottom: 10px;
    font-size: 12px;
    animation: fadeIn 0.25s ease-out;
}

.smart-router-badge.level-4 {
    background: #fff1f2;
    border: 1px solid #fecdd3;
    color: #9f1239;
}

.smart-router-badge.level-3 {
    background: #f5f3ff;
    border: 1px solid #ddd6fe;
    color: #5b21b6;
}

.smart-router-badge.level-2 {
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1e40af;
}

.smart-router-badge.level-1 {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    color: #166534;
}

.smart-router-badge .router-tag {
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.85);
    box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.smart-router-badge .router-model strong {
    font-weight: 700;
}
.smart-router-badge .router-reason {
    font-size: 11.5px;
    opacity: 0.9;
}

/* NÚT DỌN DẸP TAB RÁC */
.btn-cleanup-tabs {
    background: #fef2f2 !important;
    color: #b91c1c !important;
    border: 1px solid #fecaca !important;
    font-weight: 600;
    transition: all 0.2s ease;
}

.btn-cleanup-tabs:hover {
    background: #fee2e2 !important;
    border-color: #fca5a5 !important;
    color: #991b1b !important;
    transform: translateY(-1px);
}

.cleanup-menu-btn {
    background: #fff1f2 !important;
    color: #e11d48 !important;
    border: 1px solid #fecdd3 !important;
    margin-top: 6px;
}

.cleanup-menu-btn:hover {
    background: #ffe4e6 !important;
    border-color: #fda4af !important;
}

/* NÚT DỌN DẸP LỊCH SỬ RECENTS */
.btn-cleanup-history {
    background: #f8fafc !important;
    color: #475569 !important;
    border: 1px solid #cbd5e1 !important;
    font-weight: 600;
    transition: all 0.2s ease;
}

.btn-cleanup-history:hover {
    background: #f1f5f9 !important;
    border-color: #94a3b8 !important;
    color: #1e293b !important;
    transform: translateY(-1px);
}

.cleanup-history-menu-btn {
    background: #f8fafc !important;
    color: #475569 !important;
    border: 1px solid #cbd5e1 !important;
    margin-top: 6px;
}

.cleanup-history-menu-btn:hover {
    background: #f1f5f9 !important;
    border-color: #94a3b8 !important;
}

/* ==========================================================================
   MODAL CÀI ĐẶT & QUẢN LÝ API KEYS THEO CHUẨN NỀN TẢNG LỚN (OPENAI/ANTHROPIC)
   ========================================================================== */

.btn-api-keys {
    background: #f0fdf4 !important;
    color: #15803d !important;
    border: 1px solid #bbf7d0 !important;
    font-weight: 600;
    transition: all 0.2s ease;
}

.btn-api-keys:hover {
    background: #dcfce7 !important;
    border-color: #86efac !important;
    color: #166534 !important;
    transform: translateY(-1px);
}

.footer-gear-btn {
    background: transparent;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    padding: 6px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
    margin-left: auto;
}

.footer-gear-btn:hover {
    background: #e5e7eb;
    color: #111827;
}

/* MODAL OVERLAY */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: modalFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.sub-modal-overlay {
    z-index: 2100;
    background: rgba(15, 23, 42, 0.7);
}

@keyframes modalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes modalZoomIn {
    from { opacity: 0; transform: scale(0.96) translateY(8px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* MODAL CARD */
.modal-card {
    background: #ffffff;
    width: 100%;
    max-width: 880px;
    max-height: 85vh;
    border-radius: 16px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25), 0 0 0 1px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: modalZoomIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.sub-modal-card {
    background: #ffffff;
    width: 100%;
    max-width: 490px;
    border-radius: 14px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.35);
    overflow: hidden;
    animation: modalZoomIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid #e5e7eb;
    background: #fbfbfb;
}

.modal-title-group {
    display: flex;
    align-items: center;
    gap: 14px;
}

.modal-icon-badge {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    background: #ecfdf5;
    border: 1px solid #d1fae5;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.modal-title {
    font-size: 18px;
    font-weight: 700;
    color: #111827;
    margin: 0 0 4px;
}

.modal-subtitle {
    font-size: 13px;
    color: #6b7280;
    margin: 0;
    line-height: 1.4;
}

.modal-close-btn {
    background: transparent;
    border: none;
    color: #9ca3af;
    cursor: pointer;
    padding: 6px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.modal-close-btn:hover {
    background: #f3f4f6;
    color: #111827;
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 18px;
}

/* TOOLBAR */
.api-keys-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.toolbar-stat {
    font-size: 13px;
    font-weight: 500;
    color: #4b5563;
}

.btn-create-key {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 18px;
    background: #10a37f;
    color: #ffffff;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    transition: all 0.15s ease;
}

.btn-create-key:hover {
    background: #0d8a6a;
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgba(16, 163, 127, 0.2);
}

/* TABLE */
.api-keys-table-container {
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    overflow-x: auto;
    overflow-y: auto;
    max-height: 520px;
    background: #ffffff;
}

.api-keys-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    text-align: left;
}

.api-keys-table th {
    padding: 10px 14px;
    background: #f9fafb;
    position: sticky;
    top: 0;
    z-index: 2;
    font-weight: 600;
    color: #6b7280;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid #e5e7eb;
}

.api-keys-table td {
    padding: 12px 14px;
    border-bottom: 1px solid #f3f4f6;
    color: #1f2937;
    vertical-align: middle;
}

.api-keys-table tr:last-child td {
    border-bottom: none;
}

.api-keys-table tr:hover {
    background: #fafafa;
}

.key-name-cell {
    font-weight: 600;
    color: #111827;
    display: flex;
    align-items: center;
    gap: 6px;
}

.badge-default-key {
    font-size: 10px;
    padding: 2px 6px;
    background: #eff6ff;
    color: #2563eb;
    border: 1px solid #bfdbfe;
    border-radius: 4px;
    font-weight: 600;
}

.key-code-wrapper {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    padding: 4px 8px;
    border-radius: 6px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 12px;
    color: #334155;
}

.btn-icon-mini {
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    color: #64748b;
    font-size: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}

.btn-icon-mini:hover {
    background: #e2e8f0;
    color: #0f172a;
}

.badge-active-status {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    background: #ecfdf5;
    color: #047857;
}

.badge-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #10a37f;
}

.btn-delete-key {
    background: transparent;
    border: 1px solid #fee2e2;
    color: #dc2626;
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    transition: all 0.15s ease;
}

.btn-delete-key:hover {
    background: #fef2f2;
    border-color: #fca5a5;
    color: #b91c1c;
}

/* NOTE BOX */
.api-keys-note-box {
    display: flex;
    gap: 12px;
    padding: 14px 16px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 10px;
    font-size: 13px;
    color: #1e40af;
    line-height: 1.5;
}

.api-keys-note-box code {
    background: #dbeafe;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    font-family: monospace;
}

/* SUB MODAL */
.sub-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #e5e7eb;
    background: #fbfbfb;
}

.sub-modal-header h4 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    color: #111827;
}

.sub-modal-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.form-label {
    font-size: 13px;
    font-weight: 600;
    color: #374151;
}

.form-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 14px;
    color: #111827;
    outline: none;
    transition: border-color 0.15s;
    box-sizing: border-box;
}

.form-input:focus {
    border-color: #10a37f;
    box-shadow: 0 0 0 3px rgba(16, 163, 127, 0.15);
}

.form-select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 13.5px;
    color: #111827;
    background-color: #ffffff;
    outline: none;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
    box-sizing: border-box;
}

.form-select:focus {
    border-color: #10a37f;
    box-shadow: 0 0 0 3px rgba(16, 163, 127, 0.15);
}

.badge-scope {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 11.5px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-scope-classifier {
    background: #ecfeff;
    color: #0891b2;
    border: 1px solid #a5f3fc;
}

.badge-scope-image {
    background: #fffbeb;
    color: #d97706;
    border: 1px solid #fde68a;
}

.badge-scope-video {
    background: #fdf2f8;
    color: #db2777;
    border: 1px solid #fbcfe8;
}

.badge-scope-code {
    background: #f0fdf4;
    color: #16a34a;
    border: 1px solid #bbf7d0;
}

.badge-scope-chat {
    background: #f0f9ff;
    color: #0284c7;
    border: 1px solid #bae6fd;
}

.badge-scope-all {
    background: #f5f3ff;
    color: #7c3aed;
    border: 1px solid #ddd6fe;
}

.form-hint {
    font-size: 12px;
    color: #6b7280;
    margin: 0;
    line-height: 1.4;
}

.sub-modal-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 10px;
}

.btn-cancel {
    padding: 8px 16px;
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    color: #4b5563;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-cancel:hover {
    background: #e5e7eb;
    color: #111827;
}

.btn-primary {
    padding: 8px 18px;
    background: #10a37f;
    border: none;
    border-radius: 8px;
    color: #ffffff;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}

.btn-primary:hover {
    background: #0d8a6a;
}

.key-created-alert {
    display: flex;
    align-items: center;
    gap: 10px;
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    padding: 12px 14px;
    border-radius: 8px;
    color: #065f46;
    font-weight: 600;
    font-size: 13px;
}

.new-key-display-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 10px 14px;
    gap: 10px;
}

.new-key-display-box code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 13px;
    font-weight: 600;
    color: #0f172a;
    word-break: break-all;
}

.btn-copy-new-key {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    color: #1e293b;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
    transition: all 0.15s;
}

.btn-copy-new-key:hover {
    background: #f1f5f9;
    border-color: #94a3b8;
}


/* ========================================================
   AGENT IDENTIFIER & THREAD ROUTING STYLES
   ======================================================== */
.agent-cell-wrapper {
    display: flex;
    align-items: center;
    gap: 10px;
}
.agent-avatar-icon {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    background: #f1f5f9;
    flex-shrink: 0;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.agent-info-col {
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.agent-name-text {
    font-weight: 600;
    color: #0f172a;
    font-size: 13px;
    line-height: 1.3;
}
.agent-code-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-family: 'JetBrains Mono', Consolas, monospace;
    font-size: 11px;
    color: #475569;
    background: #f1f5f9;
    padding: 1px 6px;
    border-radius: 4px;
    width: fit-content;
}

/* Department Badges */
.badge-dept {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
}
.badge-dept-engineering {
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
}
.badge-dept-design {
    background: #fdf2f8;
    color: #be185d;
    border: 1px solid #fbcfe8;
}
.badge-dept-testing {
    background: #f0fdf4;
    color: #15803d;
    border: 1px solid #bbf7d0;
}
.badge-dept-security {
    background: #fffbeb;
    color: #b45309;
    border: 1px solid #fde68a;
}
.badge-dept-product {
    background: #faf5ff;
    color: #7e22ce;
    border: 1px solid #e9d5ff;
}
.badge-dept-acceptance {
    background: #ecfdf5;
    color: #047857;
    border: 1px solid #a7f3d0;
}
.badge-dept-general {
    background: #f8fafc;
    color: #475569;
    border: 1px solid #e2e8f0;
}

/* Thread Badges & Links */
.thread-cell-wrapper {
    display: flex;
    align-items: center;
    gap: 6px;
}
.thread-link-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-family: 'JetBrains Mono', Consolas, monospace;
    font-size: 11px;
    color: #0284c7;
    background: #f0f9ff;
    border: 1px solid #bae6fd;
    padding: 2px 7px;
    border-radius: 5px;
    text-decoration: none;
    font-weight: 500;
    transition: all 0.15s;
}
.thread-link-badge:hover {
    background: #e0f2fe;
    border-color: #7dd3fc;
    color: #0369a1;
}
.thread-pending-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: #94a3b8;
    background: #f8fafc;
    border: 1px dashed #cbd5e1;
    padding: 2px 7px;
    border-radius: 5px;
}
.btn-reset-thread {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 13px;
    padding: 2px 4px;
    border-radius: 4px;
    opacity: 0.7;
    transition: opacity 0.15s;
}
.btn-reset-thread:hover {
    opacity: 1;
    background: #f1f5f9;
}

/* Tối ưu kích thước Modal Quản lý API Key cho Agent */
#apiKeysModal .modal-card {
    max-width: 1200px !important;
    width: 95% !important;
}
#apiKeysModal .modal-body {
    padding: 20px 24px 24px !important;
}

/* ==========================================================================
   BẢNG LỊCH SỬ HOẠT ĐỘNG THỜI GIAN THỰC (DEV AKICO ⇆ AI MODELS)
   ========================================================================== */

#activityModal .activity-modal-card {
    max-width: 1350px !important;
    width: 96% !important;
    height: 88vh !important;
    max-height: 88vh !important;
    display: flex;
    flex-direction: column;
}

.activity-header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.activity-live-badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    color: #047857;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 20px;
}

.activity-live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #10b981;
    display: inline-block;
    box-shadow: 0 0 0 rgba(16, 185, 129, 0.4);
    animation: livePulse 1.8s infinite;
}

@keyframes livePulse {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7); }
    70% { transform: scale(1.1); box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(16, 185, 129, 0); }
}

.activity-modal-body {
    padding: 16px 24px 20px !important;
    display: flex;
    flex-direction: column;
    gap: 12px !important;
    overflow: hidden;
    flex: 1;
}

.activity-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 10px 14px;
}

.activity-toolbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    flex: 1;
}

.activity-filters {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.activity-select {
    padding: 6px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 12px;
    background: #ffffff;
    color: #1e293b;
    outline: none;
    cursor: pointer;
    font-family: inherit;
}

.activity-select:focus {
    border-color: #10a37f;
}

.activity-search-input {
    padding: 6px 12px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 12px;
    width: 220px;
    outline: none;
    background: #ffffff;
    color: #1e293b;
    font-family: inherit;
}

.activity-search-input:focus {
    border-color: #10a37f;
}

.activity-toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-activity-action {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    color: #334155;
    cursor: pointer;
    transition: all 0.15s ease;
    font-family: inherit;
}

.btn-activity-action:hover {
    background: #f1f5f9;
    color: #0f172a;
}

.btn-activity-clear:hover {
    background: #fef2f2;
    border-color: #fca5a5;
    color: #dc2626;
}

/* CONTAINER DANH SÁCH HOẠT ĐỘNG */
.activity-stream-container {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding-right: 4px;
}

/* THẺ HOẠT ĐỘNG ĐÔI (SPLIT CARD) */
.activity-card {
    flex-shrink: 0;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    background: #ffffff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
    overflow: hidden;
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.activity-card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
    border-color: #cbd5e1;
}

.activity-card-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 16px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    font-size: 12px;
    gap: 12px;
    flex-wrap: wrap;
}

.meta-agent-info {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: #0f172a;
}

.meta-agent-id-tag {
    font-family: 'JetBrains Mono', Consolas, monospace;
    font-size: 11px;
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    color: #475569;
    padding: 2px 6px;
    border-radius: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 140px;
    display: inline-block;
    vertical-align: middle;
}

.meta-badges-group {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.meta-time-tag {
    font-size: 11px;
    color: #64748b;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.meta-duration-tag {
    font-size: 11px;
    font-weight: 600;
    color: #0369a1;
    background: #e0f2fe;
    border: 1px solid #bae6fd;
    padding: 2px 7px;
    border-radius: 5px;
}

/* DUAL COLUMN SPLIT (CÂN BẰNG TUYỆT ĐỐI 50/50 - CHỐNG MÉO & CO RÚT CỘT) */
.activity-card-split {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    min-height: 120px;
    width: 100%;
}

@media (max-width: 768px) {
    .activity-card-split {
        grid-template-columns: minmax(0, 1fr);
    }
    .activity-col-inbound {
        border-right: none !important;
        border-bottom: 1px solid #e2e8f0;
    }
}

.activity-col-inbound {
    border-right: 1px solid #e2e8f0;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #fcfdfd;
    min-width: 0; /* Khóa cứng tỷ lệ, không cho phép co rút méo mó */
    overflow: hidden;
}

.activity-col-outbound {
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: #ffffff;
    min-width: 0; /* Khóa cứng tỷ lệ, không cho phép phình to đẩy bung cột trái */
    overflow: hidden;
}

.activity-col-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.header-label-req {
    color: #475569;
    display: flex;
    align-items: center;
    gap: 5px;
}

.header-label-resp {
    color: #0f766e;
    display: flex;
    align-items: center;
    gap: 5px;
}

.col-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.header-label-req,
.header-label-resp {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.btn-card-copy {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: #64748b;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    border-radius: 4px;
    padding: 2px 7px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-card-copy:hover {
    background: #f1f5f9;
    color: #0f172a;
    border-color: #94a3b8;
}

/* NỘI DUNG VĂN BẢN (TEXT BOXES) */
.activity-text-box {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 13px;
    line-height: 1.55;
    color: #1e293b;
    white-space: pre-wrap;
    word-break: break-word;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    padding: 10px 12px;
    position: relative;
    transition: max-height 0.2s ease;
}

.activity-text-box.collapsed {
    max-height: 105px;
    overflow: hidden;
    mask-image: linear-gradient(180deg, #000 60%, transparent);
    -webkit-mask-image: linear-gradient(180deg, #000 60%, transparent);
}

.activity-text-box.expanded {
    max-height: none;
    mask-image: none;
    -webkit-mask-image: none;
}

.activity-text-box a {
    color: #0284c7;
    text-decoration: underline;
    font-weight: 500;
    transition: color 0.15s ease;
    word-break: break-all;
}
.activity-text-box a:hover {
    color: #0369a1;
}
.activity-text-box.markdown-rendered {
    white-space: normal;
    min-width: 0;
    word-break: break-word;
    overflow-wrap: break-word;
}
.activity-text-box.markdown-rendered p {
    margin: 0 0 8px 0;
    word-break: break-word;
    overflow-wrap: break-word;
}
.activity-text-box.markdown-rendered p:last-child {
    margin-bottom: 0;
}
.activity-text-box.markdown-rendered ul, .activity-text-box.markdown-rendered ol {
    margin: 4px 0 8px 18px;
    padding: 0;
}
.activity-text-box.markdown-rendered pre {
    max-width: 100%;
    overflow-x: auto;
    background: #0f172a;
    color: #e2e8f0;
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 12px;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    margin: 8px 0;
    border: 1px solid #334155;
}
.activity-text-box.markdown-rendered pre code {
    background: transparent !important;
    padding: 0 !important;
    color: inherit;
    font-size: 12px;
    white-space: pre;
}
.activity-text-box.markdown-rendered code {
    background: #e2e8f0;
    padding: 2px 5px;
    border-radius: 4px;
    font-size: 12px;
    word-break: break-word;
}

.activity-box-top-bar,
.activity-box-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.activity-box-top-bar {
    margin-top: -2px;
    margin-bottom: -2px;
}

.activity-box-footer {
    margin-top: -4px;
}

.btn-toggle-expand {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    font-weight: 600;
    color: #0284c7;
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 2px 0;
}

.btn-toggle-expand:hover {
    color: #0369a1;
    text-decoration: underline;
}

.activity-token-count {
    font-size: 11px;
    color: #94a3b8;
    font-family: 'JetBrains Mono', Consolas, monospace;
}

/* TRẠNG THÁI RUNNING / FAILED */
.activity-running-box {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px;
    background: #f0fdf4;
    border: 1px dashed #86efac;
    border-radius: 8px;
    color: #166534;
    font-size: 13px;
    font-weight: 500;
}

.activity-queued-box {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: #fffbeb;
    border: 1px dashed #fcd34d;
    border-radius: 8px;
    color: #92400e;
    font-size: 13px;
    line-height: 1.5;
    font-weight: 500;
}

.spinner-pulse-amber {
    width: 16px;
    height: 16px;
    border: 2px solid #f59e0b;
    border-top-color: transparent;
    border-radius: 50%;
    flex-shrink: 0;
    animation: spinAround 0.8s linear infinite;
}

.spinner-pulse {
    width: 16px;
    height: 16px;
    border: 2px solid #10b981;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spinAround 0.8s linear infinite;
}

@keyframes spinAround {
    to { transform: rotate(360deg); }
}

.activity-error-box {
    padding: 12px 14px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    color: #991b1b;
    font-size: 13px;
    line-height: 1.5;
}

/* BADGES MÔ HÌNH VÀ TRẠNG THÁI */
.badge-status {
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 5px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.badge-status-success {
    background: #ecfdf5;
    color: #047857;
    border: 1px solid #a7f3d0;
}

.badge-status-running {
    background: #eff6ff;
    color: #1d4ed8;
    border: 1px solid #bfdbfe;
}

.badge-status-queued {
    background: #fefce8;
    color: #b45309;
    border: 1px solid #fde047;
}

.badge-status-failed {
    background: #fef2f2;
    color: #b91c1c;
    border: 1px solid #fecaca;
}

/* MÔ HÌNH BADGES */
.badge-model {
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 5px;
    letter-spacing: 0.3px;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.badge-model-gemini {
    background: #ecfeff;
    color: #0e7490;
    border: 1px solid #a5f3fc;
}

.badge-model-chatgpt {
    background: #f0fdf4;
    color: #15803d;
    border: 1px solid #bbf7d0;
}

.badge-model-claude {
    background: #faf5ff;
    color: #7e22ce;
    border: 1px solid #e9d5ff;
}

.badge-model-deepseek {
    background: #eff6ff;
    color: #1e40af;
    border: 1px solid #bfdbfe;
}

.badge-model-grok {
    background: #fff7ed;
    color: #c2410c;
    border: 1px solid #fed7aa;
}

.badge-model-other {
    background: #f8fafc;
    color: #475569;
    border: 1px solid #e2e8f0;
}

/* EMPTY STATE */
.activity-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
    color: #64748b;
    gap: 12px;
}

.activity-empty-icon {
    font-size: 40px;
    opacity: 0.7;
}

.activity-empty-title {
    font-size: 16px;
    font-weight: 600;
    color: #1e293b;
}

.activity-empty-subtitle {
    font-size: 13px;
    max-width: 480px;
    line-height: 1.5;
}

.badge-failover {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    background: #fff7ed;
    color: #c2410c;
    border: 1px solid #fed7aa;
    white-space: nowrap;
}


/* Badge & Topbar Button cho Lịch sử hoạt động */
.nav-item-activity {
    position: relative;
    font-weight: 500;
}

.activity-badge-pill {
    margin-left: auto;
    background: #10b981;
    color: #ffffff;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 10px;
    letter-spacing: 0.5px;
    animation: pulseBadge 2s infinite;
}

@keyframes pulseBadge {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.8; transform: scale(1.05); }
}

.btn-activity-log {
    background: linear-gradient(135deg, #0ea5e9, #0284c7) !important;
    color: #ffffff !important;
    border: 1px solid #38bdf8 !important;
    font-weight: 600 !important;
    position: relative;
    box-shadow: 0 2px 6px rgba(14, 165, 233, 0.25);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
}

.btn-activity-log:hover {
    background: linear-gradient(135deg, #0284c7, #0369a1) !important;
    box-shadow: 0 4px 12px rgba(14, 165, 233, 0.35);
    transform: translateY(-1px);
}

.live-dot-pulse {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 6px #4ade80;
    animation: liveBlink 1.5s infinite;
}

@keyframes liveBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}


/* ==========================================================================
   AI CITATION LINKS & REFERENCE BARS (FULL HYPERLINKS)
   ========================================================================== */
.ai-citation-link {
    color: #0284c7 !important;
    text-decoration: underline !important;
    font-weight: 500;
    transition: color 0.15s ease;
    word-break: break-all;
}
.ai-citation-link:hover {
    color: #0369a1 !important;
    text-decoration: underline !important;
}

.activity-links-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin: 8px 0 4px 0;
    padding: 8px 12px;
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 8px;
    font-size: 12px;
}
.links-bar-badge {
    font-weight: 600;
    color: #166534;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.links-bar-items {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}
.activity-link-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: #ffffff;
    border: 1px solid #86efac;
    color: #15803d;
    padding: 3px 9px;
    border-radius: 6px;
    text-decoration: none;
    font-size: 11px;
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    transition: all 0.15s ease;
}
.activity-link-pill:hover {
    background: #15803d;
    color: #ffffff;
    border-color: #15803d;
    transform: translateY(-1px);
    box-shadow: 0 2px 5px rgba(21, 128, 61, 0.25);
}

.message-citations-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-top: 10px;
    padding: 8px 12px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    font-size: 12px;
}
.message-citations-bar .citation-title {
    font-weight: 600;
    color: #334155;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}
.message-citations-bar .citation-pill {
    display: inline-flex;
    align-items: center;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    color: #0284c7;
    padding: 3px 9px;
    border-radius: 6px;
    text-decoration: none;
    font-size: 11px;
    font-weight: 600;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    transition: all 0.15s ease;
}
.message-citations-bar .citation-pill:hover {
    background: #0284c7;
    color: #ffffff;
    border-color: #0284c7;
    transform: translateY(-1px);
    box-shadow: 0 2px 5px rgba(2, 132, 199, 0.25);
}
