/* AI Foundation — data-model workzone diagram (dm-*).
   A trimmed subset of admin-panel/_workzone/data-model.css: the same stk-*
   layered-stack bands carry one DB-table sub-block (field · type · constraint
   chips · note) plus .stk-dec design notes. AI Foundation carries the system
   prompt singleton (prompt_settings), the AI-models registry (providers ·
   models · assignments · chat & agent lists · usage · tools — core ORM, CRUD
   in Admin), and the migration band. The page opens with two page-bespoke
   visuals: .dm-schema — the whole model in one glance (three layer bands, the
   registry hub-and-spoke, each node a jump-link to its table) — and .dm-compose
   — the four prompt layers stacked into the final system prompt. The tables
   themselves are static (no hover); only the .dm-schema jump-nodes react, being
   genuine links (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 ── */
.stk-layer--config {
  --stk-lc: var(--accent);
  --stk-lc-pale: var(--tint-8);
}
.stk-layer--ai {
  --stk-lc: var(--s3-glow);
  --stk-lc-pale: var(--s3-pale);
}
.stk-layer--migration {
  --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--idx {
  background: var(--s4);
  color: #fff;
}
.dm-c--nn {
  background: var(--s3);
  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;
}
/* Prompt singleton + AI registry tables each span the full layer width
   (stacked, one per row); notes wrap below. */
.stk-layer--config .dm-tbl,
.stk-layer--ai .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--flag {
  color: var(--s4);
  border-color: rgba(160, 88, 56, 0.35);
  background: var(--s4-pale);
}
.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--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);
}

/* a deep-linked table lands in the eye's upper third, not glued to the top */
.dm-tbl[id] {
  scroll-margin-top: 24vh;
}

/* ════════════════ SCHEMA OVERVIEW MAP ════════════════ the whole model in one
   glance — three layer bands echoing the stack accents, the registry's
   provider→models→consumers hub-and-spoke, each node a jump-link to its table. */
.dm-schema {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  margin: 1.3rem 0 1.5rem;
}
.dm-schema__band {
  border: 1px solid var(--border);
  border-left: 5px solid var(--stk-lc, var(--accent));
  border-radius: var(--radius-md);
  background: var(--stk-lc-pale, var(--tint-6));
  padding: 0.6rem 0.85rem 0.8rem;
}
.dm-schema__band--config {
  --stk-lc: var(--accent);
  --stk-lc-pale: var(--tint-8);
}
.dm-schema__band--ai {
  --stk-lc: var(--s3-glow);
  --stk-lc-pale: var(--s3-pale);
}
.dm-schema__band--migration {
  --stk-lc: var(--s2-glow);
  --stk-lc-pale: var(--s2-pale);
}

.dm-schema__lyr {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.6rem;
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: var(--heading-spacing);
}
.dm-schema__n {
  flex: 0 0 auto;
  width: 1.3rem;
  height: 1.3rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--mono);
  font-size: 0.66rem;
  font-weight: 700;
  color: var(--stk-lc, var(--accent));
  background: var(--paper);
  border: 1.5px solid var(--stk-lc, var(--accent));
  border-radius: 50%;
}

/* hub-and-spoke: ai_providers → ai_models → its four consumer tables */
.dm-schema__hub {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.4rem 0.55rem;
}
.dm-schema__arr {
  font-family: var(--mono);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-muted);
}
.dm-schema__spokes {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

/* node = jump-link to a table; clickable, so a hover lift is allowed (§Hover) */
.dm-node {
  display: inline-flex;
  flex-direction: column;
  gap: 0.05rem;
  padding: 0.35rem 0.6rem;
  background: var(--paper);
  border: 1px solid var(--accent-muted);
  border-radius: var(--radius-md);
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
  transition:
    transform 0.12s ease,
    box-shadow 0.12s ease,
    border-color 0.12s ease;
}
.dm-node small {
  font-family: var(--rubik, inherit);
  font-size: 0.62rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: var(--text-muted);
}
a.dm-node:hover {
  transform: translateY(-1px);
  border-color: var(--stk-lc, var(--accent));
  box-shadow: var(--card-shadow);
}
.dm-node--hub {
  border-width: 1.5px;
  border-color: var(--s3);
}
.dm-node--sm {
  padding: 0.25rem 0.55rem;
  font-size: 0.72rem;
}
.dm-node--solo {
  align-self: flex-start;
  margin-top: 0.6rem;
}
.dm-schema__note {
  font-size: 0.76rem;
  color: var(--text-dim);
}

@media (max-width: 720px) {
  .dm-schema__hub {
    flex-direction: column;
    align-items: flex-start;
  }
  .dm-schema__arr {
    transform: rotate(90deg);
  }
}

/* ── Prompt composition — four layers stacked top→down into the final system
   prompt; left-stripe colors the owner (admin · surface · runtime). ── */
.dm-compose {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin: 0.55rem 0 0.7rem;
}
.dm-compose__row {
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
  padding: 0.4rem 0.7rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--text-muted);
  border-radius: var(--tag-radius);
}
.dm-compose__row--admin {
  border-left-color: var(--accent);
}
.dm-compose__row--eng {
  border-left-color: var(--s3);
}
.dm-compose__row--rt {
  border-left-color: var(--s2);
}
.dm-compose__n {
  font-family: var(--mono);
  font-size: 0.66rem;
  font-weight: 700;
  color: var(--text-muted);
}
.dm-compose__t {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text);
}
.dm-compose__o {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 0.64rem;
  color: var(--text-muted);
  text-align: right;
}
.dm-compose__sum {
  margin-top: 0.15rem;
  padding: 0.42rem 0.7rem;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text);
  background: var(--tint-6);
  border: 1px dashed var(--accent-muted);
  border-radius: var(--tag-radius);
}
