/*
 * The shared theme for gentoo and corduroy.
 *
 * This file is byte-identical in both sites (gentoo: core/static/css/styles.css, corduroy: the
 * same path). Edit both or neither -- gentoo's test_theme.py checks. Site-specific rules go in
 * gentoo.css / corduroy.css, which are loaded after this and consume the tokens defined here.
 *
 * Bootstrap 5.3 underneath. The look is done by redefining Bootstrap's own CSS variables under
 * the class names the templates already use, so a template that says `thead.table-dark` or
 * `badge bg-warning` keeps saying it and simply renders in the new style. Where Bootstrap
 * compiles a value into a rule rather than a variable (form focus, checkbox checked, font
 * sizes on inputs) the rule is overridden directly, and says so.
 *
 * Tokens. Bootstrap's `--bs-*` are redefined where the theme disagrees; the few app tokens are
 * prefixed with nothing and listed under "App tokens". Dark mode is `[data-bs-theme="dark"]`
 * on <html>, set by js/theme.js before the first paint.
 */

/* ─── Font ───────────────────────────────────────────────────────────────────── */
/* Inter, vendored (webfonts/InterVariable.woff2, OFL). One upright variable file; italics
   synthesize. The relative url() is rewritten by the manifest storage the same way Font
   Awesome's is. */
@font-face {
    font-family: "Inter";
    src: url("../webfonts/InterVariable.2bf3d951bf9d.woff2") format("woff2");
    font-weight: 100 900;
    font-style: normal;
    font-display: swap;
}

/* ─── Tokens: light ──────────────────────────────────────────────────────────── */
:root,
[data-bs-theme="light"] {
    --bs-font-sans-serif: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --bs-body-font-size: 0.875rem;
    --bs-body-line-height: 1.5;

    --bs-body-bg: #fafafa;
    --bs-body-bg-rgb: 250, 250, 250;
    --bs-body-color: #1f2430;
    --bs-body-color-rgb: 31, 36, 48;
    --bs-emphasis-color: #0d1017;
    --bs-emphasis-color-rgb: 13, 16, 23;
    --bs-secondary-color: #5f6675;
    --bs-secondary-color-rgb: 95, 102, 117;
    --bs-tertiary-color: #8a91a0;
    --bs-tertiary-color-rgb: 138, 145, 160;
    --bs-secondary-bg: #f1f2f5;
    --bs-secondary-bg-rgb: 241, 242, 245;
    --bs-tertiary-bg: #f5f6f8;
    --bs-tertiary-bg-rgb: 245, 246, 248;
    --bs-heading-color: var(--bs-emphasis-color);

    --bs-border-color: #e3e5ea;
    --bs-border-color-translucent: rgba(13, 16, 23, 0.09);
    --bs-border-radius: 0.5rem;
    --bs-border-radius-sm: 0.375rem;
    --bs-border-radius-lg: 0.625rem;
    --bs-border-radius-xl: 0.75rem;

    /* The one accent. Indigo rather than Bootstrap's blue, and deliberately not the brand green:
       green already means "OK" on every status badge. */
    --bs-primary: #3559e0;
    --bs-primary-rgb: 53, 89, 224;
    --bs-primary-bg-subtle: #e9edfc;
    --bs-primary-border-subtle: #c3cdf6;
    --bs-primary-text-emphasis: #2542ab;
    --bs-link-color: #3559e0;
    --bs-link-color-rgb: 53, 89, 224;
    --bs-link-hover-color: #2946b8;
    --bs-link-hover-color-rgb: 41, 70, 184;
    --bs-focus-ring-color: rgba(53, 89, 224, 0.25);
    --bs-code-color: #3b4252;

    /* App tokens */
    --surface-1: #ffffff;           /* cards, menus, inputs */
    --surface-2: #f4f5f7;           /* table headers, wells, hover */
    --surface-3: #e9ebef;           /* pressed, tracks */
    --text-muted: var(--bs-secondary-color);
    --accent: var(--bs-primary);
    --accent-hover: #2d4ec9;
    --accent-active: #2542ab;
    --accent-contrast: #ffffff;     /* text on a filled accent */
    --shadow-menu: 0 8px 24px rgba(13, 16, 23, 0.12), 0 0 0 1px rgba(13, 16, 23, 0.04);
    --shadow-modal: 0 24px 64px rgba(13, 16, 23, 0.22);
}

/* ─── Tokens: dark ───────────────────────────────────────────────────────────── */
/* Bootstrap's own dark block already redefines the semantic subtle/emphasis colors (success,
   danger, ...); only the neutrals, the accent and the app tokens are ours. */
[data-bs-theme="dark"] {
    --bs-body-bg: #0f1115;
    --bs-body-bg-rgb: 15, 17, 21;
    --bs-body-color: #d3d7df;
    --bs-body-color-rgb: 211, 215, 223;
    --bs-emphasis-color: #f2f4f8;
    --bs-emphasis-color-rgb: 242, 244, 248;
    --bs-secondary-color: #8f97a6;
    --bs-secondary-color-rgb: 143, 151, 166;
    --bs-tertiary-color: #6b7382;
    --bs-tertiary-color-rgb: 107, 115, 130;
    --bs-secondary-bg: #1b1f27;
    --bs-secondary-bg-rgb: 27, 31, 39;
    --bs-tertiary-bg: #161a21;
    --bs-tertiary-bg-rgb: 22, 26, 33;
    --bs-heading-color: var(--bs-emphasis-color);

    --bs-border-color: #272c37;
    --bs-border-color-translucent: rgba(242, 244, 248, 0.1);

    --bs-primary: #8aa2ff;
    --bs-primary-rgb: 138, 162, 255;
    --bs-primary-bg-subtle: #1b2344;
    --bs-primary-border-subtle: #2f3d78;
    --bs-primary-text-emphasis: #b5c3ff;
    --bs-link-color: #8aa2ff;
    --bs-link-color-rgb: 138, 162, 255;
    --bs-link-hover-color: #a9baff;
    --bs-link-hover-color-rgb: 169, 186, 255;
    --bs-focus-ring-color: rgba(138, 162, 255, 0.3);
    --bs-code-color: #c3c9d4;

    --surface-1: #171a21;
    --surface-2: #1d212a;
    --surface-3: #242935;
    --accent-hover: #9db1ff;
    --accent-active: #7d95f5;
    --accent-contrast: #0f1115;
    --shadow-menu: 0 8px 24px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(242, 244, 248, 0.06);
    --shadow-modal: 0 24px 64px rgba(0, 0, 0, 0.6);
}

/* The colored text utilities are `!important` on non-adaptive `-rgb` values, and Bootstrap's own
   docs call their contrast on a dark ground failing. The emphasis variants are the adaptive ones. */
[data-bs-theme="dark"] .text-primary { color: var(--bs-primary-text-emphasis) !important; }
[data-bs-theme="dark"] .text-success { color: var(--bs-success-text-emphasis) !important; }
[data-bs-theme="dark"] .text-danger { color: var(--bs-danger-text-emphasis) !important; }
[data-bs-theme="dark"] .text-warning { color: var(--bs-warning-text-emphasis) !important; }
[data-bs-theme="dark"] .text-info { color: var(--bs-info-text-emphasis) !important; }

/* ─── Page ───────────────────────────────────────────────────────────────────── */
body {
    background-color: var(--bs-body-bg);
    color: var(--bs-body-color);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: "cv11", "ss01";
}

.content {
    padding: 1.5rem 1.75rem 3rem;
}

/* Django messages sit between the nav and the page, aligned with the content's left edge. */
.page-messages {
    padding: 1rem 1.75rem 0;
}

.page-messages .alert {
    margin-bottom: 0;
}

h1, h2, h3, h4, h5, h6,
.h1, .h2, .h3, .h4, .h5, .h6 {
    font-weight: 600;
    letter-spacing: -0.01em;
    color: var(--bs-heading-color);
}

/* Fixed sizes, a notch smaller than Bootstrap's fluid ones: this is a tool, not an article. */
h1, .h1 { font-size: 1.625rem; }
h2, .h2 { font-size: 1.375rem; }
h3, .h3 { font-size: 1.25rem; }
h4, .h4 { font-size: 1.05rem; }
h5, .h5 { font-size: 0.95rem; }
h6, .h6 { font-size: 0.875rem; }

a {
    color: var(--bs-link-color);
    text-decoration: none;
}

a:hover {
    color: var(--bs-link-hover-color);
    text-decoration: underline;
}

a:focus-visible {
    outline: 2px solid var(--bs-primary);
    outline-offset: 2px;
    border-radius: 0.2rem;
}

code {
    font-size: 0.875em;
    color: var(--bs-code-color);
}

pre {
    font-size: 0.8125rem;
    color: var(--bs-body-color);
}

hr {
    border-color: var(--bs-border-color);
    opacity: 1;
}

/* Inputs, buttons and the accordion header hard-code 1rem in Bootstrap 5.3; the body is 14px. */
.form-control,
.form-select,
.input-group-text,
.accordion-button {
    font-size: 0.875rem;
}

/* ─── Navbar ─────────────────────────────────────────────────────────────────── */
/* A light bar on the page, separated by one hairline. The active section carries an accent
   underline; nothing else in the bar is colored, so the eye lands on where you are. */
.app-nav {
    --bs-navbar-padding-y: 0.3rem;
    --bs-navbar-padding-x: 1.25rem;
    --bs-navbar-color: var(--bs-secondary-color);
    --bs-navbar-hover-color: var(--bs-emphasis-color);
    --bs-navbar-active-color: var(--bs-emphasis-color);
    --bs-navbar-brand-padding-y: 0.35rem;
    --bs-navbar-toggler-border-color: var(--bs-border-color);
    --bs-navbar-toggler-focus-width: 0.15rem;
    background-color: var(--surface-1);
    border-bottom: 1px solid var(--bs-border-color);
    min-height: 3.25rem;
}

.app-nav .brand-logo {
    display: block;
    height: 1.75rem;
    width: auto;
}

.app-nav .navbar-nav .nav-link {
    position: relative;
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0.45rem 0.7rem;
    border-radius: 0.375rem;
    transition: background-color 0.12s ease, color 0.12s ease;
}

.app-nav .navbar-nav .nav-link:hover,
.app-nav .navbar-nav .nav-link:focus-visible {
    background-color: var(--surface-2);
    color: var(--bs-emphasis-color);
}

.app-nav .navbar-nav .nav-link.active {
    color: var(--bs-emphasis-color);
}

/* Collapsed (narrow) layout: the active item is a tinted row, because an underline under a
   stacked list reads as a divider. */
.app-nav .navbar-nav .nav-link.active {
    background-color: var(--bs-primary-bg-subtle);
    color: var(--bs-primary-text-emphasis);
}

@media (min-width: 992px) {
    .app-nav .navbar-nav .nav-link.active {
        background-color: transparent;
        color: var(--bs-emphasis-color);
    }

    /* ::before, not ::after: Bootstrap draws a dropdown's caret with ::after, and this rule
       out-specifies it, so an active menu -- Gentoo's PCBA and Inventory, lit most of the
       time -- would lose its arrow and look like a plain link that does nothing. */
    .app-nav .navbar-nav .nav-link.active::before {
        content: "";
        position: absolute;
        left: 0.7rem;
        right: 0.7rem;
        bottom: calc(-0.3rem - 1px);
        height: 2px;
        border-radius: 2px 2px 0 0;
        background-color: var(--bs-primary);
    }
}

.app-nav .navbar-nav .nav-link.text-muted {
    font-size: 0.8125rem;
    font-weight: 400;
    color: var(--bs-secondary-color) !important;
    cursor: default;
}

.app-nav .navbar-nav .nav-link.text-muted:hover {
    background-color: transparent;
}

.app-nav .navbar-nav .btn-link.nav-link {
    text-decoration: none;
}

.app-nav .dropdown-toggle::after {
    opacity: 0.6;
}

/* The theme switch: an icon for the theme you are in, a menu for the one you want. */
.theme-toggle {
    display: inline-flex;
    align-items: center;
}

.theme-icon {
    display: none;
    width: 1rem;
    height: 1rem;
}

:root:not([data-bs-theme="dark"]) .theme-icon-sun { display: inline-block; }
[data-bs-theme="dark"] .theme-icon-moon { display: inline-block; }

.build-tag code {
    font-size: 0.72rem;
    color: var(--bs-tertiary-color);
}

.build-tag:hover code {
    color: var(--bs-body-color);
}

/* ─── Dropdowns ──────────────────────────────────────────────────────────────── */
.dropdown-menu {
    --bs-dropdown-bg: var(--surface-1);
    --bs-dropdown-color: var(--bs-body-color);
    --bs-dropdown-border-color: var(--bs-border-color);
    --bs-dropdown-border-radius: 0.5rem;
    --bs-dropdown-padding-y: 0.25rem;
    --bs-dropdown-font-size: 0.875rem;
    --bs-dropdown-link-color: var(--bs-body-color);
    --bs-dropdown-link-hover-color: var(--bs-emphasis-color);
    --bs-dropdown-link-hover-bg: var(--surface-2);
    --bs-dropdown-link-active-color: var(--bs-primary-text-emphasis);
    --bs-dropdown-link-active-bg: var(--bs-primary-bg-subtle);
    --bs-dropdown-item-padding-x: 0.6rem;
    --bs-dropdown-item-padding-y: 0.4rem;
    --bs-dropdown-divider-bg: var(--bs-border-color);
    --bs-dropdown-divider-margin-y: 0.25rem;
    box-shadow: var(--shadow-menu);
}

.dropdown-item {
    width: calc(100% - 0.5rem);
    margin: 0 0.25rem;
    border-radius: 0.375rem;
}

/* ─── Cards ──────────────────────────────────────────────────────────────────── */
/* A hairline, not a shadow: shadows are what made the old cards float. */
.card {
    --bs-card-bg: var(--surface-1);
    --bs-card-color: var(--bs-body-color);
    --bs-card-border-color: var(--bs-border-color);
    --bs-card-border-radius: 0.625rem;
    --bs-card-inner-border-radius: calc(0.625rem - 1px);
    --bs-card-cap-bg: transparent;
    --bs-card-cap-color: var(--bs-emphasis-color);
    --bs-card-cap-padding-y: 0.8rem;
    --bs-card-cap-padding-x: 1.1rem;
    --bs-card-spacer-y: 1.1rem;
    --bs-card-spacer-x: 1.1rem;
    box-shadow: none;
    margin-bottom: 1.25rem;
}

.card-header {
    font-weight: 600;
    border-bottom: 1px solid var(--bs-border-color);
}

.card-header h1, .card-header h2, .card-header h3, .card-header h4, .card-header h5,
.card-header .h1, .card-header .h2, .card-header .h3, .card-header .h4, .card-header .h5 {
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: -0.005em;
}

.card-footer {
    background-color: transparent;
    border-top: 1px solid var(--bs-border-color);
}

/* A table that is the card's last child ends where the card does. */
.card > .table:last-child > :last-child > tr:last-child > * {
    border-bottom: 0;
}

.card > .table:last-child > :last-child > tr:last-child > *:first-child {
    border-bottom-left-radius: var(--bs-card-inner-border-radius);
}

.card > .table:last-child > :last-child > tr:last-child > *:last-child {
    border-bottom-right-radius: var(--bs-card-inner-border-radius);
}

/* ─── Tables ─────────────────────────────────────────────────────────────────── */
/* Bootstrap 5.3 paints every cell with `--bs-table-bg: var(--bs-body-bg)`, which would hide the
   row-level rails and tints the apps draw on <tr>. Transparent restores 5.1's behavior. */
.table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--bs-body-color);
    --bs-table-border-color: var(--bs-border-color);
    --bs-table-striped-bg: rgba(var(--bs-emphasis-color-rgb), 0.022);
    --bs-table-striped-color: var(--bs-body-color);
    --bs-table-hover-bg: rgba(var(--bs-emphasis-color-rgb), 0.04);
    --bs-table-hover-color: var(--bs-body-color);
    --bs-table-active-bg: rgba(var(--bs-primary-rgb), 0.08);
    --bs-table-active-color: var(--bs-body-color);
    margin-bottom: 0;
    font-size: 0.875rem;
}

.table > :not(caption) > * > * {
    padding: 0.55rem 0.9rem;
    vertical-align: middle;
}

.table-sm > :not(caption) > * > * {
    padding: 0.3rem 0.55rem;
}

/* Hover on every table, striped or not, as a state on the cells so it wins over the stripe. */
.table > tbody > tr:hover > * {
    --bs-table-bg-state: var(--bs-table-hover-bg);
}

/* The header: light, small caps, a hairline under it. `thead.table-dark` in the markup keeps
   meaning "the header row" -- the dark is gone. The direct properties override the ones
   `.table-dark` compiles in. */
.table > thead.table-dark,
.table > thead.table-dark > tr > th,
.table > thead.table-dark > tr > td {
    --bs-table-bg: var(--surface-2);
    --bs-table-color: var(--bs-secondary-color);
    --bs-table-border-color: var(--bs-border-color);
    --bs-table-striped-bg: var(--surface-2);
    --bs-table-hover-bg: var(--surface-2);
    color: var(--bs-secondary-color);
    background-color: var(--surface-2);
    border-color: var(--bs-border-color);
}

.table > thead.table-dark > tr > th {
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--bs-border-color);
}

.table > thead > tr > th {
    font-weight: 600;
    color: var(--bs-secondary-color);
}

/* ─── Forms ──────────────────────────────────────────────────────────────────── */
.form-label {
    display: block;
    font-weight: 500;
    font-size: 0.8125rem;
    margin-bottom: 0.3rem;
    color: var(--bs-body-color);
}

/* A widget Django rendered with no class of its own (the sign-in form, a plain ModelForm
   field) gets the .form-control look, so a form does not depend on every forms.py remembering
   to set attrs. Appearance everywhere; the block layout only inside a field wrapper. */
input:not([class]):not([type="checkbox"]):not([type="radio"]):not([type="hidden"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="range"]):not([type="color"]),
select:not([class]),
textarea:not([class]) {
    font-family: inherit;
    font-size: 0.875rem;
    line-height: 1.5;
    padding: 0.4rem 0.65rem;
    border: 1px solid var(--bs-border-color);
    border-radius: 0.375rem;
    background-color: var(--surface-1);
    color: var(--bs-body-color);
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

input:not([class]):focus,
select:not([class]):focus,
textarea:not([class]):focus {
    outline: 0;
    border-color: var(--bs-primary);
    box-shadow: 0 0 0 3px rgba(var(--bs-primary-rgb), 0.18);
}

.mb-3 > input:not([class]):not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
.mb-3 > select:not([class]),
.mb-3 > textarea:not([class]),
form p > input:not([class]):not([type="checkbox"]):not([type="radio"]):not([type="hidden"]),
form p > select:not([class]),
form p > textarea:not([class]) {
    display: block;
    width: 100%;
}

form p > label:not([class]) {
    display: block;
    font-weight: 500;
    font-size: 0.8125rem;
    margin-bottom: 0.3rem;
}

.form-control,
.form-select {
    border-radius: 0.375rem;
    border-color: var(--bs-border-color);
    background-color: var(--surface-1);
    color: var(--bs-body-color);
    padding: 0.4rem 0.65rem;
    transition: border-color 0.12s ease, box-shadow 0.12s ease;
}

.form-control::placeholder {
    color: var(--bs-tertiary-color);
}

/* Focus and checked are compiled into rules in 5.3, not variables. */
.form-control:focus,
.form-select:focus,
.form-check-input:focus {
    border-color: var(--bs-primary);
    box-shadow: 0 0 0 3px rgba(var(--bs-primary-rgb), 0.18);
    background-color: var(--surface-1);
    color: var(--bs-body-color);
}

.form-control:disabled,
.form-select:disabled {
    background-color: var(--surface-2);
    color: var(--bs-secondary-color);
}

.form-control-sm,
.form-select-sm {
    font-size: 0.8125rem;
    padding: 0.25rem 0.5rem;
    border-radius: 0.3rem;
}

.form-select-sm {
    padding-right: 1.9rem;
}

.form-text {
    font-size: 0.75rem;
    color: var(--bs-secondary-color);
}

.form-check-input {
    background-color: var(--surface-1);
    border-color: rgba(var(--bs-emphasis-color-rgb), 0.3);
}

.form-check-input:checked {
    background-color: var(--bs-primary);
    border-color: var(--bs-primary);
}

.input-group-text {
    background-color: var(--surface-2);
    border-color: var(--bs-border-color);
    color: var(--bs-secondary-color);
}

.invalid-feedback {
    font-size: 0.78rem;
}

/* ─── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
    --bs-btn-font-size: 0.875rem;
    --bs-btn-font-weight: 500;
    --bs-btn-padding-y: 0.4rem;
    --bs-btn-padding-x: 0.85rem;
    --bs-btn-border-radius: 0.375rem;
    --bs-btn-focus-box-shadow: 0 0 0 3px rgba(var(--bs-primary-rgb), 0.2);
    transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease, box-shadow 0.12s ease;
}

.btn-sm {
    --bs-btn-font-size: 0.8125rem;
    --bs-btn-padding-y: 0.25rem;
    --bs-btn-padding-x: 0.6rem;
    --bs-btn-border-radius: 0.3rem;
}

.btn-lg {
    --bs-btn-font-size: 0.95rem;
    --bs-btn-padding-y: 0.55rem;
    --bs-btn-padding-x: 1.1rem;
}

.btn-primary {
    --bs-btn-color: var(--accent-contrast);
    --bs-btn-bg: var(--accent);
    --bs-btn-border-color: var(--accent);
    --bs-btn-hover-color: var(--accent-contrast);
    --bs-btn-hover-bg: var(--accent-hover);
    --bs-btn-hover-border-color: var(--accent-hover);
    --bs-btn-active-color: var(--accent-contrast);
    --bs-btn-active-bg: var(--accent-active);
    --bs-btn-active-border-color: var(--accent-active);
    --bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
    --bs-btn-disabled-color: var(--accent-contrast);
    --bs-btn-disabled-bg: var(--accent);
    --bs-btn-disabled-border-color: var(--accent);
}

.btn-outline-primary {
    --bs-btn-color: var(--bs-primary-text-emphasis);
    --bs-btn-border-color: var(--bs-primary-border-subtle);
    --bs-btn-hover-color: var(--bs-primary-text-emphasis);
    --bs-btn-hover-bg: var(--bs-primary-bg-subtle);
    --bs-btn-hover-border-color: var(--bs-primary-border-subtle);
    --bs-btn-active-color: var(--accent-contrast);
    --bs-btn-active-bg: var(--accent);
    --bs-btn-active-border-color: var(--accent);
    --bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
    --bs-btn-disabled-color: var(--bs-primary-text-emphasis);
    --bs-btn-disabled-border-color: var(--bs-primary-border-subtle);
}

/* The workhorse: a neutral bordered button. The pressed state (btn-check radios, toggles) is
   accent-tinted so a chosen option and a hovered one cannot be confused. */
.btn-outline-secondary {
    --bs-btn-color: var(--bs-body-color);
    --bs-btn-bg: var(--surface-1);
    --bs-btn-border-color: rgba(var(--bs-emphasis-color-rgb), 0.16);
    --bs-btn-hover-color: var(--bs-emphasis-color);
    --bs-btn-hover-bg: var(--surface-2);
    --bs-btn-hover-border-color: rgba(var(--bs-emphasis-color-rgb), 0.26);
    --bs-btn-active-color: var(--bs-primary-text-emphasis);
    --bs-btn-active-bg: var(--bs-primary-bg-subtle);
    --bs-btn-active-border-color: var(--bs-primary-border-subtle);
    --bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
    --bs-btn-disabled-color: var(--bs-tertiary-color);
    --bs-btn-disabled-bg: var(--surface-1);
    --bs-btn-disabled-border-color: var(--bs-border-color);
}

.btn-secondary {
    --bs-btn-color: var(--bs-emphasis-color);
    --bs-btn-bg: var(--surface-3);
    --bs-btn-border-color: var(--surface-3);
    --bs-btn-hover-color: var(--bs-emphasis-color);
    --bs-btn-hover-bg: rgba(var(--bs-emphasis-color-rgb), 0.14);
    --bs-btn-hover-border-color: rgba(var(--bs-emphasis-color-rgb), 0.14);
    --bs-btn-active-color: var(--bs-emphasis-color);
    --bs-btn-active-bg: rgba(var(--bs-emphasis-color-rgb), 0.18);
    --bs-btn-active-border-color: rgba(var(--bs-emphasis-color-rgb), 0.18);
    --bs-btn-focus-shadow-rgb: var(--bs-primary-rgb);
    --bs-btn-disabled-color: var(--bs-tertiary-color);
    --bs-btn-disabled-bg: var(--surface-2);
    --bs-btn-disabled-border-color: var(--surface-2);
}

.btn-light {
    --bs-btn-color: var(--bs-body-color);
    --bs-btn-bg: var(--surface-2);
    --bs-btn-border-color: var(--surface-2);
    --bs-btn-hover-color: var(--bs-emphasis-color);
    --bs-btn-hover-bg: var(--surface-3);
    --bs-btn-hover-border-color: var(--surface-3);
    --bs-btn-active-bg: var(--surface-3);
    --bs-btn-active-border-color: var(--surface-3);
}

.btn-link {
    --bs-btn-font-weight: 500;
    text-decoration: none;
}

.btn-link:hover {
    text-decoration: underline;
}

/* The status buttons keep their colors; only the focus ring changes to match the rest. */
.btn-outline-danger,
.btn-outline-success,
.btn-outline-warning {
    --bs-btn-bg: var(--surface-1);
}

/* ─── Badges ─────────────────────────────────────────────────────────────────── */
/* Soft chips: a tinted ground and a dark ink of the same hue, where Bootstrap fills the chip
   solid. `!important` because the `.bg-*` utilities are; two classes beat one. The status
   mapping in the templates is untouched -- `bg-warning` still means warning. */
.badge {
    --bs-badge-font-size: 0.72rem;
    --bs-badge-font-weight: 500;
    --bs-badge-padding-x: 0.5em;
    --bs-badge-padding-y: 0.32em;
    --bs-badge-border-radius: 0.3rem;
    letter-spacing: 0.01em;
    line-height: 1.2;
    vertical-align: baseline;
}

.badge.bg-primary   { background-color: var(--bs-primary-bg-subtle) !important;   color: var(--bs-primary-text-emphasis);   box-shadow: inset 0 0 0 1px var(--bs-primary-border-subtle); }
.badge.bg-secondary { background-color: var(--bs-secondary-bg-subtle) !important; color: var(--bs-secondary-text-emphasis); box-shadow: inset 0 0 0 1px var(--bs-secondary-border-subtle); }
.badge.bg-success   { background-color: var(--bs-success-bg-subtle) !important;   color: var(--bs-success-text-emphasis);   box-shadow: inset 0 0 0 1px var(--bs-success-border-subtle); }
.badge.bg-danger    { background-color: var(--bs-danger-bg-subtle) !important;    color: var(--bs-danger-text-emphasis);    box-shadow: inset 0 0 0 1px var(--bs-danger-border-subtle); }
.badge.bg-warning   { background-color: var(--bs-warning-bg-subtle) !important;   color: var(--bs-warning-text-emphasis);   box-shadow: inset 0 0 0 1px var(--bs-warning-border-subtle); }
.badge.bg-info      { background-color: var(--bs-info-bg-subtle) !important;      color: var(--bs-info-text-emphasis);      box-shadow: inset 0 0 0 1px var(--bs-info-border-subtle); }
.badge.bg-light     { background-color: var(--bs-tertiary-bg) !important;         color: var(--bs-body-color);              box-shadow: inset 0 0 0 1px var(--bs-border-color); }
.badge.bg-dark      { background-color: var(--bs-dark-bg-subtle) !important;      color: var(--bs-dark-text-emphasis);      box-shadow: inset 0 0 0 1px var(--bs-dark-border-subtle); }

/* `text-dark` rides along on the amber and cyan chips in the templates (the 5.1 way to keep
   them readable). It is `!important`, so the ink has to be too. */
.badge.bg-warning.text-dark { color: var(--bs-warning-text-emphasis) !important; }
.badge.bg-info.text-dark    { color: var(--bs-info-text-emphasis) !important; }
.badge.bg-light.text-dark   { color: var(--bs-body-color) !important; }

.badge.text-bg-primary   { background-color: var(--bs-primary-bg-subtle) !important;   color: var(--bs-primary-text-emphasis) !important; }
.badge.text-bg-secondary { background-color: var(--bs-secondary-bg-subtle) !important; color: var(--bs-secondary-text-emphasis) !important; }
.badge.text-bg-success   { background-color: var(--bs-success-bg-subtle) !important;   color: var(--bs-success-text-emphasis) !important; }
.badge.text-bg-danger    { background-color: var(--bs-danger-bg-subtle) !important;    color: var(--bs-danger-text-emphasis) !important; }
.badge.text-bg-warning   { background-color: var(--bs-warning-bg-subtle) !important;   color: var(--bs-warning-text-emphasis) !important; }
.badge.text-bg-info      { background-color: var(--bs-info-bg-subtle) !important;      color: var(--bs-info-text-emphasis) !important; }

/* ─── Alerts ─────────────────────────────────────────────────────────────────── */
/* The subtle tints Bootstrap 5.3 already uses, plus a rail on the left so a notice reads as a
   notice and not as a colored card. */
.alert {
    --bs-alert-border-radius: 0.5rem;
    --bs-alert-padding-y: 0.7rem;
    --bs-alert-padding-x: 1rem;
    font-size: 0.875rem;
    border-left-width: 3px;
    border-left-color: var(--bs-alert-color);
}

.alert-dismissible {
    padding-right: 3rem;
}

/* ─── Tabs and pills ─────────────────────────────────────────────────────────── */
/* Underline tabs. The boxed kind is what the old strip was. */
.nav-tabs {
    --bs-nav-tabs-border-width: 1px;
    --bs-nav-tabs-border-color: var(--bs-border-color);
    --bs-nav-tabs-border-radius: 0;
    --bs-nav-tabs-link-hover-border-color: transparent;
    --bs-nav-tabs-link-active-color: var(--bs-emphasis-color);
    --bs-nav-tabs-link-active-bg: transparent;
    --bs-nav-tabs-link-active-border-color: transparent;
    --bs-nav-link-color: var(--bs-secondary-color);
    --bs-nav-link-hover-color: var(--bs-emphasis-color);
    --bs-nav-link-font-weight: 500;
    --bs-nav-link-padding-y: 0.55rem;
    --bs-nav-link-padding-x: 0.9rem;
    gap: 0.25rem;
}

.nav-tabs .nav-link {
    border: 0;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    border-radius: 0;
    transition: color 0.12s ease, border-color 0.12s ease;
}

.nav-tabs .nav-link:hover,
.nav-tabs .nav-link:focus-visible {
    border-color: transparent;
    border-bottom-color: rgba(var(--bs-emphasis-color-rgb), 0.2);
    isolation: auto;
}

.nav-tabs .nav-link.active,
.nav-tabs .nav-item.show .nav-link {
    border-color: transparent;
    border-bottom-color: var(--bs-primary);
    background-color: transparent;
    color: var(--bs-emphasis-color);
}

.nav-tabs .nav-link.disabled,
.nav-tabs .nav-link.text-muted {
    color: var(--bs-tertiary-color) !important;
}

.nav-pills {
    --bs-nav-pills-border-radius: 0.375rem;
    --bs-nav-pills-link-active-color: var(--bs-primary-text-emphasis);
    --bs-nav-pills-link-active-bg: var(--bs-primary-bg-subtle);
    --bs-nav-link-color: var(--bs-secondary-color);
    --bs-nav-link-hover-color: var(--bs-emphasis-color);
    --bs-nav-link-font-weight: 500;
    --bs-nav-link-padding-y: 0.35rem;
    --bs-nav-link-padding-x: 0.7rem;
    gap: 0.15rem;
}

.nav-pills .nav-link:not(.active):hover {
    background-color: var(--surface-2);
}

/* ─── Modals ─────────────────────────────────────────────────────────────────── */
.modal {
    --bs-modal-bg: var(--surface-1);
    --bs-modal-color: var(--bs-body-color);
    --bs-modal-border-color: var(--bs-border-color);
    --bs-modal-border-radius: 0.75rem;
    --bs-modal-inner-border-radius: calc(0.75rem - 1px);
    --bs-modal-header-border-color: var(--bs-border-color);
    --bs-modal-footer-border-color: var(--bs-border-color);
    --bs-modal-box-shadow: var(--shadow-modal);
    --bs-modal-box-shadow-sm-up: var(--shadow-modal);
    --bs-modal-header-padding: 0.9rem 1.1rem;
    --bs-modal-padding: 1.1rem;
}

.modal-backdrop {
    --bs-backdrop-opacity: 0.45;
    --bs-backdrop-bg: #0d1017;
}

.modal-title {
    font-size: 1rem;
    font-weight: 600;
}

/* ─── Accordion, list group ──────────────────────────────────────────────────── */
.accordion {
    --bs-accordion-bg: var(--surface-1);
    --bs-accordion-color: var(--bs-body-color);
    --bs-accordion-border-color: var(--bs-border-color);
    --bs-accordion-border-radius: 0.5rem;
    --bs-accordion-inner-border-radius: calc(0.5rem - 1px);
    --bs-accordion-btn-color: var(--bs-body-color);
    --bs-accordion-btn-bg: var(--surface-1);
    --bs-accordion-btn-padding-y: 0.75rem;
    --bs-accordion-btn-padding-x: 1rem;
    --bs-accordion-btn-focus-box-shadow: 0 0 0 3px rgba(var(--bs-primary-rgb), 0.18);
    --bs-accordion-active-color: var(--bs-primary-text-emphasis);
    --bs-accordion-active-bg: var(--bs-primary-bg-subtle);
    --bs-accordion-body-padding-y: 0.9rem;
    --bs-accordion-body-padding-x: 1rem;
}

.accordion-button {
    font-weight: 500;
}

.list-group {
    --bs-list-group-bg: var(--surface-1);
    --bs-list-group-color: var(--bs-body-color);
    --bs-list-group-border-color: var(--bs-border-color);
    --bs-list-group-border-radius: 0.5rem;
    --bs-list-group-action-hover-bg: var(--surface-2);
    --bs-list-group-action-active-bg: var(--surface-3);
    --bs-list-group-active-color: var(--bs-primary-text-emphasis);
    --bs-list-group-active-bg: var(--bs-primary-bg-subtle);
    --bs-list-group-active-border-color: var(--bs-primary-border-subtle);
    --bs-list-group-item-padding-y: 0.55rem;
    --bs-list-group-item-padding-x: 0.9rem;
}

/* ─── Pagination, progress ───────────────────────────────────────────────────── */
.pagination {
    --bs-pagination-bg: var(--surface-1);
    --bs-pagination-color: var(--bs-body-color);
    --bs-pagination-border-color: var(--bs-border-color);
    --bs-pagination-border-radius: 0.375rem;
    --bs-pagination-hover-color: var(--bs-emphasis-color);
    --bs-pagination-hover-bg: var(--surface-2);
    --bs-pagination-hover-border-color: var(--bs-border-color);
    --bs-pagination-focus-color: var(--bs-emphasis-color);
    --bs-pagination-focus-bg: var(--surface-2);
    --bs-pagination-focus-box-shadow: 0 0 0 3px rgba(var(--bs-primary-rgb), 0.18);
    --bs-pagination-active-color: var(--accent-contrast);
    --bs-pagination-active-bg: var(--accent);
    --bs-pagination-active-border-color: var(--accent);
    --bs-pagination-disabled-color: var(--bs-tertiary-color);
    --bs-pagination-disabled-bg: var(--surface-1);
    --bs-pagination-disabled-border-color: var(--bs-border-color);
}

.progress,
.progress-stacked {
    --bs-progress-bg: var(--surface-3);
    --bs-progress-bar-bg: var(--accent);
    --bs-progress-bar-color: var(--accent-contrast);
    --bs-progress-border-radius: 999px;
    --bs-progress-height: 0.6rem;
}

/* ─── Stat cards ─────────────────────────────────────────────────────────────── */
/* One rule for both shapes: gentoo's label-above and corduroy's centered number. */
.stat-card .display-6 {
    font-size: 1.75rem;
    line-height: 1.1;
    font-weight: 600;
    letter-spacing: -0.02em;
    font-variant-numeric: tabular-nums;
    color: var(--bs-emphasis-color);
}

.stat-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--bs-secondary-color);
}

/* ─── Copyable fields ────────────────────────────────────────────────────────── */
.copyable {
    cursor: pointer;
    border-radius: 0.25rem;
    padding: 0 0.15rem;
    transition: background-color 0.12s ease;
}

.copyable:hover,
.copyable:focus-visible {
    background-color: rgba(var(--bs-primary-rgb), 0.08);
}

/* Clipboard glyph appears on hover; swaps to "Copied!" after a click. */
.copyable::after {
    content: "\2398";
    opacity: 0;
    margin-left: 0.3rem;
    font-size: 0.8em;
    color: var(--bs-secondary-color);
    transition: opacity 0.12s ease;
}

.copyable:hover::after,
.copyable:focus-visible::after {
    opacity: 1;
}

.copyable.copied::after {
    content: "Copied!";
    opacity: 1;
    color: var(--bs-success-text-emphasis);
    font-size: 0.7em;
    font-weight: 600;
}

/* ─── Sign-in ────────────────────────────────────────────────────────────────── */
.login-card {
    max-width: 24rem;
    margin: 6rem auto 0;
}

/* ─── The backup site's banner ───────────────────────────────────────────────── */
/* Shape only; each site's backup_theme.css supplies the color that says which site it is. */
.backup-site-banner {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    text-align: center;
    color: #fff;
}

/* ─── Print ──────────────────────────────────────────────────────────────────── */
/* theme.js swaps to the light theme on beforeprint; this is the fallback for a browser that
   fires no such event, and hides the chrome either way. */
@media print {
    :root,
    [data-bs-theme="dark"] {
        color-scheme: light;
    }

    .app-nav,
    .backup-site-banner,
    .page-messages {
        display: none !important;
    }

    .content {
        padding: 0;
    }
}
