/*
 * The site kit: one stylesheet every page is built from, with the Razor components in
 * Components/UI rendering its markup. Blazor's scoped CSS cannot be shared between components, so
 * per-page sheets meant copying the same thousand lines into each page (Profit and TradeAlerts were
 * line-for-line identical). A page keeps a scoped .razor.css only for visuals genuinely its own.
 *
 * Every class is prefixed `ui-`. Colours, spacing and type come from the tokens in app.css; no hex
 * here except inside rgba() tints of a token colour.
 */

/* ---------------------------------------------------------------- page frame */

.ui-page {
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
    padding-bottom: var(--space-10, 2.5rem);
}

.ui-hero {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-5) var(--space-6);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.ui-hero-text {
    min-width: 0;
    flex: 1 1 28rem;
}

.ui-hero h1 {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin: 0 0 var(--space-2);
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.01em;
}

.ui-hero h1 i {
    color: var(--brand-light);
    font-size: 1.25rem;
}

.ui-hero p {
    margin: 0;
    max-width: 68ch;
    font-size: 0.875rem;
    line-height: 1.55;
    color: var(--text-muted);
}

.ui-hero-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
}

/* ---------------------------------------------------------------- status chips */

.ui-status {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
}

.ui-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.625rem;
    border: 1px solid transparent;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1.4;
    white-space: nowrap;
}

.ui-chip i {
    font-size: 0.7rem;
}

.ui-chip.is-on,
.ui-chip.tone-good {
    background: var(--success-tint);
    border-color: rgba(74, 222, 128, 0.4);
    color: var(--success-text);
}

.ui-chip.is-off,
.ui-chip.tone-neutral {
    background: var(--bg-card-hover);
    border-color: var(--border);
    color: var(--text-secondary);
}

.ui-chip.is-live,
.ui-chip.tone-brand {
    background: var(--brand-tint);
    border-color: rgba(237, 122, 5, 0.45);
    color: var(--brand-light);
}

.ui-chip.is-error,
.ui-chip.tone-danger {
    background: var(--danger-tint);
    border-color: rgba(248, 113, 113, 0.45);
    color: var(--danger-text);
}

.ui-chip.is-info,
.ui-chip.tone-info {
    background: var(--info-tint);
    border-color: rgba(96, 165, 250, 0.4);
    color: var(--info-text);
}

.ui-chip.is-warn,
.ui-chip.tone-warn {
    background: var(--warning-tint);
    border-color: rgba(250, 204, 21, 0.4);
    color: var(--warning-text);
}

/* ---------------------------------------------------------------- summary tiles */

.ui-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
    gap: var(--space-3);
}

.ui-kpi {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    padding: var(--space-4);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md, 8px);
}

.ui-kpi-value {
    font-size: 1.5rem;
    font-weight: 600;
    line-height: 1.15;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.ui-kpi-label {
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.ui-kpi-note {
    margin-top: 0.15rem;
    font-size: 0.75rem;
    line-height: 1.45;
    color: var(--text-muted);
}

/* A figure that rests on an assumption is marked as one, everywhere it appears. */
.ui-kpi.is-assumed {
    border-style: dashed;
    border-color: var(--border-strong);
}

.ui-kpi.is-assumed .ui-kpi-value {
    color: var(--text-secondary);
}

/* ---------------------------------------------------------------- panels */

.ui-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.ui-panel-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border);
    background: var(--bg-sunken);
}

.ui-panel-head h2 {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin: 0;
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--text);
}

.ui-panel-head h2 i {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.ui-panel-note {
    margin: 0;
    padding: var(--space-3) var(--space-5);
    font-size: 0.8125rem;
    line-height: 1.55;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    background: var(--bg-sunken);
}

.ui-panel-body {
    padding: var(--space-4) var(--space-5);
}

.ui-panel-body.is-flush {
    padding: 0;
}

/* ---------------------------------------------------------------- filters */

.ui-filters {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-5);
    border-bottom: 1px solid var(--border);
}

.ui-search {
    position: relative;
    flex: 1 1 16rem;
    min-width: 12rem;
}

/* The leading icon only: a clear button's icon sits in its own button. */
.ui-search > i {
    position: absolute;
    top: 50%;
    left: 0.7rem;
    transform: translateY(-50%);
    font-size: 0.8125rem;
    color: var(--text-muted);
    pointer-events: none;
}

.ui-search input {
    width: 100%;
    padding: 0.45rem 0.75rem 0.45rem 2rem;
    background: var(--bg-card-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm, 6px);
    color: var(--text);
    font-size: 0.8125rem;
}

.ui-search input::placeholder {
    color: var(--text-muted);
}

.ui-search input:focus {
    outline: none;
    border-color: var(--brand-light);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

.ui-select {
    padding: 0.45rem 0.6rem;
    background: var(--bg-card-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm, 6px);
    color: var(--text);
    font-size: 0.8125rem;
}

.ui-select:focus {
    outline: none;
    border-color: var(--brand-light);
}

.ui-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
}

/* Flex with a gap, so an icon, label and count are spaced the same whether or not Razor kept the whitespace between them. */
.ui-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.35rem 0.75rem;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast, 0.15s ease);
    white-space: nowrap;
}

.ui-pill:hover {
    background: var(--bg-card-hover);
    color: var(--text);
}

/* Neutral, with the orange only as the outline: a filled pill next to a chart outshouts the data. */
.ui-pill.is-active {
    background: var(--bg-card-hover);
    border-color: var(--brand);
    color: var(--text);
    font-weight: 600;
}

.ui-pill .ui-pill-count {
    opacity: 0.75;
    font-variant-numeric: tabular-nums;
}

.ui-check {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.ui-check input {
    width: 0.9rem;
    height: 0.9rem;
    accent-color: var(--brand);
    cursor: pointer;
}

.ui-filters-spacer {
    flex: 1 1 auto;
}

.ui-result-count {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* ---------------------------------------------------------------- tables */

.ui-table-wrap {
    overflow-x: auto;
}

.ui-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8125rem;
}

.ui-table th {
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 0.6rem 0.75rem;
    background: var(--bg-sunken);
    border-bottom: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    text-align: left;
    white-space: nowrap;
}

.ui-table th.ui-num,
.ui-table td.ui-num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.ui-table th.ui-mid,
.ui-table td.ui-mid {
    text-align: center;
}

.ui-table th.ui-sortable {
    cursor: pointer;
    user-select: none;
}

.ui-table th.ui-sortable:hover {
    color: var(--text);
}

.ui-table th.ui-sortable i {
    margin-left: 0.25rem;
    font-size: 0.65rem;
    opacity: 0.85;
}

.ui-table td {
    padding: 0.55rem 0.75rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
    vertical-align: middle;
}

.ui-table tbody tr:hover {
    background: var(--bg-card-hover);
}

.ui-table tbody tr.is-open {
    background: var(--bg-card-hover);
}

.ui-table .ui-card-name {
    color: var(--text);
    font-weight: 500;
    text-decoration: none;
}

.ui-table .ui-card-name:hover {
    color: var(--brand-light);
    text-decoration: underline;
}

.ui-table .ui-sub {
    display: block;
    font-size: 0.6875rem;
    color: var(--text-muted);
}

/* Row tints: one strength for every tone, so a green row does not shout over a red one. */
.ui-table tr.is-good td {
    background: color-mix(in srgb, var(--success) 8%, transparent);
}

.ui-table tr.is-info td {
    background: color-mix(in srgb, var(--info) 8%, transparent);
}

.ui-table tr.is-warn td {
    background: color-mix(in srgb, var(--warning) 8%, transparent);
}

.ui-table tr.is-danger td {
    background: color-mix(in srgb, var(--danger) 8%, transparent);
}

/* Switched off or out of play: receded, not coloured. The actions cell keeps full strength so its menu
   is not see-through. */
.ui-table tr.is-dim > td:not(.ui-actions-cell) {
    opacity: 0.6;
}

.ui-table tr.is-struck td {
    color: var(--text-muted);
    text-decoration: line-through;
}

.ui-table tr.is-clickable {
    cursor: pointer;
}

.ui-table tr.is-clickable:hover td {
    color: var(--text);
}

/* A summary row; under mobile-cards it stays as a card of its own (see app.css). */
.ui-table tr.is-total td {
    border-top: 1px solid var(--border-strong);
    background: var(--bg-sunken);
    color: var(--text);
    font-weight: 600;
}

.ui-mono {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* Row actions on one line, flush right, so they line up from row to row. */
.ui-table th.ui-actions-cell,
.ui-table td.ui-actions-cell {
    width: 1%;
    text-align: right;
    white-space: nowrap;
}

.ui-actions-cell .ui-actions {
    flex-wrap: nowrap;
    justify-content: flex-end;
}

/* A long table that scrolls inside its panel or dialog, under its sticky header. */
.ui-table-wrap.is-scroll {
    max-height: 60vh;
    overflow-y: auto;
}

.ui-up {
    color: var(--success-text);
}

.ui-down {
    color: var(--danger-text);
}

.ui-flat,
.ui-table td.ui-flat {
    color: var(--text-muted);
}

/* A figure in a status colour, for what is not a movement up or down (a balance owed, a warning). */
.ui-text-good {
    color: var(--success-text);
}

.ui-text-warn {
    color: var(--warning-text);
}

.ui-text-danger {
    color: var(--danger-text);
}

/* ---------------------------------------------------------------- badges */

.ui-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.15rem 0.5rem;
    border-radius: var(--radius-sm, 6px);
    font-size: 0.6875rem;
    font-weight: 500;
    line-height: 1.5;
    white-space: nowrap;
    background: var(--bg-card-hover);
    color: var(--text-secondary);
}

.ui-badge.tone-normal,
.ui-badge.tone-neutral {
    background: var(--bg-card-hover);
    color: var(--text-secondary);
}

.ui-badge.tone-info {
    background: var(--info-tint);
    color: var(--info-text);
}

.ui-badge.tone-warn {
    background: var(--warning-tint);
    color: var(--warning-text);
}

.ui-badge.tone-danger {
    background: var(--danger-tint);
    color: var(--danger-text);
}

.ui-badge.tone-good {
    background: var(--success-tint);
    color: var(--success-text);
}

.ui-badge.tone-accent,
.ui-badge.tone-brand {
    background: var(--brand-tint);
    color: var(--brand-light);
}

/* ---------------------------------------------------------------- stock meter */

.ui-meter {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    justify-content: flex-end;
}

.ui-meter-track {
    position: relative;
    width: 3.5rem;
    height: 0.3rem;
    border-radius: 999px;
    background: var(--bg-card-hover);
    overflow: hidden;
    flex: none;
}

.ui-meter-fill {
    position: absolute;
    inset: 0 auto 0 0;
    border-radius: 999px;
    background: var(--brand);
}

.ui-meter-fill.is-low {
    background: var(--danger);
}

.ui-meter-fill.is-mid {
    background: var(--warning);
}

.ui-meter-fill.is-good {
    background: var(--success);
}

.ui-meter-text {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* ---------------------------------------------------------------- stage breakdown */

.ui-stages {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr));
    gap: var(--space-4);
    padding: var(--space-4);
    background: var(--bg-page);
}

.ui-stage-col h4 {
    margin: 0 0 var(--space-2);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.ui-stage-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.ui-stage {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.5rem;
    align-items: baseline;
    padding: 0.35rem 0.6rem;
    border-radius: var(--radius-sm, 6px);
    background: var(--bg-card);
    font-size: 0.75rem;
}

.ui-stage-name {
    color: var(--text-secondary);
}

.ui-stage-note {
    display: block;
    font-size: 0.6875rem;
    color: var(--text-muted);
}

.ui-stage-price {
    color: var(--text);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.ui-stage.is-mover {
    box-shadow: inset 2px 0 0 var(--brand);
}

/* ---------------------------------------------------------------- toggles */

.ui-switches {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr));
    gap: var(--space-4);
}

.ui-switch {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-4);
    background: var(--bg-card-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius-md, 8px);
}

.ui-switch.is-enabled {
    border-color: rgba(74, 222, 128, 0.45);
}

.ui-switch-body {
    flex: 1;
    min-width: 0;
}

.ui-switch-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0 0 0.25rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text);
}

.ui-switch-desc {
    margin: 0;
    font-size: 0.75rem;
    line-height: 1.55;
    color: var(--text-muted);
}

.ui-switch-blocked {
    margin: var(--space-2) 0 0;
    font-size: 0.75rem;
    line-height: 1.5;
    color: var(--warning-text);
}

/* A real switch, because these two control what customers trade at. */
.ui-toggle {
    position: relative;
    flex: none;
    width: 2.75rem;
    height: 1.5rem;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg-page);
    cursor: pointer;
    transition: background var(--transition-fast, 0.15s ease), border-color var(--transition-fast, 0.15s ease);
}

.ui-toggle::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 0.175rem;
    width: 1.05rem;
    height: 1.05rem;
    border-radius: 50%;
    background: var(--text-muted);
    transform: translateY(-50%);
    transition: transform var(--transition-fast, 0.15s ease), background var(--transition-fast, 0.15s ease);
}

.ui-toggle.is-on {
    background: rgba(74, 222, 128, 0.35);
    border-color: rgba(74, 222, 128, 0.6);
}

.ui-toggle.is-on::after {
    background: var(--success);
    transform: translate(1.2rem, -50%);
}

.ui-toggle.is-live.is-on {
    background: rgba(237, 122, 5, 0.35);
    border-color: rgba(237, 122, 5, 0.6);
}

.ui-toggle.is-live.is-on::after {
    background: var(--brand-light);
}

.ui-toggle:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.ui-toggle:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
}

/* ---------------------------------------------------------------- limits grid */

.ui-limits {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(13rem, 1fr));
    gap: var(--space-3);
}

.ui-limit {
    padding: var(--space-3) var(--space-4);
    background: var(--bg-card-hover);
    border: 1px solid var(--border);
    border-left: 3px solid var(--brand);
    border-radius: var(--radius-sm, 6px);
}

.ui-limit.tone-refuse {
    border-left-color: var(--danger);
}

.ui-limit.tone-deep {
    border-left-color: var(--brand);
}

.ui-limit.tone-capped {
    border-left-color: var(--text-muted);
}

.ui-limit-value {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

.ui-limit-label {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ---------------------------------------------------------------- editor */

.ui-editor {
    width: 100%;
    min-height: 24rem;
    padding: var(--space-3);
    background: var(--bg-page);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm, 6px);
    color: var(--text-secondary);
    font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    font-size: 0.78rem;
    line-height: 1.5;
    resize: vertical;
    tab-size: 2;
}

.ui-editor:focus {
    outline: none;
    border-color: var(--brand-light);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

.ui-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
}

/* ---------------------------------------------------------------- buttons */

.ui-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    min-height: 2.25rem;
    padding: 0.45rem 0.85rem;
    background: var(--bg-card-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius-md, 8px);
    color: var(--text);
    font: inherit;
    font-size: 0.8125rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background var(--transition-fast, 0.15s ease), border-color var(--transition-fast, 0.15s ease);
    white-space: nowrap;
}

.ui-btn:hover:not(:disabled) {
    background: var(--bg-card-hover);
    color: var(--text);
    border-color: var(--border-strong);
}

.ui-btn:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

/* Dark text on the logo orange: white on it is 2.8:1 and fails AA. */
.ui-btn.is-primary {
    background: var(--brand);
    border-color: transparent;
    color: var(--on-brand);
}

.ui-btn.is-primary:hover:not(:disabled) {
    background: var(--brand-hover);
    color: var(--on-brand);
    border-color: transparent;
}

.ui-btn.is-ghost {
    background: transparent;
}

/* Tinted at rest, solid under the pointer: a Clear button on every card must not outshine the page's primary action. */
.ui-btn.is-danger {
    background: var(--danger-tint);
    border-color: rgba(248, 113, 113, 0.45);
    color: var(--danger-text);
}

.ui-btn.is-danger:hover:not(:disabled) {
    background: var(--danger);
    border-color: transparent;
    color: var(--on-brand);
}

.ui-btn.is-sm {
    min-height: 1.875rem;
    padding: 0.25rem 0.6rem;
    font-size: 0.75rem;
}

.ui-btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.75rem;
    height: 1.75rem;
    padding: 0;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm, 6px);
    color: var(--text-muted);
    cursor: pointer;
}

.ui-btn-icon:hover {
    background: var(--bg-card-hover);
    color: var(--text);
}

.ui-btn-icon.is-danger {
    color: var(--danger-text);
}

.ui-btn-icon.is-danger:hover {
    color: var(--danger);
}

/* An action that reads as a link: a filter, a drill-down, a pick from a list. */
.ui-link-btn {
    padding: 0;
    background: none;
    border: 0;
    color: var(--brand-light);
    font: inherit;
    text-align: left;
    cursor: pointer;
}

.ui-link-btn:hover {
    color: var(--link-hover);
    text-decoration: underline;
}

/* ---------------------------------------------------------------- states */

.ui-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-10, 2.5rem) var(--space-6);
    text-align: center;
    color: var(--text-muted);
}

.ui-empty i {
    font-size: 2.25rem;
    opacity: 0.45;
}

.ui-empty p {
    margin: 0;
    max-width: 52ch;
    font-size: 0.875rem;
    line-height: 1.55;
}

.ui-empty p.ui-empty-hint {
    font-size: 0.8125rem;
    color: var(--text-muted);
}

.ui-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-10, 2.5rem);
    color: var(--text-muted);
    font-size: 0.875rem;
}

.ui-spinner {
    width: 2rem;
    height: 2rem;
    border: 3px solid var(--border);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: ui-spin 0.9s linear infinite;
}

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

.ui-alert {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border: 1px solid transparent;
    border-radius: var(--radius-md, 8px);
    font-size: 0.8125rem;
    line-height: 1.55;
}

.ui-alert i {
    margin-top: 0.1rem;
    font-size: 0.95rem;
}

.ui-alert.tone-danger {
    background: var(--danger-tint);
    border-color: rgba(248, 113, 113, 0.4);
    color: var(--danger-text);
}

.ui-alert.tone-good {
    background: var(--success-tint);
    border-color: rgba(74, 222, 128, 0.4);
    color: var(--success-text);
}

.ui-alert.tone-warn {
    background: var(--warning-tint);
    border-color: rgba(250, 204, 21, 0.4);
    color: var(--warning-text);
}

.ui-alert.tone-info {
    background: var(--info-tint);
    border-color: rgba(96, 165, 250, 0.4);
    color: var(--info-text);
}

.ui-alert ul {
    margin: var(--space-2) 0 0;
    padding-left: 1.1rem;
}

.ui-muted {
    color: var(--text-muted);
    font-size: 0.8125rem;
    line-height: 1.55;
}

.ui-footnote {
    margin: 0;
    padding: var(--space-3) var(--space-5);
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.75rem;
    line-height: 1.55;
}

@media (prefers-reduced-motion: reduce) {
    .ui-spinner { animation-duration: 3s; }
    .ui-toggle, .ui-toggle::after, .ui-pill, .ui-btn { transition: none; }
}

.ui-spinning {
    display: inline-block;
    animation: ui-spin 0.9s linear infinite;
}

/* ---------------------------------------------------------------- modal (job detail report) */

.ui-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1050;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 8vh var(--space-4) var(--space-6);
    background: var(--overlay);
    overflow-y: auto;
}

.ui-modal {
    width: 100%;
    max-width: 880px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
}

.ui-modal-head {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border);
}

.ui-modal-head h2 {
    flex: 1;
    margin: 0;
    font-size: 1rem;
    color: var(--text);
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
}

.ui-modal-close {
    background: none;
    border: none;
    padding: var(--space-2);
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    line-height: 1;
}

.ui-modal-close:hover { color: var(--text); }

.ui-modal-body {
    display: flex;
    flex-direction: column;
    gap: var(--space-5);
    padding: var(--space-5);
}

.ui-modal-body h3 {
    margin: 0 0 var(--space-2);
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-secondary);
}

.ui-facts {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: var(--space-3);
}

.ui-fact-label {
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
}

.ui-fact-value {
    font-weight: 600;
    color: var(--text);
    font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------- toolbar and compact tiles */

/* Chips and controls on one slim row above a page's panels. */
.ui-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
}

/* Shorter summary tiles: less padding, a slightly smaller figure, the note tight under the label. */
.ui-kpis.is-compact {
    grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
}

.ui-kpis.is-compact .ui-kpi {
    gap: 0.1rem;
    padding: 0.6rem var(--space-4);
}

.ui-kpis.is-compact .ui-kpi-value {
    font-size: 1.35rem;
}

.ui-kpis.is-compact .ui-kpi-note {
    margin-top: 0.05rem;
    line-height: 1.35;
}

/* ---------------------------------------------------------------- card hero (Cards hub: Stock, Performance) */

/* The card's own header: its art beside the picker and the figures that describe it right now. */
.ui-card-hero {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: var(--space-5);
    align-items: start;
    padding: var(--space-4) var(--space-5);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

/* A grid, not a flex column: the card picker is a .ui-search, whose filter-row flex basis would become its height here. */
.ui-card-hero-body {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    align-content: start;
    gap: var(--space-4);
    min-width: 0;
}

@media (max-width: 640px) {
    .ui-card-hero {
        grid-template-columns: 1fr;
        justify-items: center;
    }

    .ui-card-hero-body {
        width: 100%;
    }
}

/* ---------------------------------------------------------------- inline settings row (delivery queue alert) */

.ui-fields {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-4);
    margin-bottom: var(--space-4);
}

.ui-field {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.8125rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.ui-field input[type="number"] {
    width: 4.5rem;
    padding: 0.3rem 0.45rem;
    background: var(--bg-page);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm, 6px);
    color: var(--text);
    font-size: 0.8125rem;
    font-variant-numeric: tabular-nums;
    text-align: right;
}

.ui-field input:focus {
    outline: none;
    border-color: var(--brand-light);
}

.ui-field em {
    font-style: normal;
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ---------------------------------------------------------------- rules written as sentences (pricing settings) */

/* One row per rule: its name on the left, the rule as a sentence with its numbers in place on the right. */
.ui-rules {
    display: flex;
    flex-direction: column;
}

.ui-rule {
    display: grid;
    grid-template-columns: minmax(9rem, 13rem) minmax(0, 1fr);
    gap: var(--space-2) var(--space-5);
    align-items: start;
    padding: var(--space-3) 0;
    border-top: 1px solid var(--border);
}

.ui-rule:first-child {
    border-top: 0;
    padding-top: 0;
}

.ui-rule-name {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    color: var(--text);
    font-size: 0.875rem;
    font-weight: 600;
}

/* A rule with no numbers to set: plain text, and an action beside it when there is one. */
.ui-rule-text {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2) var(--space-4);
    color: var(--text-secondary);
    font-size: 0.8125rem;
    line-height: 1.55;
}

.ui-rule .ui-fields {
    margin-bottom: 0;
}

/* The figures a rule's numbers are read off: under its sentence, not under its name. */
.ui-rule > .ui-rule-note {
    grid-column: 2;
    margin: 0;
}

/* A sentence wraps where it must; the settings row it borrows from keeps each label on one line. */
.ui-rule .ui-field {
    flex-wrap: wrap;
    white-space: normal;
}

@media (max-width: 640px) {
    .ui-rule {
        grid-template-columns: minmax(0, 1fr);
    }

    .ui-rule > .ui-rule-note {
        grid-column: auto;
    }
}

/* ==========================================================================
   Phones. The ui-* layout is auto-fit grids whose minimum tracks (20rem switches, 18rem
   stages) are wider than a phone, so they overflowed sideways. One column each below
   640px; the KPI tiles go two-up.
   ========================================================================== */
@media (max-width: 640px) {
  .ui-switches,
  .ui-stages {
    grid-template-columns: 1fr;
  }

  .ui-kpis,
  .ui-kpis.is-compact {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .ui-kpis.ui-kpis-verdict {
    grid-template-columns: 1fr;
  }

  .ui-modal {
    max-width: calc(100vw - 1rem);
  }

  .ui-search {
    min-width: 0;
    flex: 1 1 100%;
  }
}

@media (max-width: 576px) {
  /* A 24rem JSON editor is most of a phone screen before the Save button */
  .ui-editor {
    min-height: 14rem;
  }

  .ui-kpi.is-hero .ui-kpi-value {
    font-size: 1.6rem;
  }

  .ui-btn-icon {
    width: 2.5rem;
    height: 2.5rem;
  }
}

/* ==========================================================================
   Site kit: shell, page header, tabs and the shared widgets in Components/UI
   ========================================================================== */

/* ---------------------------------------------------------------- page header (PageHeader) */

.ui-page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: var(--space-3) var(--space-4);
    margin-bottom: var(--space-4);
}

.ui-page-head-text {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    min-width: 0;
    flex: 1 1 24rem;
}

.ui-eyebrow {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-xs);
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.ui-eyebrow a {
    color: inherit;
    text-decoration: none;
}

.ui-eyebrow a:hover {
    color: var(--text-secondary);
}

.ui-eyebrow .bi-chevron-right {
    font-size: 0.6rem;
}

.ui-page-head h1 {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    margin: 0;
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    line-height: 1.2;
    color: var(--text);
}

.ui-page-head h1 > .bi {
    color: var(--brand-light);
    font-size: 0.85em;
}

.ui-page-head p {
    margin: 0;
    max-width: 75ch;
    color: var(--text-secondary);
    line-height: 1.5;
}

.ui-page-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-2);
}

.ui-subhead {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: var(--space-4) 0 var(--space-2);
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
}

.ui-subhead i {
    color: var(--brand-light);
}

/* ---------------------------------------------------------------- tabs: hub tabs (links) and in-page tabs (buttons) */

.ui-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
    margin-bottom: var(--space-5);
    border-bottom: 1px solid var(--border);
}

.ui-tab {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 2.75rem;
    padding: 0 var(--space-4);
    background: none;
    border: 0;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    color: var(--text-secondary);
    font: inherit;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
}

.ui-tab:hover {
    background: var(--bg-card);
    color: var(--text);
}

.ui-tab.is-active,
.ui-tab.active {
    color: var(--text);
    font-weight: 600;
}

/* In the page frame or a stack, their gap already spaces the strip from what follows; a margin doubles it.
   A strip at the top of a plain panel body keeps its margin. */
.ui-page > .ui-tabs,
.ui-stack > .ui-tabs {
    margin-bottom: 0;
}

.ui-tab.is-active::after,
.ui-tab.active::after {
    content: "";
    position: absolute;
    left: var(--space-2);
    right: var(--space-2);
    bottom: -1px;
    height: 3px;
    border-radius: 3px;
    background: var(--brand-gradient);
}

/* ---------------------------------------------------------------- counts (nav and tab badges) */

.ui-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.4rem;
    height: 1.25rem;
    padding: 0 0.4rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg-card-hover);
    color: var(--text-secondary);
    font-size: 0.6875rem;
    font-weight: 700;
    line-height: 1;
}

.ui-count.tone-danger {
    background: var(--danger);
    border-color: transparent;
    color: var(--on-brand);
}

.ui-count.tone-warn {
    background: var(--warning);
    border-color: transparent;
    color: var(--on-brand);
}

.ui-count.tone-brand {
    background: var(--brand);
    border-color: transparent;
    color: var(--on-brand);
}

/* A status dot: online, powered, open. Warn unless a tone says otherwise. */
.ui-dot {
    display: inline-block;
    flex: none;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 999px;
    background: var(--warning);
}

.ui-dot.tone-good {
    background: var(--success);
}

.ui-dot.tone-info {
    background: var(--info);
}

.ui-dot.tone-warn {
    background: var(--warning);
}

.ui-dot.tone-danger {
    background: var(--danger);
}

.ui-dot.tone-neutral {
    background: var(--text-muted);
}

/* ---------------------------------------------------------------- attention banner */

.ui-banner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-3) var(--space-4);
    padding: var(--space-3) var(--space-4);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.ui-banner > .bi {
    font-size: 1.35rem;
}

.ui-banner.tone-warn {
    border-color: rgba(250, 204, 21, 0.5);
}

.ui-banner.tone-warn > .bi {
    color: var(--warning);
}

.ui-banner.tone-danger {
    border-color: rgba(248, 113, 113, 0.55);
}

.ui-banner.tone-danger > .bi {
    color: var(--danger);
}

.ui-banner.tone-info > .bi {
    color: var(--info);
}

.ui-banner-text {
    display: flex;
    flex: 1 1 20rem;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.ui-banner-text strong {
    color: var(--text);
    font-size: 0.9375rem;
}

.ui-banner-text span {
    color: var(--text-secondary);
}

/* ---------------------------------------------------------------- KPI tiles: tones, headline, as links */

.ui-kpi.is-headline {
    position: relative;
    overflow: hidden;
}

.ui-kpi.is-headline::before {
    content: "";
    position: absolute;
    inset: 0 0 auto;
    height: 3px;
    background: var(--brand-gradient);
}

.ui-kpi.tone-good .ui-kpi-value,
.ui-kpi-note.tone-good {
    color: var(--success-text);
}

.ui-kpi.tone-warn .ui-kpi-value,
.ui-kpi-note.tone-warn {
    color: var(--warning-text);
}

.ui-kpi.tone-danger .ui-kpi-value,
.ui-kpi-note.tone-danger {
    color: var(--danger-text);
}

a.ui-kpi,
button.ui-kpi {
    color: inherit;
    font: inherit;
    text-align: left;
    text-decoration: none;
    cursor: pointer;
    transition: background var(--transition-fast), border-color var(--transition-fast);
}

a.ui-kpi:hover,
button.ui-kpi:hover {
    background: var(--bg-card-hover);
    border-color: var(--border-strong);
}

button.ui-kpi.is-selected {
    border-color: var(--brand);
    box-shadow: inset 0 0 0 1px var(--brand);
}

/* Two related figures sharing one tile, half each: the pair is the tile, the Kpis inside are its halves. */
.ui-kpi-pair {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md, 8px);
}

.ui-kpi-pair > .ui-kpi {
    min-width: 0;
    background: none;
    border: 0;
    border-radius: 0;
}

.ui-kpi-pair > .ui-kpi + .ui-kpi {
    border-left: 1px solid var(--border);
}

@media (max-width: 640px) {
    /* Half of a two-up phone tile: the label needs the width more than the padding does. */
    .ui-kpis .ui-kpi-pair > .ui-kpi {
        padding-inline: var(--space-2);
    }
}

/* A figure still loading (Kpi IsLoading): a shimmer the height of the figure, so the tile does not jump. */
.ui-kpi-value > .ui-skeleton-line {
    display: block;
    width: 5rem;
    max-width: 100%;
    height: 1em;
    margin-block: 0.075em;
}

/* ---------------------------------------------------------------- sort headers and pager */

.ui-sort {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0;
    background: none;
    border: 0;
    color: inherit;
    font: inherit;
    letter-spacing: inherit;
    text-transform: inherit;
    cursor: pointer;
}

.ui-sort:hover {
    color: var(--text);
}

.ui-sort .bi {
    font-size: 0.65rem;
    opacity: 0.55;
}

.ui-sort.is-sorted {
    color: var(--text);
}

.ui-sort.is-sorted .bi {
    color: var(--brand-light);
    opacity: 1;
}

.ui-pager {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-4);
    border-top: 1px solid var(--border);
}

.ui-pager-info {
    color: var(--text-muted);
    font-size: var(--text-sm);
}

.ui-pager-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-1);
}

.ui-pager-buttons button {
    min-width: 2.25rem;
    height: 2.25rem;
    padding: 0 0.5rem;
    background: var(--bg-card-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text);
    font: inherit;
    font-size: var(--text-sm);
    cursor: pointer;
}

.ui-pager-buttons button:hover:not(:disabled) {
    border-color: var(--border-strong);
}

.ui-pager-buttons button:disabled {
    cursor: not-allowed;
    opacity: 0.45;
}

.ui-pager-buttons button.is-current {
    background: var(--brand);
    border-color: transparent;
    color: var(--on-brand);
    font-weight: 700;
}

/* ---------------------------------------------------------------- skeleton and refresh indicator */

.ui-skeleton {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
    padding: var(--space-4);
}

.ui-skeleton-line {
    height: 0.9rem;
    border-radius: 4px;
    background: linear-gradient(90deg, var(--bg-card-hover) 0%, var(--border) 50%, var(--bg-card-hover) 100%);
    background-size: 200% 100%;
    animation: ui-shimmer 1.4s ease-in-out infinite;
}

.ui-skeleton-line:nth-child(3n + 2) {
    width: 82%;
}

.ui-skeleton-line:nth-child(3n) {
    width: 64%;
}

@keyframes ui-shimmer {
    from { background-position: 200% 0; }
    to { background-position: -200% 0; }
}

.ui-refreshing {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--text-muted);
    font-size: var(--text-xs);
}

@media (prefers-reduced-motion: reduce) {
    .ui-skeleton-line { animation: none; }
}

/* ---------------------------------------------------------------- row action menu (RowMenu) */

.ui-menu {
    position: relative;
    display: inline-block;
}

.ui-menu > summary {
    list-style: none;
}

.ui-menu > summary::-webkit-details-marker {
    display: none;
}

.ui-menu-list {
    display: flex;
    flex-direction: column;
    min-width: 11rem;
    padding: var(--space-1);
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
}

.ui-menu-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-height: 2.25rem;
    padding: 0.4rem 0.6rem;
    background: none;
    border: 0;
    border-radius: var(--radius-sm);
    color: var(--text);
    font: inherit;
    font-size: var(--text-sm);
    text-align: left;
    text-decoration: none;
    cursor: pointer;
}

.ui-menu-item:hover {
    background: var(--bg-card-hover);
    color: var(--text);
}

.ui-menu-item.tone-danger {
    color: var(--danger-text);
}

/* ---------------------------------------------------------------- modal sizes and the drawer (UiModal) */

.ui-modal.size-sm {
    max-width: 440px;
}

.ui-modal.size-lg {
    max-width: 1100px;
}

/* Nearly the whole screen, for a long read (a chat log): the dialog keeps its size and the body scrolls. */
.ui-modal-overlay.is-full {
    align-items: center;
    padding: var(--space-4);
}

.ui-modal.size-full {
    display: flex;
    flex-direction: column;
    width: 95vw;
    max-width: 95vw;
    height: 90vh;
}

.ui-modal.size-full .ui-modal-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}

.ui-modal-foot {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-5);
    border-top: 1px solid var(--border);
}

.ui-modal-overlay.is-drawer {
    justify-content: flex-end;
    padding: 0;
}

.ui-modal-overlay.is-drawer .ui-modal {
    display: flex;
    flex-direction: column;
    width: min(520px, 100vw);
    max-width: none;
    min-height: 100vh;
    border-radius: 0;
    border-width: 0 0 0 1px;
}

.ui-modal-overlay.is-drawer .ui-modal-body {
    flex: 1;
    overflow-y: auto;
}

/* ---------------------------------------------------------------- toasts (ToastHost) */

.ui-toasts {
    position: fixed;
    top: var(--space-4);
    right: var(--space-4);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    width: min(380px, calc(100vw - 2rem));
}

.ui-toast {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    color: var(--text);
    font-size: var(--text-sm);
}

.ui-toast > .bi {
    margin-top: 0.1rem;
    font-size: 1.05rem;
}

.ui-toast.tone-good > .bi {
    color: var(--success);
}

.ui-toast.tone-danger > .bi {
    color: var(--danger);
}

.ui-toast.tone-warn > .bi {
    color: var(--warning);
}

.ui-toast.tone-info > .bi {
    color: var(--info);
}

.ui-toast-text {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.ui-toast-text span {
    color: var(--text-secondary);
}

/* ---------------------------------------------------------------- form fields */

.ui-input {
    min-height: 2.5rem;
    padding: 0.45rem 0.65rem;
    background: var(--bg-sunken);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: var(--text);
    font: inherit;
    font-size: var(--text-sm);
}

.ui-input::placeholder {
    color: var(--text-muted);
}

.ui-input:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.ui-label {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    color: var(--text-secondary);
    font-size: var(--text-sm);
}

/* Wide enough for 150,000 tix, with the figures lined up on the right. Typed as input. so that it also wins
   over the narrower .ui-field number box above. */
input.ui-input.is-number {
    width: 8rem;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* At the height of the selects and search boxes beside it in a filter bar. */
.ui-input.is-compact {
    min-height: 0;
    padding: 0.4rem 0.55rem;
    background: var(--bg-card-hover);
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
}

/* app.css sets every input's border with !important, so a plain border-color would never show. */
.ui-input.is-invalid {
    border-color: var(--danger) !important;
}

.ui-range {
    width: 100%;
    accent-color: var(--brand);
    cursor: pointer;
}

/* Labelled fields laid out as a form: as many to a row as fit, bottoms aligned so a button lines up with
   the inputs. is-wide on a field gives it two columns. */
.ui-form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(12rem, 100%), 1fr));
    align-items: end;
    gap: var(--space-3) var(--space-4);
}

.ui-form-grid > .is-wide {
    grid-column: span 2;
}

.ui-form-grid > .ui-btn {
    justify-self: start;
}

.ui-form-grid .ui-select {
    min-height: 2.5rem;
}

/* ---------------------------------------------------------------- focus and entity links */

.ui-btn:focus-visible,
.ui-tab:focus-visible,
.ui-sort:focus-visible,
.ui-menu-item:focus-visible,
.ui-pager-buttons button:focus-visible,
a.ui-kpi:focus-visible,
button.ui-kpi:focus-visible,
.ui-input:focus-visible,
.ui-range:focus-visible,
.ui-link:focus-visible,
.ui-link-btn:focus-visible,
.ui-disclosure:focus-visible {
    outline: 2px solid var(--brand-light);
    outline-offset: 2px;
}

.ui-input:focus {
    border-color: var(--brand-light);
    outline: none;
}

.ui-link {
    color: var(--brand-light);
    text-decoration: none;
}

.ui-link:hover {
    color: var(--link-hover);
    text-decoration: underline;
}

/* The menu is a popover: hidden until opened, then in the top layer. Without anchor positioning the
   browser centres it, which still works; with it, it sits under its button and flips up near the bottom. */
.ui-menu-list[popover] {
    margin: 0;
    color: var(--text);
}

.ui-menu-list[popover]:not(:popover-open) {
    display: none;
}

@supports (anchor-name: --menu) {
    .ui-menu-list[popover] {
        position: fixed;
        inset: auto;
        top: anchor(bottom);
        right: anchor(right);
        margin-top: 4px;
        position-try-fallbacks: flip-block;
    }
}

button.ui-chip {
    font: inherit;
    font-size: 0.75rem;
    cursor: pointer;
}

button.ui-chip:hover {
    border-color: var(--border-strong);
}

button.ui-chip.is-selected {
    border-color: var(--brand);
    box-shadow: inset 0 0 0 1px var(--brand);
}

button.ui-chip:focus-visible {
    outline: 2px solid var(--brand-light);
    outline-offset: 2px;
}

/* ---------------------------------------------------------------- layout helpers */

/* Panels or charts side by side, wrapping to one column when there is no room for two. */
.ui-columns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(26rem, 100%), 1fr));
    gap: var(--space-4);
}

/* A wide table or chart must not push its column past the grid. */
.ui-columns > * {
    min-width: 0;
}

/* Three equal columns, one under the other once there is no room for three. */
.ui-columns.is-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

/* Two blocks at 2:1, the wide one first (is-narrow-first turns it round). Equal grow and basis ratios keep
   the 2:1 exact; when the two bases no longer fit on one line, they stack. */
.ui-split {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-4);
}

.ui-split > * {
    min-width: 0;
}

.ui-split > :first-child,
.ui-split.is-narrow-first > :last-child {
    flex: 2 1 32rem;
}

.ui-split > :last-child,
.ui-split.is-narrow-first > :first-child {
    flex: 1 1 16rem;
}

/* Several blocks inside one panel body, evenly spaced. */
.ui-stack {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.ui-stack > p,
.ui-stack > .ui-fields,
.ui-stack > .ui-subhead {
    margin: 0;
}

/* A sub-heading starts a new group: a little more room above it than below. */
.ui-stack > .ui-subhead:not(:first-child) {
    margin-top: var(--space-2);
}

/* The heading of one chart or table among several in a panel, with its figures on the right. */
.ui-chart-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--space-2);
    margin-bottom: var(--space-1);
}

.ui-chart-head h3 {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.8125rem;
    font-weight: var(--font-semibold);
}

.ui-chart-head .ui-muted {
    font-size: var(--text-xs);
}

/* Summary tiles at the top of a flush panel, above its table. */
.ui-panel-kpis {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--border);
}

/* One row wherever the panel has room for it, so panels side by side keep their tables level: the tiles
   narrow to the width of a figure instead of wrapping at the usual 12rem. */
.ui-kpis.is-row {
    grid-template-columns: repeat(auto-fit, minmax(7.5rem, 1fr));
}

/* ---------------------------------------------------------------- small cards, messages, disclosures */

/* Small cards, as many to a row as fit: one per bot, one per assignment. is-wide for cards that hold text. */
.ui-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 18rem), 1fr));
    gap: var(--space-3);
}

.ui-cards.is-wide {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 26rem), 1fr));
}

.ui-card {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    min-width: 0;
    padding: var(--space-3) var(--space-4);
    background: var(--bg-sunken);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

/* Text exactly as it is shown elsewhere (an MTGO ad): its own surface, its own line breaks. */
.ui-message {
    padding: var(--space-2) var(--space-3);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: var(--text-sm);
    line-height: 1.5;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* A full-width header button that opens and closes the section under it (with aria-expanded). */
.ui-disclosure {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    width: 100%;
    padding: var(--space-2) var(--space-3);
    background: var(--bg-sunken);
    border: 0;
    color: var(--text);
    font: inherit;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
}

.ui-disclosure:hover {
    background: var(--bg-card-hover);
}

/* Inside: the section it heads usually clips its corners. */
.ui-disclosure:focus-visible {
    outline-offset: -2px;
}

/* ---------------------------------------------------------------- avatars and legend swatches */

.ui-avatar {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 2.125rem;
    height: 2.125rem;
    overflow: hidden;
    border-radius: 50%;
    background: var(--brand-gradient);
    color: var(--on-brand);
    font-size: var(--text-xs);
    font-weight: var(--font-bold);
}

.ui-avatar.is-lg {
    width: 4.5rem;
    height: 4.5rem;
    font-size: var(--text-2xl);
}

.ui-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* A legend key in its series' colour, given inline: style="--swatch: var(--chart-2)". */
.ui-swatch {
    display: inline-block;
    flex: none;
    width: 0.625rem;
    height: 0.625rem;
    border-radius: 3px;
    background: var(--swatch, var(--text-muted));
}

/* ---------------------------------------------------------------- phones, for the patterns above */

@media (max-width: 1100px) {
    .ui-columns.is-3 {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (max-width: 640px) {
    .ui-form-grid > .is-wide {
        grid-column: auto;
    }
}

@media (max-width: 576px) {
    /* A table already turned into cards lets the page scroll, not a box inside it. */
    .ui-table-wrap.is-scroll:has(> .mobile-cards) {
        max-height: none;
    }

    .ui-actions-cell .ui-actions {
        flex-wrap: wrap;
    }
}

/* ---------------------------------------------------------------- ticket pricing */

/* The formula, rule by rule, with today's numbers substituted. */
.ui-rules {
    display: grid;
    gap: var(--space-4);
    margin: 0;
    padding: 0;
    list-style: none;
}

.ui-rules li {
    display: grid;
    gap: 0.35rem;
    max-width: 72ch;
}

.ui-rules h3 {
    margin: 0;
    color: var(--text);
    font-size: 0.9rem;
    font-weight: 600;
}

.ui-rules p {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.8125rem;
    line-height: 1.6;
}

.ui-formula {
    margin: 0;
    padding: 0.5rem 0.75rem;
    overflow-x: auto;
    background: var(--bg-page);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 0.8rem;
    white-space: pre;
}

.ui-today {
    color: var(--brand-light);
    font-weight: 600;
}

/* The stock bridge reads as one row where there is room for it: opening, the flows, closing. */
.ui-kpis.ui-bridge {
    grid-template-columns: repeat(auto-fit, minmax(8.5rem, 1fr));
    margin-bottom: var(--space-4);
}

.ui-nowrap {
    white-space: nowrap;
}
