/*
 * Group Manager — presentation layer on top of Bootstrap 5.3.
 *
 * Built to the EnergyUp International design system (design_system.md): teal
 * brand, Untitled-UI neutral scale, Inter, 8px control radius / 12px container
 * radius, soft shadows. Section 5 of that document is the source of every
 * token below; nothing here invents a colour or a radius.
 *
 * Still a deliberate copy of ERP.Modules.PlatformAdmin/wwwroot/css/admin.css
 * (spec 007 T004, research R-012). Constitution V forbids a module reaching
 * into another module's content root, and a static-asset path is as much an
 * internal as a type is: linking
 * /_content/ERP.Modules.PlatformAdmin/css/admin.css would make this surface
 * break whenever the admin surface restyles. The structural class names are
 * identical so the two layouts stay comparable.
 *
 * WHAT CHANGED: this sheet used to carry its own accent — teal #0f766e against
 * the platform's indigo — so a group manager could not mistake one console for
 * the other. The design system licenses exactly one interactive colour
 * (--brand-700) and forbids inventing another, so the two surfaces now share
 * it, and they are told apart structurally instead: the logo lockup, the
 * two-item rail, and the page titles. If the colour cue has to come back, it
 * belongs in design_system.md as a second named brand ramp, not as a local
 * override here.
 *
 * Everything here is visual: tokens, the application shell, and refinements
 * to the Bootstrap components the pages already use. No behaviour, no new
 * markup contracts — a page that only uses stock Bootstrap classes still
 * picks up the restyled cards, tables, badges, and forms.
 *
 * Light theme only, by design: the layout pins data-bs-theme="light" so the
 * console looks identical regardless of the operating-system appearance.
 *
 * NOT here: the anonymous sign-in shell (.auth-page, .auth-panel, .auth-brand*,
 * .auth-card, .auth-lede, .auth-foot, .auth-note) and the verification-code
 * field (.code-input). Those live in
 * ERP.SharedKernel.Web/wwwroot/css/auth.css — a shared-kernel asset, not
 * another module's, so the rule above holds — and the layout links it after
 * this sheet, so the platform-administration, group-manager, and company
 * sign-in screens are identical by construction rather than by three files
 * agreeing. Restyle them there, once.
 *
 * Direction is expressed with logical properties throughout (inline-start /
 * inline-end rather than left / right) so the console mirrors correctly under
 * dir="rtl" — design system §6.9.
 */

/* ---------------------------------------------------------------- tokens */

:root,
[data-bs-theme="light"] {
    color-scheme: light;

    /* brand — reserved for interactive intent, never for state */
    --brand-50: #F0F8F6;
    --brand-100: #D6EDE9;
    --brand-700: #1B6E63;
    --brand-800: #155A51;
    --brand-900: #10453E;

    /* neutrals */
    --gray-50: #F9FAFB;
    --gray-100: #F2F4F7;
    --gray-200: #EAECF0;
    --gray-300: #D0D5DD;
    --gray-400: #98A2B3;
    --gray-500: #667085;
    --gray-600: #475467;
    --gray-700: #344054;
    --gray-900: #101828;

    /* status — reserved for state, never for a button */
    --success-bg: #ECFDF3;
    --success-fg: #067647;
    --warning-bg: #FFFAEB;
    --warning-fg: #B54708;
    --error-bg: #FEF3F2;
    --error-fg: #B42318;
    --info-bg: #EFF8FF;
    --info-fg: #175CD3;

    /* surfaces */
    --canvas: var(--gray-50);
    --surface: #FFFFFF;
    --border: var(--gray-200);

    /* radius — 8px for controls, 12px for containers, nothing else */
    --r-sm: 6px;
    --r-md: 8px;
    --r-lg: 12px;
    --r-full: 9999px;

    /* elevation */
    --shadow-xs: 0 1px 2px rgba(16, 24, 40, .05);
    --shadow-sm: 0 1px 3px rgba(16, 24, 40, .10), 0 1px 2px rgba(16, 24, 40, .06);
    --shadow-lg: 0 12px 16px -4px rgba(16, 24, 40, .08), 0 4px 6px -2px rgba(16, 24, 40, .03);
    --focus-ring: 0 0 0 4px rgba(27, 110, 99, .18);

    /* type */
    --font-sans: "Inter", -apple-system, "Segoe UI Variable Text", "Segoe UI", Roboto, system-ui, sans-serif;
    --font-mono: "Cascadia Mono", "JetBrains Mono", ui-monospace, SFMono-Regular, Consolas, monospace;

    /* layout */
    --sidebar-w: 232px;
    --topbar-h: 72px;
    --content-max: 1440px;

    /* motion — §4: 150ms for colour and shadow, 200ms for expansion */
    --t-fast: 150ms ease-out;
    --t-med: 200ms ease-out;

    /*
     * Bootstrap's own variables, pointed at the same tokens. Stock components
     * on pages this sheet does not name still land inside the system.
     */
    --bs-body-font-family: var(--font-sans);
    --bs-link-color: var(--brand-700);
    --bs-link-hover-color: var(--brand-800);
    --bs-border-color: var(--border);
    --bs-secondary-color: var(--gray-600);
    --bs-tertiary-color: var(--gray-500);
    --bs-body-color: var(--gray-900);
    --bs-emphasis-color: var(--gray-900);
    --bs-focus-ring-color: rgba(27, 110, 99, .18);
}

/* ------------------------------------------------------------------ base */

body.admin-body {
    background: var(--canvas);
    color: var(--gray-900);
    font-family: var(--font-sans);
    font-size: 1rem;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.admin-body h1,
.admin-body h2,
.admin-body h3,
.admin-body h4 {
    color: var(--gray-900);
    font-weight: 600;
}

.admin-body code,
.admin-body .mono {
    font-family: var(--font-mono);
    font-size: 0.875em;
}

/*
 * Deliberately scoped to the content regions and excluding .btn. A blanket
 * `.admin-body a` rule outranks both Bootstrap's `.btn { color: … }` and this
 * sheet's own `.admin-nav-link`, which paints button-links invisible (brand
 * text on the brand fill) and repaints the sidebar nav.
 */
.admin-content a:not(.btn),
.auth-panel a:not(.btn) {
    color: var(--brand-700);
    text-decoration: none;
}

.admin-content a:not(.btn):hover,
.auth-panel a:not(.btn):hover {
    color: var(--brand-800);
    text-decoration: underline;
}

.text-muted,
.form-text,
.text-body-secondary {
    color: var(--gray-600) !important;
}

/*
 * §4 accessibility floor: a visible ring on every focusable control. Scoped to
 * the things a person actually operates — a blanket `:focus-visible` also hits
 * the programmatically focused containers Bootstrap uses (the offcanvas panel
 * takes tabindex="-1"), and repaints them on open.
 */
.admin-body a:focus-visible,
.admin-body button:focus-visible,
.admin-body input:focus-visible,
.admin-body select:focus-visible,
.admin-body textarea:focus-visible,
.admin-body summary:focus-visible,
.admin-body [role="button"]:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

/* ----------------------------------------------------------------- shell */

.admin-shell {
    display: flex;
    min-height: 100vh;
    align-items: stretch;
}

.admin-sidebar {
    background: var(--surface);
    border-inline-end: 1px solid var(--gray-200);
    display: flex;
    flex-direction: column;
}

/*
 * At lg and above the aside is the static 232px rail of §2. Below it, the
 * markup's .offcanvas-lg hands the same element to Bootstrap as a drawer —
 * declared in markup, so there is no console JavaScript to keep in step.
 */
@media (min-width: 992px) {
    .admin-sidebar {
        flex: 0 0 var(--sidebar-w);
        width: var(--sidebar-w);
        position: sticky;
        top: 0;
        height: 100vh;
    }
}

/* The logo block: brand lockup, plus the drawer's close control below lg. */
.admin-brand-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-inline-end: 12px;
    border-bottom: 1px solid var(--gray-200);
}

.admin-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    flex: 1 1 auto;
    min-width: 0;
    color: var(--gray-900);
    text-decoration: none;
}

.admin-brand:hover {
    color: var(--gray-900);
    text-decoration: none;
}

.admin-brand-mark {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
    border-radius: var(--r-md);
    background: var(--brand-50);
    color: var(--brand-700);
}

.admin-brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.25;
    min-width: 0;
}

.admin-brand-title {
    font-weight: 600;
    font-size: 0.875rem;
    color: var(--gray-900);
}

.admin-brand-sub {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--gray-500);
}

.admin-nav {
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    overflow-y: auto;
    flex: 1 1 auto;
}

.admin-nav-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gray-500);
    padding: 12px 12px 4px;
}

.admin-nav-label:first-child {
    padding-top: 0;
}

/* §3 Sidebar nav item: 40px tall, 8px radius, 12px icon gap, 14/500. */
.admin-nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 40px;
    padding: 8px 12px;
    border-radius: var(--r-md);
    color: var(--gray-700);
    font-size: 0.875rem;
    font-weight: 500;
    text-decoration: none;
    transition: background-color var(--t-fast), color var(--t-fast);
}

.admin-nav-link:hover {
    background: var(--gray-50);
    color: var(--gray-900);
    text-decoration: none;
}

/* Active is a solid brand fill — the one place teal appears in the rail. */
.admin-nav-link.active {
    background: var(--brand-700);
    color: #fff;
}

.admin-nav-link.active:hover {
    background: var(--brand-800);
    color: #fff;
}

.admin-nav-link svg {
    flex: 0 0 auto;
}

/* Trailing count badge, right-aligned (§3). */
.admin-nav-count {
    margin-inline-start: auto;
    background: var(--gray-100);
    color: var(--gray-700);
    border-radius: var(--r-sm);
    font-size: 0.75rem;
    font-weight: 500;
    padding: 2px 8px;
    font-variant-numeric: tabular-nums;
}

.admin-nav-link.active .admin-nav-count {
    background: rgba(255, 255, 255, .18);
    color: #fff;
}

/* --------------------------------------------------------- the user chip */

/*
 * §3 Topbar: 40px round avatar with a presence dot, name 14/600, email 13/400.
 * Used in the topbar on desktop and in the drawer footer on small screens —
 * one component, two placements.
 */
.user-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.user-chip-avatar {
    position: relative;
    flex: 0 0 auto;
}

/* 32px, matching workspace.css — see the note there. A photograph at 40px reads
   far heavier than the initials the size was chosen for. */
.user-chip-avatar .avatar {
    width: 32px;
    height: 32px;
    border-radius: var(--r-full);
    font-size: 0.75rem;
}

/* 8px follows the avatar down to 32px — see workspace.css. */
.user-chip-presence {
    position: absolute;
    inset-block-end: 0;
    inset-inline-end: 0;
    width: 8px;
    height: 8px;
    border-radius: var(--r-full);
    background: var(--success-fg);
    border: 2px solid var(--surface);
}

/* The markup nests spans, so the column direction has to be declared here —
   inline children would otherwise run together on one line. */
.admin-identity {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1 1 auto;
    line-height: 1.35;
}

.admin-identity-name,
.admin-identity-mail {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.admin-identity-name {
    color: var(--gray-900);
    font-weight: 600;
    font-size: 0.875rem;
}

.admin-identity-mail {
    color: var(--gray-500);
    font-size: 0.8125rem;
}

/* Icon button: 40×40 hit area, 8px radius, gray-100 hover (§3 Topbar). */
.icon-button,
.admin-signout {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
    background: transparent;
    border: 0;
    border-radius: var(--r-md);
    color: var(--gray-600);
    transition: background-color var(--t-fast), color var(--t-fast);
}

.icon-button:hover,
.admin-signout:hover {
    background: var(--gray-100);
    color: var(--gray-900);
}

/* ---------------------------------------------------------------- topbar */

.admin-main {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.admin-topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--surface);
    border-bottom: 1px solid var(--gray-200);
    padding: 0 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    min-height: var(--topbar-h);
}

.admin-topbar-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--gray-900);
    margin: 0;
}

.admin-topbar-end {
    margin-inline-start: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Only a drawer needs a handle, so the handle only exists where the drawer does. */
.admin-drawer-toggle {
    display: grid;
}

@media (min-width: 992px) {
    .admin-drawer-toggle {
        display: none;
    }
}

.admin-content {
    padding: 32px 24px 64px;
    flex: 1 1 auto;
    width: 100%;
    max-width: var(--content-max);
}

@media (max-width: 767.98px) {
    .admin-topbar {
        padding-inline: 16px;
        gap: 8px;
    }

    /* The chip keeps its avatar and loses its text: at this width the page
       title needs the room more than the address does. */
    .admin-topbar .admin-identity {
        display: none;
    }

    .admin-content {
        padding: 24px 16px 48px;
    }
}

/* -------------------------------------------------------- page furniture */

.page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
}

.page-title {
    font-size: 1.5rem;
    line-height: 2rem;
    font-weight: 600;
    margin: 0;
}

.page-subtitle {
    color: var(--gray-600);
    margin: 4px 0 0;
    font-size: 1rem;
    max-width: 46rem;
}

.page-head-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.breadcrumb {
    font-size: 0.875rem;
    margin-bottom: 12px;
    --bs-breadcrumb-divider-color: var(--gray-400);
    --bs-breadcrumb-item-padding-x: 8px;
}

.breadcrumb-item.active {
    color: var(--gray-600);
}

/*
 * Section header with a right-aligned count (§2). The count is real data —
 * the number of things in the section — so the device carries information
 * rather than decorating the gap above a card.
 */
.section-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    margin: 32px 0 16px;
}

.section-head:first-child {
    margin-top: 0;
}

.section-head-title {
    font-size: 1.125rem;
    line-height: 1.75rem;
    font-weight: 600;
    color: var(--gray-900);
    margin: 0;
}

.section-head-count {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-500);
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.section-label {
    display: block;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--gray-700);
}

/*
 * Icon tile, §1.4: 40×40, 8px radius, brand-50 ground, brand-700 glyph. The
 * console's one repeated ornament — it anchors card heads, empty states, and
 * result screens so the surfaces read as one product.
 */
.icon-tile {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    flex: 0 0 auto;
    border-radius: var(--r-md);
    background: var(--brand-50);
    color: var(--brand-700);
}

.icon-tile-lg {
    width: 56px;
    height: 56px;
    border-radius: var(--r-lg);
}

.icon-tile-success { background: var(--success-bg); color: var(--success-fg); }
.icon-tile-warning { background: var(--warning-bg); color: var(--warning-fg); }
.icon-tile-danger  { background: var(--error-bg);   color: var(--error-fg); }
.icon-tile-neutral { background: var(--gray-100);   color: var(--gray-600); }

/* ----------------------------------------------------------------- cards */

.card {
    --bs-card-bg: var(--surface);
    --bs-card-border-color: var(--gray-200);
    --bs-card-border-radius: var(--r-lg);
    --bs-card-inner-border-radius: var(--r-lg);
    --bs-card-spacer-x: 24px;
    --bs-card-spacer-y: 24px;
    box-shadow: var(--shadow-xs);
    transition: box-shadow var(--t-fast);
}

.card-title {
    font-size: 1rem;
    line-height: 1.5rem;
    font-weight: 600;
    color: var(--gray-900);
    margin-bottom: 4px;
}

/* The lede under a card title, when the card has one. */
.card-title + .form-text,
.card-title + p {
    margin-bottom: 20px;
}

.card-header {
    background: transparent;
    border-bottom-color: var(--gray-200);
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.card-header h2,
.card-header .card-title {
    margin: 0;
    font-size: 1rem;
}

/*
 * Card head with the icon tile leading — the shape §3's module card uses, put
 * to work here for the panels that carry an action rather than a metric.
 */
.card-head {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 16px;
}

.card-head .card-title {
    margin-bottom: 0;
}

.card-head-body {
    min-width: 0;
    flex: 1 1 auto;
}

.card-head-body .form-text {
    margin-top: 4px;
    margin-bottom: 0;
}

/* Stat tiles ---------------------------------------------------------- */

/*
 * Not in §3 — built from §3's Card plus the §1.1 status triplets, as rule 6
 * allows. A tile reports one number and the state that number is in; the dot
 * and the label carry the state together, never colour alone.
 */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(14rem, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--gray-200);
    border-radius: var(--r-lg);
    padding: 20px;
    box-shadow: var(--shadow-xs);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat-card-head {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--gray-600);
    font-size: 0.875rem;
    font-weight: 500;
}

.stat-dot {
    width: 8px;
    height: 8px;
    border-radius: var(--r-full);
    background: var(--stat-color, var(--gray-400));
    flex: 0 0 auto;
}

.stat-value {
    font-size: 1.875rem;
    line-height: 2.375rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin-top: 4px;
    color: var(--gray-900);
    font-variant-numeric: tabular-nums;
}

.stat-hint {
    font-size: 0.8125rem;
    color: var(--gray-500);
    margin-top: auto;
    padding-top: 4px;
}

.stat-success { --stat-color: var(--success-fg); }
.stat-neutral { --stat-color: var(--gray-400); }

/* A tile that is reporting a problem tints, so the estate's sore spots are
   findable at a glance without a status colour landing on a control. */
.stat-warning {
    --stat-color: var(--warning-fg);
    background: var(--warning-bg);
    border-color: color-mix(in srgb, var(--warning-fg) 20%, transparent);
}

.stat-warning .stat-card-head,
.stat-warning .stat-hint {
    color: var(--warning-fg);
}

.stat-danger {
    --stat-color: var(--error-fg);
    background: var(--error-bg);
    border-color: color-mix(in srgb, var(--error-fg) 20%, transparent);
}

.stat-danger .stat-card-head,
.stat-danger .stat-hint {
    color: var(--error-fg);
}

/* Key/value list ------------------------------------------------------ */

.kv-list {
    display: flex;
    flex-direction: column;
    margin: 0;
}

.kv-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 0;
    border-bottom: 1px solid var(--gray-200);
}

.kv-row:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}

.kv-row:first-child {
    padding-top: 0;
}

.kv-key {
    color: var(--gray-600);
    font-size: 0.875rem;
    flex: 0 0 auto;
}

.kv-value {
    text-align: end;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-900);
    font-variant-numeric: tabular-nums;
    min-width: 0;
    overflow-wrap: anywhere;
}

/* ---------------------------------------------------------------- table */

.table-card {
    background: var(--surface);
    border: 1px solid var(--gray-200);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-xs);
    overflow: hidden;
}

.table-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 24px;
    border-bottom: 1px solid var(--gray-200);
}

.table-card-title {
    font-size: 1rem;
    line-height: 1.5rem;
    font-weight: 600;
    margin: 0;
    color: var(--gray-900);
}

.table-card-meta {
    display: flex;
    align-items: center;
    gap: 12px;
}

.table-scroll {
    overflow-x: auto;
}

.table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--gray-900);
    --bs-table-border-color: var(--gray-200);
    margin-bottom: 0;
    font-size: 0.875rem;
}

.table > thead > tr > th {
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
    color: var(--gray-600);
    font-size: 0.75rem;
    font-weight: 500;
    padding: 12px 24px;
    white-space: nowrap;
}

.table > tbody > tr > td {
    padding: 16px 24px;
    border-bottom-color: var(--gray-200);
    vertical-align: middle;
    color: var(--gray-600);
}

.table > tbody > tr:last-child > td {
    border-bottom: 0;
}

.table-hover > tbody > tr:hover > * {
    --bs-table-accent-bg: var(--gray-50);
    background-color: var(--gray-50);
    color: var(--gray-600);
}

.table .num {
    font-variant-numeric: tabular-nums;
}

.cell-primary {
    font-weight: 500;
    color: var(--gray-900);
}

a.cell-primary {
    color: var(--gray-900) !important;
}

a.cell-primary:hover {
    color: var(--brand-700) !important;
    text-decoration: none !important;
}

.cell-sub {
    display: inline-block;
    font-size: 0.8125rem;
    color: var(--gray-500);
    line-height: 1.4;
}

/* A sub-line that is a sentence rather than a value — measured so it wraps
   instead of stretching the column it sits in. */
.cell-note {
    max-width: 30rem;
    white-space: normal;
}

.row-attention > td {
    background: var(--error-bg);
}

/* A table nested inside a card — the dense variant used by the module list. */
.table-inset {
    --bs-table-bg: transparent;
    font-size: 0.875rem;
}

.table-inset > thead > tr > th {
    background: transparent;
    padding: 8px 12px;
    border-bottom: 1px solid var(--gray-200);
    color: var(--gray-500);
    font-size: 0.75rem;
    font-weight: 500;
}

.table-inset > tbody > tr > td {
    padding: 12px;
    border-bottom: 1px solid var(--gray-200);
    vertical-align: middle;
}

.table-inset > tbody > tr:last-child > td {
    border-bottom: 0;
}

/* Identity cell ------------------------------------------------------- */

.identity {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

/* §1.1 gives avatars the gray-100 ground, which keeps teal on interaction. */
.avatar {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    border-radius: var(--r-full);
    display: grid;
    place-items: center;
    font-size: 0.875rem;
    font-weight: 600;
    background: var(--gray-100);
    color: var(--gray-700);
    text-transform: uppercase;
}

.avatar-lg {
    width: 56px;
    height: 56px;
    font-size: 1.125rem;
}

.identity-body {
    min-width: 0;
}

/* Code chip ----------------------------------------------------------- */

.chip-code {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--r-sm);
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    color: var(--gray-700);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    line-height: 1.5;
    font-variant-numeric: tabular-nums;
}

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

/*
 * §3 Badge / status pill: 2px 8px, 6px radius, 12px/500, leading 6px dot.
 * Every pill pairs its colour with a word — status is never signalled by
 * colour alone (§4).
 */
.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 8px;
    border-radius: var(--r-sm);
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1.5;
    white-space: nowrap;
    border: 1px solid transparent;
}

.pill::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: var(--r-full);
    background: currentColor;
    flex: 0 0 auto;
}

.pill-lg {
    font-size: 0.875rem;
    padding: 4px 10px;
}

.pill-success {
    color: var(--success-fg);
    background: var(--success-bg);
    border-color: color-mix(in srgb, var(--success-fg) 20%, transparent);
}

.pill-warning {
    color: var(--warning-fg);
    background: var(--warning-bg);
    border-color: color-mix(in srgb, var(--warning-fg) 20%, transparent);
}

.pill-danger {
    color: var(--error-fg);
    background: var(--error-bg);
    border-color: color-mix(in srgb, var(--error-fg) 20%, transparent);
}

.pill-neutral {
    color: var(--gray-600);
    background: var(--gray-100);
    border-color: var(--gray-200);
}

/*
 * "Invited" is a notice, not a warning — §1.1's Info triplet. Teal never
 * appears on a badge, so this is the informational blue rather than the brand.
 */
.pill-accent {
    color: var(--info-fg);
    background: var(--info-bg);
    border-color: color-mix(in srgb, var(--info-fg) 20%, transparent);
}

/* Stock badges inherit the same language for any markup not updated. */
.badge {
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: var(--r-sm);
    padding: 2px 8px;
}

.badge.text-bg-light {
    background: var(--gray-100) !important;
    color: var(--gray-700) !important;
}

.badge.text-bg-secondary {
    background: var(--gray-100) !important;
    color: var(--gray-700) !important;
}

.badge.text-bg-success {
    background: var(--success-bg) !important;
    color: var(--success-fg) !important;
}

/* ------------------------------------------------------------- controls */

/* §3 Button: 44px lg / 40px md / 36px sm, 8px radius, 14px/600. */
.btn {
    --bs-btn-border-radius: var(--r-md);
    --bs-btn-font-size: 0.875rem;
    --bs-btn-font-weight: 600;
    --bs-btn-padding-x: 16px;
    --bs-btn-padding-y: 10px;
    --bs-btn-line-height: 1.25rem;
    --bs-btn-disabled-opacity: 0.5;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background-color var(--t-fast), border-color var(--t-fast), color var(--t-fast), box-shadow var(--t-fast);
}

.btn:focus-visible {
    box-shadow: var(--focus-ring);
}

.btn-sm {
    --bs-btn-font-size: 0.875rem;
    --bs-btn-padding-x: 12px;
    --bs-btn-padding-y: 7px;
    --bs-btn-border-radius: var(--r-md);
}

.btn-lg {
    --bs-btn-font-size: 1rem;
    --bs-btn-padding-x: 20px;
    --bs-btn-padding-y: 12px;
    --bs-btn-border-radius: var(--r-md);
}

/* Primary — the only saturated fill in the system, and one per view (§6.2). */
.btn-primary {
    --bs-btn-bg: var(--brand-700);
    --bs-btn-border-color: var(--brand-700);
    --bs-btn-hover-bg: var(--brand-800);
    --bs-btn-hover-border-color: var(--brand-800);
    --bs-btn-active-bg: var(--brand-900);
    --bs-btn-active-border-color: var(--brand-900);
    --bs-btn-disabled-bg: var(--brand-700);
    --bs-btn-disabled-border-color: var(--brand-700);
}

.btn-outline-primary {
    --bs-btn-color: var(--brand-700);
    --bs-btn-border-color: var(--gray-300);
    --bs-btn-bg: var(--surface);
    --bs-btn-hover-color: var(--brand-800);
    --bs-btn-hover-bg: var(--brand-50);
    --bs-btn-hover-border-color: var(--gray-300);
    --bs-btn-active-color: var(--brand-900);
    --bs-btn-active-bg: var(--brand-100);
    --bs-btn-active-border-color: var(--gray-300);
    box-shadow: var(--shadow-xs);
}

/* Secondary — white fill, gray-300 border, gray-700 text, shadow-xs (§3). */
.btn-outline-secondary,
.btn-secondary {
    --bs-btn-color: var(--gray-700);
    --bs-btn-bg: var(--surface);
    --bs-btn-border-color: var(--gray-300);
    --bs-btn-hover-color: var(--gray-900);
    --bs-btn-hover-bg: var(--gray-50);
    --bs-btn-hover-border-color: var(--gray-300);
    --bs-btn-active-color: var(--gray-900);
    --bs-btn-active-bg: var(--gray-100);
    --bs-btn-active-border-color: var(--gray-300);
    box-shadow: var(--shadow-xs);
}

/*
 * A destructive action stays a secondary button — a status colour on a fill
 * is out (§1.1) — but its text carries the consequence.
 */
.btn-outline-danger {
    --bs-btn-color: var(--error-fg);
    --bs-btn-bg: var(--surface);
    --bs-btn-border-color: color-mix(in srgb, var(--error-fg) 30%, var(--gray-300));
    --bs-btn-hover-color: var(--error-fg);
    --bs-btn-hover-bg: var(--error-bg);
    --bs-btn-hover-border-color: color-mix(in srgb, var(--error-fg) 40%, transparent);
    --bs-btn-active-color: var(--error-fg);
    --bs-btn-active-bg: var(--error-bg);
    --bs-btn-active-border-color: color-mix(in srgb, var(--error-fg) 40%, transparent);
    box-shadow: var(--shadow-xs);
}

.btn-outline-success {
    --bs-btn-color: var(--success-fg);
    --bs-btn-bg: var(--surface);
    --bs-btn-border-color: color-mix(in srgb, var(--success-fg) 30%, var(--gray-300));
    --bs-btn-hover-color: var(--success-fg);
    --bs-btn-hover-bg: var(--success-bg);
    --bs-btn-hover-border-color: color-mix(in srgb, var(--success-fg) 40%, transparent);
    --bs-btn-active-color: var(--success-fg);
    --bs-btn-active-bg: var(--success-bg);
    --bs-btn-active-border-color: color-mix(in srgb, var(--success-fg) 40%, transparent);
    box-shadow: var(--shadow-xs);
}

.btn-link {
    --bs-btn-color: var(--brand-700);
    --bs-btn-hover-color: var(--brand-800);
    --bs-btn-font-weight: 600;
    text-decoration: none;
}

/* §3 Input: label above at 14/500 gray-700, 6px gap. */
.form-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: 6px;
}

.form-control,
.form-select {
    background-color: var(--surface);
    border: 1px solid var(--gray-300);
    color: var(--gray-900);
    border-radius: var(--r-md);
    padding: 10px 14px;
    font-size: 1rem;
    line-height: 1.5rem;
    box-shadow: var(--shadow-xs);
    transition: border-color var(--t-fast), box-shadow var(--t-fast);
}

.form-control-sm,
.form-select-sm {
    padding: 8px 12px;
    font-size: 0.875rem;
    line-height: 1.25rem;
    border-radius: var(--r-md);
}

.form-control:focus,
.form-select:focus {
    background-color: var(--surface);
    color: var(--gray-900);
    border-color: var(--brand-700);
    box-shadow: var(--focus-ring);
}

.form-control::placeholder {
    color: var(--gray-500);
}

.form-control:disabled,
.form-select:disabled {
    background-color: var(--gray-50);
    color: var(--gray-500);
}

.form-select {
    --bs-form-select-bg-img: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2398A2B3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpath d='m6 9 6 6 6-6'/%3e%3c/svg%3e");
    background-size: 20px 20px;
    padding-inline-end: 42px;
}

.form-text,
.field-hint {
    font-size: 0.875rem;
    color: var(--gray-600);
    margin-top: 6px;
}

/* §3 Checkbox: 16×16, 4px radius, brand fill when checked. */
.form-check-input {
    width: 1rem;
    height: 1rem;
    margin-top: 0.25rem;
    border-color: var(--gray-300);
    border-radius: 4px;
}

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

.form-check-input:focus {
    border-color: var(--brand-700);
    box-shadow: var(--focus-ring);
}

.form-check-label {
    font-size: 0.875rem;
    color: var(--gray-700);
    padding-inline-start: 4px;
}

fieldset legend {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-900);
}

/* --------------------------------------------------------------- alerts */

.alert {
    border-radius: var(--r-lg);
    border-width: 1px;
    padding: 16px;
    font-size: 0.875rem;
    margin-bottom: 24px;
}

.alert:last-child {
    margin-bottom: 0;
}

.alert-success {
    --bs-alert-color: var(--success-fg);
    --bs-alert-bg: var(--success-bg);
    --bs-alert-border-color: color-mix(in srgb, var(--success-fg) 22%, transparent);
}

.alert-warning {
    --bs-alert-color: var(--warning-fg);
    --bs-alert-bg: var(--warning-bg);
    --bs-alert-border-color: color-mix(in srgb, var(--warning-fg) 22%, transparent);
}

.alert-danger {
    --bs-alert-color: var(--error-fg);
    --bs-alert-bg: var(--error-bg);
    --bs-alert-border-color: color-mix(in srgb, var(--error-fg) 22%, transparent);
}

.alert-info {
    --bs-alert-color: var(--info-fg);
    --bs-alert-bg: var(--info-bg);
    --bs-alert-border-color: color-mix(in srgb, var(--info-fg) 22%, transparent);
}

.alert a {
    color: inherit;
    font-weight: 600;
}

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

/*
 * A card whose action is destructive or otherwise not routine — the tint
 * carries the warning so the button does not have to shout.
 */
.action-card {
    border: 1px solid var(--gray-200);
    border-radius: var(--r-lg);
    background: var(--surface);
    padding: 24px;
    box-shadow: var(--shadow-xs);
}

.action-card-danger {
    border-color: color-mix(in srgb, var(--error-fg) 24%, var(--gray-200));
    background: var(--error-bg);
}

.action-card-danger .action-card-title {
    color: var(--error-fg);
}

.action-card-title {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1rem;
    line-height: 1.5rem;
    font-weight: 600;
    color: var(--gray-900);
    margin-bottom: 8px;
}

.action-card > p {
    color: var(--gray-600);
    font-size: 0.875rem;
    margin-bottom: 20px;
    max-width: 44rem;
}

.action-card-danger > p {
    color: color-mix(in srgb, var(--error-fg) 88%, var(--gray-900));
}

/* ---------------------------------------------------------- empty state */

.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--gray-600);
}

.empty-state-icon {
    display: grid;
    place-items: center;
    width: 40px;
    height: 40px;
    margin: 0 auto 16px;
    border-radius: var(--r-md);
    background: var(--brand-50);
    color: var(--brand-700);
}

.empty-state-title {
    color: var(--gray-900);
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.empty-state-hint {
    font-size: 0.875rem;
    color: var(--gray-600);
    margin: 0 auto;
    max-width: 26rem;
}

/* ------------------------------------------------------- live indicator */

.live-dot {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8125rem;
    color: var(--gray-500);
}

.live-dot::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: var(--r-full);
    background: var(--success-fg);
    box-shadow: 0 0 0 0 color-mix(in srgb, var(--success-fg) 60%, transparent);
    animation: live-pulse 2.4s ease-out infinite;
}

@keyframes live-pulse {
    0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--success-fg) 50%, transparent); }
    70%  { box-shadow: 0 0 0 6px transparent; }
    100% { box-shadow: 0 0 0 0 transparent; }
}

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

.result-icon {
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    border-radius: var(--r-lg);
    margin-bottom: 20px;
}

.result-icon-success {
    background: var(--success-bg);
    color: var(--success-fg);
}

.result-icon-warning {
    background: var(--warning-bg);
    color: var(--warning-fg);
}

.result-icon-danger {
    background: var(--error-bg);
    color: var(--error-fg);
}

.form-panel {
    background: var(--surface);
    border: 1px solid var(--gray-200);
    border-radius: var(--r-lg);
    box-shadow: var(--shadow-xs);
    padding: 24px;
}

.form-panel + .form-panel {
    margin-top: 24px;
}

.form-panel-head {
    margin-bottom: 20px;
}

.form-panel-head .section-label + p {
    margin: 4px 0 0;
    font-size: 0.875rem;
    color: var(--gray-600);
}

.form-actions {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    padding-top: 24px;
    margin-top: 24px;
    border-top: 1px solid var(--gray-200);
}

/* A form's actions sitting at the foot of a card body, not a panel. */
.card-actions {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    margin-top: 20px;
}

/*
 * Measures. A form is easier to complete when its fields stop at a readable
 * width, so the two widths the console uses are named here rather than typed
 * into a style attribute on each page (§6.1).
 */
.measure-sm { max-width: 32rem; }
.measure-md { max-width: 44rem; }
.measure-center { margin-inline: auto; }

.table-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    align-items: center;
    flex-wrap: wrap;
}

.table-actions form {
    margin: 0;
}

/* --------------------------------------------------------- module lists */

/*
 * The module catalogue, on the company page and the create form. A subcategory
 * is a labelled block inside the card rather than another bordered box — the
 * nesting was three containers deep, and depth is not hierarchy.
 */
.module-group + .module-group {
    margin-top: 32px;
}

.module-group-title {
    font-size: 1.125rem;
    line-height: 1.75rem;
    font-weight: 600;
    color: var(--gray-900);
    margin: 0 0 12px;
}

.module-subgroup + .module-subgroup {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--gray-200);
}

/*
 * Subcategories side by side, for a module list that is read-only and so has
 * narrow rows. A list with editable periods keeps the single stacked column —
 * two date fields and a button do not fit beside anything. This surface's
 * module list is read-only in full (spec 008 FR-014), so it is always the grid.
 */
.module-subgrid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(22rem, 1fr));
    gap: 24px 32px;
}

.module-subgrid .module-subgroup,
.module-subgrid .module-subgroup + .module-subgroup {
    margin-top: 0;
    padding-top: 0;
    border-top: 0;
}

.module-subgroup-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 8px;
}

.module-note {
    font-size: 0.875rem;
    color: var(--gray-500);
    margin: 0;
}

/* The date pair a grant or a period change is edited through. */
.period-fields {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.period-fields .form-control {
    width: 9.5rem;
}

/* A grant row on the create form: checkbox, then its two dates. */
.grant-row {
    display: grid;
    grid-template-columns: minmax(12rem, 1.4fr) repeat(2, minmax(8rem, 1fr));
    gap: 12px;
    align-items: end;
    padding: 12px 0;
    border-bottom: 1px solid var(--gray-200);
}

.grant-row:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}

.grant-row .form-check {
    margin: 0;
    padding-bottom: 8px;
}

@media (max-width: 767.98px) {
    .grant-row {
        grid-template-columns: 1fr 1fr;
    }

    .grant-row .form-check {
        grid-column: 1 / -1;
        padding-bottom: 0;
    }
}

/* ------------------------------------------------------------- the rail */

/*
 * Below lg the aside is a Bootstrap drawer. Bootstrap's own .offcanvas-lg
 * rules zero the background and the border at lg and above; this sheet is
 * linked after Bootstrap, so the rail's own paint wins there.
 */
.admin-sidebar.offcanvas-lg {
    --bs-offcanvas-width: 280px;
    --bs-offcanvas-bg: var(--surface);
    --bs-offcanvas-border-color: var(--gray-200);
    --bs-offcanvas-padding-x: 0;
    --bs-offcanvas-padding-y: 0;
}

/* ------------------------------------------------------------- motion */

@media (prefers-reduced-motion: reduce) {
    .live-dot::before {
        animation: none;
    }

    /* §4: drop to opacity-only, never to nothing that reads as broken. */
    .admin-nav-link,
    .btn,
    .card,
    .form-control,
    .form-select {
        transition: none;
    }
}
