/* The save line (UX stage 9, Task 3): three states in the flow, saving, saved and a failure that says what to do.
 *
 * Tokens only, logical properties only, no forced overrides. The state pill is the stage 7 pill (its tones live in blocks.css and are
 * toggled by save_state.js); nothing here styles it, so this sheet never names it. The words are the page's own (_save_words.html).
 */

.ui-save {
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    min-inline-size: 0;
}

/* Nothing prints for an idle line, and a [hidden] part prints nothing even where a rule below sets a display. */
.ui-save[data-state="idle"] .ui-save__status {
    display: none;
}

.ui-save [hidden] {
    display: none;
}

.ui-save__status {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-2);
    margin: 0;
    min-inline-size: 0;
    font-size: var(--type-caption);
}

.ui-save__fail {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--sp-2);
    padding: var(--sp-2) var(--sp-3);
    border: 1px solid var(--danger-border);
    border-radius: var(--radius-md);
    background: var(--danger-bg);
    color: var(--danger-ink);
}

.ui-save__fail > p {
    flex: 1 1 12rem;
    min-inline-size: 0;
    margin: 0;
    overflow-wrap: anywhere;
}

/* The notice (UX stage 9, Task 4): a failure of a write that has no line of its own, in the flow, never floating over content. It sits as
 * the first child of main, or of the layer (the drawer, the day modal, the task panel) that main would be hidden behind. One line per
 * failing control; the text of a line is replaced, never added to. Tokens and logical properties only. */
.ui-save-notice {
    display: flex;
    flex-direction: column;
    gap: var(--sp-2);
    margin-block: var(--sp-2);
    margin-inline: var(--sp-4);
    min-inline-size: 0;
}

.ui-save-notice[hidden] {
    display: none;
}

.ui-save-notice__line {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--sp-2);
    margin: 0;
    padding: var(--sp-2) var(--sp-3);
    border: 1px solid var(--danger-border);
    border-radius: var(--radius-md);
    background: var(--danger-bg);
    color: var(--danger-ink);
}

.ui-save-notice__line [hidden] {
    display: none;
}

.ui-save-notice__line:focus-visible {
    outline: var(--focus-ring);
    outline-offset: var(--focus-offset);
}

.ui-save-notice__text {
    flex: 1 1 12rem;
    min-inline-size: 0;
    overflow-wrap: anywhere;
}

/* The close control of a toast (UX stage 9, Task 5): an error toast does not time out, so it is closed with this button or Escape. */
.toast-close {
    margin-inline-start: var(--sp-2);
    padding: 0 var(--sp-2);
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    line-height: 1;
    cursor: pointer;
}

.toast-close:focus-visible {
    outline: var(--focus-ring);
    outline-offset: var(--focus-offset);
}

/* A control that is being asked about does not look pressed twice; the cue itself is the family's (blocks.css). */
[hx-post][aria-busy="true"],
[hx-put][aria-busy="true"],
[hx-patch][aria-busy="true"],
[hx-delete][aria-busy="true"],
[hx-get][aria-busy="true"] {
    cursor: progress;
    opacity: .7;
}

@media (max-width: 767px), (pointer: coarse) {
    .ui-save__fail .btn {
        min-block-size: var(--target);
        min-inline-size: var(--target);
    }

    .ui-save__fail > p {
        flex-basis: 100%;
    }

    .ui-save-notice__line .btn,
    .toast-close {
        min-block-size: var(--target);
        min-inline-size: var(--target);
    }

    .ui-save-notice__text {
        flex-basis: 100%;
    }
}

@media (forced-colors: active) {
    .ui-save__fail,
    .ui-save-notice__line {
        border-color: CanvasText;
    }
}

@media (prefers-reduced-motion: reduce) {
    .ui-save,
    .ui-save__fail {
        scroll-behavior: auto;
    }
}
