/* ============================================================================
   UI/UX IMPROVEMENTS PATCH v1 (Oct 6, 2026)
   ----------------------------------------------------------------------------
   File mới, APPEND vào cuối ui-improvements.css hoặc load sau nó.
   Mục tiêu: 11 cải tiến UI/UX mà KHÔNG phá vỡ logic hiện có.

   1) Empty state — variant success / warn / danger / glass (bổ sung, không override)
   2) Header search ẩn THẬT cho CTV (sửa lỗi el.hidden không thắng .flex của Tailwind)
   3) Swipe to action row (CSS-only, không đụng ui-swipe-collapse.js)
   4) Color contrast — gray-500 → gray-400 ở các vùng helper/caption quan trọng
   5) Activity timeline (semantic list) — CSS thuần, không đụng DOM
   6) Theme swatch — thêm chip gradient preview trong theme picker
   7) Inventory lightbox — bổ sung focus trap + escape close + caption area
   8) Responsive card table — bổ sung data-label rule cho mobile
   9) Skeleton shimmer — bổ sung variant gradient
  10) Disclosure — bổ sung style cho <details class="ui-disclosure">
  11) Toast hook — anchor cho window.showToast() (defined trong bundle-empty-state.js)

   Tất cả selectors đều scope hoặc dùng :where() / :is() để specificity thấp nhất,
   tránh thắng các rule quan trọng hiện có. Mọi rule đều có comment giải thích
   và safe với theme dark/light/pastel của dự án.

   Last verified against: index.html (bundle.js, ui-improvements.css v303,
   ui-improvements-mobile.css v8, theme-vars.css 20260926-1, sw.js v266).
   ============================================================================ */


/* ============================================================================
   1) HEADER SEARCH ẨN THẬT CHO CTV (và các data-show-for-role khác)
   ----------------------------------------------------------------------------
   Vấn đề: bundle.js set `el.hidden = !show` cho [data-show-for-role]. Nhưng
   HTML attribute `hidden` chỉ tương đương `display: none` với UA stylesheet.
   Khi element có class Tailwind `.flex` (specificity 0,1,0) — cùng specificity
   với `[hidden]` (0,1,0) — thì thứ tự load quyết định, và Tailwind thường
   load sau nên `.flex { display: flex }` THẮNG `[hidden] { display: none }`.
   Hậu quả: header search vẫn hiển thị chiếm flex-1 với CTV.

   Fix: ép `[hidden]` thắng mọi Tailwind display utility bằng cách bump
   specificity lên 0,2,0 với `[hidden][hidden]`. Áp dụng cho mọi element
   có thuộc tính hidden, KHÔNG chỉ header search → an toàn cho toàn app.
   ============================================================================ */
[hidden][hidden] { display: none !important; }

/* Phòng trường hợp Tailwind utility .flex / .inline-flex ghi đè [hidden]
   (specificity 0,1,0 ngang nhau, phụ thuộc load order). Ép thêm 1 lớp
   cho các utility phổ biến. KHÔNG ép cho mọi [hidden] để tránh phá các
   trường hợp hợp lệ khác. */
[hidden]:is(.flex, .inline-flex, .grid, .inline-grid, .block, .inline-block, .table) { display: none !important; }


/* ============================================================================
   2) EMPTY STATE — VARIANT BỔ SUNG
   ----------------------------------------------------------------------------
   bundle-empty-state.js đã gọi createEmptyStateSafe({ variant: 'primary'/'blue' }).
   Bổ sung thêm .empty-state--success / .empty-state--warn / .empty-state--danger
   / .empty-state--glass để dùng trong 3 empty-state demo phía trên.
   KHÔNG override .empty-state / .empty-state-icon / .empty-state-title
   hiện có — chỉ thêm variant mới.
   ============================================================================ */
.empty-state--success .empty-state-icon {
    color: var(--ghz-success, #00c37a);
    background: var(--ghz-success-bg, rgba(0,195,122,0.14));
}
.empty-state--warn .empty-state-icon {
    color: var(--ghz-warning, #f59e0b);
    background: var(--ghz-warning-bg, rgba(245,158,11,0.14));
}
.empty-state--danger .empty-state-icon {
    color: var(--ghz-danger, #f87171);
    background: var(--ghz-danger-bg, rgba(248,113,113,0.14));
}
.empty-state--glass {
    background: var(--ghz-card-glass-bg, rgba(255,255,255,0.06));
    backdrop-filter: var(--ghz-card-glass-blur, blur(16px) saturate(1.3));
    -webkit-backdrop-filter: var(--ghz-card-glass-blur, blur(16px) saturate(1.3));
    border: 1px solid var(--ghz-card-glass-border, rgba(255,255,255,0.10));
    border-radius: 16px;
    padding: 32px 16px;
    text-align: center;
    color: var(--ghz-text-muted, #9ca3af);
}
.empty-state--glass .empty-state-title { color: var(--ghz-text-primary, #e5e7eb); }
.empty-state--glass .empty-state-description { color: var(--ghz-text-muted, #9ca3af); }


/* ============================================================================
   3) COLOR CONTRAST FIX (WCAG AA)
   ----------------------------------------------------------------------------
   Trước: text-gray-500 (#6b7280) trên nền tối #181b20 = ~4.4:1 → fail AA body.
   Sau:  text-gray-400 (#9ca3af) = ~7.1:1 → AAA.

   Scope CHỈ vào các vùng helper/caption KHÔNG ảnh hưởng readability chính
   (text chính của KPI vẫn là text-white / text-primary). Tailwind utility
   class gốc vẫn giữ — chỉ override trong các container dưới đây.
   ============================================================================ */

/* Helper text nhỏ dưới KPI trong #ctv-self-view + manager-stats */
#ctv-self-view .text-gray-500,
#manager-stats-block .text-gray-500,
#my-stats-details .text-gray-500 {
    color: var(--ghz-text-muted, #9ca3af) !important;
}

/* Caption phụ trong settings + legend (đủ rõ mà không phá hierarchy) */
.ui-section-copy.text-gray-500,
.field-help.text-gray-500,
.text-gray-500[id$="-subtitle"] {
    color: var(--ghz-text-muted, #9ca3af) !important;
}

/* text-gray-600 (#4b5563 = ~3:1) trên nền tối — fail AA body hoàn toàn.
   Chỉ nâng lên gray-400 ở vùng UI quan trọng để vẫn rõ nhưng không bật tone chính. */
.text-gray-600[id$="-caption"],
.text-gray-600[id$="-subtitle"] {
    color: var(--ghz-text-muted, #9ca3af) !important;
}


/* ============================================================================
   4) SWIPE TO ACTION (CSS-only)
   ----------------------------------------------------------------------------
   Khi swipe một .swipe-row sang trái, .row-content trượt đi để lộ .row-actions.
   Đã có ui-swipe-collapse.js xử lý tương tác nặng; CSS này chỉ cung cấp
   visual + transition cho các row swipe-to-reveal đơn giản hơn (checklist, ...).

   KHÔNG override .ui-swipe-collapse-* (đang được dùng bởi logic chính).
   ============================================================================ */
.swipe-row {
    position: relative;
    overflow: hidden;
    border-radius: 12px;
    background: var(--ghz-input-bg, #14171b);
    border: 1px solid var(--ghz-input-border, #2a2e35);
    isolation: isolate;
}
.swipe-row > .row-content {
    position: relative;
    z-index: 2;
    background: var(--ghz-input-bg, #14171b);
    transition: transform .2s cubic-bezier(.2,.7,.3,1);
    will-change: transform;
    touch-action: pan-y;
}
.swipe-row > .row-actions {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 12px;
    z-index: 1;
}
.swipe-row > .row-actions > button {
    padding: 8px 12px;
    border-radius: 8px;
    border: 0;
    font-weight: 600;
    font-size: 12px;
    cursor: pointer;
    color: #fff;
    line-height: 1;
    transition: filter .15s ease, transform .15s ease;
}
.swipe-row > .row-actions > button:hover { filter: brightness(1.1); }
.swipe-row > .row-actions > button:active { transform: scale(.96); }
.swipe-row > .row-actions .swipe-done { background: var(--ghz-success, #00c37a); }
.swipe-row > .row-actions .swipe-delete { background: var(--ghz-danger, #f87171); }


/* ============================================================================
   5) ACTIVITY TIMELINE (semantic list)
   ----------------------------------------------------------------------------
   <ul class="timeline" aria-label="..."> <li class="success|warn|danger">
   CSS thuần, không phụ thuộc JS. Dùng được ngay khi copy UI demo.
   ============================================================================ */
ul.timeline,
.timeline {
    list-style: none;
    padding: 0;
    margin: 0;
}
.timeline > li {
    position: relative;
    padding: 10px 0 10px 28px;
    border-left: 2px solid var(--ghz-input-border, #2a2e35);
    margin-left: 8px;
}
.timeline > li::before {
    content: '';
    position: absolute;
    left: -7px;
    top: 14px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--ghz-button-bg, #00c37a);
    box-shadow: 0 0 0 3px var(--ghz-card-bg, #181b20);
}
.timeline > li.success::before { background: var(--ghz-success, #00c37a); }
.timeline > li.warn::before { background: var(--ghz-warning, #f59e0b); }
.timeline > li.danger::before { background: var(--ghz-danger, #f87171); }
.timeline > li .time {
    font-size: 11px;
    color: var(--ghz-text-muted, #9ca3af);
    margin-top: 2px;
}
.timeline > li > p:first-child {
    color: var(--ghz-text-primary, #e5e7eb);
    font-weight: 600;
    margin: 0;
}
.timeline > li > p:nth-child(2) {
    color: var(--ghz-text-muted, #9ca3af);
    font-size: 12px;
    margin: 2px 0 0;
}


/* ============================================================================
   6) THEME SWATCH (gradient chip preview)
   ----------------------------------------------------------------------------
   Theme picker hiện có (theme-engine.js) render mỗi theme thành 1 button với
   cấu trúc: <button class="ghz-theme-option">  + nội dung text bên trong.
   Bổ sung .ghz-theme-swatch là 1 span absolute bên trái text — KHÔNG đụng
   cấu trúc gốc, chỉ thêm visual.

   Nếu theme-engine.js chưa render swatch, dùng helper JS trong
   bundle-theme-swatch.js (file mới) để tự inject.
   ============================================================================ */
.ghz-theme-swatch {
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 999px;
    margin-right: 8px;
    vertical-align: middle;
    flex-shrink: 0;
    border: 1px solid rgba(255,255,255,0.15);
    background: linear-gradient(135deg, var(--swatch-c1, #444) 0%, var(--swatch-c2, #222) 100%);
    box-shadow: inset 0 0 0 1px rgba(0,0,0,0.15);
}


/* ============================================================================
   7) INVENTORY LIGHTBOX — BỔ SUNG (không phá cấu trúc hiện có z-index 1100)
   ----------------------------------------------------------------------------
   Thêm caption region có thể đọc bằng screen reader, focus trap, ESC close.
   CSS: thêm .inventory-lightbox-caption (optional, đã có sẵn inline có thể dùng)
   ============================================================================ */
.inventory-lightbox-caption {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: max(8px, env(safe-area-inset-bottom, 0px));
    background: rgba(7, 10, 14, 0.78);
    color: #fff;
    font-size: 12px;
    padding: 6px 12px;
    border-radius: 999px;
    max-width: calc(100% - 32px);
    text-align: center;
    line-height: 1.3;
    pointer-events: none;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

/* Khi lightbox mở, đảm bảo body không cuộn được phía sau */
body:has(#inventory-lightbox:not(.hidden)) {
    overflow: hidden;
}


/* ============================================================================
   8) RESPONSIVE CARD TABLE — DATA-LABEL
   ----------------------------------------------------------------------------
   Class .responsive-card-table đã có. Bổ sung rule mobile: ẩn thead, mỗi td
   hiển thị data-label ở bên trái + nội dung bên phải. Dùng được ngay khi
   td có attribute data-label="...".
   ============================================================================ */
@media (max-width: 768px) {
    .responsive-card-table > thead { display: none; }
    .responsive-card-table > tbody > tr {
        display: block;
        background: var(--ghz-input-bg, #14171b);
        border: 1px solid var(--ghz-input-border, #2a2e35);
        border-radius: 12px;
        margin-bottom: 12px;
        padding: 12px 14px;
    }
    .responsive-card-table > tbody > tr > td {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 12px;
        padding: 6px 0;
        border: 0 !important;
    }
    .responsive-card-table > tbody > tr > td::before {
        content: attr(data-label);
        font-weight: 700;
        font-size: 11px;
        color: var(--ghz-text-muted, #9ca3af);
        text-transform: uppercase;
        letter-spacing: .05em;
        flex: 0 0 38%;
        max-width: 38%;
        line-height: 1.4;
        word-break: break-word;
    }
    .responsive-card-table > tbody > tr > td > .cell-value,
    .responsive-card-table > tbody > tr > td > *:not(script):not(style) {
        flex: 1;
        text-align: right;
        word-break: break-word;
        min-width: 0;
    }
}


/* ============================================================================
   9) SKELETON SHIMMER (gradient bar)
   ----------------------------------------------------------------------------
   .skeleton đã có (solid pulse). Bổ sung .skeleton-bar (gradient shimmer)
   cho các skeleton mới — dùng được khi không cần pulse cứng.
   ============================================================================ */
@keyframes ghz-skeleton-shimmer {
    0%   { background-position: -200% 0; }
    100% { background-position:  200% 0; }
}
.skeleton-bar {
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(90deg,
        var(--ghz-input-bg, #14171b) 0%,
        var(--ghz-input-border, #2a2e35) 50%,
        var(--ghz-input-bg, #14171b) 100%);
    background-size: 200% 100%;
    animation: ghz-skeleton-shimmer 1.6s ease-in-out infinite;
}
.skeleton-bar--wide { width: 100%; }
.skeleton-bar--narrow { width: 60%; }
.skeleton-bar--thin { height: 8px; }
.skeleton-bar--thick { height: 16px; }

@media (prefers-reduced-motion: reduce) {
    .skeleton-bar { animation: none; }
}


/* ============================================================================
   10) DISCLOSURE — <details class="ui-disclosure">
   ----------------------------------------------------------------------------
   Bổ sung style cho <details class="ui-disclosure"> nếu dự án muốn dùng
   details mới thay vì .ui-disclosure-summary (đã có sẵn ở ui-improvements.css).
   KHÔNG override ui-disclosure-summary — chỉ thêm ui-disclosure class mới.
   ============================================================================ */
.ui-disclosure {
    background: var(--ghz-card-bg, #181b20);
    border: 1px solid var(--ghz-card-border, #2a2e35);
    border-radius: 16px;
    overflow: hidden;
    margin-bottom: 12px;
    transition: border-color .15s ease, box-shadow .15s ease;
}
.ui-disclosure[open] {
    border-color: var(--ghz-card-border, #2a2e35);
    box-shadow: 0 6px 24px -10px rgba(0,0,0,0.45);
}
.ui-disclosure > summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    width: 100%;
    padding: 1rem 1.25rem;
    color: var(--ghz-text-primary, #e5e7eb);
    font-weight: 700;
    cursor: pointer;
    user-select: none;
    list-style: none;
    transition: background-color .15s ease;
}
.ui-disclosure > summary:hover { background: rgba(127,127,127,.06); }
.ui-disclosure > summary::-webkit-details-marker { display: none; }
.ui-disclosure > summary::marker { display: none; }
.ui-disclosure > summary::after {
    content: '\f078'; /* fa-chevron-down */
    font-family: 'Font Awesome 6 Free', 'Font Awesome 6 Solid', sans-serif;
    font-weight: 900;
    flex: 0 0 auto;
    color: var(--ghz-text-muted, #9ca3af);
    font-size: 12px;
    transition: transform .2s ease, color .15s ease;
}
.ui-disclosure[open] > summary::after {
    transform: rotate(180deg);
    color: var(--ghz-text-primary, #e5e7eb);
}
.ui-disclosure > .ui-disclosure-body {
    padding: 0 1.25rem 1.25rem;
    color: var(--ghz-text-muted, #9ca3af);
    font-size: 13px;
    line-height: 1.5;
}


/* ============================================================================
   11) TOAST — ANCHOR (CSS bổ sung)
   ----------------------------------------------------------------------------
   .toast-region / .app-toast đã có (xem ui-improvements.css dòng ~1500).
   Bổ sung .app-toast .action (button phụ trong toast) cho demo "Phiên sắp hết".
   ============================================================================ */
.app-toast .action {
    background: transparent;
    border: 1px solid currentColor;
    color: inherit;
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 6px;
    transition: background-color .15s ease;
}
.app-toast .action:hover {
    background-color: rgba(255,255,255,.08);
}


/* ============================================================================
   12) AVATAR STACK + CHIP INPUT (CSS bổ sung)
   ----------------------------------------------------------------------------
   Component phụ trợ cho UI demo timeline + chip nhập nhiều CTV.
   ============================================================================ */
.avatar-stack {
    display: inline-flex;
    align-items: center;
}
.avatar-stack .avatar-circle {
    width: 32px;
    height: 32px;
    font-size: 11px;
    border: 2px solid var(--ghz-card-bg, #181b20);
    margin-left: -8px;
}
.avatar-stack .avatar-circle:first-child { margin-left: 0; }
.avatar-stack .avatar-circle.more {
    background: var(--ghz-input-border, #2a2e35);
    color: var(--ghz-text-primary, #e5e7eb);
}

.chip-input {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px;
    min-height: 44px;
    background: var(--ghz-input-bg, #14171b);
    border: 1px solid var(--ghz-input-border, #2a2e35);
    border-radius: 10px;
    align-items: center;
}
.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--ghz-button-bg, #00c37a) 18%, transparent);
    color: var(--ghz-text-primary, #e5e7eb);
    font-size: 12px;
    font-weight: 600;
}
.chip > button {
    background: transparent;
    border: 0;
    color: inherit;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    font-size: 14px;
    opacity: .7;
    transition: opacity .15s ease;
}
.chip > button:hover { opacity: 1; }
.chip-input > input {
    flex: 1;
    min-width: 80px;
    background: transparent;
    border: 0;
    color: var(--ghz-text-primary, #e5e7eb);
    outline: none;
    font-size: 13px;
    padding: 4px 0;
}
.chip-input > input::placeholder { color: var(--ghz-text-muted, #9ca3af); }


/* ============================================================================
   13) REDUCED MOTION — safe guard toàn file
   ----------------------------------------------------------------------------
   Áp dụng cho mọi animation/transition defined ở trên. KHÔNG đụng rule
   @media prefers-reduced-motion đã có ở file gốc (line ~1050).
   ============================================================================ */
@media (prefers-reduced-motion: reduce) {
    .swipe-row > .row-content,
    .ui-disclosure > summary::after,
    [data-toast] { transition: none !important; }
    .skeleton-bar { animation: none !important; }
}


/* ============================================================================
   END OF UI/UX IMPROVEMENTS PATCH v1
   ============================================================================ */
