/*
 * This file is part of i-REST.
 *
 * Copyright (C) 2026 I-Motion SARL
 *
 * Proprietary and confidential: see the LICENSE file at the root of the project.
 *
 * Additions to Pico CSS; own classes are prefixed with irest-ui-.
 */

:root {
    --irest-ui-success: #2e7d32;
    --irest-ui-warning: #b26a00;
    --irest-ui-error: #c62828;
    --irest-ui-muted: #6b7280;
}

.irest-ui-brand {
    text-decoration: none;
}

.irest-ui-footer {
    color: var(--irest-ui-muted);
}

/*
 * Menu "Settings" of the menu bar (ui/_settings.html.twig): opened under its title towards the left, so that it stays
 * on the screen, with the colour schemes one per line. The selectors start with nav details.dropdown to win over
 * those of Pico (details.dropdown>summary+ul, its li and label), which would keep the list on the left of the title
 * and on a single line.
 */
nav details.dropdown.irest-ui-settings > summary + ul {
    right: 0;
    left: auto;
    min-width: 15rem;
    white-space: normal;
}

nav details.dropdown.irest-ui-settings > summary + ul li :is(fieldset, label, select) {
    margin-bottom: 0;
}

nav details.dropdown.irest-ui-settings > summary + ul li legend {
    margin-bottom: 0.25rem;
}

nav details.dropdown.irest-ui-settings > summary + ul li fieldset label {
    display: block;
    padding: 0.15rem 0;
}

nav details.dropdown.irest-ui-settings > summary + ul li select {
    width: 100%;
    margin-top: 0.25rem;
}

/* Messages after an action */
.irest-ui-flash {
    padding: 0.6rem 1rem;
    border-left: 4px solid var(--irest-ui-muted);
    background: var(--pico-card-background-color);
}

.irest-ui-flash-success {
    border-left-color: var(--irest-ui-success);
}

.irest-ui-flash-error {
    border-left-color: var(--irest-ui-error);
}

.irest-ui-flash-warning {
    border-left-color: var(--irest-ui-warning);
}

/* Refusal of an action on lines of a list (a billed ticket that cannot be forgotten): above the list, and on its line */
.irest-ui-refusal {
    margin-bottom: var(--pico-spacing);
    padding: 0.8rem 1rem;
    border: 2px solid var(--irest-ui-error);
    border-left-width: 8px;
    border-radius: var(--pico-border-radius);
    background: color-mix(in srgb, var(--irest-ui-error) 12%, var(--pico-background-color));
}

.irest-ui-refusal strong {
    color: var(--irest-ui-error);
}

.irest-ui-refusal ul {
    margin: 0.4rem 0 0;
}

.irest-ui-row-refused > td {
    background: color-mix(in srgb, var(--irest-ui-error) 12%, var(--pico-background-color));
}

.irest-ui-row-refused > td:first-child {
    box-shadow: inset 4px 0 0 var(--irest-ui-error);
}

.irest-ui-refusal-reason {
    display: block;
    color: var(--irest-ui-error);
    font-weight: 600;
}

/* Mass action above a list, shown once a line is ticked */
.irest-ui-mass button {
    width: auto;
}

/* Status of a connection or a run */
.irest-ui-status {
    font-weight: 600;
    white-space: nowrap;
}

.irest-ui-status-ok,
.irest-ui-status-succeeded,
.irest-ui-status-present {
    color: var(--irest-ui-success);
}

.irest-ui-status-anomalies,
.irest-ui-status-running,
.irest-ui-status-waiting,
.irest-ui-status-untested,
.irest-ui-status-unknown,
.irest-ui-status-different {
    color: var(--irest-ui-warning);
}

.irest-ui-status-failed,
.irest-ui-status-broken,
.irest-ui-status-missing {
    color: var(--irest-ui-error);
}

.irest-ui-status-confirmed {
    color: var(--irest-ui-success);
}

.irest-ui-status-proposed {
    color: var(--irest-ui-warning);
}

.irest-ui-status-rejected,
.irest-ui-status-disabled {
    color: var(--irest-ui-muted);
}

/* Switch of the list of workflows: a form inside a table cell, without the margins of Pico */
.irest-ui-switch {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin: 0;
}

.irest-ui-switch input,
.irest-ui-switch button {
    margin: 0;
}

/* Links between the screens of one workflow */
.irest-ui-subnav [aria-current="page"] {
    font-weight: 600;
    text-decoration: none;
}

/* Buttons side by side in a table cell */
.irest-ui-inline {
    display: flex;
    gap: 0.5rem;
    margin: 0;
}

.irest-ui-inline button {
    width: auto;
    margin: 0;
    padding: 0.3rem 0.8rem;
}

.irest-ui-qr img {
    background: #fff;
    padding: 0.5rem;
}

.irest-ui-codes {
    columns: 2;
    list-style: none;
    padding: 0;
}

.irest-ui-codes code {
    font-size: 1.1rem;
}

/* Sign-in pages, without the menu */
.irest-ui-narrow {
    max-width: 28rem;
}

/* Actions to tick on a simulation: no bullets, the following actions of a subject indented under its box */
.irest-ui-selection {
    list-style: none;
    padding-left: 0;
}

.irest-ui-selection-follow {
    display: inline-block;
    padding-left: 1.75rem;
    color: var(--irest-ui-muted);
}

/* Key of the API shown once: long, on its own line */
.irest-ui-api-key {
    word-break: break-all;
}

/*
 * Dark scheme: the borders of the form fields of Pico (#2a3140 on #13171f, contrast 1.4:1) and the status colours
 * chosen for a light background are hard to see; the values below reach at least 3:1 for the fields (WCAG 1.4.11)
 * and 4.5:1 for the texts. Same guard as Pico: the dark scheme of the system, unless a light theme is forced.
 */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --pico-form-element-border-color: #6b7689;
        --pico-switch-background-color: #6b7689;
        --irest-ui-success: #66bb6a;
        --irest-ui-warning: #ffb74d;
        --irest-ui-error: #ef5350;
        --irest-ui-muted: #9aa3b2;
    }

    /* Unticked boxes and radio buttons: a thicker border, to spot them at a glance in the lists */
    :root:not([data-theme="light"]) input:is([type="checkbox"], [type="radio"]):not([role="switch"], :checked, :indeterminate) {
        border-width: 2px;
    }
}

:root[data-theme="dark"] {
    --pico-form-element-border-color: #6b7689;
    --pico-switch-background-color: #6b7689;
    --irest-ui-success: #66bb6a;
    --irest-ui-warning: #ffb74d;
    --irest-ui-error: #ef5350;
    --irest-ui-muted: #9aa3b2;
}

:root[data-theme="dark"] input:is([type="checkbox"], [type="radio"]):not([role="switch"], :checked, :indeterminate) {
    border-width: 2px;
}

/* Simulation of a billing workflow (ui/run/_billing.html.twig): summary, one card per invoice, table of its lines */
.irest-ui-billing-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 2rem;
    padding: 0.8rem 1rem;
    border-radius: var(--pico-border-radius);
    background: var(--pico-card-sectioning-background-color);
}

.irest-ui-billing-summary strong {
    font-size: 1.15rem;
}

.irest-ui-billing-name {
    margin: 0;
    font-size: 1.1rem;
}

.irest-ui-billing-name small,
.irest-ui-billing-invoice .irest-ui-fold-title > small,
.irest-ui-billing-entity {
    color: var(--irest-ui-muted);
    font-weight: normal;
}

/* One invoice: the box of its tickets beside its foldable bar (outside the summary: a click on it must not fold) */
.irest-ui-billing-invoice {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
}

.irest-ui-billing-invoice > details {
    flex: 1;
    min-width: 0;
}

.irest-ui-billing-all {
    flex: none;
    margin: 0;
    padding-top: 1rem;
}

.irest-ui-billing-all input {
    margin: 0;
}

.irest-ui-billing-total {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    white-space: nowrap;
}

.irest-ui-billing-total small {
    font-size: 0.875rem;
    font-weight: normal;
    color: var(--irest-ui-muted);
}

.irest-ui-billing-lines {
    margin-bottom: 0;
    font-size: 0.9rem;
}

.irest-ui-billing-lines th,
.irest-ui-billing-lines td {
    vertical-align: top;
}

.irest-ui-billing-lines td:first-child {
    width: 2rem;
}

.irest-ui-billing-entity {
    display: block;
    font-size: 0.8rem;
}

/* A line at no charge (bank of hours, task not billable): greyed, its amount stays readable */
.irest-ui-billing-free > td {
    color: var(--irest-ui-muted);
}

.irest-ui-billing-free > td strong {
    color: inherit;
}

.irest-ui-billing-ticked {
    font-weight: 600;
}

.irest-ui-badge {
    display: inline-block;
    margin-top: 0.2rem;
    padding: 0.05rem 0.45rem;
    border: 1px solid currentColor;
    border-radius: 1rem;
    background: transparent;
    color: var(--irest-ui-muted);
    font-size: 0.75rem;
    white-space: nowrap;
}

.irest-ui-num {
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.irest-ui-nowrap {
    white-space: nowrap;
}

/* Text for screen readers only */
.irest-ui-sr {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* Block of filters above a list (banks of hours): fields side by side, wrapped on a narrow screen */
.irest-ui-filter {
    display: flex;
    flex-wrap: wrap;
    gap: 0 1rem;
    align-items: flex-end;
    margin-bottom: var(--pico-spacing);
    padding: 0.8rem 1rem 0;
    border-radius: var(--pico-border-radius);
    background: var(--pico-card-sectioning-background-color);
}

.irest-ui-filter > label {
    flex: 1 1 10rem;
}

.irest-ui-filter > .irest-ui-filter-check {
    flex: 0 1 auto;
    align-self: center;
}

.irest-ui-filter .irest-ui-inline {
    margin-bottom: var(--pico-spacing);
}

/* Banks of hours grouped by customer: a line above the first bank of each customer */
.irest-ui-hours-banks-grouped tr.irest-ui-hours-banks-first:not(:first-child) > td {
    border-top: 2px solid var(--pico-muted-color);
}

.irest-ui-hours-banks-low {
    color: var(--irest-ui-warning);
}

.irest-ui-hours-banks-used_up {
    color: var(--irest-ui-error);
}

/*
 * Foldable block (details.irest-ui-fold): its summary is a bar that looks clickable, with an arrow on the left in the
 * colour of the links (turned down once unfolded), a background that changes on hover, and "Show the detail" or
 * "Hide the detail" on the right. Pico's own chevron, small and on the right, is easily missed: it is hidden.
 */
details.irest-ui-fold {
    margin-bottom: var(--pico-spacing);
}

details.irest-ui-fold > summary {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    align-items: center;
    padding: 0.7rem 1rem;
    border: 1px solid var(--pico-muted-border-color);
    border-radius: var(--pico-border-radius);
    background: var(--pico-card-sectioning-background-color);
    color: var(--pico-color);
    line-height: 1.4;
    cursor: pointer;
    transition: background-color var(--pico-transition), border-color var(--pico-transition);
}

details.irest-ui-fold > summary::after {
    display: none;
}

details.irest-ui-fold > summary::before {
    content: "";
    flex: none;
    border-style: solid;
    border-width: 0.45rem 0 0.45rem 0.65rem;
    border-color: transparent transparent transparent var(--pico-primary);
    transition: transform var(--pico-transition);
}

details.irest-ui-fold[open] > summary::before {
    transform: rotate(90deg);
}

details.irest-ui-fold > summary:hover {
    border-color: var(--pico-primary);
    background: color-mix(in srgb, var(--pico-primary) 10%, var(--pico-card-sectioning-background-color));
}

details.irest-ui-fold[open] > summary {
    margin-bottom: 0.75rem;
}

/* Pico greys the summary of an open details: kept in the colour of the text */
details.irest-ui-fold[open] > summary:not([role]):not(:focus) {
    color: var(--pico-color);
}

.irest-ui-fold-title {
    flex: 1 1 12rem;
}

.irest-ui-fold-toggle {
    color: var(--pico-primary);
    font-size: 0.875rem;
    text-decoration: underline;
    white-space: nowrap;
}

details.irest-ui-fold[open] > summary .irest-ui-fold-show,
details.irest-ui-fold:not([open]) > summary .irest-ui-fold-hide {
    display: none;
}

/* Entry of the main menu of the section shown (aria-current="page", ui/layout.html.twig): bold, in the colour of the
 * links and underlined by a bar, which shows in both colour schemes */
nav a.irest-ui-menu[aria-current="page"] {
    color: var(--pico-primary);
    font-weight: 700;
    text-decoration: none;
    box-shadow: inset 0 -3px 0 var(--pico-primary);
    border-radius: 0;
}

/* Frequency of a workflow (ui/workflow/edit.html.twig): the fields of the mode chosen side by side */
.irest-ui-schedule-fields {
    display: flex;
    flex-wrap: wrap;
    gap: 0 1rem;
}

.irest-ui-schedule-fields > label {
    flex: 1 1 9rem;
}

.irest-ui-schedule-fields > label[hidden],
.irest-ui-schedule [hidden] {
    display: none;
}

.irest-ui-schedule-weekdays label {
    display: inline-block;
    margin-right: 1rem;
}
