/* ════════════════════════════════════════════════════════════════════
   QUẢN TRỊ KHO (/warehouse)
   CSS tập trung (rule dự án: 100% ở wwwroot/css, không scoped/inline).
   Dùng token --ag-* / --mud-palette-* để hợp cả Dark/Light. Màu HEX chỉ
   dùng cho NGỮ NGHĨA rủi ro (âm = đỏ, cảnh báo = cam, tốt = xanh).
   ════════════════════════════════════════════════════════════════════ */

.whs-page {
    --whs-neg: #ef4444;     /* tồn âm / lệch giảm */
    --whs-pos: #22c55e;     /* lệch tăng / điều chỉnh dương */
    --whs-warn: #f59e0b;    /* cảnh báo / thiếu giá vốn */
    --whs-line: rgba(var(--ag-fg-rgb), 0.08);
}

.whs-title {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Panel tab: chừa khoảng thở, không tràn ngang trên mobile. */
.whs-panel {
    min-height: 320px;
    overflow-x: hidden;
}

/* ── Loading / Empty dùng chung ─────────────────────────────────────── */
.whs-tab-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 36px 0;
}

.whs-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 40px 16px;
    text-align: center;
    color: rgba(var(--ag-fg-rgb), 0.5);
}

.whs-empty .mud-icon-root {
    font-size: 2.4rem;
    opacity: 0.7;
}

.whs-empty--sm {
    padding: 20px 12px;
    font-size: 0.85rem;
}

.whs-empty--ok {
    color: var(--whs-pos);
}

/* ════════════════════════════════════════════════════════════════════
   TAB 1 — Tổng quan (scorecard)
   ════════════════════════════════════════════════════════════════════ */
.whs-overview-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.82rem;
    color: rgba(var(--ag-fg-rgb), 0.6);
}

.whs-overview-meta .mud-icon-root {
    font-size: 1rem;
}

.whs-score-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
}

.whs-score {
    position: relative;
    padding: 14px 16px;
    border-radius: 12px;
    background: rgba(var(--ag-fg-rgb), 0.03);
    border: 1px solid var(--whs-line);
    transition: transform .16s ease, box-shadow .16s ease, border-color .16s ease;
}

.whs-score--click {
    cursor: pointer;
}

.whs-score--click:hover {
    transform: translateY(-2px);
    border-color: rgba(var(--ag-fg-rgb), 0.18);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
}

.whs-score--click:focus-visible {
    outline: 2px solid var(--mud-palette-primary);
    outline-offset: 2px;
}

.whs-score__top {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
}

.whs-score__label {
    font-size: 0.78rem;
    font-weight: 600;
    color: rgba(var(--ag-fg-rgb), 0.6);
    flex: 1 1 auto;
}

.whs-score__go {
    font-size: 1rem !important;
    opacity: 0.45;
}

.whs-score__value {
    font-size: 1.5rem;
    font-weight: 800;
    line-height: 1.1;
    letter-spacing: -0.01em;
}

.whs-score__hint {
    margin-top: 4px;
    font-size: 0.74rem;
    color: rgba(var(--ag-fg-rgb), 0.45);
}

/* Accent theo mức độ — viền trái + màu số/icon. */
.whs-tone-error { border-left: 3px solid var(--whs-neg); }
.whs-tone-error .whs-score__value,
.whs-tone-error .whs-score__icon { color: var(--whs-neg); }

.whs-tone-warning { border-left: 3px solid var(--whs-warn); }
.whs-tone-warning .whs-score__value,
.whs-tone-warning .whs-score__icon { color: var(--whs-warn); }

.whs-tone-success .whs-score__icon { color: var(--whs-pos); }

.whs-tone-info .whs-score__icon { color: var(--mud-palette-info); }

/* ════════════════════════════════════════════════════════════════════
   TAB — Đánh giá (sức khỏe kho + ABC + top giá trị + dead stock)
   ════════════════════════════════════════════════════════════════════ */
.whs-eval-hero {
    display: flex;
    gap: 24px;
    align-items: stretch;
    flex-wrap: wrap;
}

/* Khối điểm tổng — to, rõ, màu theo xếp loại. */
.whs-eval-score {
    flex: 0 0 180px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 8px 16px;
    border-radius: 14px;
    background: rgba(var(--ag-fg-rgb), 0.03);
    border: 1px solid var(--whs-line);
}

.whs-eval-score__num {
    font-size: 3rem;
    font-weight: 900;
    line-height: 1;
    letter-spacing: -0.02em;
}

.whs-eval-score__num span {
    font-size: 1rem;
    font-weight: 700;
    opacity: 0.5;
    margin-left: 2px;
}

.whs-eval-score__cap {
    margin-top: 8px;
    font-size: 0.76rem;
    color: rgba(var(--ag-fg-rgb), 0.5);
}

/* Màu số điểm tổng theo xếp loại (tái dùng token rủi ro). */
.whs-eval-score.whs-tone-success .whs-eval-score__num { color: var(--whs-pos); }
.whs-eval-score.whs-tone-warning .whs-eval-score__num { color: var(--whs-warn); }
.whs-eval-score.whs-tone-error   .whs-eval-score__num { color: var(--whs-neg); }
.whs-eval-score.whs-tone-info    .whs-eval-score__num { color: var(--mud-palette-info); }

/* Danh sách yếu tố cấu thành. */
.whs-eval-factors {
    flex: 1 1 380px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
}

.whs-eval-factor__head {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 4px;
}

.whs-eval-factor__label {
    font-weight: 600;
    font-size: 0.86rem;
    flex: 1 1 auto;
}

.whs-eval-factor__w {
    font-size: 0.72rem;
    color: rgba(var(--ag-fg-rgb), 0.4);
}

.whs-eval-factor__score {
    font-weight: 800;
    font-size: 0.95rem;
    min-width: 28px;
    text-align: right;
}

.whs-eval-factor__score.whs-tone-success { color: var(--whs-pos); }
.whs-eval-factor__score.whs-tone-warning { color: var(--whs-warn); }
.whs-eval-factor__score.whs-tone-error   { color: var(--whs-neg); }

.whs-eval-factor__detail {
    margin-top: 3px;
    font-size: 0.74rem;
    color: rgba(var(--ag-fg-rgb), 0.5);
}

/* 2 cột chart: ABC + Top giá trị. */
.whs-eval-charts {
    display: grid;
    grid-template-columns: 1fr 1.4fr;
    gap: 12px;
}

.whs-eval-chart { min-width: 0; }

.whs-eval-chart__title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 700;
    font-size: 0.86rem;
    margin-bottom: 6px;
}

.whs-eval-abc-table th {
    font-size: 0.74rem;
    color: rgba(var(--ag-fg-rgb), 0.5);
    font-weight: 600;
}

.whs-eval-abc-table td { font-size: 0.82rem; }
.whs-eval-abc-table .text-right { text-align: right; }

/* Callout hàng chết. */
.whs-eval-dead {
    display: flex;
    align-items: center;
    gap: 14px;
}

.whs-eval-dead__icon { color: rgba(var(--ag-fg-rgb), 0.4); }
.whs-eval-dead--warn .whs-eval-dead__icon { color: var(--whs-warn); }

.whs-eval-dead__title {
    font-weight: 700;
    font-size: 0.88rem;
}

.whs-eval-dead__body {
    font-size: 0.82rem;
    color: rgba(var(--ag-fg-rgb), 0.7);
    margin-top: 2px;
}

.whs-eval-dead__main { flex: 1 1 auto; min-width: 0; }
.whs-eval-dead__go { color: rgba(var(--ag-fg-rgb), 0.35); }

.whs-eval-dead--click { cursor: pointer; transition: border-color .16s ease, transform .16s ease; }
.whs-eval-dead--click:hover { transform: translateY(-1px); border-color: rgba(var(--ag-fg-rgb), 0.18); }
.whs-eval-dead--click:focus-visible { outline: 2px solid var(--mud-palette-primary); outline-offset: 2px; }

/* Hàng ABC bấm được → sang tab Định giá. */
.whs-eval-abc-row { cursor: pointer; }
.whs-eval-abc-row:hover td { background: rgba(var(--ag-fg-rgb), 0.05); }

@media (max-width: 900px) {
    .whs-eval-charts { grid-template-columns: 1fr; }
    .whs-eval-score { flex-basis: 100%; }
}

/* ════════════════════════════════════════════════════════════════════
   Bảng dùng chung (Tồn / Định giá / Kiểm kê / Posting / Cảnh báo)
   ════════════════════════════════════════════════════════════════════ */
.whs-toolbar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    width: 100%;
}

.whs-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.whs-search {
    max-width: 240px;
}

.whs-table .whs-mono {
    font-family: ui-monospace, "SFMono-Regular", "Consolas", monospace;
    font-size: 0.82rem;
}

.whs-neg { color: var(--whs-neg); font-weight: 700; }
.whs-pos { color: var(--whs-pos); font-weight: 700; }
.whs-muted { color: rgba(var(--ag-fg-rgb), 0.4); }

.whs-foot {
    font-weight: 800;
    background: rgba(var(--ag-fg-rgb), 0.04);
}

/* Chip phẳng nhỏ gọn dùng trong bảng/list. */
.whs-chip-flat.mud-chip {
    height: 20px;
    font-size: 0.7rem;
    margin: 0;
}

/* Ô nhập số đếm — gọn, không spinner, không margin dọc. */
.whs-count-input {
    max-width: 110px;
    margin: 0 0 0 auto;
}

.whs-count-input .mud-input-slot { text-align: right; }
.whs-count-input .mud-input-control { margin-top: 0; }

/* ════════════════════════════════════════════════════════════════════
   TAB 3/4 — Master-detail (Kiểm kê / Posting)
   ════════════════════════════════════════════════════════════════════ */
.whs-stk-list {
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 320px);
}

.whs-stk-list__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 2px 6px 6px;
    border-bottom: 1px solid var(--whs-line);
    margin-bottom: 4px;
}

.whs-stk-items {
    overflow-y: auto;
    padding: 0;
}

.whs-stk-item {
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background .14s ease, border-color .14s ease;
}

.whs-stk-item:hover {
    background: rgba(var(--ag-fg-rgb), 0.05);
}

.whs-stk-item:focus-visible {
    outline: 2px solid var(--mud-palette-primary);
    outline-offset: -2px;
}

.whs-stk-item--active {
    background: rgba(var(--mud-palette-primary-rgb), 0.12);
    border-color: rgba(var(--mud-palette-primary-rgb), 0.4);
}

.whs-stk-item__top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
}

.whs-stk-item__name {
    font-weight: 600;
    font-size: 0.86rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.whs-stk-item__meta {
    margin-top: 2px;
    font-size: 0.74rem;
    color: rgba(var(--ag-fg-rgb), 0.55);
    display: flex;
    gap: 5px;
    flex-wrap: wrap;
}

.whs-stk-detail__head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.whs-stk-detail__actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.whs-stk-detail__bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 6px 0;
}

.whs-pos-locked { color: var(--whs-warn); }

/* ════════════════════════════════════════════════════════════════════
   TAB 6 — Cảnh báo
   ════════════════════════════════════════════════════════════════════ */
.whs-alert-group__head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.whs-alert-table {
    background: transparent;
}

/* ════════════════════════════════════════════════════════════════════
   Responsive ~390px — không tràn ngang; scorecard + master-detail xếp dọc.
   ════════════════════════════════════════════════════════════════════ */
@media (max-width: 1100px) {
    .whs-score-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 600px) {
    .whs-score-grid { grid-template-columns: 1fr; }
    .whs-search { max-width: 100%; flex: 1 1 100%; }
    .whs-toolbar { gap: 6px; }
    .whs-stk-list { max-height: none; }
    .whs-stk-items { max-height: 280px; }
    .whs-stk-detail__head { flex-direction: column; }
    .whs-stk-detail__actions { width: 100%; }
    .whs-count-input { max-width: 100%; }
}
