/* Auth & Security — data-model workzone diagrams (dm-*).
   Reuses the shared stk-* layered-stack kit for the "contract → stored
   data → migration" bands (.stk-dec for the design notes), adding the
   primitives the kit lacks: DB-table sub-blocks whose field rows read
   as a matrix (field · type · constraint chips · note), the API-error
   contract panel (envelope + HTTP-coded list), and the per-layer accent
   presets. Static — no hover affordance (README §Hover).
   Loaded by _workzone/data-model.html on top of ../../module.css
   + ../../layered-stack.css.
   Placement convention: docs/architecture/README.md §Styling. */

/* ── Layer accent presets — descend warm→muted: contract on top,
   observability below ── */
.stk-layer--contract {
  --stk-lc: var(--s1);
  --stk-lc-pale: var(--s4-pale);
}
.stk-layer--idcore {
  --stk-lc: var(--s3-glow);
  --stk-lc-pale: var(--s3-pale);
}
.stk-layer--sessions {
  --stk-lc: var(--accent);
  --stk-lc-pale: var(--tint-8);
}
.stk-layer--federation {
  --stk-lc: var(--s4);
  --stk-lc-pale: var(--s4-pale);
}
.stk-layer--observ {
  --stk-lc: var(--s2-glow);
  --stk-lc-pale: var(--s2-pale);
}

/* ── 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);
}

/* ── DB-table sub-block (lives inside a .stk-layer__body) ── */
.dm-tbl {
  flex: 1 1 320px;
  min-width: 280px;
  align-self: flex-start;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  overflow: hidden;
}
/* Identity core · Sessions & access: tables span the full width (in
   Sessions — stacked), the decision blocks wrap below them. */
.stk-layer--idcore .dm-tbl,
.stk-layer--sessions .dm-tbl {
  flex-basis: 100%;
}
.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);
}
/* Landing flash for a deep-linked column row (e.g. query-engine → #col-…):
   box-shadow rides poorly on a <tr>, so wash the cells instead. */
.dm-fields tr[id]:target td {
  animation: dm-row-flash 2.6s ease-out;
}
@keyframes dm-row-flash {
  0%,
  50% {
    background-color: var(--tint-8);
  }
  100% {
    background-color: transparent;
  }
}
@media (prefers-reduced-motion: reduce) {
  .dm-fields tr[id]:target td {
    animation: none;
    background-color: var(--tint-8);
  }
}

/* ── API-error contract (L1 body): envelope + HTTP-coded list ── */
.dm-env {
  flex: 1 1 340px;
  min-width: 300px;
}
/* Envelope snippet rendered as a dark "terminal" block so it reads as code. */
.dm-env .file-tree {
  background: #241a12;
  color: #d8cab8;
  border: 1px solid #3a2c20;
  border-radius: var(--badge-radius);
  padding: 0.7rem 0.9rem;
  width: fit-content;
  max-width: 100%;
}
.dm-env .file-tree .dim {
  opacity: 0.55;
}
.dm-env .file-tree .dm-ecode {
  color: var(--s1-glow);
}
/* Panel titles are .mod-label in HTML; only the tighter margin is local. */
.dm-env__t,
.dm-codes__t {
  margin-bottom: 0.45rem;
}
.dm-codes {
  flex: 1 1 300px;
  min-width: 260px;
}
.dm-codes ul {
  list-style: none;
  column-count: 2;
  column-gap: 0.6rem;
}
.dm-codes li {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.25rem;
  break-inside: avoid;
  font-family: var(--mono);
  font-size: 0.68rem;
}
.dm-http {
  flex: 0 0 auto;
  font-weight: 700;
  font-size: 0.62rem;
  color: #fff;
  border-radius: var(--tag-radius);
  padding: 0.08rem 0.36rem;
  min-width: 2.2rem;
  text-align: center;
}
.dm-http--401 {
  background: #c0392b;
}
.dm-http--403 {
  background: #c77f2c;
}
.dm-http--404 {
  background: #5f6b7a;
}
.dm-http--409 {
  background: #b8902e;
}
.dm-http--410 {
  background: #4f8a6a;
}
.dm-http--422 {
  background: #3f7a9a;
}
.dm-http--429 {
  background: #8a5fa0;
}
.dm-ecode {
  font-weight: 700;
  color: var(--text);
}
.dm-extra {
  color: var(--accent);
}

@media (max-width: 640px) {
  .dm-codes ul {
    column-count: 1;
  }
}
