/* ============================================================================
   MIRACLE KNOWLEDGEBASE  ·  reading shell (layered on mds.css)
   ----------------------------------------------------------------------------
   The KB-specific layer: the topic/TOC sidebar, the landing search-hero +
   subject tiles, search results, the article + "On this page" aside, the
   branded landing band, and the WordPress semantic vocabulary the render
   normalizer whitelists (lvl- exp- ppe- is- cell- kb-). The generic reading
   mode (.mds-prose) itself stays in mds.css core — it is used outside the KB
   too (Home, Placeholder). Classes keep their mds- prefix; only the file
   boundary marks the layering. Linked in index.html after mds.css + shell.css.
   ============================================================================ */
:root { --mds-kbnav-w: 260px; }

.mds-kb { display: flex; align-items: flex-start; min-height: 100%; background: var(--mds-canvas); }
.mds-kb__main { flex: 1; min-width: 0; }

/* ---- topic sidebar (table of contents) ---- */
.mds-kbnav { flex: none; width: var(--mds-kbnav-w); align-self: flex-start;
    position: sticky; top: 0; max-height: 100vh; overflow-y: auto;
    background: var(--mds-surface); border-right: 1px solid var(--mds-line); padding: var(--mds-space-4) 0; }
/* search field on top — mirrors the cargo selector field look */
.mds-kbnav__search { display: flex; align-items: center; gap: var(--mds-space-2);
    margin: 0 var(--mds-space-4) var(--mds-space-4); padding: 8px 12px;
    background: var(--mds-surface); border: 1px solid var(--mds-line); border-radius: var(--mds-radius-lg); }
.mds-kbnav__search:focus-within { border-color: var(--mds-accent); }
.mds-kbnav__search i { color: var(--mds-muted); }
.mds-kbnav__search input { flex: 1; border: 0; outline: 0; background: none; font: inherit;
    font-size: var(--mds-text-sm); color: var(--mds-title); }
/* the tree */
.mds-kbtree { list-style: none; margin: 0; padding: 0; }
.mds-kbtree__group { padding: var(--mds-space-3) var(--mds-space-4) var(--mds-space-1);
    font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--mds-muted); }
.mds-kbtree__item { display: block; padding: 6px var(--mds-space-4); color: var(--mds-title);
    text-decoration: none; font-size: var(--mds-text-sm); line-height: 1.4; }
.mds-kbtree__item:hover { background: var(--mds-tint); }
.mds-kbtree__item.is-active { background: var(--mds-tint); font-weight: 700;
    box-shadow: inset 3px 0 0 var(--mds-accent); }
.mds-kbtree__item--sub { padding-left: var(--mds-space-7); color: var(--mds-text); }

/* ---- landing: search hero + subject tiles (tiles reuse .mds-cards/.mds-card) ---- */
.mds-kbhero { display: flex; align-items: center; gap: var(--mds-space-2);
    max-width: 560px; margin: 0 0 var(--mds-space-6); padding: 12px var(--mds-space-4);
    background: var(--mds-surface); border: 1px solid var(--mds-accent); border-radius: var(--mds-radius-lg); }
.mds-kbhero i { color: var(--mds-accent); font-size: var(--mds-text-lg); }
.mds-kbhero input { flex: 1; border: 0; outline: 0; background: none; font: inherit;
    font-size: var(--mds-text-lg); color: var(--mds-title); }
.mds-tile { display: block; text-decoration: none; color: inherit; }
.mds-tile__desc { margin: var(--mds-space-1) 0 0; color: var(--mds-muted);
    font-size: var(--mds-text-sm); line-height: 1.45; }

/* ---- search results list ---- */
.mds-kbresult { display: block; padding: var(--mds-space-3) 0;
    border-bottom: 1px solid var(--mds-line); text-decoration: none; }
.mds-kbresult__title { color: var(--mds-accent-ink); font-weight: 700; font-size: var(--mds-text-lg); }
.mds-kbresult__crumb { margin-left: var(--mds-space-2); color: var(--mds-muted); font-size: var(--mds-text-xs); }
.mds-kbresult__snip { margin: var(--mds-space-1) 0 0; color: var(--mds-text); line-height: 1.5; }
.mds-kbresult mark { background: var(--mds-tint); color: var(--mds-accent-ink); padding: 0 2px; }

/* ---- sidebar: home link + collapsible tree sections (parents with children) ---- */
.mds-kbnav__home { display: flex; align-items: center; gap: var(--mds-space-2);
    margin: 0 var(--mds-space-4) var(--mds-space-3); color: var(--mds-title);
    text-decoration: none; font-size: var(--mds-text-sm); font-weight: 700; }
.mds-kbnav__home i { color: var(--mds-accent); }
.mds-kbnav__home:hover { color: var(--mds-accent-ink); }

.mds-kbsec { border: 0; }
.mds-kbsec__head { display: flex; align-items: center; cursor: pointer; list-style: none;
    padding: 6px var(--mds-space-4); }
.mds-kbsec__head::-webkit-details-marker { display: none; }
.mds-kbsec__head:hover { background: var(--mds-tint); }
.mds-kbsec__link { flex: 1; color: var(--mds-title); text-decoration: none;
    font-size: var(--mds-text-sm); font-weight: 600; line-height: 1.4; }
.mds-kbsec__link.is-active { color: var(--mds-accent-ink); }
.mds-kbsec__chev { color: var(--mds-muted); font-size: 10px; transition: transform .15s ease; }
.mds-kbsec[open] > .mds-kbsec__head .mds-kbsec__chev { transform: rotate(180deg); }
/* nested items indent one step per level */
.mds-kbsec__body .mds-kbtree__item,
.mds-kbsec__body .mds-kbsec__head { padding-left: var(--mds-space-7); }
.mds-kbsec__body .mds-kbsec__body .mds-kbtree__item,
.mds-kbsec__body .mds-kbsec__body .mds-kbsec__head { padding-left: var(--mds-space-8); }

/* ---- landing subject tiles: hover affordance on the flat .mds-card ---- */
.mds-tile { transition: transform .12s ease; }
.mds-tile:hover { transform: translateY(-2px); }
.mds-tile:hover .mds-card__icon { background: var(--mds-accent); color: var(--mds-on-accent); }
.mds-tile:hover .mds-card__head { color: var(--mds-accent-ink); }

/* ---- article + right aside ("On this page" jump list + Related topics) ---- */
.mds-kbarticle { display: flex; gap: var(--mds-space-8); align-items: flex-start; }
.mds-kbarticle > .mds-prose { flex: 1 1 auto; min-width: 0; }
.mds-kbaside { flex: none; width: 220px; position: sticky; top: var(--mds-space-4);
    border-left: 1px solid var(--mds-line); padding-left: var(--mds-space-5); }
.mds-kbaside__head { margin: 0 0 var(--mds-space-2); font-size: 11px; font-weight: 700;
    letter-spacing: .06em; text-transform: uppercase; color: var(--mds-muted); }
.mds-kbaside__head--spaced { margin-top: var(--mds-space-6); }
.mds-kbaside__link { display: block; padding: var(--mds-space-1) 0; color: var(--mds-accent-ink);
    text-decoration: none; font-size: var(--mds-text-sm); line-height: 1.4; }
.mds-kbaside__link:hover { text-decoration: underline; }
/* "On this page" — a quiet left-rail of section jump links */
.mds-kbonpage__item { display: block; cursor: pointer; padding: 3px 0 3px var(--mds-space-3);
    border-left: 2px solid var(--mds-line); color: var(--mds-text); text-decoration: none;
    font-size: var(--mds-text-sm); line-height: 1.35; }
.mds-kbonpage__item:hover { color: var(--mds-accent-ink); border-left-color: var(--mds-accent); }
.mds-kbonpage__item--sub { padding-left: var(--mds-space-6); color: var(--mds-muted); }
@media (max-width: 1100px) {
    .mds-kbarticle { flex-direction: column; gap: var(--mds-space-5); }
    .mds-kbaside { width: auto; position: static; border-left: 0; padding-left: 0;
        border-top: 1px solid var(--mds-line); padding-top: var(--mds-space-4); }
}

/* ── KB reading tables ──────────────────────────────────────────────────────
   The reference work uses a light cell GRID (every cell bordered) sized to its
   content at 14px — readable for the risk matrices, PPE and comparison tables.
   The app's general .mds-prose table (full width, bottom-border only) stays as
   the other instance built it; this override is scoped to the KB shell. */
.mds-kb .mds-prose table { width: auto; max-width: 100%; font-size: var(--mds-text-sm); }
.mds-kb .mds-prose th, .mds-kb .mds-prose td { border: 1px solid var(--mds-line);
    padding: var(--mds-space-1-5) var(--mds-space-3); text-align: left; vertical-align: top; }
.mds-kb .mds-prose th { background: var(--mds-tint); color: var(--mds-title); font-weight: 700; }

/* ── KB article semantic vocabulary ─────────────────────────────────────────
   The WordPress content carries the MEANING (these classes); MIRACLE owns the
   LOOK (these colours). The render normalizer whitelists exactly these prefixes
   (lvl- exp- ppe- is- cell- kb-). Scoped to .mds-prose so cockpit views are untouched.
   ──────────────────────────────────────────────────────────────────────────── */
:root { --mds-kb-exp-none: #d4ebb5; --mds-kb-exp-low: #c2e5ed; --mds-kb-exp-high: #f5d3d0; }
/* Risk severity — the 5×5 matrix + hazard register */
.mds-prose td.lvl-low,    .mds-prose th.lvl-low    { background: #139e1a; color: #fff; }
.mds-prose td.lvl-med,    .mds-prose th.lvl-med    { background: #f7ef07; color: #1d425d; }
.mds-prose td.lvl-high,   .mds-prose th.lvl-high   { background: #fa9507; color: #1d425d; }
.mds-prose td.lvl-severe, .mds-prose th.lvl-severe { background: #f71f02; color: #fff; }
/* …and as legend swatches when used inline (a span, not a cell) */
.mds-prose span.lvl-low::before,  .mds-prose span.lvl-med::before,
.mds-prose span.lvl-high::before, .mds-prose span.lvl-severe::before {
    content: ""; display: inline-block; width: .8em; height: .8em; margin-right: .45em;
    border-radius: 2px; vertical-align: baseline; }
.mds-prose span.lvl-low::before    { background: #139e1a; }
.mds-prose span.lvl-med::before    { background: #f7ef07; }
.mds-prose span.lvl-high::before   { background: #fa9507; }
.mds-prose span.lvl-severe::before { background: #f71f02; }
/* PPE exposure level — area/activity coding */
.mds-prose td.exp-none, .mds-prose th.exp-none { background: var(--mds-kb-exp-none); }
.mds-prose td.exp-low,  .mds-prose th.exp-low  { background: var(--mds-kb-exp-low); }
.mds-prose td.exp-high, .mds-prose th.exp-high { background: var(--mds-kb-exp-high); }
/* Full-width info note — a flat tinted block for an instruction/aside (layout only) */
.mds-prose .kb-callout { padding: var(--mds-space-3) var(--mds-space-4);
    border-radius: var(--mds-radius-lg); margin: var(--mds-space-5) 0; background: var(--mds-tint); }
.mds-prose .kb-callout > :first-child { margin-top: 0; }
.mds-prose .kb-callout > :last-child  { margin-bottom: 0; }
.mds-prose .kb-callout.exp-none { background: var(--mds-kb-exp-none); }
.mds-prose .kb-callout.is-warning { background: var(--mds-danger-bg); color: var(--mds-text); font-weight: 400; }
/* PPE gear level labels */
.mds-prose .ppe-1 { color: #e61e1e; font-weight: 700; }
.mds-prose .ppe-2 { color: #ff6f00; font-weight: 700; }
.mds-prose .ppe-3 { color: #c98a00; font-weight: 700; }
.mds-prose .ppe-4 { color: #0050c8; font-weight: 700; }
/* Emphasis — a flagged warning cell/row */
.mds-prose .is-warning { color: var(--mds-danger); font-weight: 600; }
.mds-prose td.is-warning, .mds-prose tr.is-warning > td { background: var(--mds-danger-bg); }
/* Neutral header / label cell (the theme's grey question cells) */
.mds-prose td.cell-head, .mds-prose th.cell-head { background: var(--mds-raised); font-weight: 600; }

/* ── KB LANDING · hero band + subject tiles (the front door) ──
   Provenance line, title, what-it-is-for line, search. No logo — the rail carries
   the brand and we are inside the app; the provenance line is the one credibility
   cue, not a slogan. Full-bleed (the page renders these straight into .mds-detail, no
   .mds-content wrapper); the inner pages carry the topic tree. Tiles are bordered
   cards with a hover lift. */
.mds-kbband { position: relative; overflow: hidden; color: #fff;
    padding: 56px clamp(24px, 6vw, 96px) 60px;
    background: linear-gradient(135deg, #16344a 0%, var(--mds-chrome) 55%, #245063 100%); }
.mds-kbband__glow { position: absolute; top: -120px; right: 8%; width: 380px; height: 380px;
    pointer-events: none; background: radial-gradient(circle, rgba(71, 163, 175, .30), transparent 70%); }
.mds-kbband__provenance { display: inline-flex; align-items: center; gap: 10px; margin: 0 0 14px;
    font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: #bfe3e8; }
.mds-kbband__provenance::before { content: ""; width: 26px; height: 2px; background: var(--mds-accent); }
.mds-kbband__title { margin: 0; max-width: 16ch; letter-spacing: -.01em;
    font-size: clamp(30px, 4.4vw, 46px); font-weight: 700; line-height: 1.08; color: #fff; }
.mds-kbband__sub { margin: 16px 0 28px; max-width: 56ch; font-size: 17px; line-height: 1.55;
    color: rgba(255, 255, 255, .82); }
.mds-kbband__search { position: relative; z-index: 1; display: flex; align-items: center; gap: 12px;
    max-width: 620px; background: var(--mds-surface); border-radius: 999px; padding: 15px 22px;
    box-shadow: 0 18px 40px rgba(0, 0, 0, .28); }
.mds-kbband__search i { color: var(--mds-accent); font-size: 19px; }
.mds-kbband__search input { flex: 1; border: 0; outline: 0; background: none; font: inherit;
    font-size: 17px; color: var(--mds-title); }

.mds-kbbrowse { padding: 40px clamp(24px, 6vw, 96px) 64px; max-width: 1400px; }
.mds-kbbrowse__head { margin: 0 0 22px; font-size: 13px; font-weight: 700;
    letter-spacing: .08em; text-transform: uppercase; color: var(--mds-muted); }
.mds-kbsubjects { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.mds-kbsubject { display: block; text-decoration: none; background: var(--mds-surface);
    border: 1px solid var(--mds-line); border-radius: var(--mds-radius-lg); padding: 20px;
    transition: transform .12s ease, box-shadow .12s ease, border-color .12s ease; }
.mds-kbsubject:hover { transform: translateY(-3px); border-color: var(--mds-accent);
    box-shadow: 0 12px 28px rgba(29, 66, 93, .12); }
.mds-kbsubject__icon { width: 44px; height: 44px; border-radius: 12px; margin-bottom: 14px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--mds-tint); color: var(--mds-accent-ink); font-size: 19px; }
.mds-kbsubject:hover .mds-kbsubject__icon { background: var(--mds-accent); color: var(--mds-on-accent); }
.mds-kbsubject__title { margin: 0 0 5px; font-size: 17px; font-weight: 700; color: var(--mds-title); }
.mds-kbsubject__desc { margin: 0; font-size: 14px; line-height: 1.5; color: var(--mds-muted); }

/* ---- responsive: the sidebar collapses to a toggle below md ---- */
.mds-kbnav__toggle { display: none; }
@media (max-width: 767px) {
    .mds-kb { flex-direction: column; }
    .mds-kbnav { width: 100%; align-self: auto; border-right: 0;
        border-bottom: 1px solid var(--mds-line); padding: var(--mds-space-3) 0; }
    .mds-kbnav__toggle { display: flex; align-items: center; gap: var(--mds-space-2);
        margin: 0 var(--mds-space-4); padding: 8px 12px; width: calc(100% - 2 * var(--mds-space-4));
        background: none; border: 1px solid var(--mds-line); border-radius: var(--mds-radius-lg);
        color: var(--mds-title); font: inherit; font-size: var(--mds-text-sm); cursor: pointer; }
    .mds-kbnav__body { display: none; }
    .mds-kbnav.is-open .mds-kbnav__body { display: block; margin-top: var(--mds-space-3); }
}
