/* ================================================================
   SAFETY LIBRARY — safety_library.css
   vinapro_b2b theme | NukeViet Page Module
   Layout theo screenshot SafetyArch app
   Dùng --b2b-* tokens từ b2b-theme.css
   ================================================================ */

/* ── RESET & BASE ────────────────────────────────────────────── */
.kb-wrap { font-family: var(--b2b-font-base); color: var(--b2b-gray-800); }

/* ── HEADER ──────────────────────────────────────────────────── */
.kb-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 0 12px; margin-bottom: 12px;
    border-bottom: 1px solid var(--b2b-gray-200);
}
.kb-header__left { display: flex; align-items: center; gap: 14px; }
.kb-header__icon {
    width: 44px; height: 44px; display: flex; align-items: center; justify-content: center;
    background: var(--b2b-primary); border-radius: 10px; color: #fff; flex-shrink: 0;
}
.kb-header__title {
    font-size: 18px; font-weight: 800; color: var(--b2b-primary);
    letter-spacing: .02em; margin: 0; text-transform: uppercase;
}
.kb-header__sub { font-size: 11px; color: var(--b2b-gray-400); margin: 2px 0 0; letter-spacing: .04em; }

/* ── SEARCH ──────────────────────────────────────────────────── */
.kb-search-wrap { margin-bottom: 16px; }
.kb-search {
    display: flex; align-items: center; gap: 10px;
    background: #fff; border: 1.5px solid var(--b2b-gray-200);
    border-radius: 10px; padding: 0 16px; height: 46px;
    box-shadow: var(--b2b-shadow-sm);
    transition: border-color .15s, box-shadow .15s;
    max-width: 680px; margin: 0 auto;
}
.kb-search:focus-within {
    border-color: var(--b2b-primary);
    box-shadow: 0 0 0 3px rgba(26,58,92,.08);
}
.kb-search__ico { color: var(--b2b-gray-400); flex-shrink: 0; }
.kb-search__input {
    flex: 1; border: none; outline: none; background: transparent;
    font-family: var(--b2b-font-base); font-size: 14px; color: var(--b2b-gray-800);
}
.kb-search__input::placeholder { color: var(--b2b-gray-400); }

/* ── TABS 2 HÀNG ─────────────────────────────────────────────
   flex-wrap: wrap tự tạo 2 hàng khi tổng width tab > container
   Không dùng scrollbar — wrap là đúng theo design
   ─────────────────────────────────────────────────────────── */
.kb-tabs {
    background: #fff;
    border: 1.5px solid var(--b2b-gray-200);
    border-radius: 12px; margin-bottom: 20px;
    box-shadow: var(--b2b-shadow-sm);
    overflow: hidden;
}
.kb-tabs__grid {
    display: flex;
    flex-wrap: wrap;    /* ← key: tabs tự xuống hàng 2 */
    padding: 6px 8px; gap: 4px;
}
.kb-tab {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 7px 14px; border-radius: 8px;
    background: transparent; border: 1.5px solid transparent;
    cursor: pointer; font-family: var(--b2b-font-base);
    font-size: 12.5px; font-weight: 500; color: var(--b2b-gray-600);
    white-space: nowrap; text-decoration: none;
    transition: all .15s ease;
    outline: none; line-height: 1;
}
.kb-tab:hover { background: var(--b2b-gray-50); color: var(--b2b-primary); text-decoration: none; }
.kb-tab.active,
.kb-tab--all-active {
    background: rgba(26,58,92,.08);
    border-color: var(--b2b-primary);
    color: var(--b2b-primary);
    font-weight: 700;
}
.kb-tab__ico { font-size: 14px; line-height: 1; }
.kb-tab__lbl { }

/* ── CONTENT HEADER ──────────────────────────────────────────── */
.kb-content-header {
    display: flex; align-items: center; gap: 12px;
    padding: 16px 0 14px;
    border-bottom: 2px solid var(--b2b-gray-100);
    margin-bottom: 16px;
}
.kb-content-header__ico { color: var(--b2b-primary); flex-shrink: 0; }
.kb-content-header__title {
    font-size: 20px; font-weight: 800; color: var(--b2b-primary);
    margin: 0; text-transform: uppercase; letter-spacing: .01em;
}

/* ── MAIN BODY GRID: 65% + 35% ──────────────────────────────── */
.kb-body-grid {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 20px;
    align-items: start;
}

/* Khi không có sidebar (block không được parse) → full width */
.kb-body-grid:not(:has(.kb-col-side)) {
    grid-template-columns: 1fr;
}

.kb-col-main { min-width: 0; }

/* ── BẢNG THUẬT NGỮ ──────────────────────────────────────────
   Style lại table trong {CONTENT.bodytext} (CKEditor output)
   Cột: THUẬT NGỮ | ĐỊNH NGHĨA | VÍ DỤ | (CHIA SẺ nếu có)
   ─────────────────────────────────────────────────────────── */
.kb-terms { }

.kb-terms .bodytext > h2,
.kb-terms #page-bodyhtml > h2 {
    display: none; /* Tiêu đề section đã hiển thị ở kb-content-header */
}

/* Section label (Thuật ngữ & Định nghĩa) */
.kb-terms .bodytext > *:first-child,
.kb-terms #page-bodyhtml > *:first-child {
    /* Hiển thị section header nếu có */
}

.kb-terms .bodytext table,
#page-bodyhtml table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin: 0;
    font-size: 13px;
    background: #fff;
    border: 1.5px solid var(--b2b-gray-200);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: var(--b2b-shadow-sm);
}

/* Header */
.kb-terms .bodytext table thead,
#page-bodyhtml table thead { display: table-header-group; }

.kb-terms .bodytext table thead tr:has(th:empty),
#page-bodyhtml table thead tr:has(td:empty) { display: none; }

.kb-terms .bodytext table th,
#page-bodyhtml table th {
    padding: 9px 12px;
    font-size: 10px; font-weight: 700;
    text-transform: uppercase; letter-spacing: .08em;
    color: var(--b2b-gray-500);
    background: var(--b2b-gray-50);
    border-bottom: 1.5px solid var(--b2b-gray-200);
    text-align: left; white-space: nowrap;
}

.kb-terms .bodytext table td,
#page-bodyhtml table td {
    padding: 12px 12px;
    vertical-align: top;
    border-bottom: 1px solid var(--b2b-gray-100);
    font-size: 13px; line-height: 1.6; color: var(--b2b-gray-800);
}

.kb-terms .bodytext table tbody tr:last-child td,
#page-bodyhtml table tbody tr:last-child td { border-bottom: none; }

.kb-terms .bodytext table tbody tr:hover td,
#page-bodyhtml table tbody tr:hover td {
    background: rgba(26,58,92,.03);
    transition: background .1s;
}

/* Cột 1: Thuật ngữ — navy bold + EN italic */
.kb-terms .bodytext table td:first-child,
#page-bodyhtml table td:first-child {
    font-weight: 700; color: var(--b2b-gray-900);
    width: 22%; min-width: 140px;
}
.kb-terms .bodytext table td:first-child em,
#page-bodyhtml table td:first-child em {
    display: block; font-style: normal; font-weight: 400;
    font-size: 11px; color: var(--b2b-gray-400); margin-top: 2px;
    font-family: var(--b2b-font-mono, monospace);
}

/* Cột 2: Định nghĩa */
.kb-terms .bodytext table td:nth-child(2),
#page-bodyhtml table td:nth-child(2) { width: 42%; }

/* Cột 3: Ví dụ thực tế — italic amber */
.kb-terms .bodytext table td:nth-child(3),
#page-bodyhtml table td:nth-child(3) {
    font-size: 12px; color: var(--b2b-gray-500);
    font-style: italic; width: 28%;
}
.kb-terms .bodytext table td:nth-child(3) em,
#page-bodyhtml table td:nth-child(3) em {
    font-style: normal; color: var(--b2b-amber, #d97706);
}

/* Cột 4: Chia sẻ (nếu có) */
.kb-terms .bodytext table td:nth-child(4),
#page-bodyhtml table td:nth-child(4) {
    width: 8%; text-align: center; color: var(--b2b-gray-400); font-size: 12px;
}

/* Heading phân section */
.kb-terms .bodytext h2, #page-bodyhtml h2 {
    font-size: 15px; font-weight: 700; color: var(--b2b-primary);
    margin: 20px 0 10px; padding: 7px 12px;
    background: rgba(26,58,92,.06);
    border-left: 3px solid var(--b2b-primary);
    border-radius: 0 6px 6px 0;
}
.kb-terms .bodytext p, #page-bodyhtml p { margin-bottom: 8px; }
.kb-terms .bodytext ul, #page-bodyhtml ul { list-style: disc; padding-left: 1.5em; margin-bottom: 8px; }

/* ── SIDEBAR (35%) ───────────────────────────────────────────── */
.kb-col-side {
    display: flex; flex-direction: column; gap: 14px;
    position: sticky; top: 16px;
}

.kb-side-card {
    background: #fff;
    border: 1.5px solid var(--b2b-gray-200);
    border-radius: 12px;
    box-shadow: var(--b2b-shadow-sm);
    overflow: hidden;
}

.kb-side-card__head {
    display: flex; align-items: center; gap: 8px;
    padding: 12px 16px; font-size: 13.5px; font-weight: 700;
    color: var(--b2b-gray-900);
    border-bottom: 1px solid var(--b2b-gray-100);
    background: var(--b2b-gray-50);
}

.kb-side-card__body { padding: 14px 16px; }

/* Checklist */
.kb-side-card--checklist .kb-side-card__head { color: var(--b2b-primary); }

.kb-checklist { list-style: none; padding: 0; margin: 0 0 14px; display: flex; flex-direction: column; gap: 10px; }
.kb-checklist__item { display: flex; align-items: flex-start; gap: 8px; }
.kb-chk {
    width: 16px; height: 16px; margin-top: 1px; flex-shrink: 0; cursor: pointer;
    accent-color: var(--b2b-success); border-radius: 4px;
}
.kb-chk__label { font-size: 12.5px; color: var(--b2b-gray-700); cursor: pointer; margin: 0; line-height: 1.45; }
.kb-chk:checked + .kb-chk__label { color: var(--b2b-gray-400); text-decoration: line-through; }

.kb-progress-wrap { display: flex; flex-direction: column; gap: 5px; }
.kb-progress { height: 6px; background: var(--b2b-gray-100); border-radius: 999px; overflow: hidden; }
.kb-progress__fill { height: 100%; background: var(--b2b-success); border-radius: 999px; transition: width .3s ease; width: 0%; }
.kb-progress__text { font-size: 11px; color: var(--b2b-gray-400); text-align: right; }

/* AI Tip */
.kb-side-card--ai .kb-side-card__head { color: #7c3aed; }
.kb-ai-tip {
    font-size: 13px; line-height: 1.65; color: var(--b2b-gray-700);
    font-style: italic; margin: 0; padding: 0; border: none;
}

/* ── ALERT ───────────────────────────────────────────────────── */
.kb-alert { display: flex; align-items: center; gap: 8px; padding: 10px 14px; margin-bottom: 14px; background: #fff5f5; border: 1px solid #fecaca; border-radius: 8px; color: var(--b2b-error); font-size: 13px; font-weight: 500; }

/* ── SOCIAL, FIGURES, LEAD ───────────────────────────────────── */
.kb-social { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.kb-social__item { display: flex; }
.kb-lead { font-size: 14px; color: var(--b2b-gray-700); line-height: 1.7; padding: 11px 15px; margin-bottom: 16px; background: rgba(26,58,92,.05); border-left: 3px solid var(--b2b-primary); border-radius: 0 6px 6px 0; }
.kb-fig { margin: 0 0 14px; }
.kb-fig--left { float: left; margin-right: 16px; cursor: pointer; }
.kb-fig--center { float: none; clear: both; text-align: center; cursor: pointer; }
.kb-fig__img { max-width: 100%; border-radius: 8px; border: var(--b2b-border); }
.kb-fig__cap { font-size: 11px; color: var(--b2b-gray-400); text-align: center; margin-top: 4px; }

/* ── ADMIN BAR ───────────────────────────────────────────────── */
.kb-admin-bar { padding: 12px 0; border-top: 1px solid var(--b2b-gray-100); margin-top: 16px; }

/* ── RELATED ─────────────────────────────────────────────────── */
.kb-related-card { background: #fff; border: 1.5px solid var(--b2b-gray-200); border-radius: 12px; box-shadow: var(--b2b-shadow-sm); overflow: hidden; margin-top: 16px; }
.kb-related-card__head { padding: 10px 16px; border-bottom: 1px solid var(--b2b-gray-100); font-size: 13px; font-weight: 600; color: var(--b2b-gray-800); }
.kb-related-list { list-style: none; padding: 4px 0; margin: 0; }
.kb-related-list li { border-bottom: 1px solid var(--b2b-gray-100); }
.kb-related-list li:last-child { border-bottom: none; }
.kb-related-link { display: flex; align-items: flex-start; gap: 6px; padding: 8px 16px; text-decoration: none; color: var(--b2b-gray-600); font-size: 12.5px; line-height: 1.45; transition: all .14s; }
.kb-related-link:hover { background: rgba(26,58,92,.04); color: var(--b2b-primary); text-decoration: none; }
.kb-related-arr { color: var(--b2b-primary); flex-shrink: 0; font-size: 16px; line-height: 1.2; }

/* ── COMMENT ─────────────────────────────────────────────────── */
.kb-comment-wrap { margin-top: 20px; }
.kb-section-head { font-size: 14px; font-weight: 600; color: var(--b2b-gray-800); padding: 12px 0; border-bottom: 1px solid var(--b2b-gray-100); margin-bottom: 14px; }

/* ── LIST VIEW ───────────────────────────────────────────────── */
.kb-list-wrap { }
.kb-list-card { background: #fff; border: 1.5px solid var(--b2b-gray-200); border-radius: 12px; box-shadow: var(--b2b-shadow-sm); padding: 16px 20px; margin-bottom: 12px; display: flex; gap: 16px; align-items: flex-start; }
.kb-list-card__thumb { flex-shrink: 0; }
.kb-list-card__img { width: 80px; height: 80px; object-fit: cover; border-radius: 8px; border: var(--b2b-border); }
.kb-list-card__body { flex: 1; min-width: 0; }
.kb-list-card__title { font-size: 15px; font-weight: 700; margin: 0 0 6px; }
.kb-list-card__title a { color: var(--b2b-primary); text-decoration: none; }
.kb-list-card__title a:hover { text-decoration: underline; }
.kb-list-card__desc { font-size: 13px; color: var(--b2b-gray-600); margin: 0 0 6px; line-height: 1.55; }
.kb-list-card__admin { display: flex; gap: 6px; }
.kb-pagination { display: flex; justify-content: center; padding: 12px 0; }

/* ── SEARCH HIGHLIGHT ────────────────────────────────────────── */
.kb-search-highlight { background: #fef9c3; border-radius: 2px; padding: 0 1px; }
.kb-row-hidden { display: none; }

/* ── RESPONSIVE ──────────────────────────────────────────────── */
@media (max-width: 1024px) {
    .kb-body-grid { grid-template-columns: 1fr; }
    .kb-col-side { position: static; }
}

@media (max-width: 767px) {
    .kb-header__title { font-size: 14px; }
    .kb-tabs__grid { gap: 3px; padding: 4px; }
    .kb-tab { padding: 6px 10px; font-size: 11.5px; gap: 4px; }
    .kb-content-header__title { font-size: 15px; }
    .kb-list-card { flex-direction: column; }
    .kb-list-card__img { width: 100%; height: 160px; }

    /* Bảng: scroll ngang */
    .kb-terms .bodytext table, #page-bodyhtml table {
        display: block; overflow-x: auto; -webkit-overflow-scrolling: touch;
        white-space: nowrap; border-radius: 0;
    }
    .kb-terms .bodytext table td, #page-bodyhtml table td {
        white-space: normal; min-width: 120px;
    }
}

@media print {
    .kb-tabs, .kb-col-side, .kb-admin-bar, .kb-social, .kb-search-wrap { display: none !important; }
    .kb-body-grid { grid-template-columns: 1fr; }
}
