/* ==========================================================================
   EDAMA QMS building blocks (UX stage 7)

   The portal's one set of shared parts: the button family and its variants, the state pill, the 44 by 44 target, the one focus ring.
   Linked once, in `shared_ui/base_shell.html`, after `site.css` and `animations.css` and before a page's own `extra_css` and `phone.css`,
   so a page's own sheet and the phone bar still win where they mean to.

   Rules of this sheet (the census and the sheet's tests read them):
     - every colour, size and gap is a token of `tokens.css` (the type sizes, `--target`, `--focus-ring`, `--focus-offset`, `--btn-*`);
       no colour literal is written here;
     - logical properties only (`margin-inline-*`, `padding-inline-*`, `inset-inline-*`), so Arabic mirrors without a second rule;
     - no declaration here is marked important, and the only phone breakpoint is the one the portal already uses;
     - a name that a template or a script writes keeps meaning what it means: this sheet adds states, a gap and the variants, and
       declares nothing on a bare button that `site.css` already declares.

   The tasks that follow fill it: the button family, the state pill, the touch targets and the focus ring.
   ========================================================================== */

/* ==========================================================================
   The button family (Task 3)

   The family is `.btn` and the spellings the templates and scripts already write; no template is renamed. MAIN is `site.css`'s bare
   `.btn` (blue ground, white text): `.btn-primary` and `.btn--primary` are always written beside `btn` and need no rule, and this sheet
   declares nothing on a bare `.btn` but the gap below. The other four variants are lists of spellings, each with a resting rule and a
   hover rule.

   The cascade (it decides every rule here):
     - `site.css` paints EVERY `.btn:hover` (0,2,0) navy (`background: var(--brand-secondary)`) and gives `.btn.ghost` / `.btn.danger`
       (0,2,0) and their hovers (0,3,0) a look. This sheet loads later, so a rule here of the SAME specificity wins; every selector
       below is at least as specific as the `site.css` rule it replaces, and every spelling has its own hover rule that names all
       four properties (ground, text, line, shadow), so no hovered button keeps dark text on the old navy.
     - the four variants are written in the order plain, quiet, destructive, confirming: a button that carries two spellings of the SAME
       specificity takes the later (the one that says more). A compound spelling (`.btn.ghost`, 0,2,0) beats a single-class one
       (`.btn-approve`, 0,1,0) whatever the order, so no template mixes the two kinds.
     - every hover rule is written `:hover:not(:disabled)`: a disabled button shows no hover feedback (Ruling 14). The destructive and
       confirming hovers also take the line `--danger` / `--success`, because the ground change alone is about 1.04 to 1 against white.
   ========================================================================== */

/* -- resting looks -------------------------------------------------------------------------------------------------------------- */

/* PLAIN: white ground, grey line, ink text (today's `btn ghost` and the aliases that were blue fills for lack of a rule). */
.btn.ghost,
.btn--ghost,
.btn-secondary,
.btn--secondary,
.btn-outline,
.btn-outline-primary,
.btn-outline-secondary,
.btn-warning,
.ed-btn.ghost {
    background-color: var(--btn-plain-bg);
    border: 1px solid var(--btn-line);
    color: var(--ink);
}

/* QUIET: no ground and no visible line (the line is transparent so the box is the plain button's), brand text. */
.btn.quiet,
.btn--quiet,
.btn-text {
    background-color: transparent;
    border: 1px solid transparent;
    color: var(--brand-primary);
}

/* DESTRUCTIVE: an outline, red text on white (Ruling 9). */
.btn.danger,
.btn-danger,
.btn--danger,
.btn-outline-danger,
.btn-reject {
    background-color: var(--btn-plain-bg);
    border: 1px solid var(--danger-border);
    color: var(--danger-ink);
}

/* CONFIRMING: an outline, green text (`--success-ink`, never `--success`) on white (Ruling 9). */
.btn-approve,
.btn--approve,
.btn-success,
.btn--success,
.btn.ok {
    background-color: var(--btn-plain-bg);
    border: 1px solid var(--success-border);
    color: var(--success-ink);
}

/* -- hover looks: each names the four properties `site.css`'s `.btn:hover` and its own hovers set --------------------------------- */

.btn.ghost:hover:not(:disabled),
.btn--ghost:hover:not(:disabled),
.btn-secondary:hover:not(:disabled),
.btn--secondary:hover:not(:disabled),
.btn-outline:hover:not(:disabled),
.btn-outline-primary:hover:not(:disabled),
.btn-outline-secondary:hover:not(:disabled),
.btn-warning:hover:not(:disabled),
.ed-btn.ghost:hover:not(:disabled) {
    background-color: var(--btn-plain-bg);
    color: var(--ink);
    border-color: var(--brand-primary);
    box-shadow: none;
}

.btn.quiet:hover:not(:disabled),
.btn--quiet:hover:not(:disabled),
.btn-text:hover:not(:disabled) {
    background-color: transparent;
    color: var(--brand-secondary);
    border-color: transparent;
    box-shadow: none;
}

.btn.danger:hover:not(:disabled),
.btn-danger:hover:not(:disabled),
.btn--danger:hover:not(:disabled),
.btn-outline-danger:hover:not(:disabled),
.btn-reject:hover:not(:disabled) {
    background-color: var(--danger-bg);
    color: var(--danger-ink);
    border-color: var(--danger);
    box-shadow: none;
}

.btn-approve:hover:not(:disabled),
.btn--approve:hover:not(:disabled),
.btn-success:hover:not(:disabled),
.btn--success:hover:not(:disabled),
.btn.ok:hover:not(:disabled) {
    background-color: var(--success-bg);
    color: var(--success-ink);
    border-color: var(--success);
    box-shadow: none;
}

/* -- a disabled button keeps its resting look on hover --------------------------------------------------------------------------------
   The hover rules above skip a disabled button (`:not(:disabled)`), but `site.css`'s `.btn:hover` (0,2,0) still matches it and paints the
   ground navy with a shadow, which beats a single-class spelling's resting rule (`.btn-secondary`, `.btn-approve`: 0,1,0) and leaves that
   variant's dark text on navy. These rules (0,3,0 and up, written after the generic one) restore each variant's resting ground and drop
   the shadow; text and line were never touched by `.btn:hover`. */
.btn:disabled:hover {
    background-color: var(--brand-primary);
    box-shadow: none;
}

.btn.ghost:disabled:hover,
.btn--ghost:disabled:hover,
.btn-secondary:disabled:hover,
.btn--secondary:disabled:hover,
.btn-outline:disabled:hover,
.btn-outline-primary:disabled:hover,
.btn-outline-secondary:disabled:hover,
.btn-warning:disabled:hover,
.btn.danger:disabled:hover,
.btn-danger:disabled:hover,
.btn--danger:disabled:hover,
.btn-outline-danger:disabled:hover,
.btn-reject:disabled:hover,
.btn-approve:disabled:hover,
.btn--approve:disabled:hover,
.btn-success:disabled:hover,
.btn--success:disabled:hover,
.btn.ok:disabled:hover {
    background-color: var(--btn-plain-bg);
    box-shadow: none;
}

.btn.quiet:disabled:hover,
.btn--quiet:disabled:hover,
.btn-text:disabled:hover {
    background-color: transparent;
    box-shadow: none;
}

/* -- shared by every variant ---------------------------------------------------------------------------------------------------- */

.btn {
    gap: var(--btn-gap);
}

/* The gap now sits between an icon and its words in either direction of writing; the old Arabic margin on the icon would add to it. */
html[dir="rtl"] .btn i,
html[dir="rtl"] .btn svg {
    margin-inline-end: 0;
}

.btn:disabled,
.btn[aria-disabled="true"],
.ed-btn:disabled,
.ed-btn[aria-disabled="true"] {
    opacity: .5;
    cursor: not-allowed;
}

.btn[aria-busy="true"],
.ed-btn[aria-busy="true"] {
    cursor: progress;
    opacity: .7;
}

/* -- the state pill ------------------------------------------------------------------------------------------------------------------- */

/* A word on a tinted ground: never a button (no pointer, no hover), never colour alone (the word carries the state). No page prints it yet. */
.ui-pill {
    display: inline-flex;
    align-items: center;
    gap: var(--sp-1);
    padding-block: 2px;
    padding-inline: 10px;
    border: 1px solid transparent;
    border-radius: var(--radius-full);
    font-size: var(--type-caption);
    font-weight: var(--weight-semibold);
    line-height: 1.4;
    white-space: nowrap;
}

.ui-pill--late {
    background-color: var(--danger-bg);
    color: var(--danger-ink);
    border-color: var(--danger-border);
}

.ui-pill--today {
    background-color: var(--warning-bg);
    color: var(--warning-ink);
    border-color: var(--warning-border);
}

.ui-pill--info {
    background-color: var(--info-bg);
    color: var(--brand-secondary);
    border-color: var(--info-border);
}

.ui-pill--ok {
    background-color: var(--success-bg);
    color: var(--success-ink);
    border-color: var(--success-border);
}

.ui-pill--neutral {
    background-color: var(--neutral-100);
    color: var(--ink-soft);
    border-color: var(--neutral-200);
}

/* MAIN's own forced-colors rule is `site.css`'s; the variants (which set a line of their own) get theirs here. */
@media (forced-colors: active) {
    .btn.ghost,
    .btn--ghost,
    .btn-secondary,
    .btn--secondary,
    .btn-outline,
    .btn-outline-primary,
    .btn-outline-secondary,
    .btn-warning,
    .ed-btn.ghost,
    .btn.quiet,
    .btn--quiet,
    .btn-text,
    .btn.danger,
    .btn-danger,
    .btn--danger,
    .btn-outline-danger,
    .btn-reject,
    .btn-approve,
    .btn--approve,
    .btn-success,
    .btn--success,
    .btn.ok {
        border: 1px solid ButtonText;
    }

    .ui-pill {
        border-color: ButtonText;
    }
}

/* -- Empty states (stage 13) ---------------------------------------------------------------------------------------------------------- */

/* A list, board or register with nothing in it says what it holds and how to make the first one. The card is printed by
   `shared_ui/includes/ui_empty.html`; every part of it is optional, so the sheet styles each part on its own. Every colour is set on the
   card's own children, so a table cell or a page that colours its text does not reach in. Logical properties only, tokens only. The card
   wraps by itself (no width query is needed: its actions and its field names are wrapping rows). */
.ui-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--sp-3);
    box-sizing: border-box;
    inline-size: 100%;
    max-inline-size: 44ch;
    margin-inline: auto;
    padding-block: var(--sp-8);
    padding-inline: var(--sp-6);
    background-color: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    font-style: normal;
    text-align: center;
}

/* Inside a table cell: the cell is the frame, so the card draws none of its own. */
.ui-empty--inline {
    border-style: none;
    background-color: transparent;
    /* A records list is wider than a phone (its header row is not wrapped), so the cell, and 100% of it, is wider than the window: the card
       must not follow it out. 44ch stays the cap on a wide screen; on a phone the card is the window less the page's gutter, the panel's edge
       and the cell's padding on the start side (29 px at 390), and a little more on the end side, and sits centred in its cell. */
    max-inline-size: min(44ch, calc(100vw - var(--sp-12) - var(--sp-3)));
}

.ui-empty__title {
    margin: 0;
    color: var(--ink);
    font-size: var(--type-title);
    font-weight: var(--weight-semibold);
    line-height: 1.3;
}

.ui-empty__text {
    margin: 0;
    color: var(--ink-soft);
    font-size: var(--type-body);
    line-height: 1.5;
}

/* The picture of one record: a dashed frame holding only field names (never a value, never a digit). It is decoration, so it is hidden
   from a screen reader by the include. */
.ui-empty__shape {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    box-sizing: border-box;
    max-inline-size: 100%;
    padding-block: var(--sp-3);
    padding-inline: var(--sp-4);
    border: 1px dashed var(--line);
    border-radius: var(--radius-md);
}

.ui-empty__shape-label {
    flex-basis: 100%;
    color: var(--ink-soft);
    font-size: var(--type-caption);
    line-height: 1.4;
}

.ui-empty__shape-field {
    padding-block: 2px;
    padding-inline: 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius-full);
    color: var(--ink-soft);
    font-size: var(--type-caption);
    line-height: 1.4;
    overflow-wrap: anywhere;
}

.ui-empty__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
}

.ui-empty__actions .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* The 44 by 44 minimum is the touch query's, like every other target rule (test_touch_targets.QueryTests); `.btn` is 44 high everywhere. */
@media (max-width: 767px), (pointer: coarse) {
    .ui-empty__actions .btn {
        min-block-size: var(--target);
        min-inline-size: var(--target);
    }
}

.ui-empty__note {
    margin: 0;
    color: var(--ink-soft);
    font-size: var(--type-caption);
    line-height: 1.4;
}

@media (forced-colors: active) {
    .ui-empty__shape {
        border-color: CanvasText;
    }
}

/* -- focus and jumps (Task 12) -------------------------------------------------------------------------------------------------------- */

/* The ring itself is the two tokens `--focus-ring` and `--focus-offset`, read by the four shared rules (shell.css, site.css): nothing here
   draws one. What lives here is where a focused control or a jump comes to rest: never under the fixed header, never under the phone bar.
   `--bar-height` is set only where the bar is printed (phone.css, `html.has-bar`), so on a desktop the end padding is the 8 px alone. The
   nine places that used to add the header to their own `scroll-margin-top` now say 4 px (0 for the calendar plan), so every jump lands where
   it did: header + 8 here + 4 there = the old header + 12. */
html {
    scroll-padding-block-start: calc(var(--header-height) + 8px);
    scroll-padding-block-end: calc(var(--bar-height, 0px) + 8px);
}
