/* ============================================================
 * tabs-features.css
 * Styles cho 4 tính năng đã được duyệt:
 *   A5 — Sub-tab bounce + pulse (Marketing)
 *   B2 — Swipe chuyển tab (mobile)
 *   B6 — Badge realtime count-up + pulse
 *   B9b — Multi-tab split view (>=1440px)
 *
 * Rollback: xóa <link rel="stylesheet" href="tabs-features.css"> khỏi index.html
 *           + đặt localStorage.ghz_tab_v2 = '0' để chặn các module JS.
 * ============================================================ */

/* =============================================================
 * A5 — Sub-tab bounce + pulse (Marketing)
 * Icon chỉ bounce khi click (class .bounce-animating được JS gắn tạm)
 * ============================================================= */
.mkt-subtab i {
    display: inline-block;
    transition: transform 280ms cubic-bezier(0.68, -0.55, 0.27, 1.55), color 220ms;
}

.mkt-subtab.bounce-animating i {
    animation: ghz-subtab-bounce 620ms cubic-bezier(0.68, -0.55, 0.27, 1.55);
}

@keyframes ghz-subtab-bounce {
    0%   { transform: scale(0.7); }
    35%  { transform: scale(1.35); }
    55%  { transform: scale(0.92); }
    75%  { transform: scale(1.08); }
    100% { transform: scale(1); }
}

/* Badge pulse khi cập nhật */
.count-badge.ghz-pulse {
    animation: ghz-badge-pulse 800ms ease-in-out;
}
@keyframes ghz-badge-pulse {
    0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.5); }
    50%      { transform: scale(1.4); box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

/* =============================================================
 * B6 — Badge realtime cho tab chính
 * Class .ghz-count-badge được áp dựa vào config; mặc định ẩn
 * khi giá trị <= 0 (dùng class .is-zero).
 * Selector dùng [class~="ghz-count-badge"] để vượt specificity
 * của rule .mobile-tab-bar .tab-badge (width: 5px !important) trong ui-improvements.css.
 * ============================================================= */
.tab-badge.ghz-count-badge,
.mobile-tab-bar .tab-badge.ghz-count-badge,
.mobile-tab-btn .tab-badge.ghz-count-badge,
.desktop-tab-bar .tab-badge.ghz-count-badge {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    width: auto !important;
    height: 18px !important;
    min-width: 18px !important;
    max-width: none !important;
    padding: 0 6px !important;
    border-radius: 9px !important;
    font-size: 10px !important;
    line-height: 1 !important;
    color: #fff !important;
    text-indent: 0 !important;
    box-shadow: 0 0 0 1px var(--ghz-input-bg, #181b20) !important;
    background: var(--ghz-danger, #ef4444) !important;
    top: -4px !important;
    right: -6px !important;
    animation: none !important;
}
.tab-badge.ghz-count-badge.is-zero,
.mobile-tab-bar .tab-badge.ghz-count-badge.is-zero,
.mobile-tab-btn .tab-badge.ghz-count-badge.is-zero,
.desktop-tab-bar .tab-badge.ghz-count-badge.is-zero {
    display: none !important;
}
.tab-badge.ghz-count-badge.is-yellow {
    background: var(--ghz-warning, #f59e0b) !important;
}

/* =============================================================
 * B2 — Swipe gesture (mobile)
 * .ghz-swipe-stage bao bọc các tab-content để swipe chuyển
 * .ghz-swipe-progress là thanh progress hiện khi đang kéo
 * .ghz-swipe-active ngăn scroll ngang tự nhiên trong khi kéo
 * ============================================================= */
.ghz-swipe-progress {
    position: fixed;
    left: 0;
    right: 0;
    top: 0;
    height: 3px;
    background: var(--ghz-brand-color, #00c37a);
    transform-origin: 0 50%;
    transform: scaleX(0);
    z-index: 200;
    pointer-events: none;
    opacity: 0;
    transition: opacity 200ms;
}
.ghz-swipe-progress.is-active {
    opacity: 1;
}

/* =============================================================
 * B9b — Split view (desktop >= 1440px)
 * Chỉ kích hoạt khi ghz_feat_split = '1'
 * ============================================================= */
.ghz-split-toggle {
    position: relative;
    background: var(--ghz-card-bg, rgba(255,255,255,0.04));
    border: 1px solid var(--ghz-card-border, rgba(255,255,255,0.08));
    color: var(--ghz-text-primary, #e5e7eb);
    padding: 6px 12px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.18s, border-color 0.18s, transform 0.18s;
}
.ghz-split-toggle:hover {
    background: var(--ghz-input-bg, rgba(255,255,255,0.06));
    border-color: var(--ghz-brand-color, #00c37a);
}
.ghz-split-toggle.is-on {
    background: rgba(0, 195, 122, 0.12);
    border-color: var(--ghz-brand-color, #00c37a);
    color: var(--ghz-brand-color, #00c37a);
}

.ghz-split-host {
    position: relative;
}

.ghz-split-grid {
    display: grid;
    grid-template-columns: 1fr 8px 1fr;
    gap: 0;
    height: calc(100vh - 220px);
    min-height: 420px;
    background: var(--ghz-card-bg, #181b20);
    border: 1px solid var(--ghz-card-border, #2a2e35);
    border-radius: 12px;
    overflow: hidden;
    margin-top: 12px;
}
.ghz-split-grid.is-single {
    grid-template-columns: 1fr;
}
.ghz-split-pane {
    background: var(--ghz-card-bg, #181b20);
    overflow: auto;
    position: relative;
    min-width: 0;
}
.ghz-split-pane.is-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--ghz-text-muted, #9ca3af);
    font-size: 13px;
    border: 2px dashed transparent;
    transition: border-color 0.18s, background 0.18s;
}
.ghz-split-pane.is-empty.is-drop-target {
    border-color: var(--ghz-brand-color, #00c37a);
    background: rgba(0, 195, 122, 0.06);
}
.ghz-split-gutter {
    background: var(--ghz-card-border, #2a2e35);
    cursor: col-resize;
    transition: background 0.18s;
}
.ghz-split-gutter:hover,
.ghz-split-gutter.is-resizing {
    background: var(--ghz-brand-color, #00c37a);
}
.ghz-split-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--ghz-card-border, #2a2e35);
    background: var(--ghz-input-bg, rgba(255,255,255,0.02));
}
.ghz-split-header h3 {
    margin: 0;
    font-size: 14px;
    font-weight: 700;
    color: var(--ghz-text-primary, #e5e7eb);
}
.ghz-split-close {
    background: transparent;
    border: 1px solid var(--ghz-card-border, rgba(255,255,255,0.08));
    color: var(--ghz-text-muted, #9ca3af);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 11px;
    cursor: pointer;
}
.ghz-split-close:hover {
    color: var(--ghz-text-primary, #e5e7eb);
    border-color: var(--ghz-text-primary, #e5e7eb);
}
.ghz-split-body {
    padding: 16px;
    color: var(--ghz-text-muted, #9ca3af);
    font-size: 13px;
}

/* =============================================================
 * Nút Trang chủ trên desktop (đồng bộ với mobile mkt-home-btn)
 * Class .ghz-home-btn được inject bởi tabs-features-home-btn.js
 * ============================================================= */
.desktop-tab-bar .tab-pill.ghz-home-btn {
    border-left: 1px solid var(--ghz-card-border, rgba(255,255,255,0.08));
    margin-left: 6px;
    padding-left: 12px !important;
}
.desktop-tab-bar .tab-pill.ghz-home-btn i {
    color: var(--ghz-brand-color, #34d399);
}
.desktop-tab-bar .tab-pill.ghz-home-btn:hover i {
    animation: ghz-home-icon-pop 320ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
body:has(#tab-marketing:not(.hidden)) .desktop-tab-bar .tab-pill.ghz-home-btn {
    display: none !important;
}
@keyframes ghz-home-icon-pop {
    0%   { transform: scale(1); }
    50%  { transform: scale(1.18) rotate(-6deg); }
    100% { transform: scale(1); }
}

/* =============================================================
 * Reduced motion: tắt mọi animation khi user yêu cầu
 * ============================================================= */
/* =============================================================
 * Bảng xếp hạng KPI trên desktop:
 *   - Loại bỏ grid 2 cột của ui-improvements.css cho card này
 *     để card chiếm full-width y hệt mobile
 *   - KHÔNG set max-width / dashed border / "Đây là bạn" — để khớp 100% mobile
 *   - is-self highlight: GIỮ NGUYÊN style từ ui-improvements.css (không ghi đè)
 * ============================================================= */

/* === Force card ranking full-width, bỏ grid 2 cột === */
@media (min-width: 768px) {
    /* Loại bỏ display:grid để card ranking hiển thị block y hệt mobile */
    #tab-cua-toi > .space-y-6 > .card:has(#my-ranking-list),
    #tab-cua-toi > .space-y-6 > .card:has(#manager-kpi-ranking-list) {
        display: block !important;
        grid-column: 1 / -1 !important;
        width: 100% !important;
    }
}

@media (min-width: 1024px) {
    #tab-cua-toi > .space-y-6 > .card:has(#my-ranking-list),
    #tab-cua-toi > .space-y-6 > .card:has(#manager-kpi-ranking-list) {
        display: block !important;
        grid-column: 1 / -1 !important;
        width: 100% !important;
    }
}

@media (min-width: 1280px) {
    #tab-cua-toi > .space-y-6 > .card:has(#my-ranking-list),
    #tab-cua-toi > .space-y-6 > .card:has(#manager-kpi-ranking-list) {
        display: block !important;
        grid-column: 1 / -1 !important;
        width: 100% !important;
    }
}

/* === Reset mọi CSS override cho desktop — để y hệt mobile === */
@media (min-width: 1024px) {
    /* List không có max-width, padding, gap đặc biệt — y hệt mobile */
    #my-ranking-list,
    #manager-kpi-ranking-list {
        display: flex !important;
        flex-direction: column;
        gap: 8px;
        max-width: none !important;
        margin: 0 !important;
        width: 100% !important;
    }

    /* Reset tất cả override từ block cũ (nếu có) */
    #my-ranking-list .rank-card.is-self,
    #manager-kpi-ranking-list .rank-card.is-self {
        border: revert !important;
        background: revert !important;
    }
    #my-ranking-list .rank-card.is-self::after,
    #manager-kpi-ranking-list .rank-card.is-self::after {
        content: revert !important;
        display: revert !important;
    }
}

/* =============================================================
 * macOS Segmented Control style cho mkt-subtab-bar (DESKTOP)
 * User chọn: từng tab trong 1 viền liền, divider mảnh dọc,
 * active có nền đậm hơn. Style dùng chung cho mọi theme.
 * Selector này override style pill tròn mặc định của ui-improvements.css
 * nhưng KHÔNG động vào file cũ (chỉ append, dễ rollback).
 * ============================================================= */

/* ------------------------------------------------------------
 * TỐI ƯU 2026-11-07: sub-tab bar gọn + tách nút "Trang chủ"
 * ------------------------------------------------------------
 * Vấn đề trước:
 *   - 6 nút (5 sub-tab + "Trang chủ") nằm chung 1 segmented control
 *     ⇒ mỗi nút bị ép "flex: 1 1 0" nên nhãn dài ("Ngân sách &
 *     Chiến dịch", "Nội dung & Kế hoạch") bị cắt bằng ellipsis
 *     hoặc tràn, thanh bar quá rộng.
 *   - Nút "Trang chủ" là hành động điều hướng, KHÔNG phải sub-tab
 *     ⇒ để chung nhóm làm nhiễu và mất nghĩa.
 *
 * Giải pháp:
 *   - .mkt-subtabs-wrap: flex, bar chiếm hết bề ngang, nút "Trang chủ"
 *     tách ra ngoài (nút tròn, chỉ icon trên màn hình hẹp).
 *   - Nhãn 2 tầng: .mkt-subtab-label-short (mặc định, ngắn) và
 *     .mkt-subtab-label-full (hiện khi đủ bề rộng ≥ 1180px).
 *   - Badge: font tabular, tự ẩn khi 0, không làm vỡ layout.
 * ------------------------------------------------------------ */

/* Wrapper: bar + nút quay lại cùng 1 hàng
   (margin-bottom: 0 vì #tab-marketing đã có space-y-6 tự lo khoảng cách) */
.mkt-subtabs-wrap {
    display: flex;
    align-items: stretch;
    gap: 8px;
    width: 100%;
    min-width: 0;
    margin-bottom: 0;
}
.mkt-subtabs-wrap .mkt-subtab-bar {
    flex: 1 1 auto;
    min-width: 0;
    margin-bottom: 0 !important;
}

/* Nút "Trang chủ" tách riêng — nút vuông/bo nhẹ, cùng tone theme */
.mkt-home-subtab {
    flex: 0 0 auto;
    align-self: stretch;      /* cao bằng thanh bar, không bị lệch chiều cao */
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 38px;
    padding: 0 14px;
    border-radius: 12px;
    border: 1px solid var(--ghz-card-border, rgba(255,255,255,0.10));
    background: var(--ghz-card-bg, rgba(255,255,255,0.04));
    color: var(--ghz-tabbar-text, #9ca3af);
    font-size: 12.5px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background-color .16s ease, color .16s ease, border-color .16s ease;
    -webkit-tap-highlight-color: transparent;
}
.mkt-home-subtab:hover {
    background: var(--ghz-input-bg, rgba(255,255,255,0.06));
    color: var(--ghz-text-primary, #e5e7eb);
    border-color: var(--ghz-brand-color, #00c37a);
}
.mkt-home-subtab:active { transform: scale(.97); }
.mkt-home-subtab i { font-size: 13px; }
/* Ẩn chữ khi bị ép nhỏ (đã có rule ở media query bên dưới) */
.mkt-home-subtab-tx { min-width: 0; overflow: hidden; }

/* Nhãn 2 tầng trong 1 sub-tab */
.mkt-subtab-tx {
    display: inline-flex;
    align-items: center;
    min-width: 0;
    flex: 0 1 auto;
    overflow: hidden;
}
/* Mặc định hiện nhãn ngắn */
.mkt-subtab-label-full { display: none; }
.mkt-subtab-label-short {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Badge: tabular + tự ẩn khi rỗng, không đẩy layout */
.mkt-subtab .count-badge {
    font-variant-numeric: tabular-nums;
    min-width: 18px;
    text-align: center;
}
.mkt-subtab .count-badge:empty,
.mkt-subtab .count-badge.hidden { display: none !important; }

/* Container: viền liền, padding trong để tab có khoảng đẹp */
.mkt-subtab-bar.ghz-segmented {
    gap: 0 !important;
    padding: 4px !important;
    border-radius: 12px !important;
    background: var(--ghz-input-bg, rgba(255,255,255,0.04)) !important;
    border: 1px solid var(--ghz-card-border, rgba(255,255,255,0.10)) !important;
    overflow: hidden !important;
    box-shadow: var(--ghz-card-glass-shadow, 0 1px 2px rgba(0,0,0,0.04)),
                inset 0 1px 0 rgba(255,255,255,0.04) !important;
}

/* Từng tab: bỏ border-radius riêng, dùng divider dọc */
.mkt-subtab-bar.ghz-segmented .mkt-subtab {
    flex: 1 1 0;
    min-width: 0;
    padding: 10px 14px;
    border-radius: 0 !important;
    background: transparent !important;
    border: none !important;
    border-right: 1px solid var(--ghz-card-border, rgba(255,255,255,0.10)) !important;
    color: var(--ghz-tabbar-text, #9ca3af);
    font-weight: 600;
    text-align: center;
    justify-content: center;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    transition: background-color 0.18s ease, color 0.18s ease, transform 0.18s ease;
}
.mkt-subtab-bar.ghz-segmented .mkt-subtab i,
.mkt-subtab-bar.ghz-segmented .mkt-subtab .count-badge {
    flex: 0 0 auto;
}
.mkt-subtab-bar.ghz-segmented .mkt-subtab .count-badge {
    max-width: 48px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Bỏ divider ở tab cuối cùng */
.mkt-subtab-bar.ghz-segmented .mkt-subtab:last-child {
    border-right: none !important;
}

/* Hover: subtle highlight */
.mkt-subtab-bar.ghz-segmented .mkt-subtab:hover:not(.active) {
    background: var(--ghz-input-bg, rgba(255,255,255,0.06)) !important;
    color: var(--ghz-text-primary, #e5e7eb) !important;
}

/* Active: nền đậm hơn, hơi inset, icon bounce sẵn (A5 JS vẫn chạy) */
.mkt-subtab-bar.ghz-segmented .mkt-subtab.active {
    background: var(--ghz-brand-soft-18, rgba(0, 195, 122, 0.18)) !important;
    color: var(--ghz-brand-color, #00c37a) !important;
    border-color: var(--ghz-card-border, rgba(255,255,255,0.10)) !important;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.06),
                0 1px 3px rgba(0,0,0,0.25) !important;
    font-weight: 700;
}

/* Bỏ box-shadow xanh cũ của .mkt-subtab.active (pill tròn) */
.mkt-subtab-bar.ghz-segmented .mkt-subtab.active,
.mkt-subtab-bar.ghz-segmented .mkt-subtab:hover {
    box-shadow:
        inset 0 1px 0 rgba(255,255,255,0.06),
        0 1px 3px rgba(0,0,0,0.25) !important;
}

/* Divider "đè" border-right ở active (vì active đã đổi border-color) */
.mkt-subtab-bar.ghz-segmented .mkt-subtab.active + .mkt-subtab {
    border-left-color: var(--ghz-card-border, rgba(255,255,255,0.10)) !important;
}

/* Badge trong active thì tone sáng hơn để nổi */
.mkt-subtab-bar.ghz-segmented .mkt-subtab.active .count-badge {
    background: var(--ghz-brand-color, #00c37a);
    color: #ffffff;
    font-weight: 800;
}
.mkt-subtab-bar.ghz-segmented .mkt-subtab:not(.active) .count-badge {
    background: rgba(255,255,255,0.08);
    color: var(--ghz-text-muted, #9ca3af);
}

/* ------------------------------------------------------------
 * Breakpoint nhãn (2026-11-07)
 *   < 1024px : nhãn ngắn (Tổng quan / Lịch / Chiến dịch / Nội dung)
 *   ≥ 1024px : nhãn ngắn (segmented control đang bật)
 *   ≥ 1180px : nhãn đầy đủ ("Lịch đăng bài", "Ngân sách & Chiến dịch",
 *              "Nội dung & Kế hoạch") — chỉ khi đủ bề ngang để không cắt.
 * ------------------------------------------------------------ */
@media (min-width: 1180px) {
    .mkt-subtab-label-short { display: none; }
    .mkt-subtab-label-full {
        display: inline;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

/* Bề ngang trung gian: nút "Trang chủ" chỉ còn icon cho gọn */
@media (max-width: 1179px) {
    .mkt-home-subtab-tx { display: none; }
    .mkt-home-subtab { padding: 0 12px; }
}

/* Mobile: bar này đã bị ẩn bởi CSS @media <768px (set display:none) —
   nên wrapper + nút "Trang chủ" cũng phải ẩn theo (chỉ dùng mobile-tab-bar). */
@media (max-width: 768px) {
    .mkt-subtabs-wrap { display: none !important; }
}

/* Reduced motion: tắt bounce icon khi user yêu cầu */
@media (prefers-reduced-motion: reduce) {
    .mkt-subtab i,
    .count-badge,
    .tab-badge.ghz-count-badge,
    .ghz-swipe-progress,
    .ghz-split-grid {
        transition: none !important;
        animation: none !important;
    }
    .mkt-subtab.active i,
    .mkt-subtab.bounce-animating i,
    .count-badge.ghz-pulse,
    .tab-badge.ghz-count-badge.is-changed {
        animation: none !important;
    }
}
