/* Knowledge Store — module sheet.
   Diagrams shared by 2+ Knowledge Store pages, promoted here from the page
   sheets (README §Styling, placement rung 4): the DB-table matrix
   (dm-tbl · dm-fields · dm-c chips · dm-badge) used by acl-identity and
   data-model, the v1/v2 split panel (dm-split), the layered-band accent
   (stk-layer--ks), and the L2 overview diagram (ksa — the store as four
   stratified bands: Producers → Store (one entity, three projections on one
   Postgres) → Retrieval (four primitives fused under one ACL) → Consumers,
   with Curation Pass as a side process on the right rail).
   Static — no hover affordance (README §Hover).
   Loaded by index.html and the _workzone pages on top of module.css
   (+ layered-stack.css where the bands are used).
   Placement convention: docs/architecture/README.md §Styling. */

/* Layer accent — Knowledge Store bands carry the module accent. */
.stk-layer--ks {
  --stk-lc: var(--accent);
  --stk-lc-pale: var(--tint-8);
}

/* ═══════════════════════════════════════════
   L2 OVERVIEW — the store as stratified bands
   Four strata stacked top→bottom (Producers · Store · Retrieval · Consumers),
   geologically banded; Curation Pass rides a narrow right rail beside them.
   Static map; the live cross-module links live in the prose below it.
   ═══════════════════════════════════════════ */
.ksa {
  /* Break out of the 720px text column onto a wider, screen-centred canvas.
     margin-left:50% + translateX(-50%) re-centres on the viewport despite the
     narrow parent; equal 1fr side gutters keep the stack dead-centre while
     Curation Pass hangs asymmetrically in the right gutter only. */
  width: min(1080px, 100vw - 2rem);
  margin: 0.5rem 0 0.25rem 50%;
  transform: translateX(-50%);
  display: grid;
  grid-template-columns: minmax(160px, 1fr) minmax(0, 740px) minmax(160px, 1fr);
  column-gap: 1rem;
  align-items: center;
}

/* The stacked strata — the main block, centred on screen. */
.ksa__stack {
  grid-column: 2;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 16px 40px -30px rgba(46, 34, 24, 0.45);
}

/* One stratum (a layer of rock). */
.ksa__layer {
  position: relative;
  padding: 1rem 1.15rem 1.1rem;
  border-bottom: 1px solid var(--border);
}
.ksa__layer:last-child {
  border-bottom: none;
}
.ksa__cap {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.7rem;
  font-family: var(--mono);
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}
.ksa__cap b {
  color: var(--text);
  font-weight: 700;
  font-size: 0.7rem;
  letter-spacing: 0.03em;
}
.ksa__cap span {
  margin-left: auto;
  font-size: 0.56rem;
  letter-spacing: 0.05em;
}

/* Per-stratum tints — geological banding. */
.ksa__layer--l1 {
  background: linear-gradient(180deg, #f7f1e8, #f4ede2);
}
.ksa__layer--l2 {
  background: linear-gradient(180deg, var(--tint-6), var(--tint-8));
}
.ksa__layer--l3 {
  background: linear-gradient(180deg, #f1f0e6, #eef0e3);
}
.ksa__layer--l4 {
  background: linear-gradient(180deg, #f6efe7, #f3ece2);
}

/* Seam between strata — direction of flow (write down / read up). */
.ksa__flow {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.22rem 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 0.55rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
}
.ksa__flow--write {
  color: var(--s2);
}
.ksa__flow--read {
  color: var(--s3);
}

/* Generic box — producer / consumer. */
.ksa__box {
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.65rem 0.85rem;
}
.ksa__box-t {
  font-family: var(--mono);
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--text);
}
.ksa__box-d {
  margin-top: 0.25rem;
  font-size: 0.72rem;
  color: var(--text-dim);
  line-height: 1.45;
}
.ksa__box--in {
  box-shadow: inset 4px 0 0 var(--s2);
}
.ksa__box--out {
  box-shadow: inset 4px 0 0 var(--s3);
}

/* L1 producer — a single centred box. */
.ksa__producer {
  display: flex;
  justify-content: center;
}
.ksa__producer .ksa__box {
  width: 100%;
  max-width: 560px;
  text-align: center;
}

/* L2 store — entity capsule above three projection cards. */
.ksa__entity {
  max-width: 360px;
  margin: 0 auto 0.85rem;
  text-align: center;
  background: var(--paper);
  border: 1.5px solid var(--accent);
  border-radius: var(--radius-md);
  padding: 0.6rem 0.9rem;
  box-shadow: 0 4px 18px -10px rgba(184, 96, 48, 0.5);
}
.ksa__entity b {
  font-family: var(--mono);
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent);
}
.ksa__entity span {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.7rem;
  color: var(--text-dim);
}

.ksa__proj {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.6rem;
  position: relative;
}
/* Connector hairline from the entity down into the three projections. */
.ksa__proj::before {
  content: "";
  position: absolute;
  top: -0.55rem;
  left: 14%;
  right: 14%;
  height: 1px;
  background: var(--accent-muted);
  opacity: 0.45;
}
.ksa__card {
  background: var(--paper);
  border: 1px solid var(--border);
  border-top: 3px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.65rem 0.7rem;
}
.ksa__card-t {
  font-family: var(--mono);
  font-size: 0.76rem;
  font-weight: 700;
}
.ksa__card-r {
  margin-top: 0.1rem;
  font-size: 0.62rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
}
.ksa__card-d {
  margin-top: 0.38rem;
  font-size: 0.7rem;
  color: var(--text-dim);
  line-height: 1.4;
}
.ksa__card--rel {
  border-top-color: var(--s2);
}
.ksa__card--rel .ksa__card-t {
  color: var(--s2);
}
.ksa__card--vec {
  border-top-color: var(--accent);
}
.ksa__card--vec .ksa__card-t {
  color: var(--accent);
}
.ksa__card--gph {
  border-top-color: var(--s3);
}
.ksa__card--gph .ksa__card-t {
  color: var(--s3);
}

/* L3 retrieval — ACL band, four primitives, RRF fusion. */
.ksa__acl {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.85rem;
  padding: 0.5rem 0.8rem;
  background: var(--s3-pale);
  border: 1px solid rgba(106, 128, 72, 0.32);
  border-radius: var(--radius-md);
  font-size: 0.72rem;
  color: var(--text-dim);
  line-height: 1.45;
}
.ksa__acl svg {
  flex: none;
  color: var(--s3);
}
.ksa__acl b {
  font-family: var(--mono);
  font-weight: 700;
  font-size: 0.7rem;
  color: var(--s3);
}

.ksa__prims {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
}
.ksa__prim {
  padding: 0.55rem 0.4rem;
  text-align: center;
  background: var(--paper);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.ksa__prim-t {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 700;
}
.ksa__prim-d {
  margin-top: 0.2rem;
  font-size: 0.58rem;
  color: var(--text-muted);
  line-height: 1.3;
}
.ksa__prim--vec {
  border-bottom: 3px solid var(--accent);
}
.ksa__prim--vec .ksa__prim-t {
  color: var(--accent);
}
.ksa__prim--lex {
  border-bottom: 3px solid var(--accent);
}
.ksa__prim--lex .ksa__prim-t {
  color: var(--accent);
}
.ksa__prim--gph {
  border-bottom: 3px solid var(--s3);
}
.ksa__prim--gph .ksa__prim-t {
  color: var(--s3);
}
.ksa__prim--sql {
  border-bottom: 3px solid var(--s2);
}
.ksa__prim--sql .ksa__prim-t {
  color: var(--s2);
}

.ksa__fuse {
  margin: 0.3rem 0;
  text-align: center;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
}
.ksa__rrf {
  padding: 0.6rem 0.8rem;
  text-align: center;
  background: linear-gradient(180deg, var(--tint-8), var(--tint-15));
  border: 1.5px solid var(--accent);
  border-radius: var(--radius-md);
}
.ksa__rrf b {
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent);
}
.ksa__rrf span {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.64rem;
  color: var(--text-dim);
}

/* L4 consumers — two boxes side by side. */
.ksa__cons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.7rem;
}

/* Right gutter — Curation Pass, the side process hanging asymmetrically
   beside the centred stack. */
.ksa__rail {
  grid-column: 3;
  justify-self: stretch;
  display: flex;
  align-items: center;
}
.ksa__cur {
  position: relative;
  width: 100%;
  background: linear-gradient(180deg, var(--s4-pale), #f3ddd0);
  border: 1px solid rgba(160, 88, 56, 0.32);
  border-left: 4px solid var(--s4);
  border-radius: var(--radius-md);
  padding: 0.85rem 0.75rem;
}
/* Connector tab pointing into the store stratum. */
.ksa__cur::before {
  content: "";
  position: absolute;
  left: -0.5rem;
  top: 46%;
  width: 0.5rem;
  height: 2px;
  background: var(--s4);
  opacity: 0.6;
}
.ksa__cur-h {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}
.ksa__cur-h svg {
  flex: none;
  color: var(--s4);
}
.ksa__cur-h b {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--s4);
}
.ksa__cur ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.ksa__cur li {
  position: relative;
  padding-left: 0.8rem;
  font-size: 0.68rem;
  color: var(--text-dim);
  line-height: 1.4;
}
.ksa__cur li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.5em;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--s4-glow);
}
.ksa__cur code {
  font-family: var(--mono);
  font-size: 0.64rem;
  color: var(--s4);
  background: rgba(160, 88, 56, 0.1);
  padding: 0.05rem 0.3rem;
  border-radius: 4px;
}

/* ═══════════════════════════════════════════
   DB-TABLE MATRIX — field · type · constraint · note
   shared by acl-identity and data-model
   ═══════════════════════════════════════════ */

/* ── Constraint chips ── */
.dm-c {
  display: inline-flex;
  align-items: center;
  font-family: var(--mono);
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  padding: 0.12rem 0.4rem;
  border-radius: var(--pill-radius);
  line-height: 1.4;
  white-space: nowrap;
}
.dm-c--pk {
  background: var(--s1);
  color: #fff;
}
.dm-c--fk {
  background: var(--s2);
  color: #fff;
}
.dm-c--uq {
  background: #5a6a8a;
  color: #fff;
}
.dm-c--nn {
  background: var(--s3);
  color: #fff;
}
.dm-c--idx {
  background: var(--s4);
  color: #fff;
}
.dm-c--null {
  background: var(--paper);
  color: var(--text-muted);
  border: 1px solid var(--accent-muted);
}
.dm-c--chk {
  background: var(--tint-15);
  color: var(--accent);
  border: 1px solid var(--tint-25);
}
.dm-c--def {
  background: var(--s2-pale);
  color: var(--s2);
  border: 1px solid var(--tint-15);
}
.dm-c--vec {
  background: var(--tint-15);
  color: var(--accent);
  border: 1px solid var(--tint-25);
}

/* ── DB-table sub-block (lives inside a .stk-layer__body) ── */
.dm-tbl {
  flex: 1 1 100%;
  min-width: 280px;
  align-self: stretch;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  overflow: hidden;
}
.dm-tbl__head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  padding: 0.5rem 0.75rem;
  background: var(--tint-6);
  border-bottom: 1px solid var(--border);
}
.dm-tbl__name {
  font-family: var(--mono);
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--text);
}
.dm-tbl__sub {
  font-size: 0.66rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.dm-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-left: auto;
}
.dm-badge {
  font-family: var(--mono);
  font-size: 0.58rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.16rem 0.4rem;
  border-radius: var(--tag-radius);
  border: 1px solid var(--tint-25);
  color: var(--text-dim);
  background: var(--tint-6);
  white-space: nowrap;
}
.dm-badge--fk {
  color: var(--s2);
  border-color: rgba(136, 96, 64, 0.4);
  background: rgba(136, 96, 64, 0.08);
}
.dm-badge--fk::before {
  content: "⛓ ";
}
.dm-badge--flag {
  color: var(--s4);
  border-color: rgba(160, 88, 56, 0.35);
  background: var(--s4-pale);
}
.dm-badge--uniq {
  color: var(--s3);
  border-color: rgba(106, 128, 72, 0.4);
  background: var(--s3-pale);
}

/* ── Matrix-style field rows: field · type · constraint chips · note ── */
.dm-fields {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
}
.dm-fields td {
  padding: 0.32rem 0.75rem;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}
.dm-fields tr:last-child td {
  border-bottom: none;
}
.dm-fields .dm-f {
  font-family: var(--mono);
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
}
.dm-fields .dm-t {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-dim);
  white-space: nowrap;
}
.dm-fields .dm-cons {
  white-space: nowrap;
}
.dm-fields .dm-cons .dm-c {
  margin: 1px 2px 1px 0;
}
.dm-fields .dm-note {
  font-size: 0.74rem;
  color: var(--text-dim);
  line-height: 1.4;
}
.dm-fields tr.is-pk td:first-child {
  box-shadow: inset 3px 0 0 var(--s1);
}
.dm-fields tr.is-fk td:first-child {
  box-shadow: inset 3px 0 0 var(--s2);
}

/* ═══════════════════════════════════════════
   V1 / V2 SPLIT — what ships now · what is deferred
   ═══════════════════════════════════════════ */
.dm-split {
  display: flex;
  gap: 0.75rem;
}
.dm-split__col {
  flex: 1;
  padding: 0.9rem 1.05rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.dm-split__col--keep {
  border-left: 4px solid var(--s3);
}
.dm-split__col--later {
  border-left: 4px dashed var(--s2);
  background: var(--paper);
}
.dm-split__h {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}
.dm-split__t {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text);
}
.dm-split__d {
  font-size: 0.78rem;
  color: var(--text-dim);
  line-height: 1.5;
}

@media (max-width: 700px) {
  /* Phone width — no room for a side rail; centre a single column and drop
     Curation beneath the stack as a full-width band. */
  .ksa {
    width: min(740px, 100vw - 2rem);
    grid-template-columns: 1fr;
  }
  .ksa__stack,
  .ksa__rail {
    grid-column: 1;
  }
  .ksa__rail {
    padding: 0.6rem 0 0;
  }
  .ksa__cur::before {
    display: none;
  }
}
@media (max-width: 560px) {
  .ksa__proj {
    grid-template-columns: 1fr;
  }
  .ksa__proj::before {
    display: none;
  }
  .ksa__prims {
    grid-template-columns: 1fr 1fr;
  }
  .ksa__cons {
    grid-template-columns: 1fr;
  }
}
@media (max-width: 640px) {
  .dm-split {
    flex-direction: column;
  }
}
