* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', system-ui, sans-serif; background: #0f0f1a; color: #e0e0e0; min-height: 100vh; }

/* ─── Sticky header + tabs ──────────────────────────────────────────────── */
.sticky-top { position: sticky; top: 0; z-index: 100; background: #0f0f1a; }

header { display: flex; align-items: center; padding: 16px 24px; border-bottom: 1px solid #222; gap: 16px; }
header h1 { color: #00e5ff; font-size: 20px; flex-shrink: 0; }
#header-user-info { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.header-user-name { color: #e0e0e0; font-size: 13px; font-weight: 600; }
.header-user-role { color: #888; font-size: 11px; background: #1a1a2e; padding: 2px 8px; border-radius: 10px; }
.btn-logout { background: #333; border: 1px solid #555; color: #e0e0e0; padding: 5px 14px; border-radius: 6px; cursor: pointer; font-size: 12px; transition: background 0.2s; }
.btn-logout:hover { background: #f44336; border-color: #f44336; color: #fff; }

.status-badge { padding: 6px 14px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.status-running { background: #1b5e20; color: #a5d6a7; }
.status-stopped { background: #b71c1c; color: #ef9a9a; }
.status-waiting { background: #f57f17; color: #fff; }

/* Telegram health badge (v0.20.1) */
#telegram-status-badge { cursor: help; }
#telegram-status-badge.tg-down { background: #b71c1c; color: #ef9a9a; }
#telegram-status-badge.tg-degraded { background: #f57f17; color: #000; }

.tabs { display: flex; gap: 4px; padding: 8px 24px; border-bottom: 1px solid #222; overflow-x: auto; }
.tab { background: none; border: none; color: #888; padding: 8px 16px; cursor: pointer; font-size: 13px; font-weight: 600; border-radius: 6px; white-space: nowrap; position: relative; }
.tab:hover { color: #ccc; background: #1a1a2e; }
.tab.active { color: #00e5ff; background: #1a1a2e; }

/* Tab badge (số cần xử lý) */
.tab-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; font-size: 11px; font-weight: 700; margin-left: 6px; line-height: 1; }
.tab-badge-danger { background: #f44336; color: #fff; }
.tab-badge-warning { background: #ff9800; color: #fff; }
.tab-badge-info { background: #2196f3; color: #fff; }

/* Tab summary bar */
.tab-summary { display: flex; gap: 16px; padding: 10px 0; margin-bottom: 12px; color: #888; font-size: 13px; flex-wrap: wrap; }
.tab-summary-item { display: flex; align-items: center; gap: 4px; }
.tab-summary-value { color: #00e5ff; font-weight: 700; font-size: 15px; }

.tab-content { display: none; padding: 20px 24px; }
.tab-content.active { display: block; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 20px; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-5 { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }

.card { background: #1a1a2e; border: 1px solid #333; border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.card h3 { font-size: 14px; color: #888; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 12px; }

.stat-card { text-align: center; }
.stat-label { font-size: 12px; color: #888; margin-bottom: 4px; }
.stat-value { font-size: 28px; font-weight: 700; color: #00e5ff; }
.stat-sub { font-size: 11px; color: #666; margin-top: 2px; }

/* Overview section grouping */
.overview-section { margin-bottom: 24px; }
.overview-section-header { font-size: 13px; font-weight: 700; color: #aaa; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 10px; display: flex; align-items: center; gap: 6px; }
.overview-section-icon { font-size: 15px; }
.overview-period-badge { font-size: 10px; font-weight: 600; background: #2a2a4a; color: #888; padding: 2px 8px; border-radius: 10px; text-transform: none; letter-spacing: 0; }
/* Scraper status bar */
.scraper-status-bar { display: flex; gap: 24px; flex-wrap: wrap; background: #12121f; border: 1px solid #2a2a3e; border-radius: 8px; padding: 10px 16px; margin-top: -8px; margin-bottom: 8px; }
.scraper-status-item { display: flex; align-items: center; gap: 6px; }
.scraper-status-label { font-size: 12px; color: #666; }
.scraper-status-value { font-size: 13px; color: #e0e0e0; font-weight: 600; }
.scraper-status-ago { font-size: 11px; color: #888; background: #1a1a2e; padding: 2px 8px; border-radius: 10px; margin-left: 2px; }

/* Sentiment cards */
.sentiment-card { position: relative; }
.sentiment-positive { border-left: 3px solid #4caf50; }
.sentiment-negative { border-left: 3px solid #f44336; }
.sentiment-neutral { border-left: 3px solid #616161; }

/* ─── Responsive: Tablet (768px) ──────────────────────────────────────── */
@media (max-width: 768px) {
    .grid-3, .grid-4, .grid-5 { grid-template-columns: repeat(2, 1fr); }
    header { padding: 10px 12px; gap: 8px; flex-wrap: wrap; }
    header h1 { font-size: 16px; }
    .tab-content { padding: 12px; }
    .scraper-status-bar { gap: 12px; padding: 8px 12px; }
    .stat-value { font-size: 22px; }
    .card { padding: 12px; }
    .alert-footer { flex-direction: column; align-items: flex-start; }
    .alert-actions { width: 100%; }
    .alert-edit-area { min-width: unset; width: 100%; }

    /* Messages: single column layout */
    .messages-layout { flex-direction: column; height: auto; border: none; border-radius: 0; }
    .group-sidebar { width: 100%; min-width: unset; border-right: none; border-bottom: 1px solid #333; max-height: none; }
    .group-sidebar.mobile-hidden { display: none; }
    .message-panel { width: 100%; }
    .message-panel.mobile-hidden { display: none; }
    .msg-back-btn { display: block !important; }
    .sidebar-list { max-height: 50vh; }
}

/* ─── Responsive: Mobile (480px) ─────────────────────────────────────── */
@media (max-width: 480px) {
    .grid, .grid-3, .grid-4, .grid-5 { grid-template-columns: 1fr; gap: 8px; }
    header { padding: 8px 10px; }
    header h1 { font-size: 14px; }
    #header-user-info { gap: 6px; font-size: 11px; }
    .header-user-name { display: none; } /* Ẩn tên, chỉ hiện role */
    .status-badge { font-size: 10px; padding: 4px 10px; }

    /* Tabs: scroll horizontal, nhỏ hơn */
    .tabs { padding: 6px 8px; gap: 2px; }
    .tab { padding: 6px 10px; font-size: 11px; }
    .tab-badge { min-width: 16px; height: 16px; font-size: 10px; }

    .tab-content { padding: 8px; }
    .card { padding: 10px; margin-bottom: 10px; border-radius: 8px; }
    .card h3 { font-size: 12px; }

    .stat-card { padding: 8px; }
    .stat-value { font-size: 20px; }
    .stat-label { font-size: 10px; }

    /* Scraper status: stack vertical */
    .scraper-status-bar { flex-direction: column; gap: 4px; padding: 6px 10px; }

    /* Overview cards nhỏ hơn */
    .overview-section-header { font-size: 11px; }

    /* Alert cards */
    .alert-item { padding: 10px; }
    .msg-header { flex-wrap: wrap; gap: 4px; }
    .alert-group-badge { font-size: 10px; }
    .alert-actions { flex-wrap: wrap; }
    .btn-sm { padding: 4px 8px; font-size: 0.75em; }

    /* Message cards */
    .msg-item { padding: 8px; }

    /* Members — mobile: card dọc compact (contact list style) */
    .member-header-row { display: none; }
    .member-card {
        display: grid;
        grid-template-columns: 1fr auto;
        grid-template-rows: auto auto auto;
        gap: 2px 8px;
        padding: 10px 12px;
        border-bottom: 1px solid #222;
    }
    /* Row 1: Tên (trái) + thời gian (phải) */
    .member-card-main { grid-column: 1; grid-row: 1; }
    .member-card-last { grid-column: 2; grid-row: 1; text-align: right; font-size: 12px; color: #888; align-self: start; }
    .member-last-group { display: none; } /* Ẩn tên nhóm cuối trên mobile — đã hiện ở group tags */
    /* Row 2: Stats */
    .member-card-stats { grid-column: 1; grid-row: 2; font-size: 12px; color: #888; }
    .member-card-group-count { grid-column: 2; grid-row: 2; text-align: right; font-size: 12px; color: #666; }
    .member-msg-count { font-size: 14px; color: #00e5ff; font-weight: 600; }
    /* Row 3: Group tags (full width) */
    .member-groups { grid-column: 1 / -1; grid-row: 3; display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
    .member-group-tag { font-size: 10px; }
    .member-name { font-size: 13px; font-weight: 600; }

    /* Report: charts nhỏ hơn */
    .comparison-item { padding: 6px; }

    /* Filter bar: wrap vertical */
    [style*="display:flex"][style*="gap:12px"] { flex-direction: column; gap: 6px; }

    /* Settings: full width inputs */
    .settings-form input, .settings-form textarea, .settings-form select { font-size: 14px; }

    /* Inline edit textarea */
    .alert-edit-area { min-height: 200px; min-width: unset; }
}

.btn { display: inline-block; padding: 8px 16px; border-radius: 6px; border: 1px solid #333; cursor: pointer; font-size: 13px; font-weight: 600; margin: 4px; background: #1a1a2e; color: #e0e0e0; transition: all 0.15s; }
.btn-primary { background: #00b0ff; color: #000; border-color: #00b0ff; }
.btn-secondary { background: #2a2a3e; color: #ccc; border-color: #444; }
.btn-danger { background: #4a1010; color: #ef9a9a; border-color: #7f1d1d; }
.btn-danger:hover:not(:disabled) { background: #7f1d1d; color: #fff; border-color: #b71c1c; }
.btn:hover:not(:disabled) { opacity: 0.85; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; filter: grayscale(0.4); }

.input-group { display: flex; gap: 8px; }
.input-group input { flex: 1; padding: 8px 12px; border-radius: 6px; border: 1px solid #333; background: #111; color: #fff; font-size: 13px; }
.input-group input:focus { outline: none; border-color: #00b0ff; }

.select { width: 100%; padding: 8px 12px; border-radius: 6px; border: 1px solid #333; background: #111; color: #fff; font-size: 13px; margin-bottom: 12px; }

/* Bố cục tin nhắn: sidebar + nội dung */
.messages-layout { display: flex; height: calc(100vh - 160px); background: #1a1a2e; border: 1px solid #333; border-radius: 10px; overflow: hidden; }

.group-sidebar { width: 260px; min-width: 260px; border-right: 1px solid #333; display: flex; flex-direction: column; overflow: hidden; }
.sidebar-header { padding: 12px 16px; font-size: 12px; color: #888; text-transform: uppercase; letter-spacing: 1px; font-weight: 600; border-bottom: 1px solid #333; }
.sidebar-list { overflow-y: auto; flex: 1; }

.sidebar-group-item { padding: 10px 16px; cursor: pointer; border-bottom: 1px solid #222; transition: background 0.15s; }
.sidebar-group-item:hover { background: #222240; }
.sidebar-group-item.active { background: #222240; border-left: 3px solid #00e5ff; }
.group-item-row { display: flex; align-items: center; gap: 8px; }
.sidebar-group-item .group-name { font-size: 13px; font-weight: 600; flex: 1; min-width: 0; }
.group-msg-badge { font-size: 11px; font-weight: 700; color: #fff; padding: 2px 8px; border-radius: 10px; flex-shrink: 0; }
.sidebar-group-item .group-meta { font-size: 11px; color: #555; margin-top: 2px; }

.message-panel { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.msg-back-btn { display: none; background: none; border: none; color: #00e5ff; font-size: 13px; cursor: pointer; padding: 8px 12px; }
.panel-header { padding: 12px 16px; font-size: 14px; font-weight: 600; color: #00e5ff; border-bottom: 1px solid #333; flex-shrink: 0; }
.message-panel .msg-list { flex: 1; overflow-y: auto; max-height: none; padding: 8px; }

.msg-list { max-height: 600px; overflow-y: auto; }
/* Scrollbar cho msg-list và sidebar-list kế thừa từ global dark scrollbar ở trên */
.msg-item { padding: 10px 12px; border-bottom: 1px solid #222; border-radius: 6px; margin-bottom: 2px; }
.msg-item:hover { background: #1a1a2e; }
.msg-header { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.msg-sender { font-weight: 600; color: #00e5ff; font-size: 13px; }
.msg-time { font-size: 11px; color: #555; }
.msg-reactions { font-size: 11px; color: #888; margin-left: auto; background: #222; padding: 2px 8px; border-radius: 10px; }
.msg-content { font-size: 13px; color: #ddd; margin-top: 4px; line-height: 1.5; word-wrap: break-word; }

/* Khối trích dẫn / trả lời */
.msg-quote { border-left: 3px solid #00b0ff; background: #151525; padding: 6px 10px; border-radius: 0 6px 6px 0; margin: 6px 0; }
.msg-quote-name { font-size: 11px; color: #00b0ff; font-weight: 600; margin-bottom: 2px; }
.msg-quote-text { font-size: 12px; color: #999; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* @Mentions */
.msg-mention { color: #00e5ff; font-weight: 600; }

/* Nhãn phân loại */
.msg-tags { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px; }
.msg-tag { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 10px; font-weight: 600; }
.tag-positive { background: #1b5e20; color: #a5d6a7; }
.tag-negative { background: #b71c1c; color: #ef9a9a; }
.tag-neutral { background: #333; color: #aaa; }
.tag-attention { background: #ff6f00; color: #fff; }

.group-item { display: flex; justify-content: space-between; align-items: flex-start; padding: 14px 0; border-bottom: 1px solid #222; }
.group-item-detail .group-item-main { flex: 1; min-width: 0; }
.group-item-detail .group-item-actions { flex-shrink: 0; margin-left: 12px; padding-top: 4px; }
.group-name-row { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.group-name { font-weight: 600; font-size: 14px; }
.group-stats { display: flex; gap: 16px; font-size: 13px; color: #aaa; margin-bottom: 4px; }
.group-meta { font-size: 12px; color: #666; }
.group-last-msg { font-size: 12px; color: #888; margin-top: 4px; background: #151525; padding: 4px 8px; border-radius: 4px; border-left: 2px solid #333; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-icon { background: none; border: none; cursor: pointer; font-size: 14px; padding: 2px 4px; border-radius: 4px; opacity: 0.6; transition: opacity 0.15s; }
.btn-icon:hover { opacity: 1; background: #222; }
.btn-icon-danger:hover { background: #3a1515; }

/* Tìm kiếm */
.search-bar { display: flex; gap: 8px; padding: 8px 12px; border-bottom: 1px solid #222; }
.search-bar input { flex: 1; background: #1a1a2e; border: 1px solid #333; border-radius: 6px; padding: 6px 12px; color: #e0e0e0; font-size: 13px; }
.search-bar input:focus { border-color: #00e5ff; outline: none; }
.search-hit .search-group { font-size: 11px; color: #888; margin-left: auto; }
mark { background: #00e5ff33; color: #00e5ff; padding: 0 2px; border-radius: 2px; }

/* Bảng sức khỏe selector */
.health-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 8px; }
.health-table th { text-align: left; padding: 6px 8px; border-bottom: 1px solid #444; color: #888; font-size: 11px; text-transform: uppercase; }
.health-table td { padding: 5px 8px; border-bottom: 1px solid #222; }

/* Badges cho kho kiến thức */
.tag-badge { display: inline-block; padding: 1px 6px; border-radius: 8px; font-size: 10px; background: #1a2a1a; color: #81c784; margin: 1px 2px; white-space: nowrap; }
.type-badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 10px; font-weight: 600; }
.type-file { background: #263238; color: #90a4ae; }
.type-qa { background: #1a237e; color: #7986cb; }
.type-kb { background: #1b3a1b; color: #81c784; }
.type-product { background: #3e2723; color: #ffab91; }

/* Bố cục bảng thành viên */
.member-header-row { display: grid; grid-template-columns: 1fr 80px 80px 180px; gap: 8px; padding: 8px 12px; font-size: 11px; color: #666; text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; border-bottom: 1px solid #333; }
.member-card { display: grid; grid-template-columns: 1fr 80px 80px 180px; gap: 8px; padding: 10px 12px; border-bottom: 1px solid #222; align-items: center; }
.member-card > .member-groups { grid-column: 1 / -1; } /* Desktop: groups full row dưới cùng */
.member-card:hover { background: #1a1a2e; }
.member-card-main { min-width: 0; }
.member-name { font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.member-groups { display: flex; flex-wrap: wrap; gap: 4px; }
.member-group-tag { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 10px; background: #222; color: #aaa; cursor: default; }
.member-card-stats { text-align: center; }
.member-msg-count { font-size: 16px; font-weight: 700; color: #00e5ff; }
.member-card-group-count { text-align: center; font-size: 12px; color: #888; }
.member-card-last { text-align: right; }
.member-last-time { font-size: 12px; color: #aaa; }
.member-last-group { font-size: 11px; color: #555; margin-top: 2px; }
.ctv-badge { display: inline-block; background: #ff9800; color: #000; font-size: 10px; font-weight: 700; padding: 1px 5px; border-radius: 3px; margin-left: 6px; vertical-align: middle; }

/* Lifecycle badges (B5) */
.lc-badge { display: inline-block; font-size: 10px; font-weight: 600; padding: 1px 6px; border-radius: 3px; margin-left: 6px; vertical-align: middle; }
.lc-new { background: #0d47a1; color: #90caf9; }
.lc-active { background: #1b5e20; color: #a5d6a7; }
.lc-declining { background: #e65100; color: #ffcc80; }
.lc-inactive { background: #333; color: #999; }
.lc-churned { background: #b71c1c; color: #ef9a9a; }

/* At-risk cards (B5) */
/* Modal (member profile) */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.7); display: flex; align-items: center; justify-content: center; z-index: 1000; }
.modal-content { background: #1a1a2e; border: 1px solid #333; border-radius: 12px; padding: 20px; max-height: 90vh; overflow-y: auto; width: 90%; }

.at-risk-card { padding: 8px 12px; border-bottom: 1px solid #222; }
.at-risk-card:hover { background: #1a1a2e; }
.at-risk-name { font-weight: 600; font-size: 13px; color: #ffb74d; }
.at-risk-meta { font-size: 11px; color: #888; margin-top: 2px; display: flex; gap: 4px; flex-wrap: wrap; }
.at-risk-tags { margin-top: 4px; display: flex; gap: 4px; flex-wrap: wrap; }

/* Member search input (tab Thành viên) */
.member-search-wrapper { position: relative; max-width: 400px; margin-bottom: 12px; }
.member-search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: #666; pointer-events: none; }
.member-search-input { width: 100%; padding: 10px 12px 10px 36px; border: 1px solid #2a2a3e; border-radius: 10px; background: #12121f; color: #e0e0e0; font-size: 13px; outline: none; transition: border-color 0.2s, box-shadow 0.2s; }
.member-search-input::placeholder { color: #555; }
.member-search-input:focus { border-color: #00e5ff; box-shadow: 0 0 0 2px rgba(0,229,255,0.15); }
#members-list { max-height: 600px; overflow-y: auto; }
#members-list::-webkit-scrollbar { width: 6px; }
#members-list::-webkit-scrollbar-track { background: transparent; }
#members-list::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }
#members-list::-webkit-scrollbar-thumb:hover { background: #444; }

/* CTV search input */
.ctv-search-wrapper { position: relative; max-width: 400px; margin-bottom: 12px; }
.ctv-search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: #666; pointer-events: none; }
.ctv-search-input { width: 100%; padding: 10px 12px 10px 36px; border: 1px solid #2a2a3e; border-radius: 10px; background: #12121f; color: #e0e0e0; font-size: 13px; outline: none; transition: border-color 0.2s, box-shadow 0.2s; }
.ctv-search-input::placeholder { color: #555; }
.ctv-search-input:focus { border-color: #ff9800; box-shadow: 0 0 0 2px rgba(255,152,0,0.15); }

/* CTV member list */
.ctv-member-list { max-height: 320px; overflow-y: auto; margin-bottom: 12px; padding: 2px; }
.ctv-member-list::-webkit-scrollbar { width: 6px; }
.ctv-member-list::-webkit-scrollbar-track { background: transparent; }
.ctv-member-list::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }
.ctv-loading { color: #666; font-size: 13px; }

/* CTV member cards */
.ctv-member-item { display: grid; grid-template-columns: 20px 1fr; gap: 4px 10px; align-items: center; padding: 10px 12px; border: 1px solid #2a2a3e; border-radius: 8px; margin-bottom: 4px; cursor: pointer; font-size: 13px; background: #12121f; transition: background 0.15s, border-color 0.15s; }
.ctv-member-item:hover { background: #1a1a2e; border-color: #444; }
.ctv-member-item.ctv-checked { border-color: #ff9800; background: #1a1510; }
.ctv-member-item input[type="checkbox"] { grid-row: 1 / 3; align-self: center; flex-shrink: 0; accent-color: #ff9800; }
.ctv-member-row1 { display: flex; align-items: center; gap: 8px; }
.ctv-member-name { font-weight: 600; white-space: nowrap; color: #e0e0e0; }
.ctv-member-meta { color: #888; font-size: 11px; white-space: nowrap; background: #1a1a2e; padding: 1px 8px; border-radius: 8px; }
.ctv-member-row2 { grid-column: 2; }

/* CTV footer */
.ctv-footer { display: flex; align-items: center; gap: 12px; }
.ctv-selected-count { font-size: 12px; color: #888; }

.hint { font-size: 12px; color: #666; margin-bottom: 8px; }

/* Trạng thái AI */
.ai-status-panel { background: #151525; border-radius: 6px; padding: 12px; }
.ai-stat-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13px; }
.ai-stat-value { font-weight: 600; color: #00e5ff; }
.ai-pending { color: #ff9800; }
.ai-progress-bar { height: 6px; background: #333; border-radius: 3px; margin: 8px 0 4px; overflow: hidden; }
.ai-progress-fill { height: 100%; background: linear-gradient(90deg, #00e5ff, #00e676); border-radius: 3px; transition: width 0.5s; }

.alert-item { padding: 14px; border-left: 3px solid #ff6f00; margin-bottom: 10px; background: #1a1510; border-radius: 0 6px 6px 0; word-break: break-word; transition: opacity 0.3s; }
.alert-item.alert-done { opacity: 0.5; border-left-color: #4caf50; }
.alert-header-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; font-size: 0.85em; color: #999; }
.alert-header-row .msg-sender { color: #00e5ff; font-weight: 600; font-size: 1em; }
.alert-header-row .msg-time { color: #777; }
.alert-group-badge { font-size: 11px; color: #00e5ff; background: #1a1a2e; padding: 2px 8px; border-radius: 10px; margin-left: auto; }
.alert-content-block { color: #e8e8e8; font-size: 0.95em; line-height: 1.7; padding: 8px 0; border-bottom: 1px solid #222; margin-bottom: 8px; }
.alert-meta-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 6px; }
.btn-reanalyze { font-size: 0.78em; padding: 2px 8px; background: transparent; color: #90caf9; border: 1px solid #333; border-radius: 4px; cursor: pointer; margin-left: auto; opacity: 0.7; transition: opacity 0.2s; }
.btn-reanalyze:hover { opacity: 1; background: #1a237e; }
.reanalyze-status { font-size: 0.82em; display: none; margin-left: 4px; }
.alert-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 10px; flex-wrap: wrap; gap: 6px; }
.alert-assignee { font-size: 0.82em; color: #aaa; }
.alert-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.alert-priority { font-size: 0.75em; font-weight: 600; padding: 2px 8px; border-radius: 10px; margin-right: 6px; }
.alert-priority-urgent { background: #f44336; color: #fff; }
.alert-priority-high { background: #ff9800; color: #fff; }
.alert-priority-normal { background: #555; color: #ccc; }
.alert-priority-low { background: #2196f3; color: #fff; }
/* Action buttons — dark theme */
.btn-sm { padding: 5px 12px; font-size: 0.82em; border-radius: 4px; cursor: pointer; border: 1px solid transparent; transition: all 0.2s; font-weight: 500; }
.btn-sm.btn-approve { background: #1b5e20; color: #81c784; border-color: #2e7d32; }
.btn-sm.btn-approve:hover { background: #2e7d32; color: #fff; }
.btn-sm.btn-edit { background: #1a237e; color: #90caf9; border-color: #283593; }
.btn-sm.btn-edit:hover { background: #283593; color: #fff; }
.btn-sm.btn-reject { background: #4a1010; color: #ef9a9a; border-color: #7f1d1d; }
.btn-sm.btn-reject:hover { background: #7f1d1d; color: #fff; }
.btn-sm.btn-assign { background: #0d47a1; color: #90caf9; border-color: #1565c0; }
.btn-sm.btn-assign:hover { background: #1565c0; color: #fff; }
.btn-sm.btn-dismiss { background: #333; color: #999; border-color: #555; }
.btn-sm.btn-dismiss:hover { background: #444; color: #ccc; }
.btn-sm.btn-primary { background: #00838f; color: #b2ebf2; border-color: #00acc1; }
.btn-sm.btn-primary:hover { background: #00acc1; color: #fff; }
.btn-sm.btn-secondary { background: #333; color: #ccc; border-color: #555; }
.btn-sm.btn-secondary:hover { background: #444; }
.alert-filter-select { background: #1a1a2e; color: #ccc; border: 1px solid #333; border-radius: 6px; padding: 6px 12px; font-size: 0.85em; cursor: pointer; appearance: auto; -webkit-appearance: auto; }
.alert-filter-select:focus { border-color: #00e5ff; outline: none; }
.alert-filter-select option { background: #1a1a2e; color: #ccc; }
.alert-priority-select { background: #1a1a2e; color: #ccc; border: 1px solid #333; border-radius: 4px; padding: 4px 8px; font-size: 0.82em; cursor: pointer; }
.alert-priority-select:focus { border-color: #00e5ff; outline: none; }
.alert-priority-select option { background: #1a1a2e; color: #ccc; }
.alert-assign-select { background: #1a1a2e; color: #ccc; border: 1px solid #333; border-radius: 4px; padding: 4px 8px; font-size: 0.82em; cursor: pointer; max-width: 150px; }
.alert-assign-select:focus { border-color: #00e5ff; outline: none; }
.alert-assign-select option { background: #1a1a2e; color: #ccc; }
.alert-assigned-badge { font-size: 0.85em; margin: 0 4px; }

/* Alert variants */
.alert-variant-A { border-left-color: #4caf50; background: #0d1a0d; }
.alert-variant-B { border-left-color: #ff9800; }
.alert-variant-C { border-left-color: #f44336; }
.alert-variant-D { border-left-color: #666; background: #141414; }
.alert-context { font-size: 0.82em; color: #888; margin-top: 6px; }

/* AI section trong alert card */
.alert-ai { margin-top: 8px; padding: 10px 14px; border-radius: 6px; font-size: 0.88em; }
.alert-ai-sent { background: rgba(76,175,80,0.08); border: 1px solid rgba(76,175,80,0.2); }
.alert-ai-pending { background: rgba(255,152,0,0.08); border: 1px solid rgba(255,152,0,0.2); }
.alert-ai-suggestion { background: rgba(244,67,54,0.06); border: 1px solid rgba(244,67,54,0.15); }
.alert-ai-none { background: rgba(100,100,100,0.08); border: 1px solid rgba(100,100,100,0.2); color: #888; font-style: italic; }
.alert-ai-badge { font-weight: 600; display: block; margin-bottom: 6px; font-size: 0.9em; }
.alert-ai-answer { color: #d4d4d4; line-height: 1.6; margin-top: 4px; white-space: pre-wrap; }
.alert-ai-confidence { color: #888; font-size: 0.85em; margin-top: 4px; display: block; }
.alert-ai-source { color: #666; font-size: 0.8em; margin-top: 4px; }
.alert-context-box, .alert-suggestion-box, .alert-suggested-reply { margin-top: 6px; line-height: 1.5; }
.alert-diff-toggle summary { list-style: none; }
.alert-diff-toggle summary::-webkit-details-marker { display: none; }
.alert-diff-original { margin-top: 6px; padding: 10px; background: rgba(255,152,0,0.08); border: 1px dashed rgba(255,152,0,0.3); border-radius: 4px; color: #999; font-size: 0.9em; line-height: 1.5; white-space: pre-wrap; text-decoration: line-through; opacity: 0.7; }
.alert-context-box { color: #999; }
.alert-suggestion-box { color: #ffa726; }
.alert-suggested-reply { color: #81c784; }

/* Inline edit textarea */
[id^="edit-zone-"], [id^="reply-zone-"], [id^="reject-zone-"] { width: 100%; margin-top: 10px; }
.alert-edit-area { width: 100%; min-width: 50vw; min-height: 300px; margin-top: 8px; padding: 12px; background: #111; color: #e0e0e0; border: 1px solid #444; border-radius: 6px; font-size: 0.9em; line-height: 1.6; resize: vertical; font-family: inherit; box-sizing: border-box; }
.alert-edit-area:focus { border-color: #00e5ff; outline: none; }
.alert-edit-actions { display: flex; gap: 8px; margin-top: 8px; align-items: center; }
.alert-reply-area { width: 100%; min-width: 50vw; min-height: 220px; margin-top: 8px; padding: 12px; background: #111; color: #e0e0e0; border: 1px solid #444; border-radius: 6px; font-size: 0.9em; line-height: 1.6; resize: vertical; font-family: inherit; box-sizing: border-box; }
.alert-reply-area:focus { border-color: #00e5ff; outline: none; }
.alert-draft-saved { color: #4caf50; font-size: 0.8em; margin-left: 8px; opacity: 0; transition: opacity 0.3s; }
.alert-draft-saved.show { opacity: 1; }
.ai-rate-panel { display: flex; gap: 16px; align-items: center; padding: 10px 16px; background: #1a1a2e; border-radius: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.ai-rate-item { font-size: 0.9em; }
.ai-rate-bar { height: 6px; background: #333; border-radius: 3px; flex: 1; min-width: 100px; }
.ai-rate-fill { height: 100%; background: #4caf50; border-radius: 3px; transition: width 0.3s; }

/* Báo cáo */
.select-input { padding: 6px 12px; border-radius: 6px; border: 1px solid #333; background: #111; color: #fff; font-size: 13px; }
.dropdown-item { padding: 8px 14px; cursor: pointer; color: #ccc; font-size: 0.85rem; transition: background 0.15s; }
.dropdown-item:hover { background: #00e5ff22; color: #00e5ff; }
.report-period { padding: 6px 14px; background: #222; color: #888; border: 1px solid #333; font-size: 12px; font-weight: 600; }
.report-period.active { background: #00b0ff; color: #000; border-color: #00b0ff; }
.report-period:first-child { border-radius: 6px 0 0 6px; }
.report-period:last-child { border-radius: 0 6px 6px 0; }
.chart-wrap { position: relative; height: 250px; width: 100%; }

.tag-stats-grid { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 10px; }
.tag-stats-grid .stat-card { padding: 10px; }
.tag-stats-grid .stat-value { font-size: 20px; }

.comparison-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.comparison-item { background: #151525; border-radius: 8px; padding: 12px; text-align: center; }
.comparison-label { font-size: 11px; color: #888; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; }
.comparison-values { font-size: 18px; font-weight: 700; color: #e0e0e0; }
.comparison-trend { font-size: 13px; font-weight: 600; margin-top: 4px; }

/* Health Score breakdown */
.health-breakdown { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-top: 8px; padding-top: 10px; border-top: 1px solid #222; }
.health-component { text-align: center; }
.health-component-label { font-size: 9px; color: #888; text-transform: uppercase; letter-spacing: 0.3px; margin-bottom: 3px; white-space: nowrap; }
.health-component-bar { height: 4px; border-radius: 2px; background: #222; overflow: hidden; }
.health-component-fill { height: 100%; border-radius: 2px; transition: width 0.6s ease; }
.health-component-value { font-size: 11px; font-weight: 600; margin-top: 2px; }

/* Response Quality KPI cards */
.response-kpi { background: rgba(30,30,50,0.6); border: 1px solid #222; border-radius: 6px; padding: 8px 10px; text-align: center; }
.response-kpi-value { font-size: 18px; font-weight: 700; color: #e0e0e0; }
.response-kpi-label { font-size: 9px; color: #888; text-transform: uppercase; letter-spacing: 0.3px; margin-top: 2px; }

/* AI Insight — enhanced diagnosis + topics */
.insight-section { margin-bottom: 14px; }
.insight-section:last-child { margin-bottom: 0; }
.insight-heading { font-size: 13px; font-weight: 700; color: #e0e0e0; margin-bottom: 6px; }
.insight-overview { padding: 10px 12px; background: rgba(76,175,80,0.10); border-radius: 8px; border-left: 4px solid #4caf50; }
.insight-overview p { color: #c8e6c9; margin: 0; font-size: 13px; line-height: 1.5; }
.insight-diagnosis { padding: 10px 12px; background: rgba(33,150,243,0.10); border-radius: 8px; border-left: 4px solid #2196f3; }
.insight-diagnosis p { color: #90caf9; margin: 0; font-size: 13px; line-height: 1.5; }
.insight-cards { display: flex; gap: 10px; flex-wrap: wrap; }
.insight-card { flex: 1; min-width: 200px; background: rgba(30,30,50,0.6); border: 1px solid #333; border-radius: 8px; padding: 10px 12px; }
.insight-card-topic { border-color: #ff9800; border-left: 3px solid #ff9800; }
.insight-card-title { font-size: 13px; font-weight: 600; color: #e0e0e0; margin: 6px 0 4px 0; }
.insight-card-detail { font-size: 12px; color: #aaa; line-height: 1.4; }
.insight-badge { display: inline-block; font-size: 9px; font-weight: 700; padding: 2px 8px; border-radius: 10px; letter-spacing: 0.5px; text-transform: uppercase; }
.insight-items { display: flex; flex-direction: column; gap: 8px; }
.insight-item { display: flex; align-items: flex-start; gap: 10px; padding: 8px 12px; background: rgba(30,30,50,0.5); border-radius: 6px; border: 1px solid #222; }
.insight-item .insight-badge { flex-shrink: 0; margin-top: 2px; }
.insight-detail { font-size: 12px; color: #aaa; }
.insight-list { margin: 4px 0 0 0; padding-left: 20px; }
.insight-list li { font-size: 13px; color: #ccc; margin-bottom: 4px; line-height: 1.4; }

/* Trả lời tự động */
.ar-card { background: #151525; border: 1px solid #333; border-radius: 8px; padding: 14px; margin-bottom: 10px; }
.ar-card-header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.ar-question { font-size: 13px; color: #ddd; margin-bottom: 6px; padding: 8px; background: #1a1a2e; border-radius: 6px; border-left: 3px solid #ff9800; word-break: break-word; line-height: 1.6; }
.ar-answer { font-size: 13px; color: #ccc; padding: 8px; background: #1a1a2e; border-radius: 6px; border-left: 3px solid #4caf50; word-break: break-word; line-height: 1.6; }
.ar-error { font-size: 12px; color: #f44336; margin-top: 6px; }
.ar-actions { display: flex; gap: 6px; margin-top: 10px; }
.ar-confidence { font-size: 11px; font-weight: 700; color: #00e5ff; background: #1a1a2e; padding: 2px 8px; border-radius: 10px; }
.ar-status { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px; }
.ar-pending { background: #3e2723; color: #ff9800; }
.ar-approved { background: #1b5e20; color: #a5d6a7; }
.ar-sent { background: #0d3040; color: #00bcd4; }
.ar-rejected { background: #3a1515; color: #ef9a9a; }
.ar-failed { background: #b71c1c; color: #ef9a9a; }
.ar-filter { padding: 6px 14px; background: #222; color: #888; border: 1px solid #333; font-size: 12px; font-weight: 600; }
.ar-filter.active { background: #00b0ff; color: #000; border-color: #00b0ff; }
.ar-filter:first-child { border-radius: 6px 0 0 6px; }
.ar-filter:last-child { border-radius: 0 6px 6px 0; }

/* NoRag badge — trả lời từ context không có tài liệu */
.ar-norag-badge { font-size: 10px; font-weight: 600; color: #ff8f00; background: #3e2723; padding: 2px 8px; border-radius: 10px; }

/* Câu hỏi chưa trả lời được (Knowledge Gap Tracking) */
.uq-card { background: #1a1510; border: 1px solid #3e2723; border-radius: 8px; padding: 14px; margin-bottom: 10px; }
.uq-reason { font-size: 10px; font-weight: 600; padding: 2px 8px; border-radius: 10px; }
.uq-no-knowledge { background: #3e2723; color: #ff8f00; }
.uq-low-confidence { background: #3a2810; color: #ffb74d; }
.uq-status { font-size: 10px; font-weight: 600; padding: 2px 8px; border-radius: 10px; }
.uq-open { background: #1a1a2e; color: #ff9800; }
.uq-resolved { background: #1b5e20; color: #a5d6a7; }
.uq-dismissed { background: #2a2a3e; color: #666; }
.uq-filter { padding: 6px 14px; background: #222; color: #888; border: 1px solid #333; font-size: 12px; font-weight: 600; }
.uq-filter.active { background: #e65100; color: #fff; border-color: #e65100; }
.uq-filter:first-child { border-radius: 6px 0 0 6px; }
.uq-filter:last-child { border-radius: 0 6px 6px 0; }
.uq-retry-btn { background: #e65100 !important; color: #fff !important; border-color: #e65100 !important; }
.uq-retry-btn:hover { background: #ff6d00 !important; }
.uq-retry-btn:disabled { opacity: 0.6; cursor: wait; }

/* ─── Settings Form ─────────────────────────────────────────────────── */
.settings-form { display: flex; flex-direction: column; gap: 10px; }
.setting-row { display: flex; align-items: center; gap: 12px; }
.setting-row label:first-child { min-width: 180px; color: #aaa; font-size: 14px; }
.setting-row input[type="text"],
.setting-row input[type="password"],
.setting-row input[type="number"] {
    padding: 8px 12px; border-radius: 6px; border: 1px solid #444;
    background: #2a2a3a; color: #eee; font-size: 14px;
}
.setting-row textarea {
    padding: 12px 14px; border-radius: 6px; border: 1px solid #444;
    background: #2a2a3a; color: #eee; font-size: 14px; line-height: 1.6;
    font-family: 'Consolas', 'Courier New', monospace; resize: vertical; min-height: 180px;
}

/* ─── Dark scrollbar toàn bộ app ──────────────────────────────────────── */
* { scrollbar-width: thin; scrollbar-color: #333 transparent; }
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #555; }
textarea::-webkit-scrollbar { width: 5px; }
textarea::-webkit-scrollbar-thumb { background: #444; border-radius: 3px; }
.toggle-switch { position: relative; display: inline-block; width: 44px; height: 24px; cursor: pointer; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; top: 0; left: 0; right: 0; bottom: 0;
    background: #555; border-radius: 24px; transition: .3s; }
.toggle-slider::before { content: ""; position: absolute; height: 18px; width: 18px;
    left: 3px; bottom: 3px; background: #fff; border-radius: 50%; transition: .3s; }
.toggle-switch input:checked + .toggle-slider { background: #00e676; }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(20px); }
.btn-save-settings { margin-top: 4px; }

/* Slider control */
.slider-control { display: flex; align-items: center; gap: 10px; flex: 1; max-width: 300px; }
.setting-slider { -webkit-appearance: none; appearance: none; flex: 1; height: 6px; border-radius: 3px; background: #333; outline: none; }
.setting-slider::-webkit-slider-thumb { -webkit-appearance: none; appearance: none; width: 18px; height: 18px; border-radius: 50%; background: #00b0ff; cursor: pointer; border: 2px solid #0f0f1a; }
.setting-slider::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: #00b0ff; cursor: pointer; border: 2px solid #0f0f1a; }
.slider-value { min-width: 40px; text-align: center; font-weight: 700; color: #00e5ff; font-size: 14px; background: #1a1a2e; padding: 2px 8px; border-radius: 6px; }

/* Group checkbox list (auto-reply) */
.group-checkbox-list { display: flex; flex-direction: column; gap: 4px; }
.group-checkbox-list label { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: #12121f; border: 1px solid #2a2a3e; border-radius: 8px; cursor: pointer; transition: background 0.15s; }
.group-checkbox-list label:hover { background: #1a1a2e; }
.group-checkbox-list label span { font-size: 13px; }

/* CTV member meta badges */
.ctv-group-badges { display: flex; flex-wrap: wrap; gap: 4px; }
.ctv-group-tag { display: inline-block; font-size: 10px; color: #aaa; background: #1e1e30; border: 1px solid #2a2a3e; padding: 2px 8px; border-radius: 10px; white-space: nowrap; max-width: 140px; overflow: hidden; text-overflow: ellipsis; }

/* Help tooltip */
.help-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 16px; height: 16px; border-radius: 50%;
    background: #555; color: #fff; font-size: 10px; font-weight: bold;
    cursor: help; position: relative; margin-left: 4px;
    vertical-align: middle; user-select: none; flex-shrink: 0;
}
.help-icon:hover .help-tooltip,
.help-icon:focus .help-tooltip {
    display: block;
}
.help-tooltip {
    display: none; position: absolute; bottom: calc(100% + 8px); left: 50%;
    transform: translateX(-50%); background: #333; color: #ddd;
    padding: 8px 12px; border-radius: 6px; font-size: 12px; font-weight: normal;
    line-height: 1.5; width: 280px; z-index: 1000;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4); pointer-events: none;
    white-space: normal; text-align: left;
}
.help-tooltip::after {
    content: ''; position: absolute; top: 100%; left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent; border-top-color: #333;
}

/* ─── Sentiment Heatmap (B2+) ─────────────────────────────────────────── */
.heatmap-grid { border-collapse: collapse; font-size: 11px; }
.heatmap-grid th { padding: 3px 6px; color: #888; font-weight: 600; text-align: center; }
.heatmap-grid td { width: 28px; height: 24px; text-align: center; border-radius: 3px; cursor: default; position: relative; }
.heatmap-grid td:hover { outline: 1px solid #00e5ff; z-index: 1; }
.heatmap-cell { display: block; width: 100%; height: 100%; border-radius: 3px; }
.heatmap-legend { display: flex; align-items: center; gap: 6px; margin-top: 8px; font-size: 10px; color: #888; }
.heatmap-legend-bar { width: 120px; height: 8px; border-radius: 4px; background: linear-gradient(90deg, #f44336, #555, #4caf50); }

/* Anomaly cards (B2+) */
.anomaly-card { padding: 8px 12px; border-bottom: 1px solid #222; display: flex; align-items: center; gap: 10px; }
.anomaly-card:last-child { border-bottom: none; }
.anomaly-date { font-weight: 600; font-size: 13px; color: #e0e0e0; min-width: 90px; }
.anomaly-bar { flex: 1; height: 6px; background: #333; border-radius: 3px; overflow: hidden; }
.anomaly-bar-fill { height: 100%; border-radius: 3px; }
.anomaly-meta { font-size: 11px; color: #888; min-width: 120px; text-align: right; }
.anomaly-severity { font-size: 10px; font-weight: 700; padding: 2px 8px; border-radius: 10px; }
.anomaly-critical { background: #b71c1c; color: #ef9a9a; }
.anomaly-warning { background: #e65100; color: #ffcc80; }

/* KB Hit Rate (B4) */
.kb-hit-bar { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; }
.kb-hit-title { font-size: 12px; color: #ddd; min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kb-hit-count { font-size: 12px; font-weight: 700; color: #00e5ff; min-width: 40px; text-align: right; }
.kb-hit-progress { width: 80px; height: 5px; background: #333; border-radius: 3px; overflow: hidden; flex-shrink: 0; }
.kb-hit-fill { height: 100%; background: #00e5ff; border-radius: 3px; }
.kb-hit-section { margin-top: 12px; }
.kb-hit-section-title { font-size: 11px; color: #888; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 8px; font-weight: 600; }
.kb-never-used { color: #ff9800; }
.kb-high-reject .kb-hit-fill { background: #f44336; }

/* ─── Conversation Threading (B1) ─────────────────────────────────────── */
.view-toggle { display: flex; gap: 2px; background: #12121f; border: 1px solid #333; border-radius: 6px; padding: 2px; }
.view-toggle-btn { background: none; border: none; color: #888; padding: 4px 10px; font-size: 11px; font-weight: 600; cursor: pointer; border-radius: 4px; white-space: nowrap; }
.view-toggle-btn:hover { color: #ccc; }
.view-toggle-btn.active { background: #1a1a2e; color: #00e5ff; }

/* Conversation list items */
.conv-item { padding: 10px 12px; border-bottom: 1px solid #222; cursor: pointer; transition: background 0.15s; border-left: 3px solid transparent; }
.conv-item:hover { background: #1a1a2e; }
.conv-item.conv-active { background: #1a1a2e; border-left-color: #00e5ff; }
.conv-header-row { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.conv-title { font-weight: 600; font-size: 13px; color: #e0e0e0; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-count-badge { font-size: 11px; font-weight: 700; color: #00e5ff; background: #1a1a2e; padding: 2px 8px; border-radius: 10px; flex-shrink: 0; }
.conv-time { font-size: 11px; color: #555; flex-shrink: 0; }
.conv-preview { font-size: 12px; color: #999; line-height: 1.4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-preview .conv-sender { color: #00e5ff; font-weight: 600; }
.conv-participants { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.conv-participant { font-size: 10px; color: #aaa; background: #222; padding: 1px 6px; border-radius: 8px; }
.conv-stats-bar { display: flex; gap: 16px; padding: 10px 12px; background: #12121f; border-bottom: 1px solid #333; font-size: 12px; color: #888; flex-wrap: wrap; align-items: center; }
.conv-stats-bar .stat-val { color: #00e5ff; font-weight: 700; }
.conv-actions-bar { display: flex; gap: 8px; padding: 8px 12px; border-bottom: 1px solid #222; }

/* B1 UI: Master-Detail layout cho threads view */
.conv-master-detail { display: flex; height: 100%; min-height: 0; }
.conv-list-pane { flex: 0 0 340px; overflow-y: auto; border-right: 1px solid #333; min-height: 300px; }
.conv-detail-pane { flex: 1; overflow-y: auto; min-width: 0; }
.conv-detail-header { padding: 10px 12px; border-bottom: 1px solid #333; display: flex; align-items: center; gap: 8px; background: #12121f; position: sticky; top: 0; z-index: 2; }
.conv-close-btn { flex-shrink: 0; }
.conv-detail-title { font-weight: 600; color: #00e5ff; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.conv-detail-meta { font-size: 11px; color: #888; flex-shrink: 0; }
@media (max-width: 768px) {
    .conv-list-pane { flex: 1; }
    .conv-detail-pane { display: none; position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: #0f1117; z-index: 10; }
    .conv-detail-pane[style*="display: block"], .conv-detail-pane:not([style*="display: none"]):not([style=""]) { display: block; }
}

/* B1 UI: Split layout — danh sách tin nhắn (trái) + thread detail (phải) */
.messages-split { display: flex; flex: 1; min-height: 0; overflow: hidden; }
.messages-split .msg-list-pane { flex: 1; overflow-y: auto; }
.messages-split.split-active .msg-list-pane { flex: 0 0 50%; border-right: 1px solid #333; }

/* Thread detail panel (bên phải) */
.thread-detail-pane { flex: 1; overflow-y: auto; background: #0d0d18; }
.thread-detail-header { display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: #12121f; border-bottom: 1px solid #333; position: sticky; top: 0; z-index: 2; }
.thread-detail-title { font-weight: 600; color: #00e5ff; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.thread-detail-meta { font-size: 11px; color: #888; flex-shrink: 0; }
.thread-close-btn { flex-shrink: 0; }

/* Thread indicator nhỏ trên msg-header */
.msg-thread-indicator { font-size: 11px; color: #666; cursor: pointer; padding: 1px 6px; border-radius: 3px; transition: all 0.15s; white-space: nowrap; }
.msg-thread-indicator:hover { color: #00e5ff; background: rgba(0,229,255,0.1); }

/* Tin hiện tại (highlight) trong thread detail */
.msg-current { background: rgba(0,229,255,0.08) !important; border-left: 3px solid #00e5ff !important; padding-left: 9px !important; }

/* Tin đang active ở danh sách trái */
.msg-active { background: rgba(0,229,255,0.05); }

/* Ẩn thread indicator bên trong thread detail + conv detail (tránh recursive) */
.thread-detail-pane .msg-thread-indicator,
.conv-detail-pane .msg-thread-indicator { display: none; }

/* Mobile: thread detail thành overlay */
@media (max-width: 768px) {
    .messages-split.split-active .msg-list-pane { flex: 1; }
    .thread-detail-pane { position: absolute; top: 0; left: 0; right: 0; bottom: 0; background: #0f1117; z-index: 10; }
}

/* ─── Data Table (dùng chung cho tất cả tab) ─────────────────────────── */
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th { text-align: left; color: #90caf9; font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; padding: 8px 10px; border-bottom: 2px solid #2a2a3e; white-space: nowrap; }
.data-table td { padding: 7px 10px; border-bottom: 1px solid #1e1e30; color: #ccc; vertical-align: middle; }
.data-table tr:hover td { background: rgba(0,229,255,0.03); }
.data-table td.text-right, .data-table th.text-right { text-align: right; }
.data-table td.text-center, .data-table th.text-center { text-align: center; }
.data-table .td-truncate { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.data-table .empty-row td { text-align: center; color: #555; padding: 24px 10px; font-style: italic; }

/* ─── Form Select (dropdown chung) ───────────────────────────────────── */
.form-select { background: #12121f; border: 1px solid #333; border-radius: 6px; color: #ccc; font-size: 12px; padding: 6px 10px; outline: none; cursor: pointer; }
.form-select:hover { border-color: #555; }
.form-select:focus { border-color: #00e5ff; box-shadow: 0 0 0 2px rgba(0,229,255,0.1); }
.form-select option { background: #1a1a2e; color: #ccc; }

/* ─── AI Monitor — Tab Giám sát AI ───────────────────────────────────── */
.ai-section { margin-bottom: 20px; }
.ai-section-header { font-size: 13px; font-weight: 700; color: #aaa; text-transform: uppercase; letter-spacing: 1px; margin-bottom: 12px; display: flex; align-items: center; gap: 6px; }
.ai-section-icon { font-size: 15px; }

/* Stat card có sub-text */
.stat-card .stat-sub { font-size: 11px; color: #666; margin-top: 2px; }

/* Breakdown list (theo purpose / model) */
.ai-breakdown-item { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-bottom: 1px solid #1e1e30; font-size: 13px; }
.ai-breakdown-item:last-child { border-bottom: none; }
.ai-breakdown-item:hover { background: rgba(0,229,255,0.03); border-radius: 4px; }
.ai-breakdown-label { color: #e0e0e0; display: flex; align-items: center; gap: 6px; }
.ai-breakdown-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.ai-breakdown-stats { color: #888; font-size: 12px; display: flex; gap: 12px; }
.ai-breakdown-stats span { white-space: nowrap; }

/* Distribution bar + legend */
.ai-dist-bar { display: flex; gap: 2px; height: 28px; border-radius: 6px; overflow: hidden; }
.ai-dist-segment { min-width: 3px; cursor: default; transition: opacity 0.15s; position: relative; }
.ai-dist-segment:hover { opacity: 0.8; }
.ai-dist-legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; }
.ai-dist-legend-item { display: flex; align-items: center; gap: 5px; font-size: 11px; color: #999; }
.ai-dist-legend-dot { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }

/* Status badges cho table */
.ai-status-ok { color: #a5d6a7; font-weight: 600; font-size: 12px; }
.ai-status-error { color: #ef9a9a; font-weight: 600; font-size: 12px; }
.ai-batch-info { color: #888; font-size: 11px; margin-left: 4px; }
.ai-skip-badge { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 10px; }
.ai-ctv-tag { color: #2196f3; font-size: 10px; font-weight: 600; margin-left: 4px; }

/* Filter toolbar */
.ai-filter-bar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }

/* Pagination */
.ai-pagination { display: flex; gap: 10px; margin-top: 12px; justify-content: center; align-items: center; }
.ai-pagination .page-info { color: #666; font-size: 12px; }

/* Chart card */
.ai-chart-card { padding-bottom: 8px; }
.ai-chart-card canvas { width: 100% !important; }

/* Purpose badge trong bảng gọi AI gần đây */
.ai-purpose-badge { display: inline-block; font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 3px; text-transform: uppercase; letter-spacing: 0.3px; vertical-align: middle; margin-right: 6px; white-space: nowrap; }
.ai-detail-text { color: #bbb; font-size: 12px; vertical-align: middle; }

/* Tổng hợp chi phí bên cạnh filter */
.ai-usage-summary { margin-left: auto; font-size: 12px; color: #e91e63; font-weight: 600; display: flex; gap: 12px; align-items: center; }
.ai-usage-summary .summary-item { white-space: nowrap; }
.ai-usage-summary .summary-cost { font-size: 14px; }

/* Responsive */
@media (max-width: 768px) {
    .ai-breakdown-grid { grid-template-columns: 1fr !important; }
    .ai-breakdown-stats { gap: 8px; }
    .ai-dist-legend { gap: 4px 10px; }
}
@media (max-width: 480px) {
    .data-table th, .data-table td { padding: 5px 6px; font-size: 11px; }
    .ai-dist-bar { height: 20px; }
}
