/*
 * alignvu UI v2.1: Align > Datafeed Overview (application/views/dataflow/incoming.php,
 * js/modules/align/datafeed_overview/). Tabs and a "Show inactive" switch over one FeedTable per last run status,
 * whose columns are shares of the width (text wraps); a feed's previous downloads open as a detail row. The entity
 * mappings tree (.app-dfo-tree) is also used by the Datafeed Summary (css/v21_align_datafeed_summary.css).
 */

/* the page's parts use the hidden attribute; v2.1 components that set display (av-tabs is flex) must still hide */
.app-dfo [hidden] {
    display: none !important;
}

.app-dfo {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding-bottom: 32px;
}

/* ---------- Toolbar: tabs on the left, the switch on the right ---------- */

.app-dfo__toolbar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    border-bottom: 1px solid var(--border);
}

.app-dfo__tabs.av-tabs {
    border-bottom: 0;
}

.app-dfo__tab-count {
    color: var(--muted);
    font-weight: 400;
}

.app-dfo__switch {
    padding: 10px 0;
    white-space: nowrap;
}

/* ---------- The status tables ---------- */

.app-dfo__groups {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.app-dfo__group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.app-dfo .app-dfo__group-title {
    margin: 0;
    font: 600 15px/22px var(--font-display);
    color: var(--heading-ink);
}

/* ---------- The datafeeds table ---------- */

/* fixed layout: each column takes its share of the width and long text wraps instead of widening the table;
   below about 760px the table scrolls inside its frame */
.app-dfo-table {
    table-layout: fixed;
    min-width: 760px;
}

.app-dfo-table col.app-dfo__col-name { width: 16%; }
.app-dfo-table col.app-dfo__col-jurisdiction { width: 8%; }
.app-dfo-table col.app-dfo__col-status { width: 10%; }
.app-dfo-table col.app-dfo__col-date { width: 8%; }
.app-dfo-table col.app-dfo__col-file { width: 10%; }
.app-dfo-table col.app-dfo__col-entities { width: 28%; }

/* the actions column holds its icon buttons on one line: 4, or 5 with the developers' Run list */
.app-dfo-table col.app-dfo__col-actions { width: calc(4 * 30px + 2 * var(--space-4)); }
.app-dfo__frame--dev .app-dfo-table col.app-dfo__col-actions { width: calc(5 * 30px + 2 * var(--space-4)); }

.app-dfo-table th,
.app-dfo-table td {
    white-space: normal;
    overflow-wrap: break-word;   /* between words; file names (.app-dfo__file) may break anywhere */
    vertical-align: top;
}

/* headings wrap between words only */
.app-dfo-table > thead th {
    vertical-align: bottom;
    overflow-wrap: normal;
}

.app-dfo-table > tbody > tr > td,
.app-dfo-table > tbody > tr > th {
    padding-top: 9px;
    padding-bottom: 9px;
}

/* the datafeed's name leads the row */
.app-dfo-table > tbody > tr > th.app-dfo__name {
    font: 600 13px/20px var(--font-display);
    color: var(--heading-ink);
    text-align: left;
    background: var(--surface);
}

.app-dfo-table > tbody > tr:hover > th.app-dfo__name {
    background: var(--fill);
}

/* a name opens the datafeed (or the entity mapping): a button that reads as a link */
.app-dfo .app-dfo__link {
    padding: 0;
    border: 0;
    background: none;
    font: inherit;
    color: var(--heading-ink);
    text-align: left;
    cursor: pointer;
    overflow-wrap: anywhere;
}

.app-dfo .app-dfo__link:hover,
.app-dfo .app-dfo__link:focus-visible {
    text-decoration: underline;
    text-underline-offset: 2px;
}

.app-dfo :is(.app-dfo__link, .app-dfo__source, .av-iconbtn, .av-sort, .av-tab):focus-visible {
    outline: 2px solid var(--heading-ink);
    outline-offset: 2px;
}

/* a second line under a cell's value: the provider, the poll frequency, the file's type and size */
.app-dfo .app-dfo__sub {
    display: block;
    font: 400 12px/18px var(--font-display);
    color: var(--muted);
}

.app-dfo .app-dfo__source {
    display: flex;
    align-items: center;
    gap: 3px;
    width: fit-content;
    max-width: 100%;
    margin-top: 2px;
    font: 400 12px/16px var(--font-display);
    color: var(--body-ink);
    overflow-wrap: anywhere;
}

.app-dfo .app-dfo__source .av-icon {
    width: 12px;
    height: 12px;
}

.app-dfo .app-dfo__date {
    white-space: nowrap;
}

.app-dfo .app-dfo__time {
    color: var(--muted);
    white-space: nowrap;
}

.app-dfo .app-dfo__badges {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 4px;
}

.app-dfo .app-dfo__file {
    overflow-wrap: anywhere;
}

/* ---------- Entity mappings: a tree, each native table once with an arrow to each model entity it feeds ---------- */

.app-dfo-tree,
.app-dfo-tree__models {
    margin: 0;
    padding: 0;
    list-style: none;
}

.app-dfo-tree {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

/* the native table on the left, centred against its model entities on the right */
.app-dfo-tree__group {
    display: grid;
    grid-template-columns: fit-content(50%) minmax(0, 1fr);   /* a long native name takes at most half */
    align-items: center;
}

.app-dfo-tree__native {
    position: relative;
    margin-right: 10px;
    padding: 1px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    background: var(--fill);
    font: 400 12px/18px var(--font-display);
    color: var(--body-ink);
    overflow-wrap: anywhere;
}

/* the line from the native table to its model entities' branches */
.app-dfo-tree__native::after {
    content: "";
    position: absolute;
    top: 50%;
    right: -11px;
    width: 10px;
    border-top: 1px solid var(--muted);
}

.app-dfo-tree__models > li {
    position: relative;
    display: grid;
    grid-template-columns: 14px minmax(0, 1fr) auto;
    align-items: center;
    column-gap: 4px;
    min-height: 24px;
}

/* the vertical line joining the branches: from the first model entity's middle to the last one's */
.app-dfo-tree__models > li::before {
    content: "";
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    border-left: 1px solid var(--muted);
}

.app-dfo-tree__models > li:first-child::before {
    top: 50%;
}

.app-dfo-tree__models > li:last-child::before {
    bottom: 50%;
}

.app-dfo-tree__models > li:only-child::before {
    display: none;
}

/* a branch: a line ending in an arrowhead at the model entity */
.app-dfo-tree__branch {
    position: relative;
    height: 0;
    border-top: 1px solid var(--muted);
}

.app-dfo-tree__branch::after {
    content: "";
    position: absolute;
    top: -4px;
    right: -1px;
    border-left: 6px solid var(--muted);
    border-top: 3.5px solid transparent;
    border-bottom: 3.5px solid transparent;
}

.app-dfo-tree__model {
    min-width: 0;
    overflow-wrap: break-word;   /* between words; a word is broken only when it can't fit */
}

.app-dfo-tree__count {
    padding-left: 8px;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    text-align: right;
}

/* ---------- Row actions: quiet icon buttons on one line ---------- */

.app-dfo .app-dfo__actions {
    display: flex;
    justify-content: flex-end;
    flex-wrap: nowrap;
}

.app-dfo .app-dfo__actions .app-dfo__iconbtn {
    width: 30px;
    height: 30px;
}

.app-dfo .app-dfo__actions .app-dfo__iconbtn[aria-expanded="true"] {
    background: var(--fill);
}

.app-dfo-table > tbody > tr > td.app-dfo__actions-cell {
    padding-top: 4px;
    padding-bottom: 4px;
}

/* ---------- Previous downloads (a detail row under the datafeed) ---------- */

.app-dfo-table > tbody > tr.app-dfo__history > td {
    padding: 4px var(--space-4) 16px;
    background: var(--day-band);
}

.app-dfo .app-dfo__history-table {
    table-layout: auto;
    border: 1px solid var(--border);
}

.app-dfo .app-dfo__history-table th {
    background: var(--surface);
}

/* the design system's detail-row padding (.av-table__detail td) would also reach the inner table's cells */
.app-dfo .app-dfo__history-table td {
    height: auto;
    padding: 7px var(--space-4);
    background: var(--surface);
    vertical-align: top;
}

.app-dfo .app-dfo__history-table .app-dfo-tree {
    min-width: 260px;
}

.app-dfo .app-dfo__more {
    margin-top: 8px;
}

/* ---------- Remove confirmation (the Dialog under the page) ---------- */

.app-dfo-dialog .modal-body p {
    margin: 0 0 8px;
}

/* ---------- Narrower windows (sidebar open at 1100px) ---------- */

/* narrower windows: tighter cell padding, more room for the short columns, the actions two to a line and
   dates free to wrap */
@media (max-width: 1400px) {
    .app-dfo-table > thead > tr > th,
    .app-dfo-table > tbody > tr > td,
    .app-dfo-table > tbody > tr > th {
        padding-left: var(--space-3);
        padding-right: var(--space-3);
    }

    .app-dfo-table col.app-dfo__col-name { width: 15%; }
    .app-dfo-table col.app-dfo__col-jurisdiction { width: 9%; }
    .app-dfo-table col.app-dfo__col-status { width: 11%; }
    .app-dfo-table col.app-dfo__col-date { width: 9%; }
    .app-dfo-table col.app-dfo__col-file { width: 11%; }
    .app-dfo-table col.app-dfo__col-entities { width: 23%; }

    /* the entity tree stacks: the native table above, its model entities branching from a line down from it */
    .app-dfo-table .app-dfo-tree__group {
        grid-template-columns: minmax(0, 1fr);
    }

    .app-dfo-table .app-dfo-tree__native {
        justify-self: start;
        margin: 0 0 4px;
    }

    .app-dfo-table .app-dfo-tree__native::after {
        top: 100%;
        right: auto;
        left: 10px;
        width: 0;
        height: 5px;
        border-top: 0;
        border-left: 1px solid var(--muted);
    }

    .app-dfo-table .app-dfo-tree__models {
        margin-left: 10px;
    }

    .app-dfo-table .app-dfo-tree__models > li:first-child::before {
        top: -1px;
    }

    .app-dfo-table .app-dfo-tree__models > li:only-child::before {
        display: block;
        bottom: 50%;
    }
    .app-dfo-table col.app-dfo__col-actions,
    .app-dfo__frame--dev .app-dfo-table col.app-dfo__col-actions { width: calc(2 * 30px + 2 * var(--space-3)); }

    .app-dfo .app-dfo__actions {
        flex-wrap: wrap;
    }

    .app-dfo .app-dfo__date {
        white-space: normal;
    }
}
