/*
 * alignvu UI v2.1: Align > Model, Substitutions, Significant Fields, Flags & Cleans, Reference Group Code Crossover.
 * The lists reuse the Admin & Security list parts (css/v21_admin.css: app-admin, app-admin-table, app-admin-dialog);
 * this file adds each table's column widths, the Model's linked columns, the Flags & Cleans rule tree and the
 * crossover table. Rules here override css/translate.css and css/align_to.css where legacy ids are kept.
 */

/* ---------- Lists: column widths as fractions of the table, text wraps ---------- */

.app-model-table {
    width: 100%;
    table-layout: fixed;
}

.app-model-table th,
.app-model-table td {
    overflow-wrap: break-word;
}

/* column headings wrap on a narrow window rather than running into each other */
.app-model-table thead th {
    white-space: normal;
}

/* the actions column: room for the Edit and Delete icon buttons */
.app-model-table thead th:last-child {
    width: calc(2 * var(--control-height) + 16px);
}

.app-model-subs thead th:nth-child(1) { width: 18%; }
.app-model-subs thead th:nth-child(2) { width: 10%; }
.app-model-subs thead th:nth-child(3) { width: 10%; }
.app-model-subs thead th:nth-child(4) { width: 15%; }
.app-model-subs thead th:nth-child(5) { width: 12%; }
.app-model-subs thead th:nth-child(6) { width: 13%; }

.app-model-flags thead th:nth-child(1) { width: 30%; }
.app-model-flags thead th:nth-child(2) { width: 13%; }
.app-model-flags thead th:nth-child(3) { width: 22%; }
.app-model-flags thead th:nth-child(5) { width: 11%; }

/* ---------- Flags & Cleans: rule tree ---------- */

.app-model-flag__name {
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

.app-model-flag__toggle .av-icon {
    transition: transform 0.15s ease;
}

.app-model-flag__toggle[aria-expanded="true"] .av-icon {
    transform: rotate(90deg);
}

/* rules without a chevron keep their names in line with those that have one */
.app-model-flag__spacer {
    flex: none;
    width: var(--control-height);
}

/* child rules are indented under their parent */
.app-model-flags tr.app-model-flag--depth-1 > th { padding-left: calc(var(--space-4) + 28px); }
.app-model-flags tr.app-model-flag--depth-2 > th { padding-left: calc(var(--space-4) + 56px); }
.app-model-flags tr.app-model-flag--depth-3 > th { padding-left: calc(var(--space-4) + 84px); }

.app-model-flag__detail td {
    background: var(--fill);
}

.app-model-flag__detail-body {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr));
    gap: var(--space-4);
    padding-left: calc(var(--control-height) + var(--space-1));
}

.app-model-flag__detail-body h4 {
    margin: 0 0 6px;
}

.app-model-flag__rules,
.app-model-rules {
    margin: 0;
    padding: 0;
    list-style: none;
    font: 400 13px/20px var(--font-display);
    color: var(--table-ink);
}

/* the wizard's clause and clean lists: one per row with a Remove button */
.app-model-rules:empty::before {
    content: "None added yet.";
    color: var(--muted);
}

.app-model-rules__item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: 4px 0 4px var(--space-3);
    border-bottom: 1px solid var(--row-rule);
    overflow-wrap: anywhere;
}

/* "Add clause" / "Add clean": under the entries, at their natural width (css/translate.css floats them right) */
#translate-flag-add-rule,
#translate-flag-add-clean {
    width: auto;
    float: none;
}

/* css/translate.css sizes every paragraph in the wizard: keep the v2.1 type */
#translate-flags-1-modal p.av-small,
#translate-flags-2-modal p.av-small,
#translate-flags-3-modal p.av-small {
    margin: 0;
    font: 400 12px/16px var(--font-display);
    color: var(--muted);
}

#translate-flags-2-modal .app-dialog__head p.av-text,
#translate-flags-3-modal .app-dialog__head p.av-text {
    margin: 0;
    font: 400 14px/20px var(--font-display);
    color: var(--body-ink);
}

#translate-flags-1-modal p.av-field__error,
#translate-flags-2-modal p.av-field__error,
#translate-flags-3-modal p.av-field__error {
    margin: 0;
    font: 600 12px/16px var(--font-display);
    color: var(--status-removed);
}

/* ---------- Model: five linked columns ---------- */

.app-model .entity-types {
    flex-wrap: wrap;
}

/* on a narrow window the columns scroll sideways inside their frame, never the page */
.app-model__columns {
    display: grid;
    grid-template-columns: repeat(5, minmax(180px, 1fr));
    gap: var(--space-3);
    overflow-x: auto;
    padding-bottom: 2px;
}

.app-model__column {
    display: flex;
    flex-direction: column;
    min-width: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.app-model__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    min-height: calc(var(--control-height) + 16px);
    padding: 8px var(--space-3);
    border-bottom: 1px solid var(--border);
}

.app-model__head .av-cardtitle {
    margin: 0;
}

.app-model__head .app-model__add {
    height: 28px;
    padding: 0 10px;
}

.app-model__list {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: calc(100vh - var(--app-sticky-top) - 180px);
    min-height: 160px;
    overflow-y: auto;
    padding: var(--space-2);
}

.app-model__column--empty .app-model__list::before {
    content: attr(data-empty-text);
    padding: var(--space-2);
    font: 400 13px/18px var(--font-display);
    color: var(--muted);
}

.app-model__item {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    border-radius: var(--radius-sm);
}

.app-model__item.hidden {
    display: none;
}

.app-model__item:hover {
    background: var(--fill);
}

.app-model__item.active {
    background: var(--heading-ink);
}

.app-model__name {
    flex: 1 1 auto;
    min-width: 0;
    padding: 7px var(--space-2);
    border: 0;
    background: none;
    font: 400 13px/18px var(--font-display);
    color: var(--heading-ink);
    text-align: left;
    overflow-wrap: anywhere;
    cursor: pointer;
}

.app-model__item.active .app-model__name {
    font-weight: 600;
    color: var(--surface);
}

.app-model__name:focus-visible {
    outline: 2px solid var(--heading-ink);
    outline-offset: 1px;
}

/* the chosen item's Edit and Delete buttons */
.app-model__actions {
    display: none;
    flex: none;
}

.app-model__item.active .app-model__actions {
    display: flex;
}

.app-model__item.active .app-admin__icon {
    color: var(--surface);
}

.app-model__item.active .app-admin__icon:hover,
.app-model__item.active .app-admin__icon:focus-visible {
    background: var(--table-ink);
}

.app-model__value {
    padding: 7px var(--space-2);
    font: 400 13px/18px var(--font-display);
    color: var(--table-ink);
    overflow-wrap: anywhere;
}

/* Model Dialogs: the field's Yes / No questions side by side */
.app-model-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr));
    gap: var(--space-3);
}

.app-model-options .av-radio {
    display: inline-flex;
}

.app-model-allowable {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding-top: var(--space-4);
    border-top: 1px solid var(--border);
}

.app-model-allowable .av-cardtitle {
    margin: 0;
}

.app-model-allowable__add {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr) auto;
    align-items: start;
    gap: var(--space-3);
}

.app-model-allowable__add .av-btn {
    margin-top: 24px;
}

.translate-model-allowable-remove {
    display: inline-flex;
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    cursor: pointer;
}

.translate-model-allowable-list:empty::before {
    content: "No allowable values.";
    font: 400 13px/18px var(--font-display);
    color: var(--muted);
}

/* ---------- Reference Group Code Crossover ---------- */

.app-rgc__filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
}

/* The crossovers as a chip canvas with arrows (js/modules/align/rgc_crossover/ on the Overall System Mapping canvas,
   css/v21_align_system_mapping.css): datafeed | ref code | crossover ref code | crossover datafeed (with its bin) */
.app-rgc-canvas:empty {
    display: none;
}

/* a datafeed chip (shows or hides its codes) and, for users who may change crossovers, a code chip (adds one) */
.app-rgc-chip--button {
    cursor: pointer;
}

.app-rgc-chip--button:hover {
    border-color: var(--heading-ink);
    background: var(--fill);
}

.app-rgc-chip--button:focus-visible {
    outline: 2px solid var(--focus, var(--heading-ink));
    outline-offset: 2px;
}

.app-rgc-chip--button[aria-expanded="true"] {
    border-color: var(--heading-ink);
    box-shadow: inset 0 0 0 1px var(--heading-ink);
}

/* a datafeed none of whose codes has a crossover (some: .is-partial's amber edge); matches the key's
   .app-sysmap__key.is-unmapped. Two classes: css/v21_align_system_mapping.css loads later and its .app-sysmap-chip
   border and .app-sysmap-chip--native background would win over one. */
.app-sysmap-chip.app-rgc-chip--none {
    border-style: dashed;
    background: var(--fill);
}

.app-rgc__legend {
    flex-wrap: wrap;
}

/* the crossover Dialog: the code a crossover is added for, then the datafeed | code picker (wider than a medium
   Dialog, for the datafeed type Tabs) */
.modal-content.app-dialog--medium.app-rgc-dialog {
    width: min(760px, calc(100vw - 32px));
}

.app-rgc-dialog__from {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: var(--space-4);
}

.app-rgc-picker.app-sysmap-picker__cols {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.app-rgc-pick.app-sysmap-pick {
    flex-direction: column;
    align-items: flex-start;
}

/* the picker's datafeed type Tabs and code filter, under their column headings */
.app-rgc-picker__tabs {
    padding: 0 var(--space-3);
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
}

.app-rgc-picker__filter {
    padding: var(--space-3) var(--space-3) 0;
}

.app-rgc-pick__detail {
    font: 400 11.5px/16px var(--font-display);
    color: var(--muted);
}

.app-rgc-pick[aria-pressed="true"] .app-rgc-pick__detail {
    color: inherit;
}

@media (max-width: 899px) {
    .app-rgc-canvas .app-sysmap-canvas {
        overflow-x: auto;
    }

    .app-rgc-canvas .app-sysmap-canvas__head,
    .app-rgc-canvas .app-sysmap-canvas__body {
        min-width: 680px;
    }
}

/* the crossover Dialog's list names under the chosen reference code */
.app-rgc-dialog__lists {
    margin: 0;
    padding-left: var(--space-4);
    font: 400 12px/18px var(--font-display);
    color: var(--muted);
}
