/*
 * alignvu UI v2.1: Align > Overall System Mapping (application/views/configuration/configure/system_mapping.php).
 * A bar of options, a picker of four chip columns and a trace Panel per picked field: chips in columns joined by
 * right-angled lines (drawn in an SVG inside each canvas by js/modules/align/system_mapping/canvas.js).
 */

.app-sysmap {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    min-width: 0;
    /* clear of the feeds menu's open arrow, fixed at the top left of the content */
    padding-left: 44px;
}

.app-sysmap [hidden] {
    display: none !important;
}

.app-sysmap p {
    margin: 0;
}

/* ---------- Bar ---------- */

.app-sysmap__bar {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding-top: var(--space-4);
    padding-bottom: var(--space-4);
}

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

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

.app-sysmap__entities {
    flex: 1 1 320px;
    flex-wrap: wrap;
    row-gap: 0;
    min-width: 0;
}

.app-sysmap__entities .av-tab {
    padding: 6px 0;
}

.app-sysmap__legend {
    flex: 1 1 auto;
}

.app-sysmap__actions {
    margin-left: auto;
}

/* a colour key sample: a small chip as the canvas and picker draw it */
.app-sysmap__key {
    display: inline-block;
    width: 18px;
    height: 12px;
    border: 1px solid var(--muted);
    border-radius: var(--radius-xs);
    background: var(--surface);
}

.app-sysmap__key.is-partial,
.app-sysmap-pick.is-partial,
.app-sysmap-chip.is-partial {
    border-left: 4px solid var(--status-late);
}

.app-sysmap__key.is-unmapped,
.app-sysmap-pick.is-unmapped {
    border-style: dashed;
    background: var(--fill);
}

/* ---------- Picker ---------- */

.app-sysmap-picker {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.app-sysmap-picker__head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-3) var(--space-4);
}

.app-sysmap-picker__search {
    flex: 0 1 320px;
}

.app-sysmap-picker__cols {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.app-sysmap-picker__col {
    display: flex;
    flex-direction: column;
    min-width: 0;
    border-left: 1px solid var(--border);
}

.app-sysmap-picker__col:first-child {
    border-left: 0;
}

.app-sysmap-picker__heading {
    margin: 0;
    padding: 10px var(--space-4);
    background: var(--day-band);
    border-bottom: 1px solid var(--border);
    font: 600 12.5px/16px var(--font-display);
    color: var(--heading-ink);
}

.app-sysmap-picker__list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 320px;
    margin: 0;
    padding: var(--space-3);
    overflow-y: auto;
    list-style: none;
}

.app-sysmap-picker__hint {
    padding: var(--space-3) var(--space-4);
    font: 400 13px/18px var(--font-display);
    color: var(--muted);
}

.app-sysmap-pick {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 30px;
    padding: 5px 10px;
    text-align: left;
    font: 400 13px/18px var(--font-display);
    color: var(--heading-ink);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    overflow-wrap: anywhere;
}

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

.app-sysmap-pick[aria-pressed="true"] {
    background: var(--heading-ink);
    border-color: var(--heading-ink);
    color: var(--surface);
    font-weight: 600;
}

.app-sysmap-pick.is-static {
    border-style: dashed;
    font-style: italic;
}

/* a traced field: a tick before its name */
.app-sysmap-pick--traced {
    border-color: var(--heading-ink);
    font-weight: 600;
}

.app-sysmap-pick--traced::before {
    content: "";
    flex: none;
    width: 8px;
    height: 8px;
    margin-right: 8px;
    border-radius: var(--radius-pill);
    background: var(--heading-ink);
}

.app-sysmap-pick[aria-disabled="true"] {
    color: var(--muted);
    background: var(--fill);
    border-color: var(--fill);
    cursor: not-allowed;
}

/* ---------- Traces ---------- */

.app-sysmap__traces {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.app-sysmap__traces:empty {
    display: none;
}

.app-sysmap-trace {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    min-width: 0;
}

.app-sysmap-trace__head {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
}

.app-sysmap-trace__title {
    flex: 1 1 auto;
    min-width: 0;
}

.app-sysmap-trace__kind {
    display: block;
    font: 400 12px/16px var(--font-display);
    color: var(--muted);
}

.app-sysmap-trace__path {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px 6px;
    margin: 2px 0 0;
    padding: 0;
    list-style: none;
    font: 400 14px/20px var(--font-display);
    color: var(--body-ink);
}

.app-sysmap-trace__part + .app-sysmap-trace__part::before {
    content: "›";
    margin-right: 6px;
    color: var(--muted);
}

.app-sysmap-trace__part.is-last {
    font-weight: 600;
    color: var(--heading-ink);
}

.app-sysmap-trace__meta {
    flex: none;
    align-self: center;
    font: 400 13px/18px var(--font-display);
    color: var(--muted);
    white-space: nowrap;
}

.app-sysmap-trace__loading {
    font: 400 13px/18px var(--font-display);
    color: var(--muted);
}

/* ---------- Canvas: chips in columns sharing the width, joined by lines ---------- */

.app-sysmap-canvas {
    --sysmap-gap: 18px;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--surface);
}

.app-sysmap-canvas__head,
.app-sysmap-canvas__body {
    display: grid;
    grid-template-columns: var(--sysmap-template);
    column-gap: var(--sysmap-gap);
    padding: 0 var(--space-4);
}

.app-sysmap-canvas__head {
    padding-top: 10px;
    padding-bottom: 10px;
    background: var(--day-band);
    border-bottom: 1px solid var(--border);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    font: 600 12.5px/16px var(--font-display);
    color: var(--heading-ink);
    hyphens: auto;
}

.app-sysmap-canvas__body {
    position: relative;
    row-gap: 8px;
    align-items: start;
    padding-top: 12px;
    padding-bottom: 12px;
}

.app-sysmap-canvas__lines {
    position: absolute;
    top: 0;
    left: 0;
    z-index: 0;
    overflow: visible;
    pointer-events: none;
}

.app-sysmap-line {
    fill: none;
    stroke-width: 1.5;
}

.app-sysmap-line--native { stroke: var(--heading-ink); }
.app-sysmap-line--model { stroke: var(--audit-prev-week); }
.app-sysmap-arrow--native { fill: var(--heading-ink); }
.app-sysmap-arrow--model { fill: var(--audit-prev-week); }

/* chips sit above the lines */
.app-sysmap-chip {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-width: 0;
    min-height: 30px;
    padding: 4px 8px;
    color: var(--heading-ink);
    background: var(--fill);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}

.app-sysmap-chip__text {
    font: 400 12.5px/18px var(--font-display);
    overflow-wrap: break-word;
    min-width: 0;
    hyphens: auto;
}

.app-sysmap-chip__pre {
    font: 600 11px/15px var(--font-display);
    letter-spacing: 0.02em;
    text-transform: uppercase;
    color: var(--muted);
    overflow-wrap: anywhere;
}

.app-sysmap-chip__sub {
    font: 400 11.5px/16px var(--font-display);
    color: var(--muted);
    overflow-wrap: anywhere;
}

/* a chip with buttons at its end (e.g. a bin), as Field Mappings' Model Field chip has its pen and bin */
.app-sysmap-chip.has-actions {
    flex-direction: row;
    align-items: center;
    gap: 6px;
}

.app-sysmap-chip__body {
    display: flex;
    flex: 1 1 auto;
    flex-direction: column;
    min-width: 0;
}

.app-sysmap-chip__actions {
    display: flex;
    flex: none;
    align-items: center;
    gap: 2px;
    margin: -3px -4px -3px 0;
}

.app-sysmap-chip__actions .av-iconbtn {
    width: 22px;
    height: 22px;
    color: var(--heading-ink);
}

.app-sysmap-chip__actions .av-iconbtn .av-icon {
    width: 16px;
    height: 16px;
}

.app-sysmap-chip__actions .av-iconbtn:hover {
    background: var(--fill);
}

.app-sysmap-chip--native,
.app-sysmap-chip--entity {
    background: var(--surface);
    border-color: var(--muted);
}

.app-sysmap-chip--table .app-sysmap-chip__text {
    font-weight: 600;
}

.app-sysmap-chip.is-static {
    border-style: dashed;
}

.app-sysmap-chip.is-static .app-sysmap-chip__text {
    font-style: italic;
}

/* Field values: the data quality choice, the record count bar, the value list toggle, then the changes */
.app-sysmap-count {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 4px 6px;
    padding: 3px 4px 3px 8px;
    background: var(--surface);
    border-color: var(--muted);
}

.app-sysmap-count__pick {
    gap: 0;
}

.app-sysmap-count__main {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.app-sysmap-count__bar {
    flex: 1 1 auto;
    min-width: 16px;
}

.app-sysmap-count__num,
.app-sysmap-values__count span {
    font: 600 12.5px/18px var(--font-display);
    font-variant-numeric: tabular-nums;
    color: var(--heading-ink);
    white-space: nowrap;
}

.app-sysmap-count__toggle {
    width: 24px;
    height: 24px;
}

.app-sysmap-count__toggle .av-icon {
    transition: transform .15s;
}

.app-sysmap-count__toggle.is-open .av-icon {
    transform: rotate(180deg);
}

.app-sysmap-count__changes {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.app-sysmap-count__changes .av-badge {
    padding: 0 8px;
    font-size: 11.5px;
}

/* a row's value list, under the row */
.app-sysmap-values {
    position: relative;
    z-index: 1;
    max-height: 320px;
    overflow-y: auto;
}

.app-sysmap-values .av-table td {
    height: auto;
    padding-top: 5px;
    padding-bottom: 5px;
    overflow-wrap: anywhere;
}

.app-sysmap-values__count {
    display: flex;
    align-items: center;
    gap: 6px;
    min-width: 120px;
}

.app-sysmap-values__count .av-bar {
    flex: 1 1 auto;
}

/* ---------- Narrow windows ---------- */

@media (max-width: 1279px) {
    .app-sysmap-canvas {
        --sysmap-gap: 14px;
    }

    .app-sysmap-canvas__head,
    .app-sysmap-canvas__body {
        padding-left: var(--space-3);
        padding-right: var(--space-3);
    }

    .app-sysmap-chip {
        padding: 3px 5px;
    }

    .app-sysmap-chip__text {
        font-size: 12px;
    }
}

@media (max-width: 899px) {
    .app-sysmap-picker__cols {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .app-sysmap-picker__col:nth-child(3) {
        border-left: 0;
    }

    .app-sysmap-picker__col:nth-child(n + 3) {
        border-top: 1px solid var(--border);
    }

    /* the canvas keeps its columns and scrolls inside its frame */
    .app-sysmap-canvas {
        overflow-x: auto;
    }

    .app-sysmap-canvas__head,
    .app-sysmap-canvas__body {
        min-width: 760px;
    }
}
