/* The task status banner.  It reuses the look of the admin's messages. */

:root {
    --task-waiting-bg: #eceff1;
    --task-waiting-fg: #607d8b;
    --task-running-fg: #1a6fd1;
    --task-done-fg: #2e8b3d;
    --task-failed-fg: #c62828;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --task-waiting-bg: #37424a;
        --task-waiting-fg: #b0bec5;
        --task-running-fg: #7fb2ff;
        --task-done-fg: #7fdc90;
        --task-failed-fg: #ff9a92;
    }
}

:root[data-theme="dark"] {
    --task-waiting-bg: #37424a;
    --task-waiting-fg: #b0bec5;
    --task-running-fg: #7fb2ff;
    --task-done-fg: #7fdc90;
    --task-failed-fg: #ff9a92;
}

#task-status:not(:has(li)) {
    display: none;
}

/* Match the admin's messages: a 16px icon at 40px from the left. */
ul.messagelist li.task {
    /* An inset shadow, not a border, so that the icon lines up with the
     * admin's messages. */
    box-shadow: inset 4px 0 0 var(--task-color);
    position: relative;
}

/* Waiting and running have no admin icon.  Ours are masks, so that they
 * take the color of the state, and the spinner can turn. */
ul.messagelist li.task-waiting::before,
ul.messagelist li.task-running::before {
    background-color: var(--task-color);
    content: "";
    height: 16px;
    left: 40px;
    mask: var(--task-icon) center / contain no-repeat;
    position: absolute;
    top: 12px;
    width: 16px;
}

ul.messagelist li.task a {
    color: inherit;
    text-decoration: underline;
}

/* Stack the lines.  The last keeps the admin's margin below the banner. */
ul.messagelist li.task:not(:last-child) {
    margin-bottom: 0;
}

ul.messagelist li.task-waiting {
    --task-color: var(--task-waiting-fg);
    --task-icon: url("../img/clock.33c40dea2cbe.svg");
    background-color: var(--task-waiting-bg);
    background-image: none;
}

ul.messagelist li.task-running {
    --task-color: var(--task-running-fg);
    --task-icon: url("../img/spinner.68fd15511e60.svg");
    background-color: var(--message-info-bg);
    background-image: none;
}

ul.messagelist li.task-running::before {
    animation: task-spin 1s linear infinite;
}

/* These use the admin's own icons.  The admin sets them through variables,
 * but a URL in a variable is resolved against the stylesheet that uses it,
 * so we name the files, and the dark ones, ourselves. */
ul.messagelist li.task-done {
    --task-color: var(--task-done-fg);
    background-color: var(--message-success-bg);
    background-image: url("../../admin/img/icon-yes.29488ce3e9f8.svg");
}

ul.messagelist li.task-failed {
    --task-color: var(--task-failed-fg);
    background-color: var(--message-error-bg);
    background-image: url("../../admin/img/icon-no.030751157345.svg");
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) ul.messagelist li.task-done {
        background-image: url("../../admin/img/icon-yes-dark.89c587634cdd.svg");
    }

    :root:not([data-theme="light"]) ul.messagelist li.task-failed {
        background-image: url("../../admin/img/icon-no-dark.b8cdf102c9f0.svg");
    }
}

:root[data-theme="dark"] ul.messagelist li.task-done {
    background-image: url("../../admin/img/icon-yes-dark.89c587634cdd.svg");
}

:root[data-theme="dark"] ul.messagelist li.task-failed {
    background-image: url("../../admin/img/icon-no-dark.b8cdf102c9f0.svg");
}

@keyframes task-spin {
    to {
        transform: rotate(360deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    ul.messagelist li.task-running::before {
        animation: none;
    }
}
