/*
 * alignvu UI v2.1: Align > datafeed wizard setup steps (provider_product, data_feed, runlist, xsd_upload, schema_download).
 * Step pages are scoped to .app-datafeed-step (inside the view, .app-datafeed-step-host), their Dialogs to
 * .app-datafeed-feed-dialog. Parts printed by application/views/configuration/configure/datafeed_step_parts.php.
 * The step-nav rules (.app-datafeed-step__nav, the page head's Next) serve every wizard step that uses datafeedStepNav().
 */

/* v2.1 parts set display (flex, grid), which would beat the hidden attribute the scripts set */
.app-datafeed-step [hidden],
.app-datafeed-feed-dialog [hidden] {
    display: none !important;
}

/* ---------- Step navigation (js/align_to/configure/datafeed_wizard_steps.js) ---------- */

/* While a step with its own Back / Cancel / Next is shown, the page head's Next (which that Next runs) is hidden */
body:has([data-view]:not([style*="none"]) .app-datafeed-step__nav) #application-nav-next {
    display: none !important;
}

.app-datafeed-step__nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-3);
    margin-top: var(--space-2);
    padding-top: var(--space-4);
    border-top: 1px solid var(--border);
}

/* The page head's filled custom buttons (Download Settings' Run Download, AppNavigator.bindCustomButton): they carry
   both mapping-form-button (dark text) and mapping-form-button-colored (dark fill), so the label didn't show */
#application-nav-custom-buttons .mapping-form-button.mapping-form-button-colored {
    color: var(--surface);
}

#application-nav-custom-buttons .mapping-form-button.mapping-form-button-disabled {
    color: var(--muted);
    background: var(--fill);
    border-color: var(--fill);
    pointer-events: none;
}

/* ---------- Step page ---------- */

.app-datafeed-step-host {
    width: 100%;
}

.app-datafeed-step {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    width: 100%;
    padding-bottom: 32px;
}

.app-datafeed-step > .av-panel {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
    min-width: 0;
}

.app-datafeed-step .av-sectionhead h2 {
    margin: 0;
}

.app-datafeed-step p {
    margin: 0;
}

/* Datafeed Details: the text fields side by side, as many as fit */
.app-datafeed-step__grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr));
    gap: var(--space-4);
}

.app-datafeed-step .av-field {
    min-width: 0;
}

/* Details: vendor and product, then full and short name, two to a line; database on its own line; source URL
   across the width */
.app-datafeed-step__grid--details {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.app-datafeed-step__grid--details .app-datafeed-step__own-line {
    grid-column: 1;
}

.app-datafeed-step__grid--details .app-datafeed-step__full-width {
    grid-column: 1 / -1;
}

@media (max-width: 700px) {
    .app-datafeed-step__grid--details {
        grid-template-columns: minmax(0, 1fr);
    }
}

.app-datafeed-step .av-input[readonly] {
    background: var(--fill);
    color: var(--muted);
}

.app-datafeed-step__linked {
    max-width: min(560px, 100%);
}

/* Radios under their question, as in Connect's steps */
.app-datafeed-step__radios {
    align-items: flex-start;
    min-width: 0;
}

.app-datafeed-step__radios > legend {
    margin-bottom: var(--space-1);
    padding: 0;
}

.app-datafeed-step__form {
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
}

.app-datafeed-step__form > div:not(.app-datafeed-feeds) .av-field {
    max-width: min(560px, 100%);
}

/* Loading line (Files Downloaded, XSD Mappings) */
.app-datafeed-loading {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-5) 0;
}

/* ---------- Download Settings: the feeds ---------- */

.app-datafeed-feeds {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.app-datafeed-feeds .av-tabs {
    margin-bottom: var(--space-1);
}

.app-datafeed-feeds .datafeed-web,
.app-datafeed-feeds .datafeed-ftp {
    flex-direction: column;
    gap: var(--space-3);
}

.app-datafeed-feeds .datafeed-web:not([style*="none"]),
.app-datafeed-feeds .datafeed-ftp:not([style*="none"]) {
    display: flex;
}

.app-datafeed-feeds__table {
    table-layout: fixed;
}

.app-datafeed-feeds__table td {
    overflow-wrap: anywhere;
}

.app-datafeed-feeds__table--web th:nth-child(1) { width: 46%; }
.app-datafeed-feeds__table--web th:nth-child(2) { width: 18%; }
.app-datafeed-feeds__table--web th:nth-child(3) { width: 10%; }
.app-datafeed-feeds__table--web th:nth-child(4) { width: 16%; }
.app-datafeed-feeds__table--web th:nth-child(5) { width: 10%; }

.app-datafeed-feeds__table--ftp th:nth-child(1) { width: 24%; }
.app-datafeed-feeds__table--ftp th:nth-child(2) { width: 13%; }
.app-datafeed-feeds__table--ftp th:nth-child(3) { width: 13%; }
.app-datafeed-feeds__table--ftp th:nth-child(4) { width: 7%; }
.app-datafeed-feeds__table--ftp th:nth-child(5) { width: 13%; }
.app-datafeed-feeds__table--ftp th:nth-child(6) { width: 8%; }
.app-datafeed-feeds__table--ftp th:nth-child(7) { width: 12%; }
.app-datafeed-feeds__table--ftp th:nth-child(8) { width: 10%; }

.app-datafeed-feeds__table th {
    white-space: normal;
}

.app-datafeed-feeds__actions {
    text-align: right;
    white-space: nowrap;
}

.app-datafeed-feeds__add {
    display: flex;
    justify-content: flex-start;
}

.app-datafeed-feeds .av-empty p {
    margin: 0;
}

.app-datafeed-feeds .datafeed-feeds-error {
    margin: 0;
}

/* ---------- Feed Dialogs (Add / Edit web or FTP feed) ---------- */

.app-datafeed-feed-dialog {
    max-height: calc(100vh - 48px);
}

.app-datafeed-feed-dialog .modal-body {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.app-datafeed-feed-dialog__grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--space-3) var(--space-4);
}

.app-datafeed-feed-dialog__wide {
    grid-column: 1 / -1;
}

.app-datafeed-feed-dialog__file {
    flex-direction: column;
    gap: var(--space-2);
}

.app-datafeed-feed-dialog__file:not([style*="none"]) {
    display: flex;
}

/* A file input behind a secondary button, with the chosen file's name beside it */
.app-datafeed-file-picker {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
}

.app-datafeed-file-picker label.av-btn {
    position: relative;
    cursor: pointer;
}

.app-datafeed-file-picker label.av-btn:focus-within {
    outline: 2px solid var(--heading-ink);
    outline-offset: 2px;
}

.app-datafeed-xsd-upload .mapping-form-selected-file:empty::before {
    content: "none";
    color: var(--muted);
}

/* ---------- Files Downloaded: the file Tables ---------- */

.app-datafeed-runlist {
    flex-direction: column;
    gap: var(--space-3);
}

.app-datafeed-runlist:not([style*="none"]) {
    display: flex;
}

.app-datafeed-runlist .av-tabs {
    flex-wrap: wrap;
    row-gap: 0;
}

.app-datafeed-runlist .downloaded-files {
    max-height: min(60vh, 640px);
    overflow: auto;
}

.app-datafeed-files__table thead th {
    position: sticky;
    top: 0;
    z-index: 1;
}

.app-datafeed-files__name {
    overflow-wrap: anywhere;
}

/* ---------- XSD Mappings ---------- */

.app-datafeed-xsd__head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
}

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

/* node_definition.js marks a button it can't use yet with btn-inactive */
.app-datafeed-step .av-btn.btn-inactive {
    color: var(--muted);
    background: var(--fill);
    border-color: var(--fill);
    pointer-events: none;
}

.app-datafeed-xsd .mapping-xsd-body {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    min-width: 0;
}

.app-datafeed-xsd .mapping-xsd-body #mapping-table-instruction:empty {
    display: none;
}

.app-datafeed-xsd__canvas {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: var(--space-5);
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 0;
    overflow-x: auto;
}

/* The tables made from nodes sit level with their nodes (node_definition.js sets each card's top from its node's
   position), in a column on the canvas's right; the canvas is their containing block, so the column follows the
   canvas's width instead of the window's (align_to.css put them at 60vw, over a deep tree in a narrow window). */
.app-datafeed-xsd__canvas {
    --xsd-tables-width: clamp(280px, 40%, 560px);
    position: relative;
    flex-wrap: nowrap;
}

.app-datafeed-xsd__canvas .mapping-xsd {
    flex: 1 0 auto;
    min-width: 0;
    margin-right: calc(var(--xsd-tables-width) + var(--space-5));
}

.app-datafeed-xsd__canvas .mapping-xsd-new-tables {
    flex: none;
    width: 0;
}

.app-datafeed-xsd__canvas .mapping-xsd-new-table {
    left: auto;
    right: 0;
    width: var(--xsd-tables-width);
}

/* No schema: shown once loading has finished and no node was drawn */
.app-datafeed-xsd__empty {
    display: none;
}

.app-datafeed-xsd .mapping-xsd-body:has(.xsd-preloader[style*="none"]):has(.mapping-xsd:empty) .app-datafeed-xsd__empty {
    display: block;
}

.app-datafeed-xsd .mapping-xsd-body:has(.mapping-xsd:empty) .app-datafeed-xsd__canvas {
    display: none;
}

.app-datafeed-xsd .av-empty p {
    margin: 0;
}

/* align_to.css pulls the node tree out to the page edges */
.app-datafeed-xsd .mapping-xsd {
    margin-top: 0;
    margin-bottom: 0;
    margin-left: 0;
}

/* Legacy rules the feed Dialogs' fields must beat: css/application.css takes the border off password inputs and
   gives .modal-body p 16px text with margins; css/align_to.css styles #datafeed-ftp-port and .datafeed-ftp-key-file */
.app-datafeed-feed-dialog input.av-input[type="password"],
.app-datafeed-feed-dialog #datafeed-ftp-port.av-input {
    padding: 0 12px;
    font: 400 14px/20px var(--font-display);
    border: 1px solid var(--muted);
    border-radius: var(--radius-sm);
}

.app-datafeed-feed-dialog .datafeed-ftp-key-file {
    justify-content: flex-start;
    align-items: flex-start;
    margin: 0;
}

.app-datafeed-feed-dialog .modal-body p,
.app-datafeed-step .modal-body p {
    margin: 0;
    font-size: inherit;
}

.app-datafeed-feed-dialog p.av-field__error,
.app-datafeed-step p.av-field__error {
    margin: 4px 0 0;
    font: 600 12px/18px var(--font-display);
}

.app-datafeed-step-host .modal-body p.av-text {
    margin: 0;
    font-size: 14px;
}

/* XSD Mappings' node tree (drawn by node_definition.js) as v2.1 chips: a node is outlined, a node made into a table
   is filled dark, a node that is a table's column is filled grey (align_to.css made them white, green and light green) */
.app-datafeed-xsd .mapping-xsd-element-tag,
.app-datafeed-xsd .mapping-xsd-attribute-tag {
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    background-color: var(--surface);
    box-shadow: none;
}

.app-datafeed-xsd .mapping-xsd-element-tag p,
.app-datafeed-xsd .mapping-xsd-attribute-tag p {
    font: 500 12.5px/18px var(--font-display);
    color: var(--heading-ink);
    text-shadow: none;
}

.app-datafeed-xsd .mapping-xsd-element > p,
.app-datafeed-xsd .mapping-xsd-attribute > p {
    font: 400 12px/16px var(--font-display);
    color: var(--muted);
}

.app-datafeed-xsd .mapping-xsd-table-tag {
    border-color: var(--heading-ink);
    background-color: var(--heading-ink) !important;   /* align_to.css sets it with !important */
}

.app-datafeed-xsd .mapping-xsd-table-tag p {
    color: var(--surface);
}

.app-datafeed-xsd .mapping-xsd-column-tag {
    border-color: var(--muted);
    background-color: var(--fill) !important;   /* align_to.css sets it with !important */
}

/* a grey chip keeps the dark label (align_to.css made the label white with a shadow) */
.app-datafeed-xsd .mapping-xsd-column-tag p {
    color: var(--heading-ink);
    text-shadow: none;
}

/* a table's node that is also another table's column stays a dark table chip */
.app-datafeed-xsd .mapping-xsd-table-tag.mapping-xsd-column-tag {
    border-color: var(--heading-ink);
    background-color: var(--heading-ink) !important;
}

.app-datafeed-xsd .mapping-xsd-table-tag.mapping-xsd-column-tag p,
.app-datafeed-xsd .active-xsd-new-table p {
    color: var(--surface);
}

/* the nodes picked while making a table: the table dark, its columns grey */
.app-datafeed-xsd .active-xsd-new-table {
    border-color: var(--heading-ink);
    background-color: var(--heading-ink) !important;
}

.app-datafeed-xsd .active-xsd-new-column {
    border: 1px solid var(--heading-ink) !important;
    background-color: var(--fill) !important;
}

/* a table made from a node: a v2.1 card instead of a dark bar */
.app-datafeed-xsd .mapping-xsd-new-table-min {
    color: var(--heading-ink);
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    gap: var(--space-2) var(--space-3);
    flex-wrap: wrap;   /* a narrow card puts its actions under its name */
    padding: var(--space-2) var(--space-4);
}

.app-datafeed-xsd .mapping-xsd-new-table-min-details {
    flex: 1 1 160px;
    min-width: 0;
}

.app-datafeed-xsd .mapping-xsd-show-clear-cols {
    margin-left: auto;
}

.app-datafeed-xsd .mapping-xsd-new-table-min p {
    color: var(--heading-ink);
    font: 600 13px/18px var(--font-display);
    overflow-wrap: break-word;
}

.app-datafeed-xsd .mapping-xsd-show-clear-cols {
    flex: none;
    gap: var(--space-2);
}

/* the table card's pen: align_to.css styles .mapping-xsd-edit-table as a white tab */
.app-datafeed-xsd .mapping-xsd-edit-table.av-iconbtn {
    height: var(--control-height);
    margin: 0;
    padding: 0;
    background-color: transparent;
}

.app-datafeed-xsd .mapping-xsd-edit-table.av-iconbtn:hover {
    background-color: var(--fill);
}

/* the table card's Show Columns: align_to.css gives .mapping-xsd-show-new-cols a fixed width */
.app-datafeed-xsd .mapping-xsd-show-clear-cols .av-btn {
    width: auto;
}

/* its columns: align_to.css set white text, which the white card hid ("Show Columns" looked broken) */
.app-datafeed-xsd .mapping-xsd-new-table-max {
    border: 1px solid var(--border);
    border-top: 0;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    background: var(--surface);
    color: var(--heading-ink);
    padding: var(--space-3) var(--space-4);
}

.app-datafeed-xsd .mapping-xsd-new-table:has(.mapping-xsd-new-table-max[style*="block"]) .mapping-xsd-new-table-min {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.app-datafeed-xsd .mapping-xsd-new-table-max p {
    margin: 0 0 var(--space-1);
    font: 400 13px/18px var(--font-display);
    color: var(--heading-ink);
    overflow-wrap: anywhere;
}

/* the columns as two aligned columns: field, then its path */
.app-datafeed-xsd .app-datafeed-xsd__cols {
    display: grid;
    grid-template-columns: minmax(80px, max-content) minmax(0, 1fr);
    gap: 4px var(--space-4);
    font: 400 13px/18px var(--font-display);
    color: var(--heading-ink);
}

.app-datafeed-xsd .app-datafeed-xsd__cols-head {
    font-weight: 600;
    color: var(--muted);
}

.app-datafeed-xsd .app-datafeed-xsd__path {
    color: var(--body-ink);
    overflow-wrap: anywhere;
}

/* Download Settings: the scraping driver drop-down is as wide as a driver name needs, not the whole panel */
.app-datafeed-step .datafeed-scraping-driver {
    max-width: 360px;
}

.app-datafeed-step .datafeed-scraping-driver .av-select {
    width: 100%;
}
