/* Appearance framework: maps the palette tokens (palette-*.css), the font-size tokens
   (font-size-*.css) and the design-style tokens (style-*.css) onto Bootstrap and the shared
   components, so a palette, size or style only has to set tokens. Loaded once by every layout
   right after the palettes, before the style file. */

html[data-ui-font] body {
    font-family: "SiteFontFa", Tahoma, Arial, sans-serif;
}

/* text size: font-size-*.css sets the root font size (rem-based components follow) and
   --alefba-font-scale, which the apps' stylesheets multiply their px sizes by. */

/* ---- colours: Bootstrap components follow the palette's primary ---- */
html[data-ui-style] .btn-primary {
    --bs-btn-bg: var(--alefba-primary);
    --bs-btn-border-color: var(--alefba-primary);
    --bs-btn-hover-bg: var(--alefba-primary-hover);
    --bs-btn-hover-border-color: var(--alefba-primary-hover);
    --bs-btn-active-bg: var(--alefba-primary-hover);
    --bs-btn-active-border-color: var(--alefba-primary-hover);
    --bs-btn-disabled-bg: var(--alefba-primary);
    --bs-btn-disabled-border-color: var(--alefba-primary);
    --bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}

html[data-ui-style] .btn-outline-primary {
    --bs-btn-color: var(--alefba-primary);
    --bs-btn-border-color: var(--alefba-primary);
    --bs-btn-hover-bg: var(--alefba-primary);
    --bs-btn-hover-border-color: var(--alefba-primary);
    --bs-btn-active-bg: var(--alefba-primary-hover);
    --bs-btn-active-border-color: var(--alefba-primary-hover);
    --bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
}

html[data-ui-style] .btn-link {
    --bs-btn-color: var(--alefba-primary);
    --bs-btn-hover-color: var(--alefba-primary-hover);
}

html[data-ui-style] .form-check-input:checked,
html[data-ui-style] .form-switch .form-check-input:checked {
    background-color: var(--alefba-primary);
    border-color: var(--alefba-primary);
}

html[data-ui-style] .form-control:focus,
html[data-ui-style] .form-select:focus,
html[data-ui-style] .form-check-input:focus {
    border-color: color-mix(in srgb, var(--alefba-primary) 55%, transparent);
    box-shadow: 0 0 0 .25rem color-mix(in srgb, var(--alefba-primary) 22%, transparent);
}

html[data-ui-style] .nav-pills .nav-link.active,
html[data-ui-style] .nav-pills .show > .nav-link,
html[data-ui-style] .page-item.active .page-link,
html[data-ui-style] .list-group-item.active,
html[data-ui-style] .dropdown-item.active,
html[data-ui-style] .dropdown-item:active,
html[data-ui-style] .progress-bar {
    background-color: var(--alefba-primary);
    border-color: var(--alefba-primary);
}

html[data-ui-style] .text-primary,
html[data-ui-style] .link-primary {
    color: var(--alefba-primary) !important;
}

html[data-ui-style] .bg-primary,
html[data-ui-style] .text-bg-primary,
html[data-ui-style] .badge.bg-primary {
    background-color: var(--alefba-primary) !important;
}

html[data-ui-style] .border-primary {
    border-color: var(--alefba-primary) !important;
}

html[data-ui-style] .text-danger {
    color: var(--alefba-danger) !important;
}

html[data-ui-style] .nav-tabs .nav-link.active {
    border-bottom-color: var(--alefba-primary);
}

/* ---- shape: components follow the style's radius and shadow tokens ---- */
html[data-ui-style] .card,
html[data-ui-style] .modal-content,
html[data-ui-style] .dropdown-menu,
html[data-ui-style] .offcanvas,
html[data-ui-style] .toast,
html[data-ui-style] .alert,
html[data-ui-style] .list-group,
html[data-ui-style] .accordion-item,
html[data-ui-style] .table-responsive,
html[data-ui-style] .panel-list-wrap,
html[data-ui-style] .generic-editor {
    border-radius: var(--alefba-radius);
}

html[data-ui-style] .btn,
html[data-ui-style] .form-control,
html[data-ui-style] .form-select,
html[data-ui-style] .input-group-text,
html[data-ui-style] .page-link,
html[data-ui-style] .nav-pills .nav-link,
html[data-ui-style] .badge,
html[data-ui-style] .tooltip-inner,
html[data-ui-style] .popover {
    border-radius: var(--alefba-radius-sm);
}

html[data-ui-style] .btn-sm,
html[data-ui-style] .form-control-sm,
html[data-ui-style] .form-select-sm {
    border-radius: calc(var(--alefba-radius-sm) * .8);
}

html[data-ui-style] .card,
html[data-ui-style] .dropdown-menu,
html[data-ui-style] .popover {
    box-shadow: var(--alefba-shadow-sm);
}

html[data-ui-style] .modal-content,
html[data-ui-style] .offcanvas,
html[data-ui-style] .toast {
    box-shadow: var(--alefba-shadow);
}

/* ---- theme-colour of the browser chrome follows the palette ---- */
:root {
    color-scheme: light dark;
}

/* ---- the header picker (_shared/appearance.html :: menu) ----
   A fixed-width panel, one section per kind; nothing scrolls. Colour comes from the tokens only, so the
   panel sits well under every palette; the swatches are the only colour. The active option is marked by the
   soft primary tint plus the check, never by colour alone. */
html[data-ui-style] .ui-appearance-dropdown {
    --ui-ap-radius: calc(var(--alefba-radius, 16px) * 0.5625);
    width: 19rem;
    min-width: 0;
    max-height: min(88vh, 40rem);
    overflow-y: auto;
    margin-top: 8px !important;
    padding: 6px 14px 12px;
    border: 1px solid var(--alefba-border);
    border-radius: var(--alefba-radius, 16px);
    background: var(--alefba-card-bg);
    color: var(--alefba-heading);
    box-shadow: var(--alefba-shadow);
    font-size: .8125rem;
}

html[data-ui-style] .ui-appearance-section {
    padding-top: 10px;
}

html[data-ui-style] .ui-appearance-section + .ui-appearance-section {
    margin-top: 10px;
    border-top: 1px solid var(--alefba-border);
}

html[data-ui-style] .ui-appearance-section__label {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 7px;
    color: var(--alefba-muted);
    font-size: .6875rem;
    font-weight: 700;
}

html[data-ui-style] .ui-appearance-section__label .bi {
    font-size: .75rem;
}

/* every option is a plain button; the chrome comes from its layout class */
html[data-ui-style] .ui-appearance-dropdown button {
    margin: 0;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    cursor: pointer;
    transition: background-color 140ms ease, color 140ms ease, box-shadow 140ms ease;
}

html[data-ui-style] .ui-appearance-dropdown button:focus-visible {
    outline: 2px solid var(--alefba-primary);
    outline-offset: 2px;
}

/* fonts: the names in two columns */
html[data-ui-style] .ui-appearance-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2px 6px;
}

html[data-ui-style] .ui-appearance-row {
    display: flex;
    min-height: 32px;
    align-items: center;
    gap: 8px;
    padding: 4px 10px;
    border-radius: var(--ui-ap-radius);
    text-align: start;
}

html[data-ui-style] .ui-appearance-row:hover {
    background: var(--alefba-card-soft);
}

html[data-ui-style] .ui-appearance-row.active {
    background: var(--alefba-primary-soft);
    color: var(--alefba-primary-hover, var(--alefba-primary));
    font-weight: 700;
}

html[data-ui-style] .ui-appearance-row .ui-appearance-check {
    margin-inline-start: auto;
}

/* size and style: one strip of equal cells */
html[data-ui-style] .ui-appearance-strip {
    display: grid;
    grid-auto-columns: 1fr;
    grid-auto-flow: column;
    gap: 4px;
    padding: 3px;
    border-radius: calc(var(--ui-ap-radius) + 3px);
    background: var(--alefba-card-soft);
}

html[data-ui-style] .ui-appearance-cell {
    display: flex;
    min-height: 44px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 4px 2px;
    border-radius: var(--ui-ap-radius);
    color: var(--alefba-muted);
    font-size: .6875rem;
    line-height: 1.2;
}

html[data-ui-style] .ui-appearance-cell:hover {
    color: var(--alefba-heading);
}

html[data-ui-style] .ui-appearance-cell.active {
    background: var(--alefba-card-bg);
    color: var(--alefba-primary-hover, var(--alefba-primary));
    box-shadow: var(--alefba-shadow-sm, 0 1px 3px rgba(0, 0, 0, .12));
    font-weight: 700;
}

/* the strip's cells are marked by their tint; the check would only crowd them */
html[data-ui-style] .ui-appearance-cell .ui-appearance-check {
    display: none !important;
}

/* each size shows its own sample; the steps follow the four font-size files */
html[data-ui-style] .ui-appearance-sample {
    display: block;
    line-height: 1;
    font-weight: 700;
    font-size: .9rem;
}

html[data-ui-style] [data-ui-key="small"] .ui-appearance-sample { font-size: .75rem; }
html[data-ui-style] [data-ui-key="large"] .ui-appearance-sample { font-size: 1.1rem; }
html[data-ui-style] [data-ui-key="xlarge"] .ui-appearance-sample { font-size: 1.3rem; }

/* each style's cell carries a small shape with that style's corners */
html[data-ui-style] .ui-appearance-shape {
    display: block;
    width: 18px;
    height: 14px;
    border: 1.5px solid currentColor;
    border-radius: 4px;
}

html[data-ui-style] [data-ui-key="sharp"] .ui-appearance-shape { border-radius: 0; }
html[data-ui-style] [data-ui-key="soft"] .ui-appearance-shape { border-radius: 7px; background: color-mix(in srgb, currentColor 18%, transparent); }
html[data-ui-style] [data-ui-key="minimal"] .ui-appearance-shape { border-width: 1px; border-radius: 2px; }

/* palettes: a row of colour dots, the check sits on the chosen one (the swatch rules carry the dropdown class
   so they outrank the button reset above) */
html[data-ui-style] .ui-appearance-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

html[data-ui-style] .ui-appearance-dropdown .ui-appearance-swatch {
    position: relative;
    display: grid;
    width: 28px;
    height: 28px;
    padding: 0;
    place-items: center;
    border-radius: 50%;
    background: var(--ui-swatch, #999);
    color: #fff;
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12);
    font-size: 13px;
}

html[data-ui-style] .ui-appearance-dropdown .ui-appearance-swatches--night .ui-appearance-swatch {
    box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12), inset 0 0 0 7px #1c2333;
}

html[data-ui-style] .ui-appearance-dropdown .ui-appearance-swatch:hover {
    transform: scale(1.08);
}

html[data-ui-style] .ui-appearance-dropdown .ui-appearance-swatch.active {
    box-shadow: 0 0 0 2px var(--alefba-card-bg), 0 0 0 4px var(--ui-swatch, #999);
}

html[data-ui-style] .ui-appearance-dropdown .ui-appearance-swatches--night .ui-appearance-swatch.active {
    box-shadow: 0 0 0 2px var(--alefba-card-bg), 0 0 0 4px var(--ui-swatch, #999), inset 0 0 0 7px #1c2333;
}

html[data-ui-style] .ui-appearance-swatch .ui-appearance-check {
    position: relative;
    z-index: 1;
    text-shadow: 0 1px 2px rgba(0, 0, 0, .35);
}

@media (prefers-reduced-motion: reduce) {
    html[data-ui-style] .ui-appearance-dropdown button {
        transition: none;
    }
    html[data-ui-style] .ui-appearance-dropdown .ui-appearance-swatch:hover {
        transform: none;
    }
}

/* the primary colour of each palette (keep in step with palette-*.css) */
html[data-ui-style] .ui-swatch-ocean { --ui-swatch: #3461e6; }
html[data-ui-style] .ui-swatch-emerald { --ui-swatch: #0f9d6e; }
html[data-ui-style] .ui-swatch-teal { --ui-swatch: #009e8b; }
html[data-ui-style] .ui-swatch-indigo { --ui-swatch: #5b4fe8; }
html[data-ui-style] .ui-swatch-amber { --ui-swatch: #d97706; }
html[data-ui-style] .ui-swatch-rose { --ui-swatch: #d6336c; }
html[data-ui-style] .ui-swatch-slate { --ui-swatch: #334155; }
html[data-ui-style] .ui-swatch-midnight { --ui-swatch: #4f74ea; }
html[data-ui-style] .ui-swatch-forest { --ui-swatch: #34c08a; }
html[data-ui-style] .ui-swatch-lagoon { --ui-swatch: #22c3ad; }
html[data-ui-style] .ui-swatch-plum { --ui-swatch: #b07cf5; }
html[data-ui-style] .ui-swatch-ember { --ui-swatch: #f0883e; }
html[data-ui-style] .ui-swatch-graphite { --ui-swatch: #9aa4b2; }
html[data-ui-style] .ui-swatch-nord { --ui-swatch: #88c0d0; }
