/* Styles of the shared components in src/ui. Only these components use the ui- classes. */

/* ---------- Button ---------- */
.ui-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-4);
    height: 54px; padding: 0 var(--sp-12);
    border: 0; border-radius: var(--r-sm); cursor: pointer;
    font: var(--fw-bold) var(--fs-xl) var(--f-display);
    transition: transform 120ms var(--ease-out), filter 120ms var(--ease-out), opacity 120ms;
}
.ui-btn.ui-sm { height: 44px; padding: 0 var(--sp-8); font-size: var(--fs-lg); }
.ui-btn--wide { width: 100%; }
.ui-btn:hover:not(:disabled) { filter: brightness(1.05); }
.ui-btn:active:not(:disabled) { transform: translateY(2px); }
.ui-btn:disabled { opacity: .45; cursor: not-allowed; }
.ui-btn--primary { color: var(--white); background: linear-gradient(var(--son-light), var(--son)); box-shadow: var(--bevel-son); }
.ui-btn--gold { color: var(--ink-warm); background: linear-gradient(var(--gold-light), var(--ochre)); box-shadow: var(--bevel-ochre); }
.ui-btn--ghost { color: var(--ink); background: var(--plaster-2); box-shadow: var(--bevel-plaster); }
.ui-btn.ui-sm:is(.ui-btn--primary, .ui-btn--gold) { box-shadow: var(--bevel-sm); }
.ui-btn--quiet {
    height: 34px; padding: 0 var(--sp-6); border-radius: var(--r-pill);
    background: color-mix(in srgb, var(--white) 7%, transparent); color: var(--table-soft);
    font: var(--fw-regular) var(--fs-md) var(--f-ui); white-space: nowrap;
}
.ui-btn--quiet:hover:not(:disabled) { filter: none; background: color-mix(in srgb, var(--white) 12%, transparent); }
.ui-btn--quiet b { font-weight: var(--fw-bold); color: var(--white); }
.ui-btn--quiet[aria-pressed="true"] { background: var(--plaster); color: var(--ink); }
.ui-btn--link {
    height: auto; min-height: 36px; padding: var(--sp-2) var(--sp-3); background: transparent;
    font: var(--fw-regular) var(--fs-sm) var(--f-ui); color: var(--ink-3);
    text-decoration: underline; text-underline-offset: 3px;
}
.ui-btn--link:hover:not(:disabled) { filter: none; color: var(--ink); }
.ui-btn svg { width: 1.1em; height: 1.1em; flex-shrink: 0; }

/* ---------- Icon button ---------- */
.ui-icon-btn {
    width: 36px; height: 36px; flex-shrink: 0; border: 0; border-radius: var(--r-round); cursor: pointer;
    display: grid; place-items: center; color: inherit;
}
.ui-icon-btn svg { width: 16px; height: 16px; }
.ui-icon-btn--on-color { background: color-mix(in srgb, var(--white) 26%, transparent); }
.ui-icon-btn--on-light { background: var(--plaster-2); color: var(--ink); }

/* ---------- Chip ---------- */
.ui-chip {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-3);
    min-height: 38px; padding: 0 var(--sp-5);
    border: 1.5px solid var(--plaster-edge); border-radius: var(--r-sm); background: var(--white);
    cursor: pointer; font: var(--fw-semibold) var(--fs-sm) var(--f-ui); color: var(--ink-2); text-align: left;
}
.ui-chip:hover:not(:disabled) { border-color: var(--ochre); }
/* Red marks only the primary action, so a selected choice takes the table color. */
.ui-chip[aria-pressed="true"] { border-color: var(--table); background: var(--table-tint); color: var(--table); }
.ui-chip:disabled { opacity: .45; cursor: not-allowed; }
.ui-chip.ui-sm { min-height: 30px; padding: 0 var(--sp-3); font-size: var(--fs-xs); }
.ui-chip--wide { display: flex; width: 100%; justify-content: space-between; gap: var(--sp-6); min-height: 44px; font-size: var(--fs-md); color: var(--ink); }
.ui-chip--wide b { color: var(--good); font-weight: var(--fw-bold); flex-shrink: 0; }

/* ---------- Tabs ---------- */
.ui-tabs { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: var(--sp-3); padding: var(--sp-2); border-radius: var(--r-sm); background: var(--plaster-2); }
.ui-tab {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-3);
    height: 38px; border: 0; border-radius: var(--r-sm); background: transparent; cursor: pointer;
    font: var(--fw-semibold) var(--fs-md) var(--f-ui); color: var(--ink-2);
}
.ui-tab[aria-selected="true"] { background: var(--paper); color: var(--ink); box-shadow: var(--shadow-sm); }
.ui-tabs.ui-sm .ui-tab { height: 30px; font-size: var(--fs-sm); }

/* ---------- Switch ---------- */
.ui-switch-row { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-6); font: var(--fw-semibold) var(--fs-md) var(--f-ui); }
.ui-switch-row small { display: block; font: var(--fw-regular) var(--fs-sm) var(--f-ui); color: var(--ink-3); }
.ui-switch { position: relative; width: 46px; height: 28px; flex-shrink: 0; border: 0; border-radius: var(--r-pill); cursor: pointer; background: var(--plaster-edge); transition: background 150ms; }
.ui-switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: var(--r-round); background: var(--white); box-shadow: var(--shadow-sm); transition: transform 150ms var(--ease-out); }
.ui-switch[aria-checked="true"] { background: var(--good); }
.ui-switch[aria-checked="true"]::after { transform: translateX(18px); }

/* ---------- Field and input ---------- */
.ui-field { display: flex; flex-direction: column; gap: var(--sp-2); }
.ui-field-label { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-4); }
.ui-field-label label { font: var(--fw-semibold) var(--fs-sm) var(--f-ui); color: var(--ink-2); }
.ui-input {
    width: 100%; min-width: 0; height: 44px; padding: 0 var(--sp-6);
    border: 2px solid var(--plaster-2); border-radius: var(--r-sm); background: var(--white); outline: none;
    font: var(--fw-semibold) var(--fs-lg) var(--f-ui); color: var(--ink);
}
.ui-input.ui-sm { height: 36px; border-width: 1px; font: var(--fw-regular) var(--fs-sm) var(--f-ui); }
.ui-input:focus { border-color: var(--ochre); }

/* ---------- Card ---------- */
.ui-card { background: var(--plaster); border-radius: var(--r-md); box-shadow: var(--shadow-card); }
.ui-card--paper { background: var(--paper); }

/* ---------- Sheet and modal ---------- */
.ui-sheet { width: min(390px, 100%); background: var(--paper); border-radius: var(--r-lg); box-shadow: var(--shadow-pop); overflow: hidden; animation: pop-in 220ms var(--ease-out); }
.ui-sheet--md { width: min(440px, 100%); }
.ui-sheet--lg { width: min(620px, 100%); }
.ui-sheet-head { position: relative; padding: var(--sp-8) var(--sp-10); background: var(--head, var(--son)); color: var(--white); }
.ui-sheet-head--light { background: var(--head, var(--paper)); color: var(--ink); }
.ui-sheet-head--dark { background: var(--table-deep); color: var(--table-text); }
.ui-sheet-head h2 { margin: 0; font: var(--fw-heavy) var(--fs-3xl)/1.25 var(--f-title); }
.ui-sheet-head--dark h2 { font-size: var(--fs-xl); font-weight: var(--fw-bold); }
.ui-sheet-body { display: flex; flex-direction: column; gap: var(--sp-8); padding: var(--sp-8) var(--sp-10) var(--sp-8); }
.ui-backdrop {
    position: fixed; inset: 0; z-index: 40; display: flex; padding: var(--sp-10); overflow-y: auto;
    background: color-mix(in srgb, var(--table-deep) 72%, transparent); backdrop-filter: blur(4px);
}
.ui-modal { display: contents; }
/* Auto margins center the dialog. A tall dialog starts at the top, so its head stays reachable. */
.ui-modal > * { margin: auto; }

/* ---------- Badge ---------- */
.ui-badge {
    display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; gap: var(--sp-2);
    min-width: 16px; padding: var(--sp-1) var(--sp-3); border-radius: var(--r-pill);
    font: var(--fw-semibold) var(--fs-xs)/1.3 var(--f-ui); white-space: nowrap;
}
.ui-badge--neutral { background: var(--plaster-2); color: var(--ink-2); }
.ui-badge--dark { background: var(--ink); color: var(--plaster); }
.ui-badge--gold { background: color-mix(in srgb, var(--ochre) 18%, transparent); color: var(--warn); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ochre) 45%, transparent); }
.ui-badge--good { background: var(--good-bg); color: var(--good); }
.ui-badge--warn { background: var(--warn-bg); color: var(--warn); }
.ui-badge--danger { background: var(--son); color: var(--white); font-weight: var(--fw-bold); }
.ui-badge--on-dark { background: color-mix(in srgb, var(--ochre) 20%, transparent); color: var(--gold); font-weight: var(--fw-bold); }

/* ---------- Toast ---------- */
.ui-toast {
    display: inline-flex; align-items: center; gap: var(--sp-4); max-width: 100%;
    padding: var(--sp-3) var(--sp-8); border-radius: var(--r-sm); box-shadow: var(--shadow-card);
    font: var(--fw-semibold) var(--fs-sm)/1.25 var(--f-ui); animation: pop-in 220ms var(--ease-out);
}
.ui-toast-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.ui-toast--neutral { background: color-mix(in srgb, var(--paper) 95%, transparent); color: var(--ink); }
.ui-toast--good { background: var(--good-bg); color: var(--good); border: 1px solid color-mix(in srgb, var(--good) 35%, transparent); }
.ui-toast--danger { background: var(--son-bg); color: var(--son-deep); border: 1px solid color-mix(in srgb, var(--son) 35%, transparent); }
.ui-toast-close { display: grid; place-items: center; width: 22px; height: 22px; margin-right: calc(-1 * var(--sp-3)); border: 0; background: transparent; color: inherit; cursor: pointer; }
.ui-toast-close svg { width: 14px; height: 14px; }

/* ---------- Avatar ---------- */
.ui-avatar {
    --c: var(--table-dim);
    position: relative;
    width: 44px; height: 44px; flex-shrink: 0; display: grid; place-items: center;
    border: 3px solid var(--white); border-radius: var(--r-round); color: var(--white);
    background: radial-gradient(circle at 32% 24%, color-mix(in srgb, var(--c) 38%, var(--white)), var(--c) 62%, color-mix(in srgb, var(--c) 62%, var(--black)));
    box-shadow: 0 -3px 0 color-mix(in srgb, var(--black) 28%, transparent) inset, 0 2px 0 color-mix(in srgb, var(--white) 55%, transparent) inset, var(--shadow-sm);
}
.ui-avatar-fig {
    width: 80%; height: 80%; display: grid; place-items: center;
    transform: translateY(-2%);
    filter: drop-shadow(0 2px 2px color-mix(in srgb, var(--black) 35%, transparent));
}
.ui-avatar-fig svg { width: 100%; height: 100%; display: block; }
.ui-avatar.ui-sm { width: 30px; height: 30px; border-width: 2px; }
.ui-avatar--out { opacity: .3; filter: grayscale(1); }

/* ---------- Money ---------- */
.ui-money { font-family: var(--f-ui-num); font-variant-numeric: tabular-nums; white-space: nowrap; }
.ui-money--plus { color: var(--good); }
.ui-money--minus { color: var(--son); }

/* ---------- Focus ---------- */
:is(.ui-btn, .ui-icon-btn, .ui-chip, .ui-tab, .ui-switch, .ui-toast-close):focus-visible,
.ui-focus { outline: var(--ring-focus); outline-offset: 2px; }

@media (max-width: 900px) {
    .ui-btn.ui-sm, .ui-btn--quiet, .ui-btn--link, .ui-chip, .ui-tab, .ui-icon-btn, .ui-toast-close { min-height: 44px; min-width: 44px; }
    .ui-icon-btn { width: 44px; height: 44px; }
    .ui-btn--quiet { height: 44px; padding: 0 var(--sp-4); font-size: var(--fs-xs); }
    .ui-backdrop { padding: var(--sp-6); }
    .ui-avatar.ui-md { width: 34px; height: 34px; border-width: 2px; }
    /* On mobile the stage is a bottom panel, so a sheet in it needs no shadow. */
    .stage .ui-sheet { width: 100%; box-shadow: none; }
    .stage .ui-sheet-body { padding: var(--sp-6) var(--sp-2) var(--sp-2); }
}

/* ---------- Gallery (debug builds only) ---------- */
.gallery { height: 100vh; overflow-y: auto; padding: var(--sp-12); color: var(--table-text); }
.gallery h1 { font: var(--fw-bold) var(--fs-2xl) var(--f-title); margin-bottom: var(--sp-8); }
.gallery-section { margin-bottom: var(--sp-12); }
.gallery-section > h2 { font: var(--fw-semibold) var(--fs-sm) var(--f-ui); color: var(--table-muted); margin-bottom: var(--sp-4); }
.gallery-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-6); padding: var(--sp-8); border-radius: var(--r-md); background: var(--plaster); color: var(--ink); }
.gallery-dark { display: flex; gap: var(--sp-4); padding: var(--sp-6); border-radius: var(--r-sm); background: var(--table-deep); }
.gallery-color { padding: var(--sp-6); border-radius: var(--r-sm); background: var(--river); color: var(--white); }
.gallery-wide { display: flex; flex-direction: column; gap: var(--sp-6); width: 360px; }
.gallery-pad { padding: var(--sp-8); }
