/* ============================================================
   Management System (feature 024) — Register + Record.
   Ported verbatim from the genesis prototype CSS
   (ms-explore/ms-shared.css + ms-explore/direction-b.html),
   renamed to the production `msb-*` namespace the ms-v18.js
   render structure uses, and scoped under `.msb-root` so the
   bare prototype selectors (.dt/.badge/.pill/.btn/...) never
   collide with the app's existing global classes.

   The genesis design tokens (--navy/--ink/--muted/...) are
   redeclared here, mapped to the app's --color-* / --rp-* system,
   scoped to .msb-root. Register area re-matched to the v37
   prototype (feature 045): its visual roles now resolve through the
   corrected semantic tokens while decorative data fills stay unchanged
   (specs/045-v37-ui-parity/reference + scratchpad v37.css).
   ============================================================ */

.msb-root {
  /* genesis tokens mapped onto the app palette (layout.css owns --color-*) */
  --navy: var(--color-navy);
  --blue: var(--color-blue);
  --teal: var(--color-teal);
  --teal-soft: var(--color-ice-blue);
  --surface: var(--color-surface);
  --white: var(--color-white);
  --border: var(--color-border);
  --border-light: var(--color-border-light);
  --ink: var(--rp-ink);
  --ink-soft: var(--rp-ink-soft);
  --muted: var(--rp-muted);
  --muted-2: var(--color-text-secondary);
  --ok: var(--color-success);
  --ok-bg: var(--color-success-tint);
  --warn: var(--color-warning);
  --warn-bg: var(--color-warning-tint);
  --info: var(--color-info);
  --info-bg: var(--color-info-tint);
  --err: var(--color-error);
  --err-bg: var(--color-error-tint);
  --mono: var(--font-mono);

  display: block;
  color: var(--ink);
}

/* The Register / Framework flow sits inside the standard page padding (.main-content),
   so it reads as a flat surface page — no white head bar, no left rail (v28). */
.msb-page { display: block; }

/* ---- page head: plain v37 title above the Register | Framework tabs ---- */
.msb-pagehead { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; flex-wrap: wrap; margin-bottom: var(--space-4); }

/* ---- top filter toolbar: prominent search + dropdown facet buttons (v37 reference values) ---- */
.msb-tb { margin-bottom: var(--space-4); }
.msb-tb-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.msb-tb-search { position: relative; display: flex; align-items: center; flex: 1; min-width: 300px; }
.msb-tb-search > svg { position: absolute; left: 14px; width: 18px; height: 18px; color: var(--color-text-secondary); pointer-events: none; }
.msb-tb-search input { width: 100%; padding: 13px 40px 13px 42px; border: 1px solid var(--color-control-border); border-radius: var(--radius-md); font-size: 14.5px; color: var(--navy); background: var(--color-white); font-family: var(--font-primary); }
.msb-tb-search input::placeholder { color: var(--color-text-secondary); }
.msb-tb-search input:focus { outline: none; border-color: var(--color-control-border); box-shadow: var(--shadow-focus); }
.msb-tb-clear { position: absolute; right: 10px; width: 24px; height: 24px; display: flex; align-items: center; justify-content: center; border: none; background: none; color: var(--color-text-secondary); cursor: pointer; border-radius: var(--radius-sm); }
.msb-tb-clear:hover { background: var(--surface); color: var(--color-text-secondary); }
.msb-tb-clear svg { width: 14px; height: 14px; }

.msb-tb-controls { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; margin-top: var(--space-4); }

/* dropdown facet buttons + popovers */
.msb-dd-wrap { position: relative; }
.msb-dd { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 500; color: var(--color-text-secondary); background: var(--color-white); border: 1px solid var(--color-control-border); border-radius: var(--radius-md); padding: 9px 12px; cursor: pointer; font-family: var(--font-primary); white-space: nowrap; }
.msb-dd:hover { border-color: var(--color-control-border); color: var(--navy); }
.msb-dd.on { background: var(--color-ice-blue); border-color: var(--color-control-border); color: var(--navy); }
.msb-dd.open { border-color: var(--color-control-border); box-shadow: var(--shadow-focus); }
.msb-dd .caret { width: 14px; height: 14px; opacity: .6; }
.msb-dd-badge { font-family: var(--mono); font-size: 11px; background: var(--navy); color: var(--color-white); border-radius: var(--radius-full); min-width: 17px; height: 17px; display: inline-flex; align-items: center; justify-content: center; padding: 0 5px; }
.msb-dd-menu { position: absolute; top: calc(100% + 6px); left: 0; background: var(--color-white); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-md); padding: 5px; min-width: 236px; z-index: 40; max-height: 340px; overflow-y: auto; }
.msb-dd-menu[hidden] { display: none; }
.msb-dd-menu.wide { min-width: 264px; }
.msb-dd-opt { display: flex; align-items: center; gap: 9px; width: 100%; text-align: left; padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer; font-size: 12.5px; color: var(--color-text-secondary); border: none; background: none; font-family: var(--font-primary); }
.msb-dd-opt:hover { background: var(--surface); }
.msb-dd-opt.on { background: var(--color-ice-blue); color: var(--navy); font-weight: 500; }
.msb-dd-opt .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.msb-dd-opt .lbl { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msb-dd-opt .cnt { font-family: var(--mono); font-size: 11px; color: var(--color-text-secondary); flex-shrink: 0; }
.msb-dd-opt .tick { width: 15px; height: 15px; color: var(--navy); flex-shrink: 0; }
.msb-dd-foot { border-top: 1px solid var(--border-light); margin-top: 4px; padding-top: 4px; }
.msb-dd-clear { width: 100%; text-align: left; padding: 8px 10px; border-radius: var(--radius-sm); border: none; background: none; cursor: pointer; font-size: 12.5px; color: var(--color-teal-text); font-weight: 500; font-family: var(--font-primary); }
.msb-dd-clear:hover { background: var(--surface); }

/* foot row: "N documents" count + active filter chips */
.msb-tb-foot { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-top: var(--space-4); }
.msb-tb-foot .msb-reg-count { margin: 0; }
.msb-tb-foot .msb-active { margin: 0; }
.msb-clearall { border: none; background: none; cursor: pointer; font-size: 12px; color: var(--color-teal-text); font-weight: 500; font-family: var(--font-primary); padding: 9px 4px; }
.msb-clearall:hover { text-decoration: underline; }

/* Record drill-in keeps its original full-bleed framing (crumb/hero/body carry their own padding),
   so break out of the surrounding page padding. */
.msb-main { display: block; min-width: 0; margin: calc(-1 * var(--space-10)); background: var(--color-surface); min-height: calc(100vh - var(--topbar-height)); }

/* ---- status breakdown bar (register list: approved vs the rest) ---- */
.msb-statbar { display: flex; height: 8px; border-radius: var(--radius-full); overflow: hidden; background: var(--border-light); gap: 1.5px; }
.msb-statbar .seg { height: 100%; }
.msb-statbar .seg-approved { background: var(--color-success); }

/* ---- pills / chips ---- */
.msb-pill { display: inline-flex; align-items: center; font-family: var(--font-primary); font-size: 10.5px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; padding: 2px 8px; border-radius: var(--radius-full); white-space: nowrap; }
.msb-pill-approved { background: var(--ok-bg); color: var(--ok); }
.msb-pill-flagged  { background: var(--warn-bg); color: var(--warn); }
.msb-pill-pending  { background: var(--info-bg); color: var(--info); }
.msb-pill-rejected { background: var(--err-bg); color: var(--err); }
.msb-pill-queued   { background: var(--surface); color: var(--color-text-secondary); }
.msb-type-chip { display: inline-block; font-family: var(--font-heading); font-size: 10px; font-weight: 600; letter-spacing: .03em; padding: 2px 7px; border-radius: var(--radius-full); background: var(--surface); color: var(--color-text-secondary); }
.msb-doc-ref { font-family: var(--mono); font-size: 12px; color: var(--color-text-secondary); font-weight: 500; }
.msb-root .mono { font-family: var(--mono); font-size: 12px; color: var(--color-text-secondary); }

/* ---- lifecycle badge (hero meta strip) ---- */
.msb-life { display: inline-flex; align-items: center; gap: 6px; font-family: var(--font-primary); font-size: 11px; font-weight: 600; letter-spacing: .02em; padding: 3px 10px; border-radius: var(--radius-full); white-space: nowrap; }
.msb-life::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.msb-life-approved { background: var(--ok-bg); color: var(--ok); }
.msb-life-review   { background: var(--info-bg); color: var(--info); }
.msb-life-queued   { background: var(--surface); color: var(--color-text-secondary); }

/* ---- data table (scoped; even-row striping) ----
   Header colour and type come from the shared product variant in components.css. This rule used to
   restate the whole light header; it now keeps only the padding this surface needs. */
.msb-root .data-table { width: 100%; border-collapse: collapse; }
.msb-root .data-table thead th { padding: 14px 16px; }
.msb-root .data-table tbody td { padding: 14px 16px; border-bottom: 1px solid var(--border-light); font-size: 13.5px; color: var(--color-navy); vertical-align: middle; }
.msb-root .data-table tbody tr { transition: background var(--duration-fast); }
.msb-root .data-table tbody tr:nth-child(even) { background: var(--rp-surface2); }
.msb-root .data-table tbody tr:hover { background: rgba(216, 234, 233, .35); }
/* Read-only tables (record responsibilities): keep striping, drop the hover tint so static rows
   don't advertise a click they can't honour. */
.msb-root .data-table.msb-static tbody tr:hover { background: transparent; }
.msb-root .data-table.msb-static tbody tr:nth-child(even):hover { background: var(--rp-surface2); }
.msb-reg-table tbody tr { cursor: pointer; }
.msb-reg-table tbody tr:last-child td { border-bottom: none; }
.msb-root .data-table th.srt { cursor: pointer; }
.msb-root .data-table th.srt:hover { color: var(--navy); }

/* ---- register ---- */
.msb-reg { display: block; }
.msb-reg-count { font-size: 13px; color: var(--color-text-secondary); }
.msb-reg-count b { color: var(--navy); font-weight: 600; }
.msb-active { display: flex; gap: 7px; flex-wrap: wrap; }
.msb-tag { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--navy); background: var(--color-ice-blue); border-radius: var(--radius-full); padding: 4px 10px; }
.msb-tag .x { cursor: pointer; opacity: .6; font-weight: 700; border: none; background: none; color: inherit; font-size: inherit; padding: 0; }
.msb-tag .x:hover { opacity: 1; }
.msb-panel { background: var(--color-white); border: 1px solid var(--color-border); border-radius: var(--radius-lg); overflow: hidden; }
.msb-resp { min-width: 188px; }
.msb-resp .msb-statbar { margin-bottom: 5px; }
.msb-resp .line { font-size: 11.5px; color: var(--color-text-secondary); }
.msb-resp .line b { color: var(--color-navy); font-weight: 600; }
.msb-empty { padding: 48px 20px; text-align: center; color: var(--color-text-secondary); font-size: 13.5px; }
/* Published column: the state as a pill, the date or both revisions under it. The note replaces the column
   when no register is imported or the reconciliation could not be read. */
.msb-pub { line-height: 1.35; }
.msb-pub-sub { display: block; font-size: 11.5px; color: var(--muted); margin-top: 3px; white-space: nowrap; }
.msb-pub-note { color: var(--color-text-secondary); margin-left: 4px; }
/* A register entry with no file yet: greyed and not openable. */
.msb-reg-table tbody tr.msb-reg-awaiting { cursor: default; }
.msb-root .data-table tbody tr.msb-reg-awaiting td { color: var(--color-text-secondary); }

/* ---- record page ---- */
/* The record trail is the shared .breadcrumbs strip laid out as an edge-to-edge bar above the hero. */
.breadcrumbs.msb-rec-crumb { max-width: none; margin: 0; padding: 16px 30px; border-bottom: 1px solid var(--border-light); background: var(--color-white); flex-wrap: wrap; }

.msb-rec-hero { background: var(--color-white); border-bottom: 1px solid var(--border); padding: 22px 30px 24px; }
.msb-rec-hero-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; }
.msb-rec-num { font-family: var(--mono); font-size: 13px; color: var(--color-text-secondary); }
.msb-rec-title { font-size: 26px; font-weight: 600; color: var(--navy); margin-top: 4px; letter-spacing: -0.01em; line-height: 1.2; font-family: var(--font-heading); }
.msb-rec-status { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 12px; font-size: 12.5px; color: var(--color-text-secondary); }
.msb-rec-status .mono { font-size: 12px; }
.msb-rec-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* The record's tab strip sits on the hero's white, under the status line. */
.msb-rec-tabs { background: var(--color-white); border-bottom: 1px solid var(--border); padding: 0 30px; }
.msb-rec-tabs .tabs { margin-bottom: 0; border-bottom: 0; }
.msb-rec-body { padding: 26px 30px; }
/* Profile details: label over value, as many columns as fit. */
.msb-details { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px 24px; margin: 0; }
.msb-details dt { font-size: 11px; color: var(--muted); }
.msb-details dd { margin: 2px 0 0; font-size: 13px; color: var(--ink); }
.msb-card { background: var(--color-white); border: 1px solid var(--color-border-light); border-radius: var(--radius-lg); box-shadow: var(--shadow-sm); padding: 22px; margin-bottom: 22px; }
.msb-card-h { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; margin-bottom: 16px; }
.msb-card-h h3 { font-size: 15px; font-weight: 600; color: var(--navy); font-family: var(--font-heading); }
.msb-go { font-size: 12.5px; font-weight: 600; color: var(--color-text-link); cursor: pointer; display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; border: none; background: none; font-family: var(--font-primary); }
.msb-go:hover { color: var(--navy); gap: 8px; }
.msb-go svg { width: 14px; height: 14px; }

.msb-asg-count { margin-top: 10px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.msb-asgfilters { display: flex; gap: 7px; flex-wrap: wrap; margin: 8px 0 14px; }
/* Same label-count spacing as the /assignments status chips (a flex item drops the literal space). */
.msb-asgfilters .filter-chip { display: inline-flex; align-items: center; gap: 5px; }
.msb-asgfilters .msb-role-select { margin-left: auto; display: inline-flex; align-items: center; gap: 8px; }
.msb-asgfilters .msb-role-select .filter-select { width: 280px; }
.msb-asgfilters .msb-role-select .field-label { font-size: 12px; color: var(--color-text-secondary); }
.msb-asg-resp { color: var(--ink); font-weight: 500; max-width: 420px; }
.msb-asg-resp .s { font-size: 11.5px; color: var(--muted); margin-top: 3px; font-family: var(--mono); }

.msb-ver { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border-light); }
.msb-ver:last-child { border-bottom: none; }
.msb-ver-badge { font-family: var(--mono); font-size: 11px; font-weight: 500; background: var(--color-white); border: 1px solid var(--color-border); color: var(--color-info); border-radius: 6px; padding: 3px 8px; flex-shrink: 0; }
.msb-ver.current .msb-ver-badge { background: var(--navy); border-color: var(--navy); color: var(--color-white); }
.msb-ver-main { flex: 1; min-width: 0; }
.msb-ver-line { font-size: 13px; color: var(--ink); display: flex; align-items: center; gap: 8px; }
.msb-ver-meta { font-size: 11px; color: var(--muted); margin-top: 2px; font-family: var(--mono); }
.msb-ver-state { font-size: 9.5px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; padding: 1px 7px; border-radius: var(--radius-full); }
.msb-st-cur { background: var(--ok-bg); color: var(--ok); }
.msb-st-sup { background: color-mix(in srgb, var(--color-warning) 14%, var(--color-white)); color: color-mix(in srgb, var(--color-warning) 88%, var(--color-navy)); }

/* ---- buttons (scoped to the record hero and cards) ---- */
.msb-root .btn { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 500; padding: 9px 15px; border-radius: var(--radius-md); cursor: pointer; border: 1px solid var(--border); background: var(--color-white); color: var(--navy); transition: background 120ms, border-color 120ms; white-space: nowrap; font-family: var(--font-primary); }
.msb-root .btn:hover { background: var(--surface); border-color: var(--color-blue); }
.msb-root .btn svg { width: 15px; height: 15px; }
.msb-root .btn-primary { background: var(--navy); color: var(--color-white); border-color: var(--navy); }
.msb-root .btn-primary:hover { background: var(--color-blue); border-color: var(--color-blue); }
.msb-root .btn-secondary { background: var(--color-white); color: var(--navy); }
.msb-root .btn-sm { padding: 6px 11px; font-size: 12px; }

/* ---- source-PDF actions ---- */
/* Inline notice when a document has no retrievable source PDF (local sets without uploads). */
.msb-pdf-note { font-size: 12px; color: var(--ink-soft); align-self: center; }
/* Click-away layer under the facet menus (z 40): a click anywhere else closes the open menu. */
.msb-click-away { position: fixed; inset: 0; z-index: 10; background: transparent; }

/* processing placeholder (queued / extracting record card) */
.msb-proc { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--ink-soft); padding: 18px 0; }
.msb-proc .spin { width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--blue); border-radius: 50%; animation: msb-spin 0.8s linear infinite; flex-shrink: 0; }
@keyframes msb-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .msb-proc .spin { animation: none; } }

/* The app shell reduces content padding from 40px to 24px at its laptop breakpoint.
   Match the active inset so the record view is full-bleed without horizontal overflow. */
@media (max-width: 1512px) {
  .msb-main { margin: calc(-1 * var(--space-6)); }
}

/* ── Regulatory citations (feature 088) on the record's Regulations tab ──────── */

.msb-cit-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.msb-cit-note {
    font-size: 12px;
    color: var(--color-text-secondary);
    padding: 0 0 10px;
    max-width: 74ch;
}

.msb-cit-banner {
    display: block;
    border-radius: var(--radius-md);
    padding: 10px 12px;
    font-size: 12.5px;
    line-height: 1.5;
    margin-bottom: 10px;
}

.msb-cit-banner strong { display: block; font-weight: 600; }
.msb-cit-banner.warn { background: var(--warn-bg); color: var(--warn); border: 1px solid var(--color-warning-tint-border); }

.msb-cit-table .s { font-size: 11.5px; color: var(--muted); margin-top: 3px; }

/* The group header is the document's own section, not a status band, so it reads as a heading
   inside the table rather than as another row of data. */
.msb-root .data-table.msb-cit-table tbody tr.msb-cit-grp > td {
    background: var(--surface);
    font-size: 12px;
    font-weight: 600;
    color: var(--color-text-secondary);
    padding-top: 8px;
    padding-bottom: 8px;
}

.msb-cit-grp .n { font-weight: 400; color: var(--muted); margin-left: 8px; }

/* Every row opens, one at a time. Without a control on every row a reviewer can only read the one
   example the screen happened to choose for them. */
.msb-cit-disc {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 24px;
    border-radius: var(--radius-sm);
    color: var(--color-text-secondary);
    background: none;
    border: none;
    cursor: pointer;
}

.msb-cit-disc svg { width: 14px; height: 14px; transition: transform var(--duration-base, 160ms) ease; }
.msb-cit-disc.open svg { transform: rotate(180deg); }
.msb-cit-disc:hover { background: var(--surface); color: var(--color-navy); }
.msb-cit-disc:focus-visible { outline: none; box-shadow: var(--shadow-focus); }

.msb-cit-quiet { color: var(--color-text-secondary); font-size: 12.5px; }

/* Stale evidence is a separate mark from the decision: the decision stands, the alias under it
   moved. Two facts, two marks, neither overwriting the other. */
.msb-cit-stale {
    display: block;
    font-size: 11px;
    color: var(--warn);
    margin-top: 3px;
}

.msb-root .data-table.msb-cit-table tbody tr.msb-cit-exp > td { background: var(--surface); padding: 12px 14px; }

.msb-cit-ctxh { font-size: 11.5px; color: var(--muted); margin-bottom: 4px; }
.msb-cit-ctx { font-size: 13px; color: var(--color-text-primary); line-height: 1.6; max-width: 80ch; margin: 0 0 10px; }
.msb-cit-ctx.muted { color: var(--color-text-secondary); }
.msb-cit-mark { background: var(--info-bg); color: var(--color-navy); padding: 0 2px; border-radius: 2px; }

.msb-cit-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 16px;
    font-size: 11.5px;
    color: var(--color-text-secondary);
    margin-bottom: 10px;
}

.msb-cit-meta b { color: var(--color-navy); font-weight: 500; }

/* Arrived from the reverse index: the rows that reach that instrument carry a rule, so the reviewer
   can see which of the list is the reason they are here without the others being hidden. */
.msb-root .data-table.msb-cit-table tbody tr.msb-cit-marked > td:first-child {
    box-shadow: inset 3px 0 0 var(--color-teal);
}

/* The arrived-from mark, in words. The rule beside it is decoration; this is the carrier. */
.msb-cit-from {
    display: inline-block;
    margin-top: 3px;
    padding: 1px 6px;
    border-radius: var(--radius-sm);
    background: var(--info-bg);
    color: var(--color-navy);
    font-size: 11px;
}

/* 1240px of viewport is the 11-inch touch bound. The caret is the only affordance on this card,
   so it grows to the 44px target rather than staying at the 24px minimum. */
@media (max-width: 1240px) {
    .msb-cit-disc { width: 44px; height: 44px; }
}
