/* Article figures: small self-playing illustrations inside article bodies.
   Opt-in: the body contains <figure class="ub-fig ...">. Markup only lives in
   Directus; styling here, step cycling in article-figures.js.
   Without JS or with reduced motion the figure shows its final state:
   every "hide until step N" rule is keyed on [data-step], which only JS sets. */

.ub-fig {
    --fig-bg: #0b1a30;
    --fig-panel: #0f2540;
    --fig-line: rgba(232, 240, 248, .12);
    --fig-text: #e8eef6;
    --fig-muted: rgba(232, 240, 248, .58);
    --fig-bad: #ff6b6b;
    --fig-mono: Consolas, 'SFMono-Regular', Menlo, monospace;
    margin: 36px 0;
    padding: 20px;
    background: var(--fig-bg);
    border: 1px solid var(--fig-line);
    border-radius: 20px;
    color: var(--fig-text);
    font-family: var(--font-family-base, 'Montserrat', sans-serif);
    font-size: 14px;
    line-height: 1.5;
}
.ub-fig figcaption {
    margin-top: 16px;
    color: var(--fig-muted);
    font-size: 14px;
    line-height: 1.55;
}
.ub-fig__grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.ub-fig__col { display: grid; gap: 12px; align-content: start; min-width: 0; }
.ub-fig__panel {
    background: var(--fig-panel);
    border: 1px solid var(--fig-line);
    border-radius: 12px;
    padding: 12px 14px;
    min-width: 0;
}
.ub-fig__label {
    display: block;
    margin-bottom: 8px;
    color: var(--fig-muted);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
}
.ub-fig__code { display: block; font-family: var(--fig-mono); font-size: 12.5px; line-height: 1.7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ub-fig__code + .ub-fig__code { margin-top: 0; }
.ub-fig__dim { color: var(--fig-muted); }
.ub-fig__new { color: var(--teal); }
.ub-fig__field {
    display: block;
    margin-top: 6px;
    padding: 5px 10px;
    border: 1px solid var(--fig-line);
    border-radius: 8px;
    background: rgba(0, 0, 0, .18);
    font-size: 13px;
}
.ub-fig__field.ub-fig__new { border-color: var(--teal); color: var(--fig-text); box-shadow: 0 0 0 3px rgba(0, 201, 167, .14); }
.ub-fig__pill {
    display: inline-block;
    padding: 2px 10px;
    border: 1px solid var(--fig-line);
    border-radius: 999px;
    color: var(--fig-muted);
    font-size: 12px;
    white-space: nowrap;
}
.ub-fig__pill--ok { border-color: var(--teal); color: var(--teal); }
.ub-fig__pill--bad { border-color: var(--fig-bad); color: var(--fig-bad); }

/* Elements that appear with a step fade and rise a little. */
.ub-fig [data-from] { transition: opacity .45s ease, transform .45s ease, max-height .45s ease; }
.ub-fig[data-step="0"] [data-from="1"],
.ub-fig[data-step="0"] [data-from="2"], .ub-fig[data-step="1"] [data-from="2"],
.ub-fig[data-step="0"] [data-from="3"], .ub-fig[data-step="1"] [data-from="3"], .ub-fig[data-step="2"] [data-from="3"],
.ub-fig[data-step="0"] [data-from="4"], .ub-fig[data-step="1"] [data-from="4"], .ub-fig[data-step="2"] [data-from="4"], .ub-fig[data-step="3"] [data-from="4"],
.ub-fig[data-step="0"] [data-from="5"], .ub-fig[data-step="1"] [data-from="5"], .ub-fig[data-step="2"] [data-from="5"], .ub-fig[data-step="3"] [data-from="5"], .ub-fig[data-step="4"] [data-from="5"] {
    opacity: 0;
    transform: translateY(6px);
}

/* 1. Model: one attribute reaches the DB schema, the API and the form. */
.ub-fig--model .ub-fig__panel--meta { grid-row: span 3; }

/* 2. Access: one table, three roles. data-roles lists the steps that see a row. */
.ub-fig__roles { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.ub-fig__roles .ub-fig__pill { transition: background .3s, color .3s, border-color .3s; }
.ub-fig[data-step="0"] .ub-fig__roles [data-role="0"],
.ub-fig[data-step="1"] .ub-fig__roles [data-role="1"],
.ub-fig[data-step="2"] .ub-fig__roles [data-role="2"],
.ub-fig:not([data-step]) .ub-fig__roles [data-role="0"] { background: var(--teal); border-color: var(--teal); color: #071525; font-weight: 600; }
.ub-fig__rows { display: grid; gap: 0; }
.ub-fig__row {
    display: grid;
    grid-template-columns: 56px minmax(0, 1.4fr) minmax(0, 1fr) 96px;
    gap: 10px;
    padding: 7px 0;
    border-bottom: 1px solid var(--fig-line);
    font-size: 13px;
    transition: opacity .4s ease;
}
.ub-fig__row:last-child { border-bottom: 0; }
.ub-fig__row > span:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.ub-fig__row--head { color: var(--fig-muted); font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.ub-fig[data-step="0"] .ub-fig__row[data-roles]:not([data-roles~="0"]),
.ub-fig[data-step="1"] .ub-fig__row[data-roles]:not([data-roles~="1"]),
.ub-fig[data-step="2"] .ub-fig__row[data-roles]:not([data-roles~="2"]),
.ub-fig:not([data-step]) .ub-fig__row[data-roles]:not([data-roles~="0"]) { opacity: .16; }
.ub-fig__where { margin-top: 12px; }
.ub-fig__where [data-role] { display: none; }
.ub-fig[data-step="0"] .ub-fig__where [data-role="0"],
.ub-fig[data-step="1"] .ub-fig__where [data-role="1"],
.ub-fig[data-step="2"] .ub-fig__where [data-role="2"],
.ub-fig:not([data-step]) .ub-fig__where [data-role="0"] { display: inline; }

/* 3. Migration: rows get allocations, then the acceptance checks pass. */
.ub-fig--migration .ub-fig__row { grid-template-columns: 56px minmax(0, 1fr) minmax(0, 1.2fr); }
.ub-fig--migration .ub-fig__row > span:last-child { text-align: left; }
.ub-fig__checks { display: grid; gap: 8px; margin-top: 12px; }
.ub-fig__check { display: flex; gap: 10px; align-items: flex-start; font-size: 13.5px; }
.ub-fig__check::before {
    content: '✓';
    flex: none;
    width: 20px;
    height: 20px;
    margin-top: 1px;
    border-radius: 50%;
    background: var(--teal);
    color: #071525;
    display: grid;
    place-items: center;
    font-size: 12px;
    font-weight: 700;
}

/* 4. AI: proposal, server check, new proposal, human decision. */
.ub-fig__flow { display: grid; gap: 8px; }
.ub-fig__msg {
    padding: 10px 14px;
    border: 1px solid var(--fig-line);
    border-radius: 12px;
    background: var(--fig-panel);
    font-size: 13.5px;
}
.ub-fig__msg b { display: block; margin-bottom: 2px; color: var(--fig-muted); font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.ub-fig__msg--user { justify-self: end; max-width: 86%; background: rgba(0, 201, 167, .1); border-color: rgba(0, 201, 167, .35); }
.ub-fig__msg--ai { max-width: 86%; }
.ub-fig__msg--server { font-family: var(--fig-mono); font-size: 12.5px; background: rgba(0, 0, 0, .22); }
.ub-fig__msg--server.is-bad { color: var(--fig-bad); }
.ub-fig__msg--server.is-ok { color: var(--teal); }
.ub-fig__msg--done { border-color: var(--teal); }

@media (max-width: 640px) {
    .ub-fig { padding: 14px; margin: 28px 0; }
    .ub-fig__grid { grid-template-columns: minmax(0, 1fr); }
    .ub-fig--model .ub-fig__panel--meta { grid-row: auto; }
    .ub-fig__row { grid-template-columns: 48px minmax(0, 1fr) 84px; }
    .ub-fig__row > .ub-fig__opt { display: none; }
    .ub-fig--migration .ub-fig__row { grid-template-columns: 48px minmax(0, 1fr) minmax(0, 1.2fr); }
    .ub-fig__msg--user, .ub-fig__msg--ai { max-width: 100%; }
}

/* 5. Split of work: task → code / model / person. Static, no steps. */
.ub-fig__split { display: grid; gap: 0; }
.ub-fig__split-head,
.ub-fig__split-row {
    display: grid;
    grid-template-columns: minmax(0, .8fr) repeat(3, minmax(0, 1fr));
    gap: 14px;
    padding: 12px 4px;
    border-bottom: 1px solid var(--fig-line);
}
.ub-fig__split-row:last-child { border-bottom: 0; }
.ub-fig__split-head { padding-top: 0; color: var(--fig-muted); font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
.ub-fig__split-head span:nth-child(2) { color: var(--fig-muted); }
.ub-fig__split-head span:nth-child(3) { color: var(--teal); }
.ub-fig__split-head span:nth-child(4) { color: var(--fig-text); }
.ub-fig__split-row b { font-weight: 600; }
.ub-fig__split-row span { font-size: 13.5px; color: var(--fig-muted); }
.ub-fig__split-row span:nth-of-type(2) { color: var(--fig-text); border-left: 2px solid var(--teal); padding-left: 10px; }
.ub-fig__split-row span:nth-of-type(3) { color: var(--fig-text); }

/* 6. Diff: the changed fragment lights up when code finds it. */
.ub-fig__clause { margin: 0; font-size: 15px; line-height: 1.6; color: var(--fig-text); }
.ub-fig__mark { border-radius: 4px; padding: 1px 3px; transition: background .4s, color .4s; }
.ub-fig__mark--del { background: rgba(255, 107, 107, .16); color: #ffb3b3; text-decoration: line-through; }
.ub-fig__mark--ins { background: rgba(0, 201, 167, .16); color: var(--teal); }
.ub-fig[data-step="0"] .ub-fig__mark { background: transparent; color: inherit; text-decoration: none; }
.ub-fig__flow--after { margin-top: 12px; }

/* 7. Pipeline: sources the user may not see stay greyed out. */
.ub-fig__chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.ub-fig__pill--off { opacity: .4; text-decoration: line-through; }

/* 8. Route: the server method sends each request to its model. */
.ub-fig--route .ub-fig__row { grid-template-columns: minmax(0, 1.2fr) 28px minmax(0, 1fr); align-items: center; font-size: 14px; }
.ub-fig--route .ub-fig__row > span:last-child { text-align: left; }
.ub-fig__arrow { color: var(--teal); font-size: 18px; text-align: center; }

@media (max-width: 640px) {
    .ub-fig__split-head { display: none; }
    .ub-fig__split-row { grid-template-columns: minmax(0, 1fr); gap: 6px; padding: 14px 0; }
    .ub-fig__split-row span::before { content: attr(data-who) ' · '; color: var(--fig-muted); font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; }
    .ub-fig__split-row span:nth-of-type(2) { padding-left: 8px; }
    .ub-fig--route .ub-fig__row { grid-template-columns: minmax(0, 1fr) 22px minmax(0, 1fr); }
}

/* Route has no "first role": without steps both routes stay readable. */
.ub-fig.ub-fig--route:not([data-step]) .ub-fig__row[data-roles] { opacity: 1; }
