/* BASE Dashboard design tokens and the readability rules every page needs.

   Loaded by base.html on every page (whatever the page does with style.css),
   and by login.html and 500.html, after Bootstrap and Font Awesome and before
   style.css, sheet.css and any page's own styles. So:
     - a rule here at Bootstrap's own specificity wins over Bootstrap by order;
     - a later stylesheet overrides a rule here by setting the variable it reads
       (sheet.css maps its --sheet-* values onto these), or at equal specificity.
   Each token is defined once, here. A colour that differs between Bootstrap's
   light and dark modes is set on both scopes below, so a light panel inside a
   dark page (data-bs-theme="light") gets the light values.

   Contrast (WCAG): text 4.5:1, control edges and focus rings 3:1. The pairs
   below are checked by tests/test_design_tokens.py. */

:root {
    /* Brand */
    --base-primary: #0b5695;
    --base-primary-rgb: 11, 86, 149;
    --base-primary-dark: #084570;
    --base-primary-light: #1a6db0;
    --base-primary-on-dark: #7cc0f5;        /* 7.87:1 on #212529 */
    --base-primary-on-dark-hover: #a9d6f9;

    /* Status fills: white text on each, except warning, which takes its ink. */
    --base-success: #146c43;                /* white 6.45:1 */
    --base-danger: #b02a37;                 /* white 6.50:1 */
    --base-info: #1a6db0;                   /* white 5.44:1 */
    --base-warning: #ffc107;
    --base-warning-ink: #664d03;            /* on the warning fill 4.90:1 */
    /* Status text on the dark theme, and danger text on a light surface. */
    --base-success-on-dark: #75d69a;
    --base-danger-on-dark: #f1aeb5;
    --base-warning-on-dark: #ffd43b;
    --base-muted-on-dark: #adb5bd;
    --base-danger-text: #9b1c24;

    /* Focus ring shape (its colour is per mode, below) and the tap floor. */
    --base-focus-width: 3px;
    --base-focus-offset: 2px;
    --base-tap-min: 44px;

    /* Type: nothing smaller than .8rem. */
    --base-font-xs: .8rem;
    --base-font-sm: .875rem;
    --base-font-md: 1rem;
    --base-font-lg: 1.125rem;
    --base-font-xl: 1.25rem;
    --base-font-2xl: 1.5rem;
    --base-font-3xl: 2rem;
    --base-font-display: 2.5rem;

    /* Radius and motion */
    --base-radius-sm: 4px;
    --base-radius-md: 8px;
    --base-radius-lg: 12px;
    --base-radius-pill: 50rem;
    --base-duration-fast: 150ms;
    --base-duration-base: 250ms;
    --base-ease: ease-out;
}

/* ── Per colour mode ─────────────────────────────────────────────────────────
   The --base-*-fg values are not new colours: each names the token that reads
   on the current surface (the brand blue on light, its on-dark tint on dark),
   so a rule can use one variable and still follow the nearest data-bs-theme. */
:root,
[data-bs-theme="light"] {
    --base-input-border: #6c757d;           /* 4.69:1 on white, 4.36:1 on #f4f7fb */
    --base-focus-color: #0b5695;            /* 7.17:1 on #f8f9fa */
    --base-primary-fg: var(--base-primary);
    --base-primary-fg-hover: var(--base-primary-dark);
    --base-secondary-fg: #565e64;           /* outline-secondary: 5.9:1 on #f4f7fb */
    --base-secondary-edge: #565e64;
    --base-success-fg: var(--base-success);
    --base-danger-fg: var(--base-danger);
    /* A person's name as a chip (.badge-person): 8.05:1. */
    --base-person-bg: #dbe8f4;
    --base-person-fg: #084570;

    /* Bootstrap follows the brand. */
    --bs-primary: var(--base-primary);
    --bs-primary-rgb: var(--base-primary-rgb);
    --bs-link-color: var(--base-primary);
    --bs-link-color-rgb: var(--base-primary-rgb);
    --bs-link-hover-color: var(--base-primary-dark);
    --bs-link-hover-color-rgb: 8, 69, 112;  /* --base-primary-dark */
}

[data-bs-theme="dark"] {
    --base-input-border: #868e96;           /* 4.01:1 on #2b3035, 4.64:1 on #212529 */
    --base-focus-color: #ffc107;
    --base-primary-fg: var(--base-primary-on-dark);
    --base-primary-fg-hover: var(--base-primary-on-dark-hover);
    --base-secondary-fg: #dee2e6;
    --base-secondary-edge: var(--base-muted-on-dark);
    --base-success-fg: var(--base-success-on-dark);
    --base-danger-fg: var(--base-danger-on-dark);
    --base-person-bg: #234b70;              /* white 9.08:1 */
    --base-person-fg: #ffffff;

    /* Brand blue is 2.0:1 as link text on the dark theme; its tint is 7.87:1. */
    --bs-link-color: var(--base-primary-on-dark);
    --bs-link-color-rgb: 124, 192, 245;     /* --base-primary-on-dark */
    --bs-link-hover-color: var(--base-primary-on-dark-hover);
    --bs-link-hover-color-rgb: 169, 214, 249;  /* --base-primary-on-dark-hover */
}

/* Root size in %, so the browser's own text-size setting still scales it:
   17px at the default 16px. sheet.css sets its own for the instructor pages. */
html {
    font-size: 106.25%;
}

/* ── Buttons ─────────────────────────────────────────────────────────────────
   Colours go through Bootstrap's --bs-btn-* variables, never background or
   color directly: Bootstrap's :focus-visible and :active rules read those
   variables, and a button styled any other way turns transparent there. */
.btn-primary,
.btn-brand {
    --bs-btn-color: #fff;
    --bs-btn-bg: var(--base-primary);
    --bs-btn-border-color: var(--base-primary);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--base-primary-light);
    --bs-btn-hover-border-color: var(--base-primary-light);
    --bs-btn-focus-shadow-rgb: var(--base-primary-rgb);
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: var(--base-primary-dark);
    --bs-btn-active-border-color: var(--base-primary-dark);
    --bs-btn-disabled-color: #fff;
    --bs-btn-disabled-bg: var(--base-primary);
    --bs-btn-disabled-border-color: var(--base-primary);
}

/* On dark, the text and edge take the on-dark tint (the brand is 2.0:1 there);
   hovered, pressed or selected, the button fills with the brand under white. */
.btn-outline-primary,
.btn-brand-outline {
    --bs-btn-color: var(--base-primary-fg);
    --bs-btn-border-color: var(--base-primary-fg);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--base-primary);
    --bs-btn-hover-border-color: var(--base-primary-fg);
    --bs-btn-focus-shadow-rgb: var(--base-primary-rgb);
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: var(--base-primary);
    --bs-btn-active-border-color: var(--base-primary-fg);
    --bs-btn-disabled-color: var(--base-primary-fg);
    --bs-btn-disabled-bg: transparent;
    --bs-btn-disabled-border-color: var(--base-primary-fg);
}

/* A white button on a brand-blue surface (System Monitor's header). Brand text
   on white is 7.56:1; hovered, #084570 on #e9ecef 8.45:1; pressed, #084570 on
   #dbe8f4 8.05:1. Its ring is white: see "On a brand-blue surface" below. */
.btn-on-brand {
    --bs-btn-color: var(--base-primary);
    --bs-btn-bg: #fff;
    --bs-btn-border-color: #fff;
    --bs-btn-hover-color: var(--base-primary-dark);
    --bs-btn-hover-bg: #e9ecef;
    --bs-btn-hover-border-color: #e9ecef;
    --bs-btn-focus-shadow-rgb: 255, 255, 255;
    --bs-btn-active-color: var(--base-primary-dark);
    --bs-btn-active-bg: #dbe8f4;
    --bs-btn-active-border-color: #dbe8f4;
    --bs-btn-disabled-color: var(--base-primary);
    --bs-btn-disabled-bg: #fff;
    --bs-btn-disabled-border-color: #fff;
}

/* Bootstrap's greys, green and red outlines sit under 4.5:1 on the light
   pages' #f4f7fb and under 3:1 on the dark theme. */
.btn-outline-secondary {
    --bs-btn-color: var(--base-secondary-fg);
    --bs-btn-border-color: var(--base-secondary-edge);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: #565e64;
    --bs-btn-hover-border-color: var(--base-secondary-edge);
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: #565e64;
    --bs-btn-active-border-color: var(--base-secondary-edge);
    --bs-btn-disabled-color: var(--base-secondary-fg);
    --bs-btn-disabled-border-color: var(--base-secondary-edge);
}

.btn-outline-success {
    --bs-btn-color: var(--base-success-fg);
    --bs-btn-border-color: var(--base-success-fg);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--base-success);
    --bs-btn-hover-border-color: var(--base-success-fg);
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: var(--base-success);
    --bs-btn-active-border-color: var(--base-success-fg);
    --bs-btn-disabled-color: var(--base-success-fg);
    --bs-btn-disabled-border-color: var(--base-success-fg);
}

.btn-outline-danger {
    --bs-btn-color: var(--base-danger-fg);
    --bs-btn-border-color: var(--base-danger-fg);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--base-danger);
    --bs-btn-hover-border-color: var(--base-danger-fg);
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: var(--base-danger);
    --bs-btn-active-border-color: var(--base-danger-fg);
    --bs-btn-disabled-color: var(--base-danger-fg);
    --bs-btn-disabled-border-color: var(--base-danger-fg);
}

/* Bootstrap's info and warning buttons put black text on cyan and yellow. */
.btn-info {
    --bs-btn-color: #fff;
    --bs-btn-bg: var(--base-info);
    --bs-btn-border-color: var(--base-info);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: var(--base-primary);
    --bs-btn-hover-border-color: var(--base-primary);
    --bs-btn-focus-shadow-rgb: 26, 109, 176;  /* --base-info */
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: var(--base-primary-dark);
    --bs-btn-active-border-color: var(--base-primary-dark);
    --bs-btn-disabled-color: #fff;
    --bs-btn-disabled-bg: var(--base-info);
    --bs-btn-disabled-border-color: var(--base-info);
}

.btn-warning {
    --bs-btn-color: var(--base-warning-ink);
    --bs-btn-bg: var(--base-warning);
    --bs-btn-border-color: var(--base-warning);
    --bs-btn-hover-color: var(--base-warning-ink);
    --bs-btn-hover-bg: #ffca2c;
    --bs-btn-hover-border-color: #ffca2c;
    --bs-btn-active-color: var(--base-warning-ink);
    --bs-btn-active-bg: #ffcd39;
    --bs-btn-active-border-color: #ffcd39;
    --bs-btn-disabled-color: var(--base-warning-ink);
    --bs-btn-disabled-bg: var(--base-warning);
    --bs-btn-disabled-border-color: var(--base-warning);
}

/* Tap floor: 44px for every button, small ones included. */
.btn,
.btn-sm,
.btn-xs {
    min-height: var(--base-tap-min);
}

.btn-group-sm > .btn {
    min-width: var(--base-tap-min);
}

/* The close icon keeps its size; the button around it grows to 44px. */
.btn-close {
    --bs-btn-close-opacity: .85;
    box-sizing: border-box;
    min-width: var(--base-tap-min);
    min-height: var(--base-tap-min);
}

/* The dark theme inverts every close icon to white; on yellow it stays dark. */
[data-bs-theme="dark"] .bg-warning .btn-close,
[data-bs-theme="dark"] .text-bg-warning .btn-close,
.toast-warning .btn-close {
    filter: none;
}

/* ── Form fields ─────────────────────────────────────────────────────────────
   Bootstrap's own edge is 1.63:1 on a dark card. 16px or larger, so a phone
   does not zoom into a field when it takes focus. */
.form-control,
.form-select,
.form-check-input {
    border-color: var(--base-input-border);
}

.form-control,
.form-select {
    min-height: var(--base-tap-min);
}

.form-control,
.form-select,
.form-control-sm,
.form-select-sm,
.input-group-sm > .form-control,
.input-group-sm > .form-select {
    font-size: max(1rem, 16px);
}

/* The rule above would otherwise shrink the large sizes. */
.form-control-lg,
.form-select-lg {
    font-size: 1.25rem;
}

/* A checkbox or radio row is a 44px target; the label wraps beside the box. */
.form-check {
    display: flex;
    align-items: center;
    gap: .5rem;
    min-height: var(--base-tap-min);
}

.form-check-inline {
    display: inline-flex;
}

.form-check > .form-check-input {
    flex-shrink: 0;
    margin-top: 0;
}

/* ── Focus ───────────────────────────────────────────────────────────────────
   One ring, 3px and 2px clear, in the current mode's focus colour (yellow on
   dark, brand blue on light: each 3:1 or better). Bootstrap's translucent glow,
   pale blue edge and outline:0 are switched off so they cannot win. A text
   field shows the ring whenever it has focus, since a tap puts the caret there
   just as the keyboard does. */
.btn {
    --bs-btn-focus-box-shadow: none;
}

.btn:focus,
.btn-close:focus,
.page-link:focus,
.accordion-button:focus,
.form-select:focus,
.form-check-input:focus {
    box-shadow: none;
}

.form-control:focus,
.form-select:focus,
.form-check-input:focus {
    border-color: var(--base-input-border);
    box-shadow: none;
}

a:focus-visible,
button:focus-visible,
summary:focus-visible,
:where([tabindex]:not([tabindex="-1"])):focus-visible,
.btn:focus-visible,
.btn-check:focus-visible + .btn,
.btn-close:focus-visible,
.nav-link:focus-visible,
.page-link:focus-visible,
.accordion-button:focus-visible,
.form-select:focus-visible,
.form-check-input:focus-visible,
.form-control:focus {
    outline: var(--base-focus-width) solid var(--base-focus-color);
    outline-offset: var(--base-focus-offset);
    box-shadow: none;
}

/* On a brand-blue surface (.surface-brand, and any .btn-on-brand) the ring sits
   on the blue, where the light scope's blue ring is 1:1 and the yellow 3.66:1
   at best. White is 7.56:1 on #0b5695 and 5.98:1 on System Monitor's header
   (10% white over it). After the rules above, at their specificity, so it wins. */
.surface-brand :focus-visible,
.surface-brand .btn:focus-visible,
.btn-on-brand:focus-visible {
    outline-color: #fff;
}

/* Checked: the brand fill; the edge takes the on-dark tint on dark (3:1). */
.form-check-input:checked,
.form-check-input[type="checkbox"]:indeterminate {
    background-color: var(--base-primary);
    border-color: var(--base-primary-fg);
}

/* ── Badges and status fills ─────────────────────────────────────────────────
   One fill and text pair per status. No white on yellow or cyan. */
.badge {
    --bs-badge-font-size: max(.75em, var(--base-font-xs));
}

.badge.bg-success,
.text-bg-success {
    background-color: var(--base-success) !important;
    color: #fff !important;
}

.badge.bg-danger,
.text-bg-danger {
    background-color: var(--base-danger) !important;
    color: #fff !important;
}

.badge.bg-info,
.text-bg-info {
    background-color: var(--base-info) !important;
    color: #fff !important;
}

.badge.bg-primary,
.text-bg-primary {
    background-color: var(--base-primary) !important;
    color: #fff !important;
}

.badge.bg-secondary,
.text-bg-secondary {
    background-color: #6c757d !important;   /* white 4.69:1 */
    color: #fff !important;
}

.badge.bg-warning,
.text-bg-warning {
    background-color: var(--base-warning) !important;
    color: var(--base-warning-ink) !important;
}

.badge.bg-light {
    background-color: #f8f9fa !important;
    color: #495057 !important;              /* on #f8f9fa 7.8:1 */
}

/* A brand fill that still takes Bootstrap's bg-opacity-* helpers: the tint
   behind a stat tile is the brand at that opacity, never the full fill. */
.bg-primary {
    background-color: rgba(var(--base-primary-rgb), var(--bs-bg-opacity, 1)) !important;
}

/* A person's name (an instructor, a co-instructor) as a chip. One look on every
   page, in the current mode's pair. Not a .badge, so status rules never reach it. */
.badge-person {
    display: inline-block;
    padding: .35em .65em;
    font-size: max(.75em, var(--base-font-xs));
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    vertical-align: baseline;
    border-radius: var(--base-radius-pill);
    background-color: var(--base-person-bg);
    color: var(--base-person-fg);
}

.badge.bg-success,
.badge.bg-danger,
.badge.bg-info,
.badge.bg-primary,
.badge.bg-secondary,
.badge.bg-warning,
.badge.bg-light {
    font-weight: 600 !important;
}

/* Toasts, one colour pair per kind, each 8:1 or better. Bootstrap's own
   warning and info colours put white text on yellow (1.6:1) and cyan (1.9:1). */
.toast.toast-success {
    background-color: #0f5132;
    color: #ffffff;
}

.toast.toast-warning {
    background-color: #ffe69c;
    color: #212529;
}

.toast.toast-danger {
    background-color: #842029;
    color: #ffffff;
}

.toast.toast-info {
    background-color: #055160;
    color: #ffffff;
}

/* Where notify() puts its toasts (static/js/toast.js): bottom right, on top of
   the page. On a phone with the lesson sheet's tab bar (76px) they sit above it. */
.toast-stack {
    position: fixed;
    right: 0;
    bottom: 0;
    z-index: 1090;
    width: min(100%, 26rem);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: .5rem;
    pointer-events: none;
}

.toast-stack .toast-container {
    position: static;
    display: flex;
    flex-direction: column;
    gap: .5rem;
    width: 100%;
}

.toast-stack .toast {
    width: 100%;
    max-width: 100%;
    pointer-events: auto;
}

@media (max-width: 767.98px) {
    body.has-sheet-tabs .toast-stack {
        bottom: calc(76px + env(safe-area-inset-bottom, 0px));
    }
}

/* A small spinner in brand blue, or its on-dark tint on the dark theme. Inside
   a button it takes the button's own text colour. */
.spinner-border-sm {
    border-color: var(--base-primary-fg) !important;
    border-right-color: transparent !important;
}

.btn .spinner-border-sm {
    border-color: currentcolor !important;
    border-right-color: transparent !important;
}

/* Dialogs grow from 95% in 200ms and leave a little faster, and the phone menu
   opens in 200ms (Bootstrap's own are a 300ms drop and a 350ms slide). Here,
   not in style.css, so the pages that leave that file out get the same. */
.modal.fade .modal-dialog {
    transform: scale(.95);
    transition: transform .16s ease-in;
}

.modal.show .modal-dialog {
    transform: none;
    transition: transform .2s var(--base-ease);
}

.collapsing {
    transition: height .2s var(--base-ease);
}

/* No decorative motion for anyone who has asked their device for less. */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }

    .modal.fade .modal-dialog {
        transform: none;
    }
}

/* One page header for every admin page (templates/_page_header.html): title block left, actions right,
   and the actions wrap under the title on a phone. Colours follow the mode, and a brand-blue surface
   (System Monitor) turns the icon and text white. */
.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem 1rem;
    margin-bottom: 1.5rem;
}
.page-header__main {
    flex: 1 1 16rem;
    min-width: 0;
}
.page-header__title {
    margin: 0;
    font-size: var(--base-font-2xl);
    font-weight: 600;
    line-height: 1.25;
    overflow-wrap: anywhere;
}
.page-header__icon {
    margin-right: 0.5rem;
    color: var(--base-primary);
}
[data-bs-theme="dark"] .page-header__icon {
    color: var(--base-primary-on-dark);
}
.page-header__intro {
    margin: 0.25rem 0 0;
    color: var(--bs-secondary-color);
}
.page-header__actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.75rem;
    min-width: 0;
}
.surface-brand .page-header {
    margin-bottom: 0;
    color: #ffffff;
}
.surface-brand .page-header__icon,
.surface-brand .page-header__intro {
    color: inherit;
}

/* A stat tile reads label first (the h2) and shows the number above it. */
.stat-tile {
    display: flex;
    flex-direction: column;
    align-items: center;
}
.stat-tile > i { order: 0; }
.stat-tile__value { order: 1; }
.stat-tile__label { order: 2; }
