/*
 * Buttons.
 *
 * A button names the action — «Создать объект», «В архив» — never «ОК» or «Далее». That is a
 * content rule, but it is why there is no "primary/secondary" pair of generic labels here:
 * the variant carries weight, the text carries meaning.
 *
 * Hover changes background and border colour only, over 120ms. No shift, no scale, no glow.
 * Pressed state is colour, never size.
 */

.app-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-1);
    height: var(--control);
    padding: 0 var(--inset-btn);
    border: 1px solid var(--border-2);
    border-radius: var(--radius-control);
    background: var(--surface);
    color: var(--text);
    font-size: var(--fs-body);
    line-height: var(--lh-flat);
    white-space: nowrap;
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition);
}

.app-btn:hover {
    background: var(--surface-2);
    border-color: var(--border-3);
    color: var(--text);
    text-decoration: none;
}

.app-btn:active {
    background: var(--muted);
    border-color: var(--border-3);
}

.app-btn--primary {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--surface);
    font-weight: var(--fw-medium);
}

.app-btn--primary:hover {
    border-color: var(--accent-press);
    background: var(--accent-press);
    color: var(--surface);
}

.app-btn--primary:active {
    border-color: var(--accent-press-2);
    background: var(--accent-press-2);
}

.app-btn--quiet {
    padding: 0 var(--inset-control);
    border-color: transparent;
    background: transparent;
    color: var(--accent);
}

.app-btn--quiet:hover {
    border-color: transparent;
    background: var(--accent-soft);
    color: var(--accent);
}

.app-btn--quiet:active {
    border-color: transparent;
    background: var(--accent-soft-2);
}

.app-btn--danger {
    border-color: var(--negative);
    color: var(--negative);
}

.app-btn--danger:hover {
    border-color: var(--negative);
    background: var(--negative-soft);
    color: var(--negative);
}

.app-btn--danger-solid {
    border-color: var(--negative);
    background: var(--negative);
    color: var(--surface);
    font-weight: var(--fw-medium);
}

.app-btn--danger-solid:hover {
    border-color: var(--negative-press);
    background: var(--negative-press);
    color: var(--surface);
}

.app-btn--danger:active {
    background: var(--scale-negative-1);
}

.app-btn--danger-solid:active {
    border-color: var(--negative-press);
    background: var(--negative-press);
}

.app-btn--sm {
    height: var(--control-sm);
    padding: 0 var(--inset-control);
}

.app-btn--lg {
    height: var(--control-lg);
    padding: 0 var(--inset-btn-lg);
    font-size: var(--fs-text);
}

.app-btn--block {
    width: 100%;
}

.app-btn:disabled,
.app-btn[aria-disabled='true'],
.app-btn[aria-disabled='true']:active {
    border-color: var(--border);
    background: var(--surface-2);
    color: var(--text-disabled);
    cursor: not-allowed;
}

/* --- Icon button --------------------------------------------------------------------- */

/* A glyph alone is guessed, not read, so every icon button carries a tooltip; the markup
   helper refuses to render one without it. */
.app-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: var(--icon-btn);
    height: var(--icon-btn);
    padding: 0;
    border: 1px solid var(--border-2);
    border-radius: var(--radius-control);
    background: var(--surface);
    color: var(--text-2);
    cursor: pointer;
    transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.app-icon-btn:hover {
    background: var(--surface-2);
    border-color: var(--border-3);
    color: var(--text);
}

.app-icon-btn:active {
    background: var(--muted);
    border-color: var(--border-3);
}

/* In a card header the button has no outline until the pointer arrives. */
.app-icon-btn--head {
    border-color: transparent;
    background: transparent;
}

.app-icon-btn--head:hover {
    border-color: var(--border-2);
    background: var(--surface-2);
}

/* An action that does not apply right now: shown, explained by its tooltip, and inert.
   aria-disabled rather than the disabled attribute — a disabled button takes no pointer
   events, and the explanation would be unreachable. */
.app-icon-btn[aria-disabled='true'] {
    border-color: var(--border);
    background: var(--surface-2);
    color: var(--text-disabled);
    cursor: not-allowed;
}

.app-icon-btn[aria-disabled='true']:hover,
.app-icon-btn[aria-disabled='true']:active {
    border-color: var(--border);
    background: var(--surface-2);
    color: var(--text-disabled);
}

/*
 * An empty slot in a row of actions.
 *
 * Glyphs in a list stand strictly one under another (core.md §4.4), so a row with
 * fewer actions than its neighbours keeps their places rather than shifting the column.
 */
.app-icon-btn--blank {
    visibility: hidden;
    pointer-events: none;
}

/* A gain and a loss keep the colours they have everywhere else in the project. */
.app-icon-btn--positive {
    color: var(--positive);
}

.app-icon-btn--positive:hover {
    border-color: var(--positive);
    background: var(--scale-positive-1);
    color: var(--positive);
}

/* A switch that is on fills its outline glyph: the star of a product on the home page (mockup В.Б1). */
.app-icon-btn[aria-pressed='true'] .app-icon {
    fill: currentcolor;
}

.app-icon-btn--negative {
    color: var(--negative);
}

.app-icon-btn--negative:hover {
    border-color: var(--negative);
    background: var(--negative-soft);
    color: var(--negative);
}

.app-icon-btn--danger:hover {
    border-color: var(--negative);
    background: var(--negative-soft);
    color: var(--negative);
}

/* --- Loading ring -------------------------------------------------------------------- */

.app-spinner {
    display: block;
    flex: none;
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: app-spin 700ms linear infinite;
}

/* --- Touch --------------------------------------------------------------------------- */

@media (pointer: coarse) {
    .app-btn {
        height: var(--control-touch);
        border-radius: var(--radius);
    }

    .app-icon-btn {
        width: var(--icon-btn-touch);
        height: var(--icon-btn-touch);
        border-radius: var(--radius);
    }
}

/*
 * A value that copies itself when clicked.
 *
 * It looks like the text it carries, not like a button: what the owner wants is the number, and
 * the glyph beside it is the whole announcement that a click will do something. The tooltip says
 * what (core.md §16.1).
 */
.app-copy {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 0;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.app-copy .app-icon {
    color: var(--text-4);
    transition: color var(--transition);
}

.app-copy:hover .app-icon {
    color: var(--accent);
}

/*
 * One line under a page-level primary action: the condition or the side effect of pressing
 * it (core.md §9.10) — «займёт около двух минут», «текущий файл будет заменён». Not a tooltip,
 * because the owner must see it before deciding to hover; not a dialog, because the action is
 * reversible. Quiet, one line, never wraps into a paragraph.
 */
.app-btn-note {
    max-width: var(--w-prose);
    margin: var(--space-1) 0 0;
    color: var(--text-3);
    font-size: var(--fs-caption);
    line-height: var(--lh-tight);
}
