/* ==========================================================================
   Preliminary Study: layout only. Look and feel come from components/ui.css.
   ========================================================================== */
@layer app-pages {

    /* Status tabs: statuses with no studies are hidden, and so is a count that has not arrived. */
    #prelimStatusTabs { margin-bottom: 0.75rem; }
    .prelim-history-line { display: block; }
    #prelimHistoryOnly[hidden] { display: none; }
    #prelimStatusTabs wa-tab[hidden],
    #prelimStatusTabs .ui-count[hidden] { display: none; }
    #prelimStatusTabs .ui-count { margin-left: 0.4rem; }

    /* Engineer filter: two columns wide, because full names are long (one column on a narrow screen). */
    #prelimFilterAssignee { grid-column: span 2; }
    @media (max-width: 520px) {
        #prelimFilterAssignee { grid-column: 1 / -1; }
    }

    /* Open studies by engineer: one line each - name, workload bar, open and late counts. */
    .prelim-load {
        display: grid;
        grid-template-columns: minmax(10rem, 1fr) minmax(6rem, 2fr) 5rem 5rem;
        align-items: center;
        gap: 0.25rem 1rem;
        width: 100%;
        min-height: var(--d26-target);
        padding: 0.35rem 0.5rem;
        background: none;
        border: 1px solid transparent;
        border-radius: var(--d26-radius-control);
        color: var(--d26-ink);
        font: inherit;
        font-size: 0.875rem;
        text-align: left;
    }
    .prelim-load--btn { cursor: pointer; }
    .prelim-load--btn:hover { border-color: var(--d26-accent); }
    .prelim-load--btn[aria-pressed="true"] { background: var(--d26-accent-soft); border-color: var(--d26-accent); }
    .prelim-load-name { font-weight: 600; }
    .prelim-load-chart { display: grid; gap: 0.2rem; }
    .prelim-load-track { display: block; height: 0.625rem; overflow: hidden; border-radius: 999px; background: var(--d26-draft-bg); }
    /* the segments share the bar by their counts; the white gap keeps neighbours apart */
    .prelim-load-bar { display: flex; gap: 2px; height: 100%; }
    .prelim-load-words { color: var(--d26-ink-2); font-size: 0.75rem; }
    .prelim-load-key {
        display: flex; flex-wrap: wrap; gap: 0.25rem 1rem;
        margin: 0 0 0.5rem; padding: 0 0.5rem; list-style: none;
        color: var(--d26-ink-2); font-size: 0.75rem;
    }
    .prelim-load-key li { display: flex; align-items: center; gap: 0.35rem; }
    .prelim-swatch { width: 0.75rem; height: 0.75rem; border-radius: 3px; }
    /* one colour per open status (finished and dropped studies are not open) */
    .prelim-seg--ongoing { background: var(--d26-leave-fg); }
    .prelim-seg--by_today { background: var(--d26-wait-fg); }
    .prelim-seg--to_be_check { background: var(--d26-settled-fg); }
    .prelim-seg--to_send { background: var(--d26-accent); }
    .prelim-seg--hold { background: var(--d26-draft-fg); }
    .prelim-load-open { white-space: nowrap; }
    .prelim-load-late { color: var(--d26-bad-fg); font-weight: 600; white-space: nowrap; }
    @media (max-width: 640px) {
        .prelim-load { grid-template-columns: 1fr auto auto; }
        .prelim-load-name,
        .prelim-load-chart { grid-column: 1 / -1; }
    }

    /* Quota alerts: the tile for clients over their limit stands out (it also has an icon and words). */
    #prelimQuotaAlerts .ui-tiles { margin: 0; }
    #prelimQuotaAlerts .prelim-quota-problem { background: var(--d26-bad-bg); border-color: var(--d26-bad-fg); }
    #prelimQuotaAlerts .prelim-quota-problem > i { color: var(--d26-bad-fg); }

    /* Study dialog, Details tab: the locked fields read as plain text (small grey label, dark value, no box). */
    .prelim-view .ui-form-grid { row-gap: 1.25rem; padding-block: 0.5rem 0.75rem; }
    .prelim-view wa-textarea::part(form-control-label),
    .prelim-view wa-select::part(form-control-label) {
        margin: 0 0 0.125rem; color: var(--d26-ink-muted); font-size: 0.6875rem; font-weight: 600; text-transform: uppercase;
    }
    .prelim-view wa-textarea::part(base),
    .prelim-view wa-select::part(combobox) {
        min-height: 0; padding: 0; background: transparent; border-color: transparent; color: var(--d26-ink);
    }
    .prelim-view wa-textarea::part(textarea) { min-height: 0; padding: 0; color: var(--d26-ink); }
    .prelim-view wa-select::part(combobox) { opacity: 1; cursor: default; }
    .prelim-view wa-select::part(display-input) { color: var(--d26-ink); cursor: default; }
    .prelim-view wa-select::part(expand-icon) { display: none; }

    /* Results search: the whole row is tinted by outcome, always with a "Feasible" / "Not feasible" label too.
       The label gets a white ground so it stays distinct on the tint; small text is darkened for contrast. */
    .prelim-results tbody tr.prelim-outcome--ok td { background: var(--d26-ok-bg); }
    .prelim-results tbody tr.prelim-outcome--bad td { background: var(--d26-bad-bg); }
    .prelim-outcome--ok .ui-chip--ok, .prelim-outcome--bad .ui-chip--bad { background: var(--d26-card); }
    .prelim-outcome--ok .ui-sub, .prelim-outcome--bad .ui-sub { color: var(--d26-ink-2); }

    /* Archive study pop-up: which study, what happens, then the reason. */
    .prelim-archive-card {
        margin: 0 0 0.875rem; padding: 0.625rem 0.875rem; background: var(--d26-surface);
        border: 1px solid var(--d26-line); border-radius: var(--d26-radius-card);
    }
    .prelim-archive-card strong, .prelim-archive-card span { display: block; }
    .prelim-archive-card .ui-note { margin: 0; }
    .prelim-archive-facts { margin: 0 0 1rem; padding: 0; list-style: none; color: var(--d26-ink-2); font-size: 0.875rem; }
    .prelim-archive-facts li { display: flex; align-items: baseline; gap: 0.625rem; padding: 0.2rem 0; }
    .prelim-archive-facts i { width: 1.25rem; text-align: center; }
    .prelim-archive-reasons { display: flex; flex-wrap: wrap; gap: 0.5rem; margin: 0 0 0.75rem; }
    .prelim-archive-reasons wa-button[aria-pressed="true"]::part(base) { background: var(--d26-accent-soft); border-color: var(--d26-accent); }
    .prelim-archive-count { display: block; text-align: right; }

    /* Study team window: the add box above, then one row per person. */
    .prelim-team-add { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.625rem; margin: 0.75rem 0 1rem; }
    .prelim-team-add > :first-child { flex: 1 1 16rem; }
    .prelim-team-list { margin: 0; padding: 0; list-style: none; }
    .prelim-team-row {
        display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem;
        min-height: var(--d26-target); padding: 0.625rem 0; border-top: 1px solid var(--d26-line);
    }
    .prelim-team-avatar {
        display: inline-flex; flex: 0 0 auto; align-items: center; justify-content: center; width: 2.25rem; height: 2.25rem;
        border-radius: 999px; background: var(--d26-accent-soft); color: var(--d26-accent-hover); font-size: 0.8125rem; font-weight: 700;
    }
    .prelim-team-who { display: flex; flex: 1 1 14rem; flex-direction: column; gap: 0.125rem; min-width: 0; }
    .prelim-team-name { font-weight: 600; overflow-wrap: anywhere; }
    .prelim-team-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; color: var(--d26-ink-2); font-size: 0.8125rem; }
    .prelim-team-confirm { flex: 1 1 100%; }

    /* Study dialog, Results tab: room between the Add result form and the first card. */
    .prelim-result-add { margin-bottom: 1rem; }
    .prelim-result-add .ui-subhead { margin-top: 0; }
    .prelim-result-add--above { padding-bottom: 1rem; border-bottom: 1px solid var(--d26-line); }   /* saved results follow */

    /* Study dialog, Files tab: room between the reminder, the open button and the link box. */
    #prelimPanelFiles wa-callout,
    .prelim-folder-open { margin-bottom: 1rem; }

    /* Client quota filters: the summary sentence sits on its own line. */
    .prelim-ledger-summary { grid-column: 1 / -1; margin: 0; }

    /* The studies list: the card switch is the shared data_table(cards="wide"); on a wide table the actions stay in view while it scrolls sideways. */
    @container (width > 55rem) {
        .ui-table--cards-wide th.prelim-col-act, .ui-table--cards-wide td.prelim-col-act { position: sticky; right: 0; box-shadow: -1px 0 0 var(--d26-line); }
        .ui-table--cards-wide td.prelim-col-act { background: var(--d26-card); }
        .ui-table--cards-wide th.prelim-col-act { background: var(--d26-surface); }
        .ui-table--cards-wide tbody tr:hover td.prelim-col-act { background: var(--d26-surface); }
    }
    @container (width <= 55rem) { .ui-table--cards-wide td.prelim-col-act > * + * { margin-left: 0; } }       /* stacked buttons in a card line up */

    /* Client quota table: the cells start at the top because a client can have a note under it. */
    .prelim-ledger td { vertical-align: top; }

    /* Client quota table: the limit with its Edit, or the box with Save and Cancel. */
    .prelim-limit { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 0.5rem; }
    /* Share link dialog: room between the link box and the buttons under it. */
    .prelim-share-actions { margin: 0.75rem 0; flex-wrap: wrap; }

    /* Results table: the actions stay in view while it scrolls sideways (a tinted row keeps its tint). */
    .prelim-results th.prelim-col-act, .prelim-results td.prelim-col-act { position: sticky; right: 0; box-shadow: -1px 0 0 var(--d26-line); white-space: nowrap; }
    .prelim-results td.prelim-col-act { background: var(--d26-card); }
    .prelim-results th.prelim-col-act { background: var(--d26-surface); }

    /* Results table: the long text columns keep a readable width instead of squashing. */
    .prelim-results td:nth-child(1) { min-width: 14rem; }  /* Option */
    .prelim-results td:nth-child(2) { min-width: 9rem; }   /* Study */
    .prelim-results td:nth-child(11) { min-width: 12rem; } /* Notes */
}
