/* ============================================================
   INVENTORY MODALS — hệ hiển thị thống nhất cho tab Nhập/Xuất
   (2026-11-07)

   Áp dụng cho:
     - #inventory-device-detail-modal   (chi tiết thiết bị)
     - #inventory-recent-detail-modal   (chi tiết hoạt động gần đây)
     - #inventory-imei-history-modal    (lịch sử IMEI)
     - #inventory-knox-detail-modal     (chi tiết Knox)
     - #inventory-repair-handover-modal (bàn giao sửa chữa / bảo hành)
     - #admin-edit-modal                (sửa nhập / sửa xuất / hủy / hoàn xuất)

   Nguyên tắc:
     1) Mọi màu dùng token --ghz-* ⇒ tự đổi theo 22 theme (sáng/tối).
     2) Dòng "nhãn – giá trị" dùng CHUNG 1 lưới 2 cột ⇒ nhãn thành cột
        thẳng hàng, giá trị căn phải (thay vì justify-between rời rạc).
     3) Header/footer tách rõ, scroll chỉ trong vùng nội dung.
   ============================================================ */

/* ---------- 1. Header chuẩn ---------- */
.inv-modal-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    padding-bottom: 0.75rem;
    margin-bottom: 0.875rem;
    border-bottom: 1px solid var(--ghz-card-border, #2a2e35);
    flex-shrink: 0;
}

.inv-modal-head-main {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.inv-modal-head-icon {
    flex: 0 0 2.25rem;
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 0.7rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    background: color-mix(in srgb, var(--ghz-brand-color, #00c37a) 14%, transparent);
    border: 1px solid color-mix(in srgb, var(--ghz-brand-color, #00c37a) 30%, transparent);
    color: var(--ghz-brand-text, var(--ghz-brand-color, #00c37a));
}

.inv-modal-head-icon.is-info {
    background: var(--ghz-info-bg, rgba(59, 130, 246, 0.14));
    border-color: color-mix(in srgb, var(--ghz-info, #3b82f6) 30%, transparent);
    color: var(--ghz-info, #3b82f6);
}

.inv-modal-head-icon.is-warning {
    background: var(--ghz-warning-bg, rgba(234, 179, 8, 0.14));
    border-color: color-mix(in srgb, var(--ghz-warning, #eab308) 30%, transparent);
    color: var(--ghz-warning, #eab308);
}

.inv-modal-title {
    margin: 0;
    font-size: 1.05rem;
    line-height: 1.35;
    font-weight: 800;
    letter-spacing: -0.01em;
    color: var(--ghz-text-primary, #fff);
    overflow-wrap: anywhere;
}

.inv-modal-sub {
    margin: 0.15rem 0 0;
    font-size: 0.75rem;
    line-height: 1.45;
    color: var(--ghz-text-muted, #9ca3af);
}

/* Icon dùng chung (ngoài .ui-section-title) — trước đây không có rule
   nên icon trong header modal lịch sử IMEI bị co 13x19px, méo. */
.mkt-section-icon {
    width: 30px;
    height: 30px;
    border-radius: 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--ghz-input-bg, rgba(255, 255, 255, 0.06));
    color: var(--ghz-text-primary, #e5e7eb);
    font-size: 14px;
    flex-shrink: 0;
}

.mkt-section-icon.brand {
    background: color-mix(in srgb, var(--ghz-brand-color, #00c37a) 14%, transparent);
    color: var(--ghz-brand-text, var(--ghz-brand-color, #00c37a));
}

/* ---------- 2. Dòng nhãn – giá trị (lưới 2 cột) ---------- */
.inv-kv-scope .flex.justify-between {
    display: grid !important;
    grid-template-columns: minmax(6.5rem, 34%) minmax(0, 1fr);
    align-items: baseline;
    justify-content: normal;
    column-gap: 0.875rem;
    row-gap: 0.15rem;
    padding: 0.42rem 0;
    border-bottom: 1px solid color-mix(in srgb, var(--ghz-card-border, #2a2e35) 55%, transparent);
}

.inv-kv-scope .flex.justify-between:last-child {
    border-bottom: 0;
}

/* Nhãn: nhỏ, nhạt, không xuống dòng */
.inv-kv-scope .flex.justify-between > :first-child {
    font-size: 0.8rem !important;
    font-weight: 600 !important;
    color: var(--ghz-text-secondary, #9ca3af) !important;
    line-height: 1.4;
}

/* Giá trị: đậm, căn phải, không tràn */
.inv-kv-scope .flex.justify-between > :last-child {
    min-width: 0;
    text-align: right;
    overflow-wrap: anywhere;
    line-height: 1.45;
}

.inv-kv-scope .flex.justify-between > :last-child.text-lg,
.inv-kv-scope .flex.justify-between > :last-child.text-base {
    font-size: 0.9rem !important;
    font-weight: 700 !important;
}

.inv-kv-scope .flex.justify-between > :last-child.text-xs {
    font-size: 0.8rem !important;
}

/* Ô copy (IMEI) trong dòng kv */
.inv-kv-scope .flex.justify-between .copyable-field {
    justify-content: flex-end;
}

/* Dòng ghi chú dài: căn trái cho dễ đọc */
.inv-kv-scope .flex.justify-between > :last-child.whitespace-pre-wrap {
    text-align: left;
}

/* ---------- 3. Card con trong modal chi tiết ---------- */
.inv-detail-card {
    border-radius: 0.9rem;
    padding: 0.9rem 1rem;
    border: 1px solid var(--ghz-card-border, #2a2e35);
    background: color-mix(in srgb, var(--ghz-input-bg, rgba(255, 255, 255, 0.04)) 55%, transparent);
}

.inv-detail-card > .ui-subsection-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.65rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid color-mix(in srgb, var(--ghz-card-border, #2a2e35) 70%, transparent);
    font-size: 0.85rem;
    letter-spacing: 0.01em;
}

/* ---------- 4. Ảnh thiết bị trong modal ---------- */
#inventory-device-detail-body img[data-inventory-lightbox],
#inventory-recent-detail-body img[data-inventory-lightbox] {
    display: block;
    width: auto;
    max-width: 26rem !important;
    max-height: 11rem !important;
    margin: 0 auto;
    border-radius: 0.7rem;
    border: 1px solid var(--ghz-card-border, #2a2e35);
    background: var(--ghz-input-bg, rgba(255, 255, 255, 0.03));
    object-fit: contain;
}

/* ---------- 5. Khối thanh toán trong modal chi tiết ---------- */
.inv-pay-block {
    margin-top: 0.75rem;
    padding: 0.75rem 0.85rem;
    border-radius: 0.75rem;
    border: 1px solid var(--ghz-card-border, #2a2e35);
    background: color-mix(in srgb, var(--ghz-input-bg, rgba(255, 255, 255, 0.04)) 45%, transparent);
}

.inv-pay-block-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.55rem;
}

.inv-pay-block-title {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.72rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--ghz-text-secondary, #9ca3af);
}

.inv-pay-block-title i {
    color: var(--ghz-brand-text, var(--ghz-brand-color, #00c37a));
    font-size: 0.7rem;
}

.inv-pay-status {
    font-size: 0.7rem;
    font-weight: 800;
    padding: 0.15rem 0.55rem;
    border-radius: 999px;
    color: var(--ghz-warning-text, var(--ghz-warning, #fbbf24));
    background: var(--ghz-warning-bg, color-mix(in srgb, var(--ghz-warning, #fbbf24) 12%, transparent));
    border: 1px solid color-mix(in srgb, var(--ghz-warning, #fbbf24) 38%, transparent);
}

.inv-pay-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-bottom: 0.55rem;
}

.inv-pay-chips .inv-pay-chip {
    padding: 0.2rem 0.6rem;
    font-size: 0.7rem;
    pointer-events: none;
}

.inv-pay-rows {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.inv-pay-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    padding: 0.32rem 0.5rem;
    border-radius: 0.5rem;
    background: color-mix(in srgb, var(--ghz-text-primary, #fff) 4%, transparent);
}

.inv-pay-row-label {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.78rem;
    color: var(--ghz-text-secondary, #9ca3af);
    min-width: 0;
}

.inv-pay-row-label i {
    font-size: 0.68rem;
    color: var(--ghz-brand-text, var(--ghz-brand-color, #00c37a));
    flex-shrink: 0;
}

.inv-pay-row-value {
    font-size: 0.8rem;
    font-weight: 700;
    white-space: nowrap;
}

.inv-pay-row-value.is-paid {
    color: var(--ghz-warning-text, var(--ghz-warning, #fbbf24));
}

.inv-pay-row-value.is-unpaid {
    color: var(--ghz-text-muted, #9ca3af);
    font-weight: 500;
}

.inv-pay-total-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    margin-top: 0.55rem;
    padding-top: 0.5rem;
    border-top: 1px dashed color-mix(in srgb, var(--ghz-card-border, #2a2e35) 80%, transparent);
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--ghz-text-secondary, #9ca3af);
}

.inv-pay-total-row .inv-pay-total-value {
    font-size: 0.95rem;
    font-weight: 800;
    color: var(--ghz-warning-text, var(--ghz-warning, #fbbf24));
}

/* ---------- 6. Badge trạng thái ---------- */
.inv-status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.3rem 0.7rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 800;
    line-height: 1.25;
    border: 1px solid transparent;
}

.inv-status-badge.is-green {
    color: var(--ghz-success, #34d399);
    border-color: color-mix(in srgb, var(--ghz-success, #34d399) 40%, transparent);
    background: var(--ghz-success-bg, color-mix(in srgb, var(--ghz-success, #34d399) 12%, transparent));
}

.inv-status-badge.is-yellow {
    color: var(--ghz-warning-text, var(--ghz-warning, #fbbf24));
    border-color: color-mix(in srgb, var(--ghz-warning, #fbbf24) 40%, transparent);
    background: var(--ghz-warning-bg, color-mix(in srgb, var(--ghz-warning, #fbbf24) 12%, transparent));
}

.inv-status-badge.is-gray {
    color: var(--ghz-text-secondary, #e2e8f0);
    border-color: var(--ghz-card-border, #2a2e35);
    background: color-mix(in srgb, var(--ghz-text-muted, #9ca3af) 12%, transparent);
}

/* ---------- 6. Nút hành động trong modal chi tiết ---------- */
.inv-action-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 0.9rem;
    border-top: 1px solid var(--ghz-card-border, #2a2e35);
}

.inv-action-bar .grid {
    gap: 0.5rem;
}

/* ---------- 7. Modal lịch sử IMEI ---------- */
#inventory-imei-history-modal > .card {
    width: min(46rem, 100%) !important;
    max-width: 46rem !important;
}

#inventory-imei-history-modal .inventory-imei-history-body {
    padding: 0.9rem 1.1rem 1.25rem;
    max-height: calc(100dvh - 11rem);
}

/* Nền thẻ lịch sử: dùng --ghz-input-bg (nền Ô INPUT của theme) thay cho
   --ghz-card-glass-bg (gradient bán trong suốt).
   Lý do: ở theme sáng/pastel, --ghz-card-glass-bg là gradient pastel 50%
   alpha ⇒ màu nền thực tế bị pha loang, chữ nhãn (--ghz-text-muted) chỉ đạt
   ~2.1:1 – 4.5:1 ⇒ FAIL WCAG AA.
   --ghz-input-bg là nền dùng chung cho ô nhập của theme (đục hơn, đồng nhất
   với input trong modal) ⇒ tương phản ổn định ở mọi theme.
   KHÔNG override màu chữ .imei-history-title / .imei-history-time /
   .imei-history-section-count ở đây — ui-improvements.css đã gán màu accent
   theo loại thao tác (Nhập kho/Xuất kho/Sửa…) và màu text-muted riêng cho
   từng theme; override ở đây sẽ làm mất màu nhận diện đó. */
#inventory-imei-history-modal .imei-history-content {
    background: var(--ghz-input-bg, rgba(255, 255, 255, 0.06)) !important;
    border-color: var(--ghz-card-border, #2a2e35) !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
}

#inventory-imei-history-modal .ui-section-title.with-icon {
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
    padding: 0 !important;
    margin: 0 !important;
    font-size: 1.05rem !important;
    font-weight: 800 !important;
    color: var(--ghz-text-primary, #fff) !important;
}

.imei-history-section-title {
    display: flex !important;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.65rem !important;
    padding-bottom: 0.45rem;
    border-bottom: 1px solid color-mix(in srgb, var(--ghz-card-border, #2a2e35) 60%, transparent);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 0.72rem !important;
    font-weight: 800 !important;
    color: var(--ghz-text-primary, #e5e7eb) !important;
}

/* Icon trong tiêu đề mục lịch sử: ô vuông bo nhẹ, màu brand */
.imei-history-section-title > i {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 0.45rem;
    font-size: 0.7rem;
    background: color-mix(in srgb, var(--ghz-brand-color, #00c37a) 14%, transparent);
    border: 1px solid color-mix(in srgb, var(--ghz-brand-color, #00c37a) 28%, transparent);
    color: var(--ghz-brand-text, var(--ghz-brand-color, #00c37a));
    flex-shrink: 0;
}

.imei-history-section-count {
    background: color-mix(in srgb, var(--ghz-text-muted, #9ca3af) 16%, transparent) !important;
    color: var(--ghz-text-secondary, #9ca3af) !important;
}

/* ---------- 8. Modal chi tiết hoạt động gần đây ---------- */
#inventory-device-detail-modal > .card {
    width: min(48rem, 100%) !important;
    max-width: 48rem !important;
}

#inventory-recent-detail-modal > .card {
    width: min(56rem, 100%) !important;
    max-width: 56rem !important;
}

#inventory-recent-detail-body {
    align-items: start;
}

/* ---------- 9. Modal chi tiết Knox ---------- */
#inventory-knox-detail-modal > .card {
    width: min(40rem, 100%) !important;
    max-width: 40rem !important;
}

#inventory-knox-detail-modal .inventory-knox-detail-body {
    max-height: min(60vh, calc(100dvh - 14rem));
    overflow: auto;
    font-size: 0.78rem;
}

/* ---------- 10. Modal admin edit (sửa nhập / sửa xuất) ---------- */
#admin-edit-modal > .card {
    width: min(34rem, 100%) !important;
    max-width: 34rem !important;
}

#admin-edit-fields {
    display: flex !important;
    flex-direction: column;
    gap: 0.85rem !important;
}

#admin-edit-fields > * + * {
    margin-top: 0 !important;
}

#admin-edit-fields > div {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

#admin-edit-fields label {
    margin-bottom: 0 !important;
    font-size: 0.78rem !important;
    font-weight: 700 !important;
    color: var(--ghz-text-secondary, #9ca3af) !important;
}

#admin-edit-fields input:not([type="checkbox"]),
#admin-edit-fields select,
#admin-edit-fields textarea {
    font-size: 0.9rem;
}

/* Khối sửa hình thức thanh toán */
.inv-pay-edit {
    background: color-mix(in srgb, var(--ghz-input-bg, rgba(255, 255, 255, 0.04)) 60%, transparent);
    border-color: var(--ghz-card-border, #2a2e35);
}

.inv-pay-edit .inv-pay-edit-group > p {
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.68rem !important;
    font-weight: 800 !important;
    color: var(--ghz-text-muted, #9ca3af) !important;
}

/* ---------- 11. Modal bàn giao sửa chữa / bảo hành ---------- */
#inventory-repair-handover-modal > .card {
    width: min(34rem, 100%) !important;
    max-width: 34rem !important;
}

#inventory-repair-handover-form {
    gap: 0.85rem !important;
}

#inventory-repair-handover-form .inv-field > span {
    display: block;
    margin-bottom: 0.3rem;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--ghz-text-secondary, #9ca3af);
}

/* ---------- 12. Responsive ---------- */
@media (max-width: 640px) {
    .inv-modal-head {
        padding-bottom: 0.6rem;
        margin-bottom: 0.7rem;
    }

    .inv-modal-title {
        font-size: 0.98rem !important;
    }

    .inv-modal-sub {
        font-size: 0.7rem;
    }

    .inv-modal-head-icon {
        flex-basis: 2rem;
        width: 2rem;
        height: 2rem;
        font-size: 0.8rem;
    }

    /* 2 cột nhãn/giá trị chật trên mobile ⇒ xuống 1 cột dọc */
    .inv-kv-scope .flex.justify-between {
        grid-template-columns: minmax(0, 1fr);
        row-gap: 0.05rem;
        padding: 0.35rem 0;
    }

    .inv-kv-scope .flex.justify-between > :last-child {
        text-align: left;
    }

    .inv-kv-scope .flex.justify-between > :last-child.text-lg,
    .inv-kv-scope .flex.justify-between > :last-child.text-base {
        font-size: 0.85rem !important;
    }

    #inventory-device-detail-body img[data-inventory-lightbox],
    #inventory-recent-detail-body img[data-inventory-lightbox] {
        max-width: 100% !important;
        max-height: 8rem !important;
    }

    /* 2 cột ở modal hoạt động gần đây quá chật trên mobile */
    #inventory-recent-detail-body {
        grid-template-columns: minmax(0, 1fr) !important;
        gap: 0.6rem !important;
    }

    #inventory-imei-history-modal .inventory-imei-history-body {
        padding: 0.7rem 0.8rem 1rem;
    }
}
