/* ============================================================
 * 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).
 * ============================================================= */

/* 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);
}

/* Mobile: bar này đã bị ẩn bởi CSS @media <768px (set display:none), không cần lo */

/* 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;
    }
}
